mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-10-16 04:31:44 +00:00
Merge pull request #454 from SquidDev-CC/ComputerCraft/hotfix/lazy-computer-peripheral
[WIP] Only instantiate ServerComputer on tile ticks
This commit is contained in:
@@ -9,7 +9,6 @@ package dan200.computercraft.shared.computer.blocks;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -17,9 +16,9 @@ public class ComputerPeripheral
|
||||
implements IPeripheral
|
||||
{
|
||||
private final String m_type;
|
||||
private final ServerComputer m_computer;
|
||||
private final ComputerProxy m_computer;
|
||||
|
||||
public ComputerPeripheral( String type, ServerComputer computer )
|
||||
public ComputerPeripheral( String type, ComputerProxy computer )
|
||||
{
|
||||
m_type = type;
|
||||
m_computer = computer;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package dan200.computercraft.shared.computer.blocks;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
|
||||
/**
|
||||
* A proxy object for computer objects, delegating to {@link ServerComputer} or {@link TileComputer} where appropriate.
|
||||
*/
|
||||
public abstract class ComputerProxy
|
||||
{
|
||||
protected abstract TileComputerBase getTile();
|
||||
|
||||
public void turnOn()
|
||||
{
|
||||
TileComputerBase tile = getTile();
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
tile.m_startOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
computer.turnOn();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
TileComputerBase tile = getTile();
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
tile.m_startOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
computer.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void reboot()
|
||||
{
|
||||
TileComputerBase tile = getTile();
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
tile.m_startOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
computer.reboot();
|
||||
}
|
||||
}
|
||||
|
||||
public int assignID()
|
||||
{
|
||||
TileComputerBase tile = getTile();
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
return tile.m_computerID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return computer.getID();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOn()
|
||||
{
|
||||
ServerComputer computer = getTile().getServerComputer();
|
||||
return computer != null && computer.isOn();
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
TileComputerBase tile = getTile();
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
return tile.m_label;
|
||||
}
|
||||
else
|
||||
{
|
||||
return computer.getLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ public class TileComputer extends TileComputerBase
|
||||
// Statics
|
||||
|
||||
// Members
|
||||
|
||||
private ComputerProxy m_proxy;
|
||||
|
||||
public TileComputer()
|
||||
{
|
||||
}
|
||||
@@ -47,6 +48,23 @@ public class TileComputer extends TileComputerBase
|
||||
return computer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputerProxy createProxy()
|
||||
{
|
||||
if( m_proxy == null )
|
||||
{
|
||||
m_proxy = new ComputerProxy()
|
||||
{
|
||||
@Override
|
||||
protected TileComputerBase getTile()
|
||||
{
|
||||
return TileComputer.this;
|
||||
}
|
||||
};
|
||||
}
|
||||
return m_proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDroppedItems( @Nonnull NonNullList<ItemStack> drops, boolean creative )
|
||||
{
|
||||
|
||||
@@ -389,6 +389,8 @@ public abstract class TileComputerBase extends TileGeneric
|
||||
|
||||
protected abstract ServerComputer createComputer( int instanceID, int id );
|
||||
|
||||
public abstract ComputerProxy createProxy();
|
||||
|
||||
// ITerminalTile
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user