From d6aa9936495e45881323b06b18074ab1ef1825c9 Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Wed, 24 Jun 2015 17:18:33 +0100 Subject: [PATCH] Try to handle better the flowers' cache. Another stab at fixing the "flowers bind poorly after chunk reload" issue. --- .../java/vazkii/botania/api/package-info.java | 2 +- .../api/subtile/SubTileFunctional.java | 31 +++++++++++++------ .../api/subtile/SubTileGenerating.java | 31 +++++++++++++------ 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/main/java/vazkii/botania/api/package-info.java b/src/main/java/vazkii/botania/api/package-info.java index bb51be56d..6a5269ecc 100644 --- a/src/main/java/vazkii/botania/api/package-info.java +++ b/src/main/java/vazkii/botania/api/package-info.java @@ -1,4 +1,4 @@ -@API(owner = "Botania", apiVersion = "52", provides = "BotaniaAPI") +@API(owner = "Botania", apiVersion = "53", provides = "BotaniaAPI") package vazkii.botania.api; import cpw.mods.fml.common.API; diff --git a/src/main/java/vazkii/botania/api/subtile/SubTileFunctional.java b/src/main/java/vazkii/botania/api/subtile/SubTileFunctional.java index 1459d90d7..139c30d85 100644 --- a/src/main/java/vazkii/botania/api/subtile/SubTileFunctional.java +++ b/src/main/java/vazkii/botania/api/subtile/SubTileFunctional.java @@ -106,11 +106,16 @@ public class SubTileFunctional extends SubTileEntity { } if(!needsNew && linkedPool != null) { - TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord); - if(!(tileAt instanceof IManaPool) || tileAt.isInvalid()) { + if(supertile.getWorldObj().blockExists(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord) && !linkedPool.isInvalid()) { + TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord); + if(!(tileAt instanceof IManaPool) || tileAt.isInvalid()) { + linkedPool = null; + needsNew = true; + } else linkedPool = tileAt; + } else { + cachedPoolCoordinates = new ChunkCoordinates(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord); linkedPool = null; - needsNew = true; - } else linkedPool = tileAt; + } } if(needsNew) { @@ -162,13 +167,19 @@ public class SubTileFunctional extends SubTileEntity { public void writeToPacketNBT(NBTTagCompound cmp) { cmp.setInteger(TAG_MANA, mana); - int x = linkedPool == null ? 0 : linkedPool.xCoord; - int y = linkedPool == null ? -1 : linkedPool.yCoord; - int z = linkedPool == null ? 0 : linkedPool.zCoord; + if(cachedPoolCoordinates != null) { + cmp.setInteger(TAG_POOL_X, cachedPoolCoordinates.posX); + cmp.setInteger(TAG_POOL_Y, cachedPoolCoordinates.posY); + cmp.setInteger(TAG_POOL_Z, cachedPoolCoordinates.posZ); + } else { + int x = linkedPool == null ? 0 : linkedPool.xCoord; + int y = linkedPool == null ? -1 : linkedPool.yCoord; + int z = linkedPool == null ? 0 : linkedPool.zCoord; - cmp.setInteger(TAG_POOL_X, x); - cmp.setInteger(TAG_POOL_Y, y); - cmp.setInteger(TAG_POOL_Z, z); + cmp.setInteger(TAG_POOL_X, x); + cmp.setInteger(TAG_POOL_Y, y); + cmp.setInteger(TAG_POOL_Z, z); + } } @Override diff --git a/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java b/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java index 170b8f871..b7010a21f 100644 --- a/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java +++ b/src/main/java/vazkii/botania/api/subtile/SubTileGenerating.java @@ -99,11 +99,16 @@ public class SubTileGenerating extends SubTileEntity { } if(!needsNew && linkedCollector != null) { - TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord); - if(!(tileAt instanceof IManaCollector) || tileAt.isInvalid()) { + if(supertile.getWorldObj().blockExists(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord) && !linkedCollector.isInvalid()) { + TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord); + if(!(tileAt instanceof IManaCollector) || tileAt.isInvalid()) { + linkedCollector = null; + needsNew = true; + } else linkedCollector = tileAt; + } else { + cachedCollectorCoordinates = new ChunkCoordinates(linkedCollector.xCoord, linkedCollector.yCoord, linkedCollector.zCoord); linkedCollector = null; - needsNew = true; - } else linkedCollector = tileAt; + } } if(needsNew) { @@ -190,13 +195,19 @@ public class SubTileGenerating extends SubTileEntity { cmp.setInteger(TAG_MANA, mana); cmp.setInteger(TAG_TICKS_EXISTED, ticksExisted); - int x = linkedCollector == null ? 0 : linkedCollector.xCoord; - int y = linkedCollector == null ? -1 : linkedCollector.yCoord; - int z = linkedCollector == null ? 0 : linkedCollector.zCoord; + if(cachedCollectorCoordinates != null) { + cmp.setInteger(TAG_COLLECTOR_X, cachedCollectorCoordinates.posX); + cmp.setInteger(TAG_COLLECTOR_Y, cachedCollectorCoordinates.posY); + cmp.setInteger(TAG_COLLECTOR_Z, cachedCollectorCoordinates.posZ); + } else { + int x = linkedCollector == null ? 0 : linkedCollector.xCoord; + int y = linkedCollector == null ? -1 : linkedCollector.yCoord; + int z = linkedCollector == null ? 0 : linkedCollector.zCoord; - cmp.setInteger(TAG_COLLECTOR_X, x); - cmp.setInteger(TAG_COLLECTOR_Y, y); - cmp.setInteger(TAG_COLLECTOR_Z, z); + cmp.setInteger(TAG_COLLECTOR_X, x); + cmp.setInteger(TAG_COLLECTOR_Y, y); + cmp.setInteger(TAG_COLLECTOR_Z, z); + } } @Override