From 7711505b927786fbd1fe47fd36fa206f52454e0e Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 13 Jun 2012 21:19:08 -0700 Subject: [PATCH] New onChunkUnload event for TileEntities, for psxlover. --- .../net/minecraft/src/TileEntity.java.patch | 7 ++- .../net/minecraft/src/World.java.patch | 55 +++++++++++-------- .../net/minecraft/src/TileEntity.java.patch | 7 ++- .../net/minecraft/src/World.java.patch | 55 +++++++++++-------- 4 files changed, 78 insertions(+), 46 deletions(-) diff --git a/forge/patches/minecraft/net/minecraft/src/TileEntity.java.patch b/forge/patches/minecraft/net/minecraft/src/TileEntity.java.patch index b403a1b25..631037287 100644 --- a/forge/patches/minecraft/net/minecraft/src/TileEntity.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/TileEntity.java.patch @@ -1,6 +1,6 @@ --- ../src_base/minecraft/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 -@@ -223,4 +223,24 @@ +@@ -223,4 +223,29 @@ public static void addNewTileEntityMapping(Class tileEntityClass, String id) { addMapping(tileEntityClass, id); } @@ -24,4 +24,9 @@ + * @param pkt The data packet + */ + public void onDataPacket(NetworkManager net, Packet132TileEntityData pkt){} ++ ++ /** ++ * Called when the chunk this TileEntity is on is Unloaded. ++ */ ++ public void onChunkUnload(){} } diff --git a/forge/patches/minecraft/net/minecraft/src/World.java.patch b/forge/patches/minecraft/net/minecraft/src/World.java.patch index 3d190cdd1..4791bdb87 100644 --- a/forge/patches/minecraft/net/minecraft/src/World.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/World.java.patch @@ -92,7 +92,18 @@ } } } -@@ -2098,18 +2119,18 @@ +@@ -2078,6 +2099,10 @@ + + if (!this.entityRemoval.isEmpty()) + { ++ for (Object tile : entityRemoval) ++ { ++ ((TileEntity)tile).onChunkUnload(); ++ } + this.loadedTileEntityList.removeAll(this.entityRemoval); + this.entityRemoval.clear(); + } +@@ -2098,18 +2123,18 @@ { this.loadedTileEntityList.add(var8); } @@ -115,18 +126,18 @@ } } -@@ -2122,13 +2143,13 @@ +@@ -2122,13 +2147,13 @@ public void addTileEntity(Collection par1Collection) { - if (this.scanningTileEntities) -- { -- this.addedTileEntityList.addAll(par1Collection); -- } -- else + List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList; + for(Object entity : par1Collection) { +- this.addedTileEntityList.addAll(par1Collection); +- } +- else +- { - this.loadedTileEntityList.addAll(par1Collection); + if(((TileEntity)entity).canUpdate()) + { @@ -135,7 +146,7 @@ } } -@@ -2150,7 +2171,7 @@ +@@ -2150,7 +2175,7 @@ int var4 = MathHelper.floor_double(par1Entity.posZ); byte var5 = 32; @@ -144,7 +155,7 @@ { par1Entity.lastTickPosX = par1Entity.posX; par1Entity.lastTickPosY = par1Entity.posY; -@@ -2327,7 +2348,14 @@ +@@ -2327,7 +2352,14 @@ if (var11 == Block.fire.blockID || var11 == Block.lavaMoving.blockID || var11 == Block.lavaStill.blockID) { return true; @@ -160,7 +171,7 @@ } } } -@@ -2631,25 +2659,19 @@ +@@ -2631,25 +2663,19 @@ */ public void setBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity) { @@ -198,21 +209,21 @@ } } -@@ -2658,27 +2680,10 @@ +@@ -2658,27 +2684,10 @@ */ public void removeBlockTileEntity(int par1, int par2, int par3) { - TileEntity var4 = this.getBlockTileEntity(par1, par2, par3); - - if (var4 != null && this.scanningTileEntities) -- { ++ Chunk chunk = getChunkFromChunkCoords(par1 >> 4, par3 >> 4); ++ if (chunk != null) + { - var4.invalidate(); - this.addedTileEntityList.remove(var4); - } - else -+ Chunk chunk = getChunkFromChunkCoords(par1 >> 4, par3 >> 4); -+ if (chunk != null) - { +- { - if (var4 != null) - { - this.addedTileEntityList.remove(var4); @@ -229,7 +240,7 @@ } } -@@ -2704,7 +2709,8 @@ +@@ -2704,7 +2713,8 @@ */ public boolean isBlockNormalCube(int par1, int par2, int par3) { @@ -239,7 +250,7 @@ } /** -@@ -2720,7 +2726,7 @@ +@@ -2720,7 +2730,7 @@ if (var5 != null && !var5.isEmpty()) { Block var6 = Block.blocksList[this.getBlockId(par1, par2, par3)]; @@ -248,7 +259,7 @@ } else { -@@ -2985,6 +2991,7 @@ +@@ -2985,6 +2995,7 @@ } } } @@ -256,7 +267,7 @@ Profiler.endSection(); -@@ -3308,7 +3315,7 @@ +@@ -3308,7 +3319,7 @@ private int computeBlockLightValue(int par1, int par2, int par3, int par4, int par5, int par6) { @@ -265,7 +276,7 @@ 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; -@@ -3668,10 +3675,10 @@ +@@ -3668,10 +3679,10 @@ public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) { this.entitiesWithinAABBExcludingEntity.clear(); @@ -280,7 +291,7 @@ for (int var7 = var3; var7 <= var4; ++var7) { -@@ -3692,10 +3699,10 @@ +@@ -3692,10 +3703,10 @@ */ public List getEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB) { @@ -295,7 +306,7 @@ ArrayList var7 = new ArrayList(); for (int var8 = var3; var8 <= var4; ++var8) -@@ -3840,7 +3847,10 @@ +@@ -3840,7 +3851,10 @@ { var8 = null; } @@ -307,7 +318,7 @@ return par1 > 0 && var8 == null && var9.canPlaceBlockOnSide(this, par2, par3, par4, par6); } } -@@ -4449,4 +4459,39 @@ +@@ -4449,4 +4463,39 @@ { return this.worldInfo.getTerrainType() == WorldType.FLAT ? 0.0D : 63.0D; } diff --git a/forge/patches/minecraft_server/net/minecraft/src/TileEntity.java.patch b/forge/patches/minecraft_server/net/minecraft/src/TileEntity.java.patch index 9252c1311..ea26b9c53 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/TileEntity.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/TileEntity.java.patch @@ -1,6 +1,6 @@ --- ../src_base/minecraft_server/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/TileEntity.java 0000-00-00 00:00:00.000000000 -0000 -@@ -207,4 +207,24 @@ +@@ -207,4 +207,29 @@ public static void addNewTileEntityMapping(Class tileEntityClass, String id) { addMapping(tileEntityClass, id); } @@ -24,4 +24,9 @@ + * @param pkt The data packet + */ + public void onDataPacket(NetworkManager net, Packet132TileEntityData pkt){} ++ ++ /** ++ * Called when the chunk this TileEntity is on is Unloaded. ++ */ ++ public void onChunkUnload(){} } diff --git a/forge/patches/minecraft_server/net/minecraft/src/World.java.patch b/forge/patches/minecraft_server/net/minecraft/src/World.java.patch index ed1b498a5..ae81b7b70 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/World.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/World.java.patch @@ -62,7 +62,18 @@ } } } -@@ -1634,14 +1646,16 @@ +@@ -1614,6 +1626,10 @@ + + if (!this.entityRemoval.isEmpty()) + { ++ for (Object tile : entityRemoval) ++ { ++ ((TileEntity)tile).onChunkUnload(); ++ } + this.loadedTileEntityList.removeAll(this.entityRemoval); + this.entityRemoval.clear(); + } +@@ -1634,14 +1650,16 @@ { this.loadedTileEntityList.add(var8); } @@ -81,18 +92,18 @@ } } -@@ -1658,13 +1672,13 @@ +@@ -1658,13 +1676,13 @@ public void addTileEntity(Collection par1Collection) { - if (this.scanningTileEntities) -- { -- this.addedTileEntityList.addAll(par1Collection); -- } -- else + List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList; + for(Object entity : par1Collection) { +- this.addedTileEntityList.addAll(par1Collection); +- } +- else +- { - this.loadedTileEntityList.addAll(par1Collection); + if(((TileEntity)entity).canUpdate()) + { @@ -101,7 +112,7 @@ } } -@@ -1686,7 +1700,7 @@ +@@ -1686,7 +1704,7 @@ int var4 = MathHelper.floor_double(par1Entity.posZ); byte var5 = 32; @@ -110,7 +121,7 @@ { par1Entity.lastTickPosX = par1Entity.posX; par1Entity.lastTickPosY = par1Entity.posY; -@@ -1909,6 +1923,13 @@ +@@ -1909,6 +1927,13 @@ if (var11 == Block.fire.blockID || var11 == Block.lavaMoving.blockID || var11 == Block.lavaStill.blockID) { return true; @@ -124,7 +135,7 @@ } } } -@@ -2192,25 +2213,21 @@ +@@ -2192,25 +2217,21 @@ */ public void setBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity) { @@ -163,21 +174,21 @@ } } -@@ -2219,27 +2236,10 @@ +@@ -2219,27 +2240,10 @@ */ public void removeBlockTileEntity(int par1, int par2, int par3) { - TileEntity var4 = this.getBlockTileEntity(par1, par2, par3); - - if (var4 != null && this.scanningTileEntities) -- { ++ Chunk var5 = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); ++ if (var5 != null) + { - var4.invalidate(); - this.addedTileEntityList.remove(var4); - } - else -+ Chunk var5 = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4); -+ if (var5 != null) - { +- { - if (var4 != null) - { - this.addedTileEntityList.remove(var4); @@ -194,7 +205,7 @@ } } -@@ -2265,7 +2265,8 @@ +@@ -2265,7 +2269,8 @@ */ public boolean isBlockNormalCube(int par1, int par2, int par3) { @@ -204,7 +215,7 @@ } /** -@@ -2281,7 +2282,7 @@ +@@ -2281,7 +2286,7 @@ if (var5 != null && !var5.isEmpty()) { Block var6 = Block.blocksList[this.getBlockId(par1, par2, par3)]; @@ -213,7 +224,7 @@ } else { -@@ -2540,6 +2541,7 @@ +@@ -2540,6 +2545,7 @@ } } } @@ -221,7 +232,7 @@ Profiler.endSection(); -@@ -2863,7 +2865,7 @@ +@@ -2863,7 +2869,7 @@ private int computeBlockLightValue(int par1, int par2, int par3, int par4, int par5, int par6) { @@ -230,7 +241,7 @@ 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; -@@ -3196,10 +3198,10 @@ +@@ -3196,10 +3202,10 @@ public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) { this.entitiesWithinAABBExcludingEntity.clear(); @@ -245,7 +256,7 @@ for (int var7 = var3; var7 <= var4; ++var7) { -@@ -3220,10 +3222,10 @@ +@@ -3220,10 +3226,10 @@ */ public List getEntitiesWithinAABB(Class par1Class, AxisAlignedBB par2AxisAlignedBB) { @@ -260,7 +271,7 @@ ArrayList var7 = new ArrayList(); for (int var8 = var3; var8 <= var4; ++var8) -@@ -3349,6 +3351,11 @@ +@@ -3349,6 +3355,11 @@ { var8 = null; } @@ -272,7 +283,7 @@ return par1 > 0 && var8 == null && var9.canPlaceBlockOnSide(this, par2, par3, par4, par6); } -@@ -3864,4 +3871,38 @@ +@@ -3864,4 +3875,38 @@ { return this.getChunkProvider().findClosestStructure(this, par1Str, par2, par3, par4); }