From 497d437a3744bbd2b2b44c41bbbbeaca8e9142f4 Mon Sep 17 00:00:00 2001 From: Prototik Date: Sat, 29 Aug 2015 18:21:31 +0700 Subject: [PATCH] Add list wrapper for tileentities --- patches/net/minecraft/world/World.java.patch | 130 ++++++++++-------- .../cauldron/CauldronHooks.java | 5 +- .../cauldron/command/CauldronCommand.java | 2 +- .../java/org/spigotmc/WatchdogThread.java | 4 +- 4 files changed, 81 insertions(+), 60 deletions(-) diff --git a/patches/net/minecraft/world/World.java.patch b/patches/net/minecraft/world/World.java.patch index fb6fac9..ca19a50 100644 --- a/patches/net/minecraft/world/World.java.patch +++ b/patches/net/minecraft/world/World.java.patch @@ -98,7 +98,7 @@ public abstract class World implements IBlockAccess { /** -@@ -82,16 +137,16 @@ +@@ -82,16 +137,17 @@ public final MapStorage perWorldStorage; public boolean scheduledUpdatesAreImmediate; @@ -110,7 +110,8 @@ + public Queue loadedEntityList_KC = new ConcurrentLinkedQueue(); // KCauldron + public List loadedEntityList = new kcauldron.wrapper.QueueToList(loadedEntityList_KC); // KCauldron + public List unloadedEntityList = com.google.common.collect.ImmutableList.of(); // KCauldron -+ public List loadedTileEntityList = new LinkedList(); // KCauldron ++ public Queue loadedTileEntityList_KC = new ConcurrentLinkedQueue(); // KCauldron ++ public List loadedTileEntityList = new kcauldron.wrapper.QueueToList(loadedTileEntityList_KC); // KCauldron + private List addedTileEntityList = new ArrayList(); // KCauldron + public List field_147483_b = com.google.common.collect.ImmutableList.of(); // KCauldron public List playerEntities = new ArrayList(); @@ -121,7 +122,7 @@ protected final int DIST_HASH_MAGIC = 1013904223; public float prevRainingStrength; public float rainingStrength; -@@ -100,26 +155,88 @@ +@@ -100,26 +156,88 @@ public int lastLightningBolt; public EnumDifficulty difficultySetting; public Random rand = new Random(); @@ -217,7 +218,7 @@ private static final String __OBFID = "CL_00000140"; public boolean restoringBlockSnapshots = false; public boolean captureBlockSnapshots = false; -@@ -166,6 +283,27 @@ +@@ -166,6 +284,27 @@ return this.provider.worldChunkMgr; } @@ -245,7 +246,7 @@ @SideOnly(Side.CLIENT) public World(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_) { -@@ -179,6 +317,12 @@ +@@ -179,6 +318,12 @@ this.worldInfo = new WorldInfo(p_i45368_4_, p_i45368_2_); this.provider = p_i45368_3_; perWorldStorage = new MapStorage((ISaveHandler)null); @@ -258,7 +259,7 @@ } // Broken up so that the WorldClient gets the chance to set the mapstorage object before the dimension initializes -@@ -207,8 +351,175 @@ +@@ -207,8 +352,175 @@ this.calculateInitialWeather(); } @@ -434,7 +435,7 @@ this.ambientTickCountdown = this.rand.nextInt(12000); this.spawnHostileMobs = true; this.spawnPeacefulMobs = true; -@@ -216,7 +527,6 @@ +@@ -216,7 +528,6 @@ this.lightUpdateBlockList = new int[32768]; this.saveHandler = p_i45369_1_; this.theProfiler = p_i45369_5_; @@ -442,7 +443,7 @@ this.worldInfo = p_i45369_1_.loadWorldInfo(); if (p_i45369_4_ != null) -@@ -235,13 +545,26 @@ +@@ -235,13 +546,26 @@ if (this.worldInfo == null) { this.worldInfo = new WorldInfo(p_i45369_3_, p_i45369_2_); @@ -469,7 +470,7 @@ this.chunkProvider = this.createChunkProvider(); if (this instanceof WorldServer) -@@ -294,6 +617,7 @@ +@@ -294,6 +618,7 @@ this.calculateInitialSkylight(); this.calculateInitialWeather(); } @@ -477,7 +478,7 @@ private static MapStorage s_mapStorage; private static ISaveHandler s_savehandler; -@@ -336,6 +660,18 @@ +@@ -336,6 +661,18 @@ public Block getBlock(int p_147439_1_, int p_147439_2_, int p_147439_3_) { @@ -496,7 +497,7 @@ if (p_147439_1_ >= -30000000 && p_147439_3_ >= -30000000 && p_147439_1_ < 30000000 && p_147439_3_ < 30000000 && p_147439_2_ >= 0 && p_147439_2_ < 256) { Chunk chunk = null; -@@ -404,7 +740,7 @@ +@@ -404,7 +741,7 @@ } } @@ -505,7 +506,7 @@ { return this.chunkProvider.chunkExists(p_72916_1_, p_72916_2_); } -@@ -421,6 +757,27 @@ +@@ -421,6 +758,27 @@ public boolean setBlock(int p_147465_1_, int p_147465_2_, int p_147465_3_, Block p_147465_4_, int p_147465_5_, int p_147465_6_) { @@ -533,7 +534,7 @@ if (p_147465_1_ >= -30000000 && p_147465_3_ >= -30000000 && p_147465_1_ < 30000000 && p_147465_3_ < 30000000) { if (p_147465_2_ < 0) -@@ -448,8 +805,22 @@ +@@ -448,8 +806,22 @@ this.capturedBlockSnapshots.add(blockSnapshot); } @@ -556,7 +557,7 @@ if (!flag && blockSnapshot != null) { this.capturedBlockSnapshots.remove(blockSnapshot); -@@ -460,6 +831,7 @@ +@@ -460,6 +832,7 @@ this.func_147451_t(p_147465_1_, p_147465_2_, p_147465_3_); this.theProfiler.endSection(); @@ -564,7 +565,7 @@ if (flag && blockSnapshot == null) // Don't notify clients or update physics while capturing blockstates { // Modularize client and physic updates -@@ -496,6 +868,19 @@ +@@ -496,6 +869,19 @@ public int getBlockMetadata(int p_72805_1_, int p_72805_2_, int p_72805_3_) { @@ -584,7 +585,7 @@ if (p_72805_1_ >= -30000000 && p_72805_3_ >= -30000000 && p_72805_1_ < 30000000 && p_72805_3_ < 30000000) { if (p_72805_2_ < 0) -@@ -511,7 +896,7 @@ +@@ -511,7 +897,7 @@ Chunk chunk = this.getChunkFromChunkCoords(p_72805_1_ >> 4, p_72805_3_ >> 4); p_72805_1_ &= 15; p_72805_3_ &= 15; @@ -593,7 +594,7 @@ } } else -@@ -610,6 +995,12 @@ +@@ -610,6 +996,12 @@ public void notifyBlockChange(int p_147444_1_, int p_147444_2_, int p_147444_3_, Block p_147444_4_) { @@ -606,7 +607,7 @@ this.notifyBlocksOfNeighborChange(p_147444_1_, p_147444_2_, p_147444_3_, p_147444_4_); } -@@ -694,6 +1085,21 @@ +@@ -694,6 +1086,21 @@ try { @@ -628,7 +629,7 @@ block.onNeighborBlockChange(this, p_147460_1_, p_147460_2_, p_147460_3_, p_147460_4_); } catch (Throwable throwable1) -@@ -1307,6 +1713,13 @@ +@@ -1307,6 +1714,13 @@ public boolean spawnEntityInWorld(Entity p_72838_1_) { @@ -642,7 +643,7 @@ // do not drop any items while restoring blocksnapshots. Prevents dupes if (!this.isRemote && (p_72838_1_ == null || (p_72838_1_ instanceof net.minecraft.entity.item.EntityItem && this.restoringBlockSnapshots))) return false; -@@ -1319,23 +1732,99 @@ +@@ -1319,23 +1733,99 @@ flag = true; } @@ -745,7 +746,7 @@ return true; } } -@@ -1346,6 +1835,8 @@ +@@ -1346,6 +1836,8 @@ { ((IWorldAccess)this.worldAccesses.get(i)).onEntityCreate(p_72923_1_); } @@ -754,7 +755,7 @@ } public void onEntityRemoved(Entity p_72847_1_) -@@ -1354,6 +1845,8 @@ +@@ -1354,6 +1846,8 @@ { ((IWorldAccess)this.worldAccesses.get(i)).onEntityDestroy(p_72847_1_); } @@ -763,7 +764,7 @@ } public void removeEntity(Entity p_72900_1_) -@@ -1396,7 +1889,7 @@ +@@ -1396,7 +1890,7 @@ this.getChunkFromChunkCoords(i, j).removeEntity(p_72973_1_); } @@ -772,7 +773,7 @@ this.onEntityRemoved(p_72973_1_); } -@@ -1408,40 +1901,58 @@ +@@ -1408,40 +1902,58 @@ public List getCollidingBoundingBoxes(Entity p_72945_1_, AxisAlignedBB p_72945_2_) { this.collidingBoundingBoxes.clear(); @@ -845,7 +846,7 @@ for (int j2 = 0; j2 < list.size(); ++j2) { -@@ -1797,11 +2308,22 @@ +@@ -1797,11 +2309,22 @@ Entity entity; CrashReport crashreport; CrashReportCategory crashreportcategory; @@ -868,7 +869,7 @@ try { ++entity.ticksExisted; -@@ -1838,35 +2360,29 @@ +@@ -1838,35 +2361,29 @@ } } @@ -924,7 +925,7 @@ if (entity.ridingEntity != null) { if (!entity.ridingEntity.isDead && entity.ridingEntity.riddenByEntity == entity) -@@ -1884,7 +2400,9 @@ +@@ -1884,7 +2401,9 @@ { try { @@ -934,7 +935,7 @@ } catch (Throwable throwable1) { -@@ -1909,37 +2427,68 @@ +@@ -1909,37 +2428,68 @@ if (entity.isDead) { @@ -963,10 +964,10 @@ - while (iterator.hasNext()) - { - TileEntity tileentity = (TileEntity)iterator.next(); -+ Iterator tileEntityIterator = loadedTileEntityList.iterator(); ++ Iterator tileEntityIterator = loadedTileEntityList_KC.iterator(); + int tilesThisCycle = 0; + for (tileLimiter.initTick(); tileEntityIterator.hasNext() && (tilesThisCycle % 10 == 0 || tileLimiter.shouldContinue()); tileTickPosition++, tilesThisCycle++) { -+ tileTickPosition = (tileTickPosition < loadedTileEntityList.size()) ? tileTickPosition : 0; ++ tileTickPosition = (tileTickPosition < loadedTileEntityList_KC.size()) ? tileTickPosition : 0; + TileEntity tileentity = tileEntityIterator.next(); + + // Spigot start @@ -1018,7 +1019,7 @@ crashreport = CrashReport.makeCrashReport(throwable, "Ticking block entity"); crashreportcategory = crashreport.makeCategory("Block entity being ticked"); tileentity.func_145828_a(crashreportcategory); -@@ -1955,23 +2504,13 @@ +@@ -1955,23 +2505,13 @@ } } } @@ -1047,7 +1048,7 @@ if (!this.field_147483_b.isEmpty()) { for (Object tile : field_147483_b) -@@ -1981,6 +2520,7 @@ +@@ -1981,6 +2521,7 @@ this.loadedTileEntityList.removeAll(this.field_147483_b); this.field_147483_b.clear(); } @@ -1055,7 +1056,19 @@ this.field_147481_N = false; -@@ -2016,17 +2556,23 @@ +@@ -1994,9 +2535,9 @@ + + if (!tileentity1.isInvalid()) + { +- if (!this.loadedTileEntityList.contains(tileentity1)) ++ if (!this.loadedTileEntityList_KC.contains(tileentity1)) + { +- this.loadedTileEntityList.add(tileentity1); ++ this.loadedTileEntityList_KC.add(tileentity1); + } + } + else +@@ -2016,17 +2557,23 @@ this.addedTileEntityList.clear(); } @@ -1069,7 +1082,7 @@ - List dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; - for(TileEntity entity : (Collection)p_147448_1_) + // Cauldron start -+ Collection dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; // List -> Collection for CB loadedTileEntityList type change ++ Collection dest = field_147481_N ? addedTileEntityList : loadedTileEntityList_KC; // List -> Collection for CB loadedTileEntityList type change + for(Object entity : p_147448_1_) { - if(entity.canUpdate()) dest.add(entity); @@ -1082,7 +1095,7 @@ } public void updateEntity(Entity p_72870_1_) -@@ -2036,21 +2582,33 @@ +@@ -2036,21 +2583,33 @@ public void updateEntityWithOptionalForce(Entity p_72866_1_, boolean p_72866_2_) { @@ -1117,7 +1130,7 @@ p_72866_1_.lastTickPosX = p_72866_1_.posX; p_72866_1_.lastTickPosY = p_72866_1_.posY; p_72866_1_.lastTickPosZ = p_72866_1_.posZ; -@@ -2134,6 +2692,7 @@ +@@ -2134,6 +2693,7 @@ p_72866_1_.riddenByEntity = null; } } @@ -1125,7 +1138,7 @@ } } -@@ -2500,7 +3059,7 @@ +@@ -2500,7 +3060,7 @@ @SideOnly(Side.CLIENT) public String getDebugLoadedEntities() { @@ -1134,7 +1147,7 @@ } @SideOnly(Side.CLIENT) -@@ -2570,7 +3129,7 @@ +@@ -2570,7 +3130,7 @@ return; } @@ -1143,7 +1156,16 @@ { if (this.field_147481_N) { -@@ -2612,7 +3171,7 @@ +@@ -2591,7 +3151,7 @@ + } + else + { +- this.loadedTileEntityList.add(p_147455_4_); ++ this.loadedTileEntityList_KC.add(p_147455_4_); + } + } + Chunk chunk = this.getChunkFromChunkCoords(p_147455_1_ >> 4, p_147455_3_ >> 4); +@@ -2612,7 +3172,7 @@ public void func_147457_a(TileEntity p_147457_1_) { @@ -1152,7 +1174,7 @@ } public boolean func_147469_q(int p_147469_1_, int p_147469_2_, int p_147469_3_) -@@ -2718,7 +3277,15 @@ +@@ -2718,7 +3278,15 @@ if (i <= 0) { @@ -1169,7 +1191,7 @@ } } -@@ -2754,7 +3321,15 @@ +@@ -2754,7 +3322,15 @@ if (j <= 0) { @@ -1186,7 +1208,7 @@ } } -@@ -2777,8 +3352,41 @@ +@@ -2777,8 +3353,41 @@ protected void setActivePlayerChunksAndCheckLight() { this.activeChunkSet.clear(); @@ -1229,7 +1251,7 @@ int i; EntityPlayer entityplayer; int j; -@@ -2788,17 +3396,28 @@ +@@ -2788,17 +3397,28 @@ for (i = 0; i < this.playerEntities.size(); ++i) { entityplayer = (EntityPlayer)this.playerEntities.get(i); @@ -1264,7 +1286,7 @@ } this.theProfiler.endSection(); -@@ -2810,7 +3429,7 @@ +@@ -2810,7 +3430,7 @@ this.theProfiler.startSection("playerCheckLight"); @@ -1273,7 +1295,7 @@ { i = this.rand.nextInt(this.playerEntities.size()); entityplayer = (EntityPlayer)this.playerEntities.get(i); -@@ -3280,12 +3899,23 @@ +@@ -3280,12 +3900,23 @@ { int i = 0; @@ -1300,7 +1322,7 @@ ++i; } } -@@ -3298,9 +3928,10 @@ +@@ -3298,9 +3929,10 @@ for (int i = 0; i < p_72868_1_.size(); ++i) { Entity entity = (Entity)p_72868_1_.get(i); @@ -1312,7 +1334,7 @@ this.onEntityAdded(entity); } } -@@ -3308,14 +3939,25 @@ +@@ -3308,14 +3940,25 @@ public void unloadEntities(List p_72828_1_) { @@ -1340,7 +1362,7 @@ } public PathEntity getPathEntityToEntity(Entity p_72865_1_, Entity p_72865_2_, float p_72865_3_, boolean p_72865_4_, boolean p_72865_5_, boolean p_72865_6_, boolean p_72865_7_) -@@ -3464,6 +4106,12 @@ +@@ -3464,6 +4107,12 @@ for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); @@ -1353,7 +1375,7 @@ double d5 = entityplayer1.getDistanceSq(p_72977_1_, p_72977_3_, p_72977_5_); if ((p_72977_7_ < 0.0D || d5 < p_72977_7_ * p_72977_7_) && (d4 == -1.0D || d5 < d4)) -@@ -3489,7 +4137,12 @@ +@@ -3489,7 +4138,12 @@ for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); @@ -1367,7 +1389,7 @@ if (!entityplayer1.capabilities.disableDamage && entityplayer1.isEntityAlive()) { double d5 = entityplayer1.getDistanceSq(p_72846_1_, p_72846_3_, p_72846_5_); -@@ -3612,11 +4265,11 @@ +@@ -3612,11 +4266,11 @@ } } @@ -1381,7 +1403,7 @@ } } } -@@ -3660,6 +4313,18 @@ +@@ -3660,6 +4314,18 @@ public void updateAllPlayersSleepingFlag() {} @@ -1400,18 +1422,18 @@ public float getWeightedThunderStrength(float p_72819_1_) { return (this.prevThunderingStrength + (this.thunderingStrength - this.prevThunderingStrength) * p_72819_1_) * this.getRainStrength(p_72819_1_); -@@ -3932,8 +4597,8 @@ +@@ -3932,8 +4598,8 @@ */ public void addTileEntity(TileEntity entity) { - List dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; - if(entity.canUpdate()) -+ Collection dest = field_147481_N ? addedTileEntityList : loadedTileEntityList; // Cauldron - List -> Collection for CB loadedTileEntityList type change ++ Collection dest = field_147481_N ? addedTileEntityList : loadedTileEntityList_KC; // Cauldron - List -> Collection for CB loadedTileEntityList type change + if (CauldronHooks.canUpdate(entity)) { dest.add(entity); } -@@ -4020,13 +4685,82 @@ +@@ -4020,13 +4686,82 @@ public int countEntities(EnumCreatureType type, boolean forSpawnCount) { int count = 0; diff --git a/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java b/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java index 24ee581..150b7ae 100644 --- a/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java +++ b/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java @@ -335,7 +335,7 @@ public class CauldronHooks writer.name("loadedChunks").value(world.theChunkProviderServer.loadedChunkHashMap_KC.size()); writer.name("activeChunks").value(world.activeChunkSet.size()); writer.name("entities").value(world.loadedEntityList_KC.size()); - writer.name("tiles").value(world.loadedTileEntityList.size()); + writer.name("tiles").value(world.loadedTileEntityList_KC.size()); TObjectIntHashMap chunkEntityCounts = new TObjectIntHashMap(); TObjectIntHashMap classEntityCounts = new TObjectIntHashMap(); @@ -365,9 +365,8 @@ public class CauldronHooks TObjectIntHashMap chunkTileCounts = new TObjectIntHashMap(); TObjectIntHashMap classTileCounts = new TObjectIntHashMap(); writer.name("tiles").beginArray(); - for (int i = 0; i < world.loadedTileEntityList.size(); i++) + for (TileEntity tile : world.loadedTileEntityList_KC) { - TileEntity tile = (TileEntity) world.loadedTileEntityList.get(i); if (logAll) { writer.beginObject(); diff --git a/src/main/java/net/minecraftforge/cauldron/command/CauldronCommand.java b/src/main/java/net/minecraftforge/cauldron/command/CauldronCommand.java index 89a3dc0..efc4e37 100644 --- a/src/main/java/net/minecraftforge/cauldron/command/CauldronCommand.java +++ b/src/main/java/net/minecraftforge/cauldron/command/CauldronCommand.java @@ -115,7 +115,7 @@ public class CauldronCommand extends Command ChatColor.GOLD + " Loaded Chunks: " + ChatColor.GRAY + world.theChunkProviderServer.loadedChunkHashMap_KC.size() + ChatColor.GOLD + " Active Chunks: " + ChatColor.GRAY + world.activeChunkSet.size() + ChatColor.GOLD + " Entities: " + ChatColor.GRAY + world.loadedEntityList_KC.size() + - ChatColor.GOLD + " Tile Entities: " + ChatColor.GRAY + world.loadedTileEntityList.size() + ChatColor.GOLD + " Tile Entities: " + ChatColor.GRAY + world.loadedTileEntityList_KC.size() ); sender.sendMessage(ChatColor.GOLD + " Entities Last Tick: " + ChatColor.GRAY + world.entitiesTicked + ChatColor.GOLD + " Tiles Last Tick: " + ChatColor.GRAY + world.tilesTicked diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java index d2acc65..b7da4a5 100644 --- a/src/main/java/org/spigotmc/WatchdogThread.java +++ b/src/main/java/org/spigotmc/WatchdogThread.java @@ -90,7 +90,7 @@ public class WatchdogThread extends Thread log.log(Level.SEVERE, " Dimension:" + world.provider.dimensionId); log.log(Level.SEVERE, " Loaded Chunks: " + world.theChunkProviderServer.loadedChunkHashMap_KC.size() + " Active Chunks: " + world.activeChunkSet.size() - + " Entities: " + world.loadedEntityList_KC.size() + " Tile Entities: " + world.loadedTileEntityList.size()); + + " Entities: " + world.loadedEntityList_KC.size() + " Tile Entities: " + world.loadedTileEntityList_KC.size()); log.log(Level.SEVERE, " Entities Last Tick: " + world.entitiesTicked); log.log(Level.SEVERE, " Tiles Last Tick: " + world.tilesTicked); } @@ -156,7 +156,7 @@ public class WatchdogThread extends Thread log.log(Level.WARNING, " Loaded Chunks: " + world.theChunkProviderServer.loadedChunkHashMap_KC.size() + " Active Chunks: " + world.activeChunkSet.size() + " Entities: " + world.loadedEntityList_KC.size() + - " Tile Entities: " + world.loadedTileEntityList.size()); + " Tile Entities: " + world.loadedTileEntityList_KC.size()); log.log(Level.WARNING, " Entities Last Tick: " + world.entitiesTicked); log.log(Level.WARNING, " Tiles Last Tick: " + world.tilesTicked); }