From 17a43aef7cfd4a376ed31f3365104e8025f99512 Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Fri, 17 Apr 2015 11:49:14 +0100 Subject: [PATCH] The Elven Portal will now stop functioning if any of its components are in unloaded chunks, it will not dismantle itself like it did before. --- .../common/block/tile/TileAlfPortal.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java b/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java index 1ac3e8287..1780d7e0a 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java @@ -66,6 +66,7 @@ public class TileAlfPortal extends TileMod { public int ticksOpen = 0; int ticksSinceLastItem = 0; private boolean closeNow = false; + private boolean hasUnloadedParts = false; private static final Function CONVERTER_X_Z = new Function() { @Override @@ -95,36 +96,38 @@ public class TileAlfPortal extends TileMod { ticksOpen = 0; return; } - - ticksOpen++; - - if(ticksOpen > 60) { - ticksSinceLastItem++; - if(ConfigHandler.elfPortalParticlesEnabled) - blockParticle(meta); - - AxisAlignedBB aabb = getPortalAABB(); - List items = worldObj.getEntitiesWithinAABB(EntityItem.class, aabb); - if(!worldObj.isRemote) - for(EntityItem item : items) { - if(item.isDead) - continue; - - ItemStack stack = item.getEntityItem(); - if(stack != null && (!(stack.getItem() instanceof IElvenItem) || !((IElvenItem) stack.getItem()).isElvenItem(stack)) && !item.getEntityData().hasKey(TAG_PORTAL_FLAG)) { - item.setDead(); - addItem(stack); - ticksSinceLastItem = 0; - } - } - - if(ticksSinceLastItem >= 20) { - if(!worldObj.isRemote) - resolveRecipes(); - } - } - int newMeta = getValidMetadata(); + + if(!hasUnloadedParts) { + ticksOpen++; + + if(ticksOpen > 60) { + ticksSinceLastItem++; + if(ConfigHandler.elfPortalParticlesEnabled) + blockParticle(meta); + + AxisAlignedBB aabb = getPortalAABB(); + List items = worldObj.getEntitiesWithinAABB(EntityItem.class, aabb); + if(!worldObj.isRemote) + for(EntityItem item : items) { + if(item.isDead) + continue; + + ItemStack stack = item.getEntityItem(); + if(stack != null && (!(stack.getItem() instanceof IElvenItem) || !((IElvenItem) stack.getItem()).isElvenItem(stack)) && !item.getEntityData().hasKey(TAG_PORTAL_FLAG)) { + item.setDead(); + addItem(stack); + ticksSinceLastItem = 0; + } + } + + if(ticksSinceLastItem >= 20) { + if(!worldObj.isRemote) + resolveRecipes(); + } + } + } else closeNow = false; + if(closeNow) { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 | 2); for(int i = 0; i < 36; i++) @@ -136,6 +139,8 @@ public class TileAlfPortal extends TileMod { blockParticle(meta); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 1 | 2); } + + hasUnloadedParts = false; } private void blockParticle(int meta) { @@ -324,6 +329,11 @@ public class TileAlfPortal extends TileMod { int x = xCoord + pos[0]; int y = yCoord + pos[1]; int z = zCoord + pos[2]; + if(!worldObj.blockExists(x, y, z)) { + hasUnloadedParts = true; + return true; // Don't fuck everything up if there's a chunk unload + } + Block blockat = worldObj.getBlock(x, y, z); if(block == Blocks.air ? blockat.isAir(worldObj, x, y, z) : blockat == block) { if(meta == -1)