Add in an "EntityEvent.EnteringChunk" event. Useful for your entity chunkloading stuff.

This commit is contained in:
Christian committed 2012-09-26 08:52:40 -04:00
1 parent 1df9b144cd
commit 5fb999fa22
2 files changed
+57 -30

No files matched your search

@@ -6,12 +6,12 @@ import net.minecraftforge.event.Event;
public class EntityEvent extends Event
{
public final Entity entity;
public EntityEvent(Entity entity)
{
this.entity = entity;
}
public static class CanUpdate extends EntityEvent
{
public boolean canUpdate = false;
@@ -20,4 +20,21 @@ public class EntityEvent extends Event
super(entity);
}
}
public static class EnteringChunk extends EntityEvent
{
public int newChunkX;
public int newChunkZ;
public int oldChunkX;
public int oldChunkZ;
public EnteringChunk(Entity entity, int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ)
{
super(entity);
this.newChunkX = newChunkX;
this.newChunkZ = newChunkZ;
this.oldChunkX = oldChunkX;
this.oldChunkZ = oldChunkZ;
}
}
}
@@ -1,16 +1,17 @@
--- ../src_base/common/net/minecraft/src/Chunk.java
+++ ../src_work/common/net/minecraft/src/Chunk.java
@@ -9,6 +9,9 @@
@@ -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
{
@@ -122,7 +125,9 @@
@@ -122,7 +126,9 @@
{
for (int var8 = 0; var8 < var5; ++var8)
{
@@ -21,7 +22,7 @@
if (var9 != 0)
{
@@ -134,6 +139,48 @@
@@ -134,6 +140,48 @@
}
this.storageArrays[var10].setExtBlockID(var6, var8 & 15, var7, var9);
@@ -32,11 +33,11 @@
+ }
+
+ /**
+ * Metadata sensitive Chunk constructor for use in new ChunkProviders that
+ * 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 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
@@ -70,7 +71,7 @@
}
}
}
@@ -507,7 +554,7 @@
@@ -507,7 +555,7 @@
*/
public int getBlockID(int par1, int par2, int par3)
{
@@ -79,7 +80,7 @@
{
return 0;
}
@@ -523,7 +570,7 @@
@@ -523,7 +571,7 @@
*/
public int getBlockMetadata(int par1, int par2, int par3)
{
@@ -88,7 +89,7 @@
{
return 0;
}
@@ -564,6 +611,11 @@
@@ -564,6 +612,11 @@
}
else
{
@@ -100,7 +101,7 @@
ExtendedBlockStorage var10 = this.storageArrays[par2 >> 4];
boolean var11 = false;
@@ -594,7 +646,7 @@
@@ -594,7 +647,7 @@
{
Block.blocksList[var8].breakBlock(this.worldObj, var12, par2, var13, var8, var9);
}
@@ -109,7 +110,7 @@
{
this.worldObj.removeBlockTileEntity(var12, par2, var13);
}
@@ -638,29 +690,21 @@
@@ -638,29 +691,21 @@
Block.blocksList[par4].onBlockAdded(this.worldObj, var12, par2, var13);
}
@@ -142,7 +143,7 @@
}
}
@@ -675,7 +719,7 @@
@@ -675,7 +720,7 @@
*/
public boolean setBlockMetadata(int par1, int par2, int par3, int par4)
{
@@ -151,7 +152,7 @@
if (var5 == null)
{
@@ -695,7 +739,7 @@
@@ -695,7 +740,7 @@
var5.setExtBlockMetadata(par1, par2 & 15, par3, par4);
int var7 = var5.getExtBlockID(par1, par2 & 15, par3);
@@ -160,7 +161,7 @@
{
TileEntity var8 = this.getChunkBlockTileEntity(par1, par2, par3);
@@ -716,7 +760,7 @@
@@ -716,7 +761,7 @@
*/
public int getSavedLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4)
{
@@ -169,7 +170,7 @@
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));
}
@@ -726,6 +770,11 @@
@@ -726,6 +771,11 @@
*/
public void setLightValue(EnumSkyBlock par1EnumSkyBlock, int par2, int par3, int par4, int par5)
{
@@ -181,7 +182,7 @@
ExtendedBlockStorage var6 = this.storageArrays[par3 >> 4];
if (var6 == null)
@@ -754,7 +803,7 @@
@@ -754,7 +804,7 @@
*/
public int getBlockLightValue(int par1, int par2, int par3, int par4)
{
@@ -190,7 +191,16 @@
if (var5 == null)
{
@@ -857,33 +906,33 @@
@@ -807,7 +857,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;
@@ -857,33 +907,33 @@
ChunkPosition var4 = new ChunkPosition(par1, par2, par3);
TileEntity var5 = (TileEntity)this.chunkTileEntityMap.get(var4);
@@ -235,7 +245,7 @@
}
/**
@@ -898,7 +947,7 @@
@@ -898,7 +948,7 @@
if (this.isChunkLoaded)
{
@@ -244,7 +254,7 @@
}
}
@@ -913,8 +962,14 @@
@@ -913,8 +963,14 @@
par4TileEntity.yCoord = par2;
par4TileEntity.zCoord = this.zPosition * 16 + par3;
@@ -261,7 +271,7 @@
par4TileEntity.validate();
this.chunkTileEntityMap.put(var5, par4TileEntity);
}
@@ -953,6 +1008,7 @@
@@ -953,6 +1009,7 @@
List var4 = var1[var3];
this.worldObj.addLoadedEntities(var4);
}
@@ -269,7 +279,7 @@
}
/**
@@ -977,6 +1033,7 @@
@@ -977,6 +1034,7 @@
List var4 = var5[var3];
this.worldObj.unloadEntities(var4);
}
@@ -277,7 +287,7 @@
}
/**
@@ -993,8 +1050,8 @@
@@ -993,8 +1051,8 @@
*/
public void getEntitiesWithinAABBForEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB, List par3List)
{
@@ -288,7 +298,7 @@
if (var4 < 0)
{
@@ -1042,8 +1099,8 @@
@@ -1042,8 +1100,8 @@
*/
public void getEntitiesOfTypeWithinAAAB(Class par1Class, AxisAlignedBB par2AxisAlignedBB, List par3List)
{
@@ -299,7 +309,7 @@
if (var4 < 0)
{
@@ -1227,6 +1284,15 @@
@@ -1227,6 +1285,15 @@
*/
public void fillChunk(byte[] par1ArrayOfByte, int par2, int par3, boolean par4)
{
@@ -315,7 +325,7 @@
int var5 = 0;
int var6;
@@ -1323,12 +1389,26 @@
@@ -1323,12 +1390,26 @@
}
this.generateHeightMap();
@@ -341,20 +351,20 @@
+ }
+ tileEntity.updateContainingBlockInfo();
+ }
+
+
+ for (TileEntity tileEntity : invalidList)
+ {
+ tileEntity.invalidate();
}
}
@@ -1437,4 +1517,18 @@
@@ -1437,4 +1518,18 @@
}
}
}
+
+ /** FORGE: Used to remove only invalid TileEntities */
+ public void cleanChunkBlockTileEntity(int x, int y, int z)
+ public void cleanChunkBlockTileEntity(int x, int y, int z)
+ {
+ ChunkPosition position = new ChunkPosition(x, y, z);
+ if (isChunkLoaded)