mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-15 11:45:42 +00:00
Cache direction of modems within the tile
This ensures the world is not accessed from another thread. Closes #410
This commit is contained in:
parent
c3454a195d
commit
c9b0894f26
@ -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 )
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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 )
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user