393 lines
15 KiB
Diff
393 lines
15 KiB
Diff
--- ../src_base/common/net/minecraft/src/World.java
|
|
+++ ../src_work/common/net/minecraft/src/World.java
|
|
@@ -10,8 +10,21 @@
|
|
import java.util.Random;
|
|
import java.util.Set;
|
|
|
|
+import net.minecraftforge.common.MinecraftForge;
|
|
+import net.minecraftforge.common.ForgeDirection;
|
|
+import net.minecraftforge.event.entity.EntityEvent;
|
|
+import net.minecraftforge.event.world.WorldEvent;
|
|
+import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
|
|
+
|
|
public abstract class World implements IBlockAccess
|
|
{
|
|
+ /**
|
|
+ * Used in the getEntitiesWithinAABB functions to expand the search area for entities.
|
|
+ * Modders should change this variable to a higher value if it is less then the radius
|
|
+ * of one of there entities.
|
|
+ */
|
|
+ public static double MAX_ENTITY_RADIUS = 2.0D;
|
|
+
|
|
/**
|
|
* boolean; if true updates scheduled by scheduleBlockUpdate happen immediately
|
|
*/
|
|
@@ -167,6 +180,7 @@
|
|
this.chunkProvider = this.createChunkProvider();
|
|
this.calculateInitialSkylight();
|
|
this.calculateInitialWeather();
|
|
+ MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(this));
|
|
}
|
|
|
|
public World(ISaveHandler par1ISaveHandler, String par2Str, WorldSettings par3WorldSettings, WorldProvider par4WorldProvider, Profiler par5Profiler)
|
|
@@ -213,6 +227,7 @@
|
|
|
|
this.calculateInitialSkylight();
|
|
this.calculateInitialWeather();
|
|
+ MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(this));
|
|
}
|
|
|
|
/**
|
|
@@ -269,7 +284,8 @@
|
|
*/
|
|
public boolean isAirBlock(int par1, int par2, int par3)
|
|
{
|
|
- return this.getBlockId(par1, par2, par3) == 0;
|
|
+ int id = getBlockId(par1, par2, par3);
|
|
+ return id == 0 || Block.blocksList[id] == null || Block.blocksList[id].isAirBlock(this, par1, par2, par3);
|
|
}
|
|
|
|
/**
|
|
@@ -278,7 +294,8 @@
|
|
public boolean blockHasTileEntity(int par1, int par2, int par3)
|
|
{
|
|
int var4 = this.getBlockId(par1, par2, par3);
|
|
- return Block.blocksList[var4] != null && Block.blocksList[var4].hasTileEntity();
|
|
+ int meta = this.getBlockMetadata(par1, par2, par3);
|
|
+ return Block.blocksList[var4] != null && Block.blocksList[var4].hasTileEntity(meta);
|
|
}
|
|
|
|
/**
|
|
@@ -1009,7 +1026,7 @@
|
|
int var12 = this.getBlockMetadata(var8, var9, var10);
|
|
Block var13 = Block.blocksList[var11];
|
|
|
|
- if ((!par4 || var13 == null || var13.getCollisionBoundingBoxFromPool(this, var8, var9, var10) != null) && var11 > 0 && var13.canCollideCheck(var12, par3))
|
|
+ if (var13 != null && (!par4 || var13 == null || var13.getCollisionBoundingBoxFromPool(this, var8, var9, var10) != null) && var11 > 0 && var13.canCollideCheck(var12, par3))
|
|
{
|
|
MovingObjectPosition var14 = var13.collisionRayTrace(this, var8, var9, var10, par1Vec3, par2Vec3);
|
|
|
|
@@ -1209,6 +1226,12 @@
|
|
*/
|
|
public void playSoundAtEntity(Entity par1Entity, String par2Str, float par3, float par4)
|
|
{
|
|
+ PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(par1Entity, par2Str, par3, par4);
|
|
+ if (MinecraftForge.EVENT_BUS.post(event))
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+ par2Str = event.name;
|
|
if (par1Entity != null && par2Str != null)
|
|
{
|
|
Iterator var5 = this.worldAccesses.iterator();
|
|
@@ -1887,7 +1910,7 @@
|
|
|
|
if (var8 != null)
|
|
{
|
|
- var8.removeChunkBlockTileEntity(var6.xCoord & 15, var6.yCoord, var6.zCoord & 15);
|
|
+ var8.cleanChunkBlockTileEntity(var6.xCoord & 15, var6.yCoord, var6.zCoord & 15);
|
|
}
|
|
}
|
|
}
|
|
@@ -1897,6 +1920,10 @@
|
|
|
|
if (!this.entityRemoval.isEmpty())
|
|
{
|
|
+ for (Object tile : entityRemoval)
|
|
+ {
|
|
+ ((TileEntity)tile).onChunkUnload();
|
|
+ }
|
|
this.loadedTileEntityList.removeAll(this.entityRemoval);
|
|
this.entityRemoval.clear();
|
|
}
|
|
@@ -1917,7 +1944,9 @@
|
|
{
|
|
this.loadedTileEntityList.add(var9);
|
|
}
|
|
-
|
|
+ }
|
|
+ else
|
|
+ {
|
|
if (this.chunkExists(var9.xCoord >> 4, var9.zCoord >> 4))
|
|
{
|
|
Chunk var10 = this.getChunkFromChunkCoords(var9.xCoord >> 4, var9.zCoord >> 4);
|
|
@@ -1927,8 +1956,6 @@
|
|
var10.setChunkBlockTileEntity(var9.xCoord & 15, var9.yCoord, var9.zCoord & 15, var9);
|
|
}
|
|
}
|
|
-
|
|
- this.markBlockNeedsUpdate(var9.xCoord, var9.yCoord, var9.zCoord);
|
|
}
|
|
}
|
|
|
|
@@ -1941,13 +1968,13 @@
|
|
|
|
public void addTileEntity(Collection par1Collection)
|
|
{
|
|
- if (this.scanningTileEntities)
|
|
- {
|
|
- this.addedTileEntityList.addAll(par1Collection);
|
|
- }
|
|
- else
|
|
- {
|
|
- this.loadedTileEntityList.addAll(par1Collection);
|
|
+ List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList;
|
|
+ for(Object entity : par1Collection)
|
|
+ {
|
|
+ if(((TileEntity)entity).canUpdate())
|
|
+ {
|
|
+ dest.add(entity);
|
|
+ }
|
|
}
|
|
}
|
|
|
|
@@ -1968,7 +1995,14 @@
|
|
int var3 = MathHelper.floor_double(par1Entity.posX);
|
|
int var4 = MathHelper.floor_double(par1Entity.posZ);
|
|
byte var5 = 32;
|
|
-
|
|
+ boolean canUpdate = !par2 || this.checkChunksExist(var3 - var5, 0, var4 - var5, var3 + var5, 0, var4 + var5);
|
|
+ if (!canUpdate)
|
|
+ {
|
|
+ EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(par1Entity);
|
|
+ MinecraftForge.EVENT_BUS.post(event);
|
|
+ canUpdate = event.canUpdate;
|
|
+ }
|
|
+ if (canUpdate)
|
|
if (!par2 || this.checkChunksExist(var3 - var5, 0, var4 - var5, var3 + var5, 0, var4 + var5))
|
|
{
|
|
par1Entity.lastTickPosX = par1Entity.posX;
|
|
@@ -2204,6 +2238,14 @@
|
|
{
|
|
return true;
|
|
}
|
|
+ else
|
|
+ {
|
|
+ Block block = Block.blocksList[var11];
|
|
+ if (block != null && block.isBlockBurning(this, var8, var9, var10))
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
@@ -2510,25 +2552,21 @@
|
|
*/
|
|
public void setBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity)
|
|
{
|
|
- if (par4TileEntity != null && !par4TileEntity.isInvalid())
|
|
- {
|
|
- if (this.scanningTileEntities)
|
|
- {
|
|
- par4TileEntity.xCoord = par1;
|
|
- par4TileEntity.yCoord = par2;
|
|
- par4TileEntity.zCoord = par3;
|
|
- this.addedTileEntityList.add(par4TileEntity);
|
|
- }
|
|
- else
|
|
- {
|
|
- this.loadedTileEntityList.add(par4TileEntity);
|
|
- Chunk var5 = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
|
|
-
|
|
- if (var5 != null)
|
|
- {
|
|
- var5.setChunkBlockTileEntity(par1 & 15, par2, par3 & 15, par4TileEntity);
|
|
- }
|
|
- }
|
|
+ if (par4TileEntity == null || par4TileEntity.isInvalid())
|
|
+ {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (par4TileEntity.canUpdate())
|
|
+ {
|
|
+ List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList;
|
|
+ dest.add(par4TileEntity);
|
|
+ }
|
|
+
|
|
+ Chunk chunk = getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
|
|
+ if (chunk != null)
|
|
+ {
|
|
+ chunk.setChunkBlockTileEntity(par1 & 15, par2, par3 & 15, par4TileEntity);
|
|
}
|
|
}
|
|
|
|
@@ -2537,27 +2575,10 @@
|
|
*/
|
|
public void removeBlockTileEntity(int par1, int par2, int par3)
|
|
{
|
|
- TileEntity var4 = this.getBlockTileEntity(par1, par2, par3);
|
|
-
|
|
- if (var4 != null && this.scanningTileEntities)
|
|
- {
|
|
- var4.invalidate();
|
|
- this.addedTileEntityList.remove(var4);
|
|
- }
|
|
- else
|
|
- {
|
|
- if (var4 != null)
|
|
- {
|
|
- this.addedTileEntityList.remove(var4);
|
|
- this.loadedTileEntityList.remove(var4);
|
|
- }
|
|
-
|
|
- Chunk var5 = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
|
|
-
|
|
- if (var5 != null)
|
|
- {
|
|
- var5.removeChunkBlockTileEntity(par1 & 15, par2, par3 & 15);
|
|
- }
|
|
+ Chunk chunk = getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
|
|
+ if (chunk != null)
|
|
+ {
|
|
+ chunk.removeChunkBlockTileEntity(par1 & 15, par2, par3 & 15);
|
|
}
|
|
}
|
|
|
|
@@ -2583,7 +2604,8 @@
|
|
*/
|
|
public boolean isBlockNormalCube(int par1, int par2, int par3)
|
|
{
|
|
- return Block.isNormalCube(this.getBlockId(par1, par2, par3));
|
|
+ Block block = Block.blocksList[getBlockId(par1, par2, par3)];
|
|
+ return block != null && block.isBlockNormalCube(this, par1, par2, par3);
|
|
}
|
|
|
|
/**
|
|
@@ -2591,8 +2613,7 @@
|
|
*/
|
|
public boolean doesBlockHaveSolidTopSurface(int par1, int par2, int par3)
|
|
{
|
|
- Block var4 = Block.blocksList[this.getBlockId(par1, par2, par3)];
|
|
- return var4 == null ? false : (var4.blockMaterial.isOpaque() && var4.renderAsNormalBlock() ? true : (var4 instanceof BlockStairs ? (this.getBlockMetadata(par1, par2, par3) & 4) == 4 : (var4 instanceof BlockHalfSlab ? (this.getBlockMetadata(par1, par2, par3) & 8) == 8 : false)));
|
|
+ return isBlockSolidOnSide(par1, par2, par3, ForgeDirection.UP);
|
|
}
|
|
|
|
/**
|
|
@@ -2608,7 +2629,7 @@
|
|
if (var5 != null && !var5.isEmpty())
|
|
{
|
|
Block var6 = Block.blocksList[this.getBlockId(par1, par2, par3)];
|
|
- return var6 == null ? false : var6.blockMaterial.isOpaque() && var6.renderAsNormalBlock();
|
|
+ return var6 == null ? false : isBlockNormalCube(par1, par2, par3);
|
|
}
|
|
else
|
|
{
|
|
@@ -3035,7 +3056,7 @@
|
|
|
|
private int computeBlockLightValue(int par1, int par2, int par3, int par4, int par5, int par6)
|
|
{
|
|
- int var7 = Block.lightValue[par5];
|
|
+ int var7 = (par5 == 0 || Block.blocksList[par5] == null ? 0 : Block.blocksList[par5].getLightValue(this, par2, par3, par4));
|
|
int var8 = this.getSavedLightValue(EnumSkyBlock.Block, par2 - 1, par3, par4) - par6;
|
|
int var9 = this.getSavedLightValue(EnumSkyBlock.Block, par2 + 1, par3, par4) - par6;
|
|
int var10 = this.getSavedLightValue(EnumSkyBlock.Block, par2, par3 - 1, par4) - par6;
|
|
@@ -3303,10 +3324,10 @@
|
|
public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB)
|
|
{
|
|
this.entitiesWithinAABBExcludingEntity.clear();
|
|
- int var3 = MathHelper.floor_double((par2AxisAlignedBB.minX - 2.0D) / 16.0D);
|
|
- int var4 = MathHelper.floor_double((par2AxisAlignedBB.maxX + 2.0D) / 16.0D);
|
|
- int var5 = MathHelper.floor_double((par2AxisAlignedBB.minZ - 2.0D) / 16.0D);
|
|
- int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxZ + 2.0D) / 16.0D);
|
|
+ int var3 = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var4 = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var5 = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D);
|
|
|
|
for (int var7 = var3; var7 <= var4; ++var7)
|
|
{
|
|
@@ -3327,10 +3348,10 @@
|
|
*/
|
|
public List getEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB)
|
|
{
|
|
- int var3 = MathHelper.floor_double((par2AxisAlignedBB.minX - 2.0D) / 16.0D);
|
|
- int var4 = MathHelper.floor_double((par2AxisAlignedBB.maxX + 2.0D) / 16.0D);
|
|
- int var5 = MathHelper.floor_double((par2AxisAlignedBB.minZ - 2.0D) / 16.0D);
|
|
- int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxZ + 2.0D) / 16.0D);
|
|
+ int var3 = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var4 = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var5 = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D);
|
|
+ int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D);
|
|
ArrayList var7 = new ArrayList();
|
|
|
|
for (int var8 = var3; var8 <= var4; ++var8)
|
|
@@ -3460,7 +3481,10 @@
|
|
{
|
|
var9 = null;
|
|
}
|
|
-
|
|
+ if (var9 != null && var9.isBlockReplaceable(this, par2, par3, par4))
|
|
+ {
|
|
+ var9 = null;
|
|
+ }
|
|
return par1 > 0 && var9 == null && var10.canPlaceBlockOnSide(this, par2, par3, par4, par6);
|
|
}
|
|
}
|
|
@@ -3958,4 +3982,65 @@
|
|
var7.destroyBlockPartially(par1, par2, par3, par4, par5);
|
|
}
|
|
}
|
|
+
|
|
+ /**
|
|
+ * Adds a single TileEntity to the world.
|
|
+ * @param entity The TileEntity to be added.
|
|
+ */
|
|
+ public void addTileEntity(TileEntity entity)
|
|
+ {
|
|
+ List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList;
|
|
+ if(entity.canUpdate())
|
|
+ {
|
|
+ dest.add(entity);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determine if the given block is considered solid on the
|
|
+ * specified side. Used by placement logic.
|
|
+ *
|
|
+ * @param X Block X Position
|
|
+ * @param Y Block Y Position
|
|
+ * @param Z Block Z Position
|
|
+ * @param side The Side in question
|
|
+ * @return True if the side is solid
|
|
+ */
|
|
+ public boolean isBlockSolidOnSide(int X, int Y, int Z, ForgeDirection side)
|
|
+ {
|
|
+ return isBlockSolidOnSide(X, Y, Z, side, false);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Determine if the given block is considered solid on the
|
|
+ * specified side. Used by placement logic.
|
|
+ *
|
|
+ * @param X Block X Position
|
|
+ * @param Y Block Y Position
|
|
+ * @param Z Block Z Position
|
|
+ * @param side The Side in question
|
|
+ * @param _default The defult to return if the block doesn't exist.
|
|
+ * @return True if the side is solid
|
|
+ */
|
|
+ public boolean isBlockSolidOnSide(int X, int Y, int Z, ForgeDirection side, boolean _default)
|
|
+ {
|
|
+ if (X < -30000000 || Z < -30000000 || X >= 30000000 || Z >= 30000000)
|
|
+ {
|
|
+ return _default;
|
|
+ }
|
|
+
|
|
+ Chunk var5 = this.chunkProvider.provideChunk(X >> 4, Z >> 4);
|
|
+ if (var5 == null || var5.isEmpty())
|
|
+ {
|
|
+ return _default;
|
|
+ }
|
|
+
|
|
+ Block block = Block.blocksList[getBlockId(X, Y, Z)];
|
|
+ if(block == null)
|
|
+ {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ return block.isBlockSolidOnSide(this, X, Y, Z, side);
|
|
+ }
|
|
}
|