diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java b/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java index 0a574704c..5ae306a37 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java @@ -23,7 +23,7 @@ public abstract class TilePeripheralBase extends TileGeneric { // Statics - private EnumFacing m_dir; + protected EnumFacing m_dir; private int m_anim; private boolean m_changed; @@ -97,6 +97,11 @@ public abstract class TilePeripheralBase extends TileGeneric return m_dir; } + public EnumFacing getCachedDirection() + { + return m_dir; + } + @Override public void setDirection( EnumFacing dir ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java index 36127dd66..c5378c2a4 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileAdvancedModem.java @@ -8,8 +8,8 @@ package dan200.computercraft.shared.peripheral.modem; import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -40,7 +40,7 @@ public class TileAdvancedModem extends TileModemBase @Override public Vec3d getPosition() { - BlockPos pos = m_entity.getPos().offset( m_entity.getDirection() ); + BlockPos pos = m_entity.getPos().offset( m_entity.getCachedDirection() ); return new Vec3d( pos.getX(), pos.getY(), pos.getZ() ); } @@ -57,9 +57,40 @@ public class TileAdvancedModem extends TileModemBase } // Members + private boolean m_hasDirection = false; public TileAdvancedModem() { + m_dir = EnumFacing.DOWN; + } + + @Override + public void onLoad() + { + super.onLoad(); + updateDirection(); + } + + @Override + public void updateContainingBlockInfo() + { + m_hasDirection = false; + } + + @Override + public void update() + { + super.update(); + updateDirection(); + } + + private void updateDirection() + { + if( !m_hasDirection ) + { + m_hasDirection = true; + m_dir = getDirection(); + } } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java index de4c32d25..c7aa49efb 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java @@ -99,7 +99,7 @@ public class TileCable extends TileModemBase @Override public Vec3d getPosition() { - EnumFacing direction = m_entity.getDirection(); + EnumFacing direction = m_entity.getCachedDirection(); BlockPos pos = m_entity.getPos().offset( direction ); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } @@ -244,6 +244,8 @@ public class TileCable extends TileModemBase private boolean m_destroyed; private int m_lastSearchID; + + private boolean m_hasDirection = false; public TileCable() { @@ -272,6 +274,28 @@ public class TileCable extends TileModemBase super.destroy(); } + @Override + public void onLoad() + { + super.onLoad(); + updateDirection(); + } + + @Override + public void updateContainingBlockInfo() + { + m_hasDirection = false; + } + + private void updateDirection() + { + if( !m_hasDirection ) + { + m_hasDirection = true; + m_dir = getDirection(); + } + } + @Override public EnumFacing getDirection() { @@ -551,6 +575,7 @@ public class TileCable extends TileModemBase public void update() { super.update(); + updateDirection(); if( !getWorld().isRemote ) { synchronized( m_peripheralsByName ) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java index 6f02bb24c..c28152ad9 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWirelessModem.java @@ -12,8 +12,8 @@ import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.common.BlockPeripheral; import dan200.computercraft.shared.peripheral.common.BlockPeripheralVariant; import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -26,7 +26,7 @@ public class TileWirelessModem extends TileModemBase private static class Peripheral extends WirelessModemPeripheral { private TileModemBase m_entity; - + public Peripheral( TileModemBase entity ) { super( false ); @@ -39,12 +39,12 @@ public class TileWirelessModem extends TileModemBase { return m_entity.getWorld(); } - + @Nonnull @Override public Vec3d getPosition() { - BlockPos pos = m_entity.getPos().offset( m_entity.getDirection() ); + BlockPos pos = m_entity.getPos().offset( m_entity.getCachedDirection() ); return new Vec3d( pos.getX(), pos.getY(), pos.getZ() ); } @@ -53,7 +53,7 @@ public class TileWirelessModem extends TileModemBase { if( other instanceof Peripheral ) { - Peripheral otherModem = (Peripheral)other; + Peripheral otherModem = (Peripheral) other; return otherModem.m_entity == m_entity; } return false; @@ -62,8 +62,40 @@ public class TileWirelessModem extends TileModemBase // Members + private boolean m_hasDirection = false; + public TileWirelessModem() { + m_dir = EnumFacing.DOWN; + } + + @Override + public void onLoad() + { + super.onLoad(); + updateDirection(); + } + + @Override + public void updateContainingBlockInfo() + { + m_hasDirection = false; + } + + @Override + public void update() + { + super.update(); + updateDirection(); + } + + private void updateDirection() + { + if( !m_hasDirection ) + { + m_hasDirection = true; + m_dir = getDirection(); + } } @Override