mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
Adds a chunk constructor with full block id range, that's metadata sensitive, has intelligent coord ordering, and which allows for generation at greater heights than 127.
452 lines
16 KiB
Diff
452 lines
16 KiB
Diff
--- ../src_base/common/net/minecraft/src/Chunk.java
|
|
+++ ../src_work/common/net/minecraft/src/Chunk.java
|
|
@@ -9,6 +9,10 @@
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
+
|
|
+import net.minecraftforge.common.MinecraftForge;
|
|
+import net.minecraftforge.event.entity.EntityEvent;
|
|
+import net.minecraftforge.event.world.ChunkEvent;
|
|
|
|
public class Chunk
|
|
{
|
|
@@ -124,7 +128,9 @@
|
|
{
|
|
for (int var8 = 0; var8 < var5; ++var8)
|
|
{
|
|
- byte var9 = par2ArrayOfByte[var6 << 11 | var7 << 7 | var8];
|
|
+ /* FORGE: The following change, a cast from unsigned byte to int,
|
|
+ * fixes a vanilla bug when generating new chunks that contain a block ID > 127 */
|
|
+ int var9 = par2ArrayOfByte[var6 << 11 | var7 << 7 | var8] & 0xFF;
|
|
|
|
if (var9 != 0)
|
|
{
|
|
@@ -143,6 +149,90 @@
|
|
}
|
|
|
|
/**
|
|
+ * Metadata sensitive Chunk constructor for use in new ChunkProviders that
|
|
+ * use metadata sensitive blocks during generation.
|
|
+ *
|
|
+ * @param world The world this chunk belongs to
|
|
+ * @param ids A ByteArray containing all the BlockID's to set this chunk to
|
|
+ * @param metadata A ByteArray containing all the metadata to set this chunk to
|
|
+ * @param chunkX The chunk's X position
|
|
+ * @param chunkZ The Chunk's Z position
|
|
+ */
|
|
+ public Chunk(World world, byte[] ids, byte[] metadata, int chunkX, int chunkZ)
|
|
+ {
|
|
+ this(world, chunkX, chunkZ);
|
|
+ int var5 = ids.length / 256;
|
|
+
|
|
+ for (int x = 0; x < 16; ++x)
|
|
+ {
|
|
+ for (int z = 0; z < 16; ++z)
|
|
+ {
|
|
+ for (int y = 0; y < var5; ++y)
|
|
+ {
|
|
+ int idx = x << 11 | z << 7 | y;
|
|
+ int id = ids[idx] & 0xFF;
|
|
+ int meta = metadata[idx];
|
|
+
|
|
+ if (id != 0)
|
|
+ {
|
|
+ int var10 = y >> 4;
|
|
+
|
|
+ if (this.storageArrays[var10] == null)
|
|
+ {
|
|
+ this.storageArrays[var10] = new ExtendedBlockStorage(var10 << 4);
|
|
+ }
|
|
+
|
|
+ this.storageArrays[var10].setExtBlockID(x, y & 15, z, id);
|
|
+ this.storageArrays[var10].setExtBlockMetadata(x, y & 15, z, meta);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * A Chunk Constructor which handles shorts to allow block ids > 256 (full 4096 range)
|
|
+ * Meta data sensitive
|
|
+ * NOTE: The x,y,z order of the array is different from the native Chunk constructor to allow for generation > y127
|
|
+ * NOTE: This is possibly more efficient than the standard constructor due to less memory skipping
|
|
+ *
|
|
+ * @param world The world this chunk belongs to
|
|
+ * @param ids A ShortArray containing all the BlockID's to set this chunk to (x is low order, z is mid, y is high)
|
|
+ * @param metadata A ByteArray containing all the metadata to set this chunk to
|
|
+ * @param chunkX The chunk's X position
|
|
+ * @param chunkZ The Chunk's Z position
|
|
+ */
|
|
+ public Chunk(World world, short[] ids, byte[] metadata, int chunkX, int chunkZ)
|
|
+ {
|
|
+ this(world, chunkX, chunkZ);
|
|
+ int max = ids.length / 256;
|
|
+
|
|
+ for (int y = 0; y < max; ++y)
|
|
+ {
|
|
+ for (int x = 0; x < 16; ++x)
|
|
+ {
|
|
+ for (int z = 0; z < 16; ++z)
|
|
+ {
|
|
+ int idx = y << 8 | z << 4 | x;
|
|
+ int id = ids[idx] & 0xFFFFFF;
|
|
+ int meta = metadata[idx];
|
|
+
|
|
+ if (id != 0) {
|
|
+ int storageBlock = y >> 4;
|
|
+
|
|
+ if (this.storageArrays[storageBlock] == null) {
|
|
+ this.storageArrays[storageBlock] = new ExtendedBlockStorage(storageBlock << 4);
|
|
+ }
|
|
+
|
|
+ this.storageArrays[storageBlock].setExtBlockID(x, y & 15, z, id);
|
|
+ this.storageArrays[storageBlock].setExtBlockMetadata(x, y & 15, z, meta);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
* Checks whether the chunk is at the X/Z location specified
|
|
*/
|
|
public boolean isAtLocation(int par1, int par2)
|
|
@@ -206,7 +296,7 @@
|
|
{
|
|
int var5 = this.getBlockID(var2, var4 - 1, var3);
|
|
|
|
- if (Block.lightOpacity[var5] == 0)
|
|
+ if (getBlockLightOpacity(var2, var4 - 1, var3) == 0)
|
|
{
|
|
--var4;
|
|
continue;
|
|
@@ -512,7 +602,10 @@
|
|
|
|
public int getBlockLightOpacity(int par1, int par2, int par3)
|
|
{
|
|
- return Block.lightOpacity[this.getBlockID(par1, par2, par3)];
|
|
+ int x = (xPosition << 4) + par1;
|
|
+ int z = (zPosition << 4) + par3;
|
|
+ Block block = Block.blocksList[getBlockID(par1, par2, par3)];
|
|
+ return (block == null ? 0 : block.getLightOpacity(worldObj, x, par2, z));
|
|
}
|
|
|
|
/**
|
|
@@ -520,7 +613,7 @@
|
|
*/
|
|
public int getBlockID(int par1, int par2, int par3)
|
|
{
|
|
- if (par2 >> 4 >= this.storageArrays.length)
|
|
+ if (par2 >> 4 >= this.storageArrays.length || par2 >> 4 < 0)
|
|
{
|
|
return 0;
|
|
}
|
|
@@ -536,7 +629,7 @@
|
|
*/
|
|
public int getBlockMetadata(int par1, int par2, int par3)
|
|
{
|
|
- if (par2 >> 4 >= this.storageArrays.length)
|
|
+ if (par2 >> 4 >= this.storageArrays.length || par2 >> 4 < 0)
|
|
{
|
|
return 0;
|
|
}
|
|
@@ -577,6 +670,11 @@
|
|
}
|
|
else
|
|
{
|
|
+ if (par2 >> 4 >= storageArrays.length || par2 >> 4 < 0)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
ExtendedBlockStorage var10 = this.storageArrays[par2 >> 4];
|
|
boolean var11 = false;
|
|
|
|
@@ -607,7 +705,7 @@
|
|
{
|
|
Block.blocksList[var8].breakBlock(this.worldObj, var12, par2, var13, var8, var9);
|
|
}
|
|
- else if (Block.blocksList[var8] instanceof BlockContainer && var8 != par4)
|
|
+ else if (Block.blocksList[var8] != null && Block.blocksList[var8].hasTileEntity(var9))
|
|
{
|
|
this.worldObj.removeBlockTileEntity(var12, par2, var13);
|
|
}
|
|
@@ -627,7 +725,7 @@
|
|
}
|
|
else
|
|
{
|
|
- if (Block.lightOpacity[par4 & 4095] > 0)
|
|
+ if (getBlockLightOpacity(par1, par2, par3) > 0)
|
|
{
|
|
if (par2 >= var7)
|
|
{
|
|
@@ -651,29 +749,21 @@
|
|
Block.blocksList[par4].onBlockAdded(this.worldObj, var12, par2, var13);
|
|
}
|
|
|
|
- if (Block.blocksList[par4] instanceof BlockContainer)
|
|
+ if (Block.blocksList[par4] != null && Block.blocksList[par4].hasTileEntity(par5))
|
|
{
|
|
var14 = this.getChunkBlockTileEntity(par1, par2, par3);
|
|
|
|
if (var14 == null)
|
|
{
|
|
- var14 = ((BlockContainer)Block.blocksList[par4]).createNewTileEntity(this.worldObj);
|
|
+ var14 = Block.blocksList[par4].createTileEntity(this.worldObj, par5);
|
|
this.worldObj.setBlockTileEntity(var12, par2, var13, var14);
|
|
}
|
|
|
|
if (var14 != null)
|
|
{
|
|
var14.updateContainingBlockInfo();
|
|
+ var14.blockMetadata = par5;
|
|
}
|
|
- }
|
|
- }
|
|
- else if (var8 > 0 && Block.blocksList[var8] instanceof BlockContainer)
|
|
- {
|
|
- var14 = this.getChunkBlockTileEntity(par1, par2, par3);
|
|
-
|
|
- if (var14 != null)
|
|
- {
|
|
- var14.updateContainingBlockInfo();
|
|
}
|
|
}
|
|
|
|
@@ -688,7 +778,7 @@
|
|
*/
|
|
public boolean setBlockMetadata(int par1, int par2, int par3, int par4)
|
|
{
|
|
- ExtendedBlockStorage var5 = this.storageArrays[par2 >> 4];
|
|
+ ExtendedBlockStorage var5 = (par2 >> 4 >= storageArrays.length || par2 >> 4 < 0 ? null : storageArrays[par2 >> 4]);
|
|
|
|
if (var5 == null)
|
|
{
|
|
@@ -708,7 +798,7 @@
|
|
var5.setExtBlockMetadata(par1, par2 & 15, par3, par4);
|
|
int var7 = var5.getExtBlockID(par1, par2 & 15, par3);
|
|
|
|
- if (var7 > 0 && Block.blocksList[var7] instanceof BlockContainer)
|
|
+ if (var7 > 0 && Block.blocksList[var7] != null && Block.blocksList[var7].hasTileEntity(par4))
|
|
{
|
|
TileEntity var8 = this.getChunkBlockTileEntity(par1, par2, par3);
|
|
|
|
@@ -729,7 +819,7 @@
|
|
*/
|
|
public int getSavedLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4)
|
|
{
|
|
- ExtendedBlockStorage var5 = this.storageArrays[par3 >> 4];
|
|
+ ExtendedBlockStorage var5 = (par3 >> 4 >= storageArrays.length || par3 >> 4 < 0 ? null : storageArrays[par3 >> 4]);
|
|
return var5 == null ? (this.canBlockSeeTheSky(par2, par3, par4) ? par1EnumSkyBlock.defaultLightValue : 0) : (par1EnumSkyBlock == EnumSkyBlock.Sky ? var5.getExtSkylightValue(par2, par3 & 15, par4) : (par1EnumSkyBlock == EnumSkyBlock.Block ? var5.getExtBlocklightValue(par2, par3 & 15, par4) : par1EnumSkyBlock.defaultLightValue));
|
|
}
|
|
|
|
@@ -739,6 +829,11 @@
|
|
*/
|
|
public void setLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4, int par5)
|
|
{
|
|
+ if (par3 >> 4 >= storageArrays.length || par3 >> 4 < 0)
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
ExtendedBlockStorage var6 = this.storageArrays[par3 >> 4];
|
|
|
|
if (var6 == null)
|
|
@@ -767,7 +862,7 @@
|
|
*/
|
|
public int getBlockLightValue(int par1, int par2, int par3, int par4)
|
|
{
|
|
- ExtendedBlockStorage var5 = this.storageArrays[par2 >> 4];
|
|
+ ExtendedBlockStorage var5 = (par2 >> 4 >= storageArrays.length || par2 >> 4 < 0 ? null : storageArrays[par2 >> 4]);
|
|
|
|
if (var5 == null)
|
|
{
|
|
@@ -820,7 +915,7 @@
|
|
{
|
|
var4 = this.entityLists.length - 1;
|
|
}
|
|
-
|
|
+ MinecraftForge.EVENT_BUS.post(new EntityEvent.EnteringChunk(par1Entity, this.xPosition, this.zPosition, par1Entity.chunkCoordX, par1Entity.chunkCoordZ));
|
|
par1Entity.addedToChunk = true;
|
|
par1Entity.chunkCoordX = this.xPosition;
|
|
par1Entity.chunkCoordY = var4;
|
|
@@ -870,33 +965,33 @@
|
|
ChunkPosition var4 = new ChunkPosition(par1, par2, par3);
|
|
TileEntity var5 = (TileEntity)this.chunkTileEntityMap.get(var4);
|
|
|
|
+ if (var5 != null && var5.isInvalid())
|
|
+ {
|
|
+ chunkTileEntityMap.remove(var4);
|
|
+ var5 = null;
|
|
+ }
|
|
+
|
|
if (var5 == null)
|
|
{
|
|
int var6 = this.getBlockID(par1, par2, par3);
|
|
|
|
- if (var6 <= 0 || !Block.blocksList[var6].hasTileEntity())
|
|
+ int meta = this.getBlockMetadata(par1, par2, par3);
|
|
+
|
|
+ if (var6 <= 0 || !Block.blocksList[var6].hasTileEntity(meta))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (var5 == null)
|
|
{
|
|
- var5 = ((BlockContainer)Block.blocksList[var6]).createNewTileEntity(this.worldObj);
|
|
+ var5 = Block.blocksList[var6].createTileEntity(this.worldObj, meta);
|
|
this.worldObj.setBlockTileEntity(this.xPosition * 16 + par1, par2, this.zPosition * 16 + par3, var5);
|
|
}
|
|
|
|
var5 = (TileEntity)this.chunkTileEntityMap.get(var4);
|
|
}
|
|
|
|
- if (var5 != null && var5.isInvalid())
|
|
- {
|
|
- this.chunkTileEntityMap.remove(var4);
|
|
- return null;
|
|
- }
|
|
- else
|
|
- {
|
|
- return var5;
|
|
- }
|
|
+ return var5;
|
|
}
|
|
|
|
/**
|
|
@@ -911,7 +1006,7 @@
|
|
|
|
if (this.isChunkLoaded)
|
|
{
|
|
- this.worldObj.loadedTileEntityList.add(par1TileEntity);
|
|
+ this.worldObj.addTileEntity(par1TileEntity);
|
|
}
|
|
}
|
|
|
|
@@ -926,8 +1021,14 @@
|
|
par4TileEntity.yCoord = par2;
|
|
par4TileEntity.zCoord = this.zPosition * 16 + par3;
|
|
|
|
- if (this.getBlockID(par1, par2, par3) != 0 && Block.blocksList[this.getBlockID(par1, par2, par3)] instanceof BlockContainer)
|
|
- {
|
|
+ Block block = Block.blocksList[getBlockID(par1, par2, par3)];
|
|
+ if (block != null && block.hasTileEntity(getBlockMetadata(par1, par2, par3)))
|
|
+ {
|
|
+ TileEntity old = (TileEntity)chunkTileEntityMap.get(var5);
|
|
+ if (old != null)
|
|
+ {
|
|
+ old.invalidate();
|
|
+ }
|
|
par4TileEntity.validate();
|
|
this.chunkTileEntityMap.put(var5, par4TileEntity);
|
|
}
|
|
@@ -963,6 +1064,7 @@
|
|
{
|
|
this.worldObj.addLoadedEntities(this.entityLists[var1]);
|
|
}
|
|
+ MinecraftForge.EVENT_BUS.post(new ChunkEvent.Load(this));
|
|
}
|
|
|
|
/**
|
|
@@ -983,6 +1085,7 @@
|
|
{
|
|
this.worldObj.unloadEntities(this.entityLists[var3]);
|
|
}
|
|
+ MinecraftForge.EVENT_BUS.post(new ChunkEvent.Unload(this));
|
|
}
|
|
|
|
/**
|
|
@@ -999,8 +1102,8 @@
|
|
*/
|
|
public void getEntitiesWithinAABBForEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB, List par3List)
|
|
{
|
|
- int var4 = MathHelper.floor_double((par2AxisAlignedBB.minY - 2.0D) / 16.0D);
|
|
- int var5 = MathHelper.floor_double((par2AxisAlignedBB.maxY + 2.0D) / 16.0D);
|
|
+ int var4 = MathHelper.floor_double((par2AxisAlignedBB.minY - World.MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var5 = MathHelper.floor_double((par2AxisAlignedBB.maxY + World.MAX_ENTITY_RADIUS) / 16.0D);
|
|
|
|
if (var4 < 0)
|
|
{
|
|
@@ -1047,8 +1150,8 @@
|
|
*/
|
|
public void getEntitiesOfTypeWithinAAAB(Class par1Class, AxisAlignedBB par2AxisAlignedBB, List par3List, IEntitySelector par4IEntitySelector)
|
|
{
|
|
- int var5 = MathHelper.floor_double((par2AxisAlignedBB.minY - 2.0D) / 16.0D);
|
|
- int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxY + 2.0D) / 16.0D);
|
|
+ int var5 = MathHelper.floor_double((par2AxisAlignedBB.minY - World.MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxY + World.MAX_ENTITY_RADIUS) / 16.0D);
|
|
|
|
if (var5 < 0)
|
|
{
|
|
@@ -1231,6 +1334,15 @@
|
|
*/
|
|
public void fillChunk(byte[] par1ArrayOfByte, int par2, int par3, boolean par4)
|
|
{
|
|
+ Iterator iterator = chunkTileEntityMap.values().iterator();
|
|
+ while(iterator.hasNext())
|
|
+ {
|
|
+ TileEntity tileEntity = (TileEntity)iterator.next();
|
|
+ tileEntity.updateContainingBlockInfo();
|
|
+ tileEntity.getBlockMetadata();
|
|
+ tileEntity.getBlockType();
|
|
+ }
|
|
+
|
|
int var5 = 0;
|
|
int var6;
|
|
|
|
@@ -1327,12 +1439,26 @@
|
|
}
|
|
|
|
this.generateHeightMap();
|
|
- Iterator var10 = this.chunkTileEntityMap.values().iterator();
|
|
-
|
|
- while (var10.hasNext())
|
|
- {
|
|
- TileEntity var9 = (TileEntity)var10.next();
|
|
- var9.updateContainingBlockInfo();
|
|
+
|
|
+ List<TileEntity> invalidList = new ArrayList<TileEntity>();
|
|
+ iterator = chunkTileEntityMap.values().iterator();
|
|
+ while (iterator.hasNext())
|
|
+ {
|
|
+ TileEntity tileEntity = (TileEntity)iterator.next();
|
|
+ int x = tileEntity.xCoord & 15;
|
|
+ int y = tileEntity.yCoord;
|
|
+ int z = tileEntity.zCoord & 15;
|
|
+ Block block = tileEntity.getBlockType();
|
|
+ if (block == null || block.blockID != getBlockID(x, y, z) || tileEntity.getBlockMetadata() != getBlockMetadata(x, y, z))
|
|
+ {
|
|
+ invalidList.add(tileEntity);
|
|
+ }
|
|
+ tileEntity.updateContainingBlockInfo();
|
|
+ }
|
|
+
|
|
+ for (TileEntity tileEntity : invalidList)
|
|
+ {
|
|
+ tileEntity.invalidate();
|
|
}
|
|
}
|
|
|
|
@@ -1441,4 +1567,18 @@
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+ /** FORGE: Used to remove only invalid TileEntities */
|
|
+ public void cleanChunkBlockTileEntity(int x, int y, int z)
|
|
+ {
|
|
+ ChunkPosition position = new ChunkPosition(x, y, z);
|
|
+ if (isChunkLoaded)
|
|
+ {
|
|
+ TileEntity entity = (TileEntity)chunkTileEntityMap.get(position);
|
|
+ if (entity != null && entity.isInvalid())
|
|
+ {
|
|
+ chunkTileEntityMap.remove(position);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
}
|