From 0bddc4b573c8d7cbd9feb42e95c7a4fe792e93fd Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Mon, 24 Mar 2014 15:20:52 +0000 Subject: [PATCH] Collector and Pool binding coordinates are cached rather than loaded directly from NBT. --- .../api/subtile/SubTileFunctional.java | 20 ++++++++++++------ .../api/subtile/SubTileGenerating.java | 21 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/MODSRC/vazkii/botania/api/subtile/SubTileFunctional.java b/MODSRC/vazkii/botania/api/subtile/SubTileFunctional.java index d88e8b85c..64074892e 100644 --- a/MODSRC/vazkii/botania/api/subtile/SubTileFunctional.java +++ b/MODSRC/vazkii/botania/api/subtile/SubTileFunctional.java @@ -42,6 +42,8 @@ public class SubTileFunctional extends SubTileEntity { TileEntity linkedPool = null; public int knownMana = -1; + ChunkCoordinates cachedPoolCoordinates = null; + @Override public boolean canUpdate() { return true; @@ -74,8 +76,18 @@ public class SubTileFunctional extends SubTileEntity { final int range = 6; boolean needsNew = false; - if(linkedPool == null) + if(linkedPool == null) { needsNew = true; + + if(cachedPoolCoordinates != null) { + TileEntity tileAt = supertile.worldObj.getBlockTileEntity(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ); + if(tileAt != null && tileAt instanceof IManaPool) { + linkedPool = tileAt; + needsNew = false; + } + cachedPoolCoordinates = null; + } + } if(!needsNew) { TileEntity tileAt = supertile.worldObj.getBlockTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord); @@ -124,11 +136,7 @@ public class SubTileFunctional extends SubTileEntity { int y = cmp.getInteger(TAG_POOL_Y); int z = cmp.getInteger(TAG_POOL_Z); - if(supertile.worldObj != null) { - TileEntity tileAt = supertile.worldObj.getBlockTileEntity(x, y, z); - if(tileAt != null && tileAt instanceof IManaPool) - linkedPool = tileAt; - } + cachedPoolCoordinates = new ChunkCoordinates(x, y, z); } @Override diff --git a/MODSRC/vazkii/botania/api/subtile/SubTileGenerating.java b/MODSRC/vazkii/botania/api/subtile/SubTileGenerating.java index 3f7d968b7..03e855d61 100644 --- a/MODSRC/vazkii/botania/api/subtile/SubTileGenerating.java +++ b/MODSRC/vazkii/botania/api/subtile/SubTileGenerating.java @@ -24,6 +24,7 @@ import net.minecraft.util.StatCollector; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.internal.IManaNetwork; import vazkii.botania.api.mana.IManaCollector; +import vazkii.botania.api.mana.IManaPool; import cpw.mods.fml.common.network.PacketDispatcher; /** @@ -43,6 +44,8 @@ public class SubTileGenerating extends SubTileEntity { protected TileEntity linkedCollector = null; public int knownMana = -1; + ChunkCoordinates cachedCollectorCoordinates = null; + @Override public boolean canUpdate() { return true; @@ -76,9 +79,19 @@ public class SubTileGenerating extends SubTileEntity { final int range = 6; boolean needsNew = false; - if(linkedCollector == null) + if(linkedCollector == null) { needsNew = true; + if(cachedCollectorCoordinates != null) { + TileEntity tileAt = supertile.worldObj.getBlockTileEntity(cachedCollectorCoordinates.posX, cachedCollectorCoordinates.posY, cachedCollectorCoordinates.posZ); + if(tileAt != null && tileAt instanceof IManaCollector) { + linkedCollector = tileAt; + needsNew = false; + } + cachedCollectorCoordinates = null; + } + } + if(!needsNew) { TileEntity tileAt = supertile.worldObj.getBlockTileEntity(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord); if(!(tileAt instanceof IManaCollector)) { @@ -156,11 +169,7 @@ public class SubTileGenerating extends SubTileEntity { int y = cmp.getInteger(TAG_COLLECTOR_Y); int z = cmp.getInteger(TAG_COLLECTOR_Z); - if(supertile.worldObj != null) { - TileEntity tileAt = supertile.worldObj.getBlockTileEntity(x, y, z); - if(tileAt != null && tileAt instanceof IManaCollector) - linkedCollector = tileAt; - } + cachedCollectorCoordinates = new ChunkCoordinates(x, y, z); } @Override