1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-07 08:52:59 +00:00

Handle managing computer inputs/outputs separatly

The Computer class currently has several resposiblities such as storing
id/label, managing redstone/peirpherals, handling management of the
computer (on/off/events) and updating the output.

In order to simplify this a little bit, we move our IAPIEnvironment
implementation into a separate file, and store all "world state"
(redstone + peripherals) in there. While we still need to have some
level of updating them within the main Computer instance, it's
substantially simpler.
This commit is contained in:
SquidDev
2019-02-11 16:21:51 +00:00
parent 9f2884bc0f
commit d6e0f368df
10 changed files with 559 additions and 551 deletions

View File

@@ -9,6 +9,7 @@ package dan200.computercraft.shared.command;
import com.google.common.collect.Sets;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.core.apis.IAPIEnvironment;
import dan200.computercraft.core.computer.Computer;
import dan200.computercraft.core.tracking.ComputerTracker;
import dan200.computercraft.core.tracking.Tracking;
@@ -126,7 +127,7 @@ public final class CommandComputerCraft extends CommandDelegate
IPeripheral peripheral = computer.getPeripheral( i );
if( peripheral != null )
{
table.row( header( "Peripheral " + Computer.s_sideNames[i] ), text( peripheral.getType() ) );
table.row( header( "Peripheral " + IAPIEnvironment.SIDE_NAMES[i] ), text( peripheral.getType() ) );
}
}

View File

@@ -51,6 +51,7 @@ public abstract class BlockGeneric extends Block implements ITileEntityProvider
@Override
@Deprecated
@SuppressWarnings( "deprecation" )
public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbour )
{
TileEntity tile = world.getTileEntity( pos );

View File

@@ -105,7 +105,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public void update()
{
super.update();
m_computer.advance( 0.05 );
m_computer.advance();
m_changedLastFrame = m_computer.pollAndResetChanged() || m_changed;
m_changed = false;
@@ -283,22 +283,22 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public int getRedstoneOutput( int side )
{
return m_computer.getRedstoneOutput( side );
return m_computer.getEnvironment().getExternalRedstoneOutput( side );
}
public void setRedstoneInput( int side, int level )
{
m_computer.setRedstoneInput( side, level );
m_computer.getEnvironment().setRedstoneInput( side, level );
}
public int getBundledRedstoneOutput( int side )
{
return m_computer.getBundledRedstoneOutput( side );
return m_computer.getEnvironment().getExternalBundledRedstoneOutput( side );
}
public void setBundledRedstoneInput( int side, int combination )
{
m_computer.setBundledRedstoneInput( side, combination );
m_computer.getEnvironment().setBundledRedstoneInput( side, combination );
}
public void addAPI( ILuaAPI api )
@@ -306,7 +306,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
m_computer.addAPI( api );
}
@SuppressWarnings( "deprecation" )
@Deprecated
public void addAPI( dan200.computercraft.core.apis.ILuaAPI api )
{
m_computer.addAPI( api );
@@ -314,12 +314,12 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public void setPeripheral( int side, IPeripheral peripheral )
{
m_computer.setPeripheral( side, peripheral );
m_computer.getEnvironment().setPeripheral( side, peripheral );
}
public IPeripheral getPeripheral( int side )
{
return m_computer.getPeripheral( side );
return m_computer.getEnvironment().getPeripheral( side );
}
public void setLabel( String label )