mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-05-29 04:34:10 +00:00
Convert computer sides to an enum
Previously we just relied on magic int values, which was confusing and potentially error-prone. We could use EnumFacing, but that's a) dependent on MC and b) incorrect, as we're referring to local coordinates.
This commit is contained in:
parent
34602ec4be
commit
63dc0daa09
@ -8,6 +8,7 @@ package dan200.computercraft.core.apis;
|
|||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.core.computer.IComputerEnvironment;
|
import dan200.computercraft.core.computer.IComputerEnvironment;
|
||||||
import dan200.computercraft.core.filesystem.FileSystem;
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
@ -18,16 +19,10 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
public interface IAPIEnvironment
|
public interface IAPIEnvironment
|
||||||
{
|
{
|
||||||
String[] SIDE_NAMES = new String[] {
|
|
||||||
"bottom", "top", "back", "front", "right", "left",
|
|
||||||
};
|
|
||||||
|
|
||||||
int SIDE_COUNT = 6;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface IPeripheralChangeListener
|
interface IPeripheralChangeListener
|
||||||
{
|
{
|
||||||
void onPeripheralChanged( int side, @Nullable IPeripheral newPeripheral );
|
void onPeripheralChanged( ComputerSide side, @Nullable IPeripheral newPeripheral );
|
||||||
}
|
}
|
||||||
|
|
||||||
int getComputerID();
|
int getComputerID();
|
||||||
@ -49,22 +44,22 @@ public interface IAPIEnvironment
|
|||||||
|
|
||||||
void queueEvent( String event, Object[] args );
|
void queueEvent( String event, Object[] args );
|
||||||
|
|
||||||
void setOutput( int side, int output );
|
void setOutput( ComputerSide side, int output );
|
||||||
|
|
||||||
int getOutput( int side );
|
int getOutput( ComputerSide side );
|
||||||
|
|
||||||
int getInput( int side );
|
int getInput( ComputerSide side );
|
||||||
|
|
||||||
void setBundledOutput( int side, int output );
|
void setBundledOutput( ComputerSide side, int output );
|
||||||
|
|
||||||
int getBundledOutput( int side );
|
int getBundledOutput( ComputerSide side );
|
||||||
|
|
||||||
int getBundledInput( int side );
|
int getBundledInput( ComputerSide side );
|
||||||
|
|
||||||
void setPeripheralChangeListener( @Nullable IPeripheralChangeListener listener );
|
void setPeripheralChangeListener( @Nullable IPeripheralChangeListener listener );
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
IPeripheral getPeripheral( int side );
|
IPeripheral getPeripheral( ComputerSide side );
|
||||||
|
|
||||||
String getLabel();
|
String getLabel();
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import dan200.computercraft.api.lua.ILuaAPI;
|
|||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.core.tracking.TrackingField;
|
import dan200.computercraft.core.tracking.TrackingField;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -245,32 +246,33 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
// IPeripheralChangeListener
|
// IPeripheralChangeListener
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPeripheralChanged( int side, IPeripheral newPeripheral )
|
public void onPeripheralChanged( ComputerSide side, IPeripheral newPeripheral )
|
||||||
{
|
{
|
||||||
synchronized( m_peripherals )
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
if( m_peripherals[side] != null )
|
int index = side.ordinal();
|
||||||
|
if( m_peripherals[index] != null )
|
||||||
{
|
{
|
||||||
// Queue a detachment
|
// Queue a detachment
|
||||||
final PeripheralWrapper wrapper = m_peripherals[side];
|
final PeripheralWrapper wrapper = m_peripherals[index];
|
||||||
if( wrapper.isAttached() ) wrapper.detach();
|
if( wrapper.isAttached() ) wrapper.detach();
|
||||||
|
|
||||||
// Queue a detachment event
|
// Queue a detachment event
|
||||||
m_environment.queueEvent( "peripheral_detach", new Object[] { IAPIEnvironment.SIDE_NAMES[side] } );
|
m_environment.queueEvent( "peripheral_detach", new Object[] { side.getName() } );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign the new peripheral
|
// Assign the new peripheral
|
||||||
m_peripherals[side] = newPeripheral == null ? null
|
m_peripherals[index] = newPeripheral == null ? null
|
||||||
: new PeripheralWrapper( newPeripheral, IAPIEnvironment.SIDE_NAMES[side] );
|
: new PeripheralWrapper( newPeripheral, side.getName() );
|
||||||
|
|
||||||
if( m_peripherals[side] != null )
|
if( m_peripherals[index] != null )
|
||||||
{
|
{
|
||||||
// Queue an attachment
|
// Queue an attachment
|
||||||
final PeripheralWrapper wrapper = m_peripherals[side];
|
final PeripheralWrapper wrapper = m_peripherals[index];
|
||||||
if( m_running && !wrapper.isAttached() ) wrapper.attach();
|
if( m_running && !wrapper.isAttached() ) wrapper.attach();
|
||||||
|
|
||||||
// Queue an attachment event
|
// Queue an attachment event
|
||||||
m_environment.queueEvent( "peripheral", new Object[] { IAPIEnvironment.SIDE_NAMES[side] } );
|
m_environment.queueEvent( "peripheral", new Object[] { side.getName() } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,16 +339,13 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
{
|
{
|
||||||
// isPresent
|
// isPresent
|
||||||
boolean present = false;
|
boolean present = false;
|
||||||
int side = parseSide( args );
|
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
||||||
if( side >= 0 )
|
if( side != null )
|
||||||
{
|
{
|
||||||
synchronized( m_peripherals )
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
PeripheralWrapper p = m_peripherals[side];
|
PeripheralWrapper p = m_peripherals[side.ordinal()];
|
||||||
if( p != null )
|
if( p != null ) present = true;
|
||||||
{
|
|
||||||
present = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Object[] { present };
|
return new Object[] { present };
|
||||||
@ -354,21 +353,14 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
// getType
|
// getType
|
||||||
String type = null;
|
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
||||||
int side = parseSide( args );
|
if( side != null )
|
||||||
if( side >= 0 )
|
|
||||||
{
|
{
|
||||||
|
String type = null;
|
||||||
synchronized( m_peripherals )
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
PeripheralWrapper p = m_peripherals[side];
|
PeripheralWrapper p = m_peripherals[side.ordinal()];
|
||||||
if( p != null )
|
if( p != null ) return new Object[] { p.getType() };
|
||||||
{
|
|
||||||
type = p.getType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( type != null )
|
|
||||||
{
|
|
||||||
return new Object[] { type };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -377,12 +369,12 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
{
|
{
|
||||||
// getMethods
|
// getMethods
|
||||||
String[] methods = null;
|
String[] methods = null;
|
||||||
int side = parseSide( args );
|
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
||||||
if( side >= 0 )
|
if( side != null )
|
||||||
{
|
{
|
||||||
synchronized( m_peripherals )
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
PeripheralWrapper p = m_peripherals[side];
|
PeripheralWrapper p = m_peripherals[side.ordinal()];
|
||||||
if( p != null )
|
if( p != null )
|
||||||
{
|
{
|
||||||
methods = p.getMethods();
|
methods = p.getMethods();
|
||||||
@ -403,16 +395,16 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
// call
|
// call
|
||||||
int side = parseSide( args );
|
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
||||||
String methodName = getString( args, 1 );
|
String methodName = getString( args, 1 );
|
||||||
Object[] methodArgs = Arrays.copyOfRange( args, 2, args.length );
|
Object[] methodArgs = Arrays.copyOfRange( args, 2, args.length );
|
||||||
|
|
||||||
if( side >= 0 )
|
if( side != null )
|
||||||
{
|
{
|
||||||
PeripheralWrapper p;
|
PeripheralWrapper p;
|
||||||
synchronized( m_peripherals )
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
p = m_peripherals[side];
|
p = m_peripherals[side.ordinal()];
|
||||||
}
|
}
|
||||||
if( p != null )
|
if( p != null )
|
||||||
{
|
{
|
||||||
@ -425,19 +417,4 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Privates
|
|
||||||
|
|
||||||
private int parseSide( Object[] args ) throws LuaException
|
|
||||||
{
|
|
||||||
String side = getString( args, 0 );
|
|
||||||
for( int n = 0; n < IAPIEnvironment.SIDE_NAMES.length; n++ )
|
|
||||||
{
|
|
||||||
if( side.equals( IAPIEnvironment.SIDE_NAMES[n] ) )
|
|
||||||
{
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ package dan200.computercraft.core.apis;
|
|||||||
import dan200.computercraft.api.lua.ILuaAPI;
|
import dan200.computercraft.api.lua.ILuaAPI;
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -64,56 +65,40 @@ public class RedstoneAPI implements ILuaAPI
|
|||||||
{
|
{
|
||||||
// getSides
|
// getSides
|
||||||
Map<Object, Object> table = new HashMap<>();
|
Map<Object, Object> table = new HashMap<>();
|
||||||
for( int i = 0; i < IAPIEnvironment.SIDE_NAMES.length; i++ )
|
for( int i = 0; i < ComputerSide.NAMES.length; i++ )
|
||||||
{
|
{
|
||||||
table.put( i + 1, IAPIEnvironment.SIDE_NAMES[i] );
|
table.put( i + 1, ComputerSide.NAMES[i] );
|
||||||
}
|
}
|
||||||
return new Object[] { table };
|
return new Object[] { table };
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
// setOutput
|
// setOutput
|
||||||
int side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
boolean output = getBoolean( args, 1 );
|
boolean output = getBoolean( args, 1 );
|
||||||
m_environment.setOutput( side, output ? 15 : 0 );
|
m_environment.setOutput( side, output ? 15 : 0 );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2: // getOutput
|
||||||
{
|
return new Object[] { m_environment.getOutput( parseSide( args ) ) > 0 };
|
||||||
// getOutput
|
case 3: // getInput
|
||||||
int side = parseSide( args );
|
return new Object[] { m_environment.getInput( parseSide( args ) ) > 0 };
|
||||||
return new Object[] { m_environment.getOutput( side ) > 0 };
|
|
||||||
}
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
// getInput
|
|
||||||
int side = parseSide( args );
|
|
||||||
return new Object[] { m_environment.getInput( side ) > 0 };
|
|
||||||
}
|
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
// setBundledOutput
|
// setBundledOutput
|
||||||
int side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
int output = getInt( args, 1 );
|
int output = getInt( args, 1 );
|
||||||
m_environment.setBundledOutput( side, output );
|
m_environment.setBundledOutput( side, output );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 5:
|
case 5: // getBundledOutput
|
||||||
{
|
return new Object[] { m_environment.getBundledOutput( parseSide( args ) ) };
|
||||||
// getBundledOutput
|
case 6: // getBundledInput
|
||||||
int side = parseSide( args );
|
return new Object[] { m_environment.getBundledInput( parseSide( args ) ) };
|
||||||
return new Object[] { m_environment.getBundledOutput( side ) };
|
|
||||||
}
|
|
||||||
case 6:
|
|
||||||
{
|
|
||||||
// getBundledInput
|
|
||||||
int side = parseSide( args );
|
|
||||||
return new Object[] { m_environment.getBundledInput( side ) };
|
|
||||||
}
|
|
||||||
case 7:
|
case 7:
|
||||||
{
|
{
|
||||||
// testBundledInput
|
// testBundledInput
|
||||||
int side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
int mask = getInt( args, 1 );
|
int mask = getInt( args, 1 );
|
||||||
int input = m_environment.getBundledInput( side );
|
int input = m_environment.getBundledInput( side );
|
||||||
return new Object[] { (input & mask) == mask };
|
return new Object[] { (input & mask) == mask };
|
||||||
@ -122,7 +107,7 @@ public class RedstoneAPI implements ILuaAPI
|
|||||||
case 9:
|
case 9:
|
||||||
{
|
{
|
||||||
// setAnalogOutput/setAnalogueOutput
|
// setAnalogOutput/setAnalogueOutput
|
||||||
int side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
int output = getInt( args, 1 );
|
int output = getInt( args, 1 );
|
||||||
if( output < 0 || output > 15 )
|
if( output < 0 || output > 15 )
|
||||||
{
|
{
|
||||||
@ -132,34 +117,20 @@ public class RedstoneAPI implements ILuaAPI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 10:
|
case 10:
|
||||||
case 11:
|
case 11: // getAnalogOutput/getAnalogueOutput
|
||||||
{
|
return new Object[] { m_environment.getOutput( parseSide( args ) ) };
|
||||||
// getAnalogOutput/getAnalogueOutput
|
|
||||||
int side = parseSide( args );
|
|
||||||
return new Object[] { m_environment.getOutput( side ) };
|
|
||||||
}
|
|
||||||
case 12:
|
case 12:
|
||||||
case 13:
|
case 13: // getAnalogInput/getAnalogueInput
|
||||||
{
|
return new Object[] { m_environment.getInput( parseSide( args ) ) };
|
||||||
// getAnalogInput/getAnalogueInput
|
|
||||||
int side = parseSide( args );
|
|
||||||
return new Object[] { m_environment.getInput( side ) };
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int parseSide( Object[] args ) throws LuaException
|
private static ComputerSide parseSide( Object[] args ) throws LuaException
|
||||||
{
|
{
|
||||||
String side = getString( args, 0 );
|
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
||||||
for( int n = 0; n < IAPIEnvironment.SIDE_NAMES.length; n++ )
|
if( side == null ) throw new LuaException( "Invalid side." );
|
||||||
{
|
return side;
|
||||||
if( side.equals( IAPIEnvironment.SIDE_NAMES[n] ) )
|
|
||||||
{
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new LuaException( "Invalid side." );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,13 +223,13 @@ public class Computer
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public IPeripheral getPeripheral( int side )
|
public IPeripheral getPeripheral( int side )
|
||||||
{
|
{
|
||||||
return internalEnvironment.getPeripheral( side );
|
return internalEnvironment.getPeripheral( ComputerSide.valueOf( side ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setPeripheral( int side, IPeripheral peripheral )
|
public void setPeripheral( int side, IPeripheral peripheral )
|
||||||
{
|
{
|
||||||
internalEnvironment.setPeripheral( side, peripheral );
|
internalEnvironment.setPeripheral( ComputerSide.valueOf( side ), peripheral );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -252,5 +252,5 @@ public class Computer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static final String[] s_sideNames = IAPIEnvironment.SIDE_NAMES;
|
public static final String[] s_sideNames = ComputerSide.NAMES;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.core.computer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A side on a computer. Unlike {@link net.minecraft.util.EnumFacing}, this is relative to the direction the computer is
|
||||||
|
* facing..
|
||||||
|
*/
|
||||||
|
public enum ComputerSide
|
||||||
|
{
|
||||||
|
BOTTOM( "bottom" ),
|
||||||
|
TOP( "top" ),
|
||||||
|
BACK( "back" ),
|
||||||
|
FRONT( "front" ),
|
||||||
|
RIGHT( "right" ),
|
||||||
|
LEFT( "left" );
|
||||||
|
|
||||||
|
public static final String[] NAMES = new String[] { "bottom", "top", "back", "front", "right", "left" };
|
||||||
|
|
||||||
|
public static final int COUNT = 6;
|
||||||
|
|
||||||
|
private static final ComputerSide[] VALUES = values();
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
ComputerSide( String name ) {this.name = name;}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static ComputerSide valueOf( int side )
|
||||||
|
{
|
||||||
|
return VALUES[side];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static ComputerSide valueOfInsensitive( @Nonnull String name )
|
||||||
|
{
|
||||||
|
for( ComputerSide side : VALUES )
|
||||||
|
{
|
||||||
|
if( side.name.equalsIgnoreCase( name ) ) return side;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -26,12 +26,12 @@ import javax.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
public class ComputerSystem extends ComputerAccess implements IComputerSystem
|
public class ComputerSystem extends ComputerAccess implements IComputerSystem
|
||||||
{
|
{
|
||||||
private final IAPIEnvironment m_environment;
|
private final IAPIEnvironment environment;
|
||||||
|
|
||||||
ComputerSystem( IAPIEnvironment environment )
|
ComputerSystem( IAPIEnvironment environment )
|
||||||
{
|
{
|
||||||
super( environment );
|
super( environment );
|
||||||
this.m_environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -45,7 +45,7 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem
|
|||||||
@Override
|
@Override
|
||||||
public IFileSystem getFileSystem()
|
public IFileSystem getFileSystem()
|
||||||
{
|
{
|
||||||
FileSystem fs = m_environment.getFileSystem();
|
FileSystem fs = environment.getFileSystem();
|
||||||
return fs == null ? null : fs.getMountWrapper();
|
return fs == null ? null : fs.getMountWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +53,6 @@ public class ComputerSystem extends ComputerAccess implements IComputerSystem
|
|||||||
@Override
|
@Override
|
||||||
public String getLabel()
|
public String getLabel()
|
||||||
{
|
{
|
||||||
return m_environment.getLabel();
|
return environment.getLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,17 +41,17 @@ public final class Environment implements IAPIEnvironment
|
|||||||
private final Computer computer;
|
private final Computer computer;
|
||||||
|
|
||||||
private boolean internalOutputChanged = false;
|
private boolean internalOutputChanged = false;
|
||||||
private final int[] internalOutput = new int[SIDE_COUNT];
|
private final int[] internalOutput = new int[ComputerSide.COUNT];
|
||||||
private final int[] internalBundledOutput = new int[SIDE_COUNT];
|
private final int[] internalBundledOutput = new int[ComputerSide.COUNT];
|
||||||
|
|
||||||
private final int[] externalOutput = new int[SIDE_COUNT];
|
private final int[] externalOutput = new int[ComputerSide.COUNT];
|
||||||
private final int[] externalBundledOutput = new int[SIDE_COUNT];
|
private final int[] externalBundledOutput = new int[ComputerSide.COUNT];
|
||||||
|
|
||||||
private boolean inputChanged = false;
|
private boolean inputChanged = false;
|
||||||
private final int[] input = new int[SIDE_COUNT];
|
private final int[] input = new int[ComputerSide.COUNT];
|
||||||
private final int[] bundledInput = new int[SIDE_COUNT];
|
private final int[] bundledInput = new int[ComputerSide.COUNT];
|
||||||
|
|
||||||
private final IPeripheral[] peripherals = new IPeripheral[SIDE_COUNT];
|
private final IPeripheral[] peripherals = new IPeripheral[ComputerSide.COUNT];
|
||||||
private IPeripheralChangeListener peripheralListener = null;
|
private IPeripheralChangeListener peripheralListener = null;
|
||||||
|
|
||||||
Environment( Computer computer )
|
Environment( Computer computer )
|
||||||
@ -111,85 +111,89 @@ public final class Environment implements IAPIEnvironment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInput( int side )
|
public int getInput( ComputerSide side )
|
||||||
{
|
{
|
||||||
return input[side];
|
return input[side.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBundledInput( int side )
|
public int getBundledInput( ComputerSide side )
|
||||||
{
|
{
|
||||||
return bundledInput[side];
|
return bundledInput[side.ordinal()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOutput( int side, int output )
|
public void setOutput( ComputerSide side, int output )
|
||||||
{
|
{
|
||||||
|
int index = side.ordinal();
|
||||||
synchronized( internalOutput )
|
synchronized( internalOutput )
|
||||||
{
|
{
|
||||||
if( internalOutput[side] != output )
|
if( internalOutput[index] != output )
|
||||||
{
|
{
|
||||||
internalOutput[side] = output;
|
internalOutput[index] = output;
|
||||||
internalOutputChanged = true;
|
internalOutputChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOutput( int side )
|
public int getOutput( ComputerSide side )
|
||||||
{
|
{
|
||||||
synchronized( internalOutput )
|
synchronized( internalOutput )
|
||||||
{
|
{
|
||||||
return computer.isOn() ? internalOutput[side] : 0;
|
return computer.isOn() ? internalOutput[side.ordinal()] : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBundledOutput( int side, int output )
|
public void setBundledOutput( ComputerSide side, int output )
|
||||||
{
|
{
|
||||||
|
int index = side.ordinal();
|
||||||
synchronized( internalOutput )
|
synchronized( internalOutput )
|
||||||
{
|
{
|
||||||
if( internalBundledOutput[side] != output )
|
if( internalBundledOutput[index] != output )
|
||||||
{
|
{
|
||||||
internalBundledOutput[side] = output;
|
internalBundledOutput[index] = output;
|
||||||
internalOutputChanged = true;
|
internalOutputChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBundledOutput( int side )
|
public int getBundledOutput( ComputerSide side )
|
||||||
{
|
{
|
||||||
synchronized( internalOutput )
|
synchronized( internalOutput )
|
||||||
{
|
{
|
||||||
return computer.isOn() ? internalBundledOutput[side] : 0;
|
return computer.isOn() ? internalBundledOutput[side.ordinal()] : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getExternalRedstoneOutput( int side )
|
public int getExternalRedstoneOutput( ComputerSide side )
|
||||||
{
|
{
|
||||||
return computer.isOn() ? externalOutput[side] : 0;
|
return computer.isOn() ? externalOutput[side.ordinal()] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getExternalBundledRedstoneOutput( int side )
|
public int getExternalBundledRedstoneOutput( ComputerSide side )
|
||||||
{
|
{
|
||||||
return computer.isOn() ? externalBundledOutput[side] : 0;
|
return computer.isOn() ? externalBundledOutput[side.ordinal()] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRedstoneInput( int side, int level )
|
public void setRedstoneInput( ComputerSide side, int level )
|
||||||
{
|
{
|
||||||
if( input[side] != level )
|
int index = side.ordinal();
|
||||||
|
if( input[index] != level )
|
||||||
{
|
{
|
||||||
input[side] = level;
|
input[index] = level;
|
||||||
inputChanged = true;
|
inputChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBundledRedstoneInput( int side, int combination )
|
public void setBundledRedstoneInput( ComputerSide side, int combination )
|
||||||
{
|
{
|
||||||
if( bundledInput[side] != combination )
|
int index = side.ordinal();
|
||||||
|
if( bundledInput[index] != combination )
|
||||||
{
|
{
|
||||||
bundledInput[side] = combination;
|
bundledInput[index] = combination;
|
||||||
inputChanged = true;
|
inputChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +226,7 @@ public final class Environment implements IAPIEnvironment
|
|||||||
|
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
||||||
for( int i = 0; i < SIDE_COUNT; i++ )
|
for( int i = 0; i < ComputerSide.COUNT; i++ )
|
||||||
{
|
{
|
||||||
if( externalOutput[i] != internalOutput[i] )
|
if( externalOutput[i] != internalOutput[i] )
|
||||||
{
|
{
|
||||||
@ -255,24 +259,25 @@ public final class Environment implements IAPIEnvironment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPeripheral getPeripheral( int side )
|
public IPeripheral getPeripheral( ComputerSide side )
|
||||||
{
|
{
|
||||||
synchronized( peripherals )
|
synchronized( peripherals )
|
||||||
{
|
{
|
||||||
return peripherals[side];
|
return peripherals[side.ordinal()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPeripheral( int side, IPeripheral peripheral )
|
public void setPeripheral( ComputerSide side, IPeripheral peripheral )
|
||||||
{
|
{
|
||||||
synchronized( peripherals )
|
synchronized( peripherals )
|
||||||
{
|
{
|
||||||
IPeripheral existing = peripherals[side];
|
int index = side.ordinal();
|
||||||
|
IPeripheral existing = peripherals[index];
|
||||||
if( (existing == null && peripheral != null) ||
|
if( (existing == null && peripheral != null) ||
|
||||||
(existing != null && peripheral == null) ||
|
(existing != null && peripheral == null) ||
|
||||||
(existing != null && !existing.equals( peripheral )) )
|
(existing != null && !existing.equals( peripheral )) )
|
||||||
{
|
{
|
||||||
peripherals[side] = peripheral;
|
peripherals[index] = peripheral;
|
||||||
if( peripheralListener != null ) peripheralListener.onPeripheralChanged( side, peripheral );
|
if( peripheralListener != null ) peripheralListener.onPeripheralChanged( side, peripheral );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ package dan200.computercraft.shared.command;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
|
||||||
import dan200.computercraft.core.computer.Computer;
|
import dan200.computercraft.core.computer.Computer;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.core.tracking.ComputerTracker;
|
import dan200.computercraft.core.tracking.ComputerTracker;
|
||||||
import dan200.computercraft.core.tracking.Tracking;
|
import dan200.computercraft.core.tracking.Tracking;
|
||||||
import dan200.computercraft.core.tracking.TrackingContext;
|
import dan200.computercraft.core.tracking.TrackingContext;
|
||||||
@ -115,12 +115,12 @@ public final class CommandComputerCraft extends CommandDelegate
|
|||||||
table.row( header( "Position" ), linkPosition( context, computer ) );
|
table.row( header( "Position" ), linkPosition( context, computer ) );
|
||||||
table.row( header( "Family" ), text( computer.getFamily().toString() ) );
|
table.row( header( "Family" ), text( computer.getFamily().toString() ) );
|
||||||
|
|
||||||
for( int i = 0; i < 6; i++ )
|
for( ComputerSide side : ComputerSide.values() )
|
||||||
{
|
{
|
||||||
IPeripheral peripheral = computer.getPeripheral( i );
|
IPeripheral peripheral = computer.getPeripheral( side );
|
||||||
if( peripheral != null )
|
if( peripheral != null )
|
||||||
{
|
{
|
||||||
table.row( header( "Peripheral " + IAPIEnvironment.SIDE_NAMES[i] ), text( peripheral.getType() ) );
|
table.row( header( "Peripheral " + side.getName() ), text( peripheral.getType() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
package dan200.computercraft.shared.computer.blocks;
|
package dan200.computercraft.shared.computer.blocks;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
import dan200.computercraft.shared.network.Containers;
|
import dan200.computercraft.shared.network.Containers;
|
||||||
@ -112,13 +113,14 @@ public class TileComputer extends TileComputerBase
|
|||||||
updateInput();
|
updateInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
// For legacy reasons, computers invert the meaning of "left" and "right"
|
|
||||||
private static final int[] s_remapSide = new int[] { 0, 1, 2, 3, 5, 4 };
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int remapLocalSide( int localSide )
|
protected ComputerSide remapLocalSide( ComputerSide localSide )
|
||||||
{
|
{
|
||||||
return s_remapSide[localSide];
|
// For legacy reasons, computers invert the meaning of "left" and "right". A computer's front is facing
|
||||||
|
// towards you, but a turtle's front is facing the other way.
|
||||||
|
if( localSide == ComputerSide.RIGHT ) return ComputerSide.LEFT;
|
||||||
|
if( localSide == ComputerSide.LEFT ) return ComputerSide.RIGHT;
|
||||||
|
return localSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputerState getState()
|
public ComputerState getState()
|
||||||
|
@ -9,6 +9,7 @@ package dan200.computercraft.shared.computer.blocks;
|
|||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralTile;
|
import dan200.computercraft.api.peripheral.IPeripheralTile;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.BundledRedstone;
|
import dan200.computercraft.shared.BundledRedstone;
|
||||||
import dan200.computercraft.shared.Peripherals;
|
import dan200.computercraft.shared.Peripherals;
|
||||||
import dan200.computercraft.shared.common.IDirectionalTile;
|
import dan200.computercraft.shared.common.IDirectionalTile;
|
||||||
@ -124,15 +125,15 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
public boolean getRedstoneConnectivity( EnumFacing side )
|
public boolean getRedstoneConnectivity( EnumFacing side )
|
||||||
{
|
{
|
||||||
if( side == null ) return false;
|
if( side == null ) return false;
|
||||||
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side.getOpposite() ) );
|
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side.getOpposite() ) );
|
||||||
return !isRedstoneBlockedOnSide( localDir );
|
return !isRedstoneBlockedOnSide( localDir );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRedstoneOutput( EnumFacing side )
|
public int getRedstoneOutput( EnumFacing side )
|
||||||
{
|
{
|
||||||
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
|
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
|
||||||
if( !isRedstoneBlockedOnSide( localDir ) && getWorld() != null && !getWorld().isRemote )
|
if( !isRedstoneBlockedOnSide( localDir ) && world != null && !world.isRemote )
|
||||||
{
|
{
|
||||||
ServerComputer computer = getServerComputer();
|
ServerComputer computer = getServerComputer();
|
||||||
if( computer != null ) return computer.getRedstoneOutput( localDir );
|
if( computer != null ) return computer.getRedstoneOutput( localDir );
|
||||||
@ -143,24 +144,18 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
@Override
|
@Override
|
||||||
public boolean getBundledRedstoneConnectivity( @Nonnull EnumFacing side )
|
public boolean getBundledRedstoneConnectivity( @Nonnull EnumFacing side )
|
||||||
{
|
{
|
||||||
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
|
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
|
||||||
return !isRedstoneBlockedOnSide( localDir );
|
return !isRedstoneBlockedOnSide( localDir );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBundledRedstoneOutput( @Nonnull EnumFacing side )
|
public int getBundledRedstoneOutput( @Nonnull EnumFacing side )
|
||||||
{
|
{
|
||||||
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
|
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
|
||||||
if( !isRedstoneBlockedOnSide( localDir ) )
|
if( !isRedstoneBlockedOnSide( localDir ) && !world.isRemote )
|
||||||
{
|
{
|
||||||
if( !getWorld().isRemote )
|
ServerComputer computer = getServerComputer();
|
||||||
{
|
if( computer != null ) return computer.getBundledRedstoneOutput( localDir );
|
||||||
ServerComputer computer = getServerComputer();
|
|
||||||
if( computer != null )
|
|
||||||
{
|
|
||||||
return computer.getBundledRedstoneOutput( localDir );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -259,17 +254,17 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
m_on = m_startOn;
|
m_on = m_startOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isPeripheralBlockedOnSide( int localSide )
|
protected boolean isPeripheralBlockedOnSide( ComputerSide localSide )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isRedstoneBlockedOnSide( int localSide )
|
protected boolean isRedstoneBlockedOnSide( ComputerSide localSide )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int remapLocalSide( int localSide )
|
protected ComputerSide remapLocalSide( ComputerSide localSide )
|
||||||
{
|
{
|
||||||
return localSide;
|
return localSide;
|
||||||
}
|
}
|
||||||
@ -277,7 +272,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
|||||||
private void updateSideInput( ServerComputer computer, EnumFacing dir, BlockPos offset )
|
private void updateSideInput( ServerComputer computer, EnumFacing dir, BlockPos offset )
|
||||||
{
|
{
|
||||||
EnumFacing offsetSide = dir.getOpposite();
|
EnumFacing offsetSide = dir.getOpposite();
|
||||||
int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) );
|
ComputerSide localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) );
|
||||||
if( !isRedstoneBlockedOnSide( localDir ) )
|
if( !isRedstoneBlockedOnSide( localDir ) )
|
||||||
{
|
{
|
||||||
computer.setRedstoneInput( localDir, getWorld().getRedstonePower( offset, dir ) );
|
computer.setRedstoneInput( localDir, getWorld().getRedstonePower( offset, dir ) );
|
||||||
|
@ -14,6 +14,7 @@ import dan200.computercraft.api.lua.ILuaAPI;
|
|||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||||
import dan200.computercraft.core.computer.Computer;
|
import dan200.computercraft.core.computer.Computer;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.core.computer.IComputerEnvironment;
|
import dan200.computercraft.core.computer.IComputerEnvironment;
|
||||||
import dan200.computercraft.shared.common.ServerTerminal;
|
import dan200.computercraft.shared.common.ServerTerminal;
|
||||||
import dan200.computercraft.shared.network.NetworkHandler;
|
import dan200.computercraft.shared.network.NetworkHandler;
|
||||||
@ -272,22 +273,22 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
|||||||
m_computer.queueEvent( event, arguments );
|
m_computer.queueEvent( event, arguments );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRedstoneOutput( int side )
|
public int getRedstoneOutput( ComputerSide side )
|
||||||
{
|
{
|
||||||
return m_computer.getEnvironment().getExternalRedstoneOutput( side );
|
return m_computer.getEnvironment().getExternalRedstoneOutput( side );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRedstoneInput( int side, int level )
|
public void setRedstoneInput( ComputerSide side, int level )
|
||||||
{
|
{
|
||||||
m_computer.getEnvironment().setRedstoneInput( side, level );
|
m_computer.getEnvironment().setRedstoneInput( side, level );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBundledRedstoneOutput( int side )
|
public int getBundledRedstoneOutput( ComputerSide side )
|
||||||
{
|
{
|
||||||
return m_computer.getEnvironment().getExternalBundledRedstoneOutput( side );
|
return m_computer.getEnvironment().getExternalBundledRedstoneOutput( side );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBundledRedstoneInput( int side, int combination )
|
public void setBundledRedstoneInput( ComputerSide side, int combination )
|
||||||
{
|
{
|
||||||
m_computer.getEnvironment().setBundledRedstoneInput( side, combination );
|
m_computer.getEnvironment().setBundledRedstoneInput( side, combination );
|
||||||
}
|
}
|
||||||
@ -303,12 +304,24 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
|||||||
m_computer.addAPI( api );
|
m_computer.addAPI( api );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setPeripheral( int side, IPeripheral peripheral )
|
public void setPeripheral( int side, IPeripheral peripheral )
|
||||||
|
{
|
||||||
|
setPeripheral( ComputerSide.valueOf( side ), peripheral );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPeripheral( ComputerSide side, IPeripheral peripheral )
|
||||||
{
|
{
|
||||||
m_computer.getEnvironment().setPeripheral( side, peripheral );
|
m_computer.getEnvironment().setPeripheral( side, peripheral );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public IPeripheral getPeripheral( int side )
|
public IPeripheral getPeripheral( int side )
|
||||||
|
{
|
||||||
|
return getPeripheral( ComputerSide.valueOf( side ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPeripheral getPeripheral( ComputerSide side )
|
||||||
{
|
{
|
||||||
return m_computer.getEnvironment().getPeripheral( side );
|
return m_computer.getEnvironment().getPeripheral( side );
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.pocket.IPocketAccess;
|
import dan200.computercraft.api.pocket.IPocketAccess;
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.common.IColouredItem;
|
import dan200.computercraft.shared.common.IColouredItem;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||||
@ -130,14 +131,14 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
|||||||
public void invalidatePeripheral()
|
public void invalidatePeripheral()
|
||||||
{
|
{
|
||||||
IPeripheral peripheral = m_upgrade == null ? null : m_upgrade.createPeripheral( this );
|
IPeripheral peripheral = m_upgrade == null ? null : m_upgrade.createPeripheral( this );
|
||||||
setPeripheral( 2, peripheral );
|
setPeripheral( ComputerSide.BACK, peripheral );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Map<ResourceLocation, IPeripheral> getUpgrades()
|
public Map<ResourceLocation, IPeripheral> getUpgrades()
|
||||||
{
|
{
|
||||||
return m_upgrade == null ? Collections.emptyMap() : Collections.singletonMap( m_upgrade.getUpgradeID(), getPeripheral( 2 ) );
|
return m_upgrade == null ? Collections.emptyMap() : Collections.singletonMap( m_upgrade.getUpgradeID(), getPeripheral( ComputerSide.BACK ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPocketUpgrade getUpgrade()
|
public IPocketUpgrade getUpgrade()
|
||||||
|
@ -12,6 +12,7 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
|||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.api.media.IMedia;
|
import dan200.computercraft.api.media.IMedia;
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.PocketUpgrades;
|
import dan200.computercraft.shared.PocketUpgrades;
|
||||||
import dan200.computercraft.shared.common.IColouredItem;
|
import dan200.computercraft.shared.common.IColouredItem;
|
||||||
import dan200.computercraft.shared.computer.blocks.ComputerState;
|
import dan200.computercraft.shared.computer.blocks.ComputerState;
|
||||||
@ -136,7 +137,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
|||||||
// Update pocket upgrade
|
// Update pocket upgrade
|
||||||
if( upgrade != null )
|
if( upgrade != null )
|
||||||
{
|
{
|
||||||
upgrade.update( computer, computer.getPeripheral( 2 ) );
|
upgrade.update( computer, computer.getPeripheral( ComputerSide.BACK ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +166,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
|||||||
if( upgrade != null )
|
if( upgrade != null )
|
||||||
{
|
{
|
||||||
computer.updateValues( player, stack, upgrade );
|
computer.updateValues( player, stack, upgrade );
|
||||||
stop = upgrade.onRightClick( world, computer, computer.getPeripheral( 2 ) );
|
stop = upgrade.onRightClick( world, computer, computer.getPeripheral( ComputerSide.BACK ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.computer.blocks.ComputerPeripheral;
|
import dan200.computercraft.shared.computer.blocks.ComputerPeripheral;
|
||||||
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
||||||
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
||||||
@ -311,13 +312,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isPeripheralBlockedOnSide( int localSide )
|
protected boolean isPeripheralBlockedOnSide( ComputerSide localSide )
|
||||||
{
|
{
|
||||||
return hasPeripheralUpgradeOnSide( localSide );
|
return hasPeripheralUpgradeOnSide( localSide );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isRedstoneBlockedOnSide( int localSide )
|
protected boolean isRedstoneBlockedOnSide( ComputerSide localSide )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -559,15 +560,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
|||||||
|
|
||||||
// Privates
|
// Privates
|
||||||
|
|
||||||
private boolean hasPeripheralUpgradeOnSide( int side )
|
private boolean hasPeripheralUpgradeOnSide( ComputerSide side )
|
||||||
{
|
{
|
||||||
ITurtleUpgrade upgrade;
|
ITurtleUpgrade upgrade;
|
||||||
switch( side )
|
switch( side )
|
||||||
{
|
{
|
||||||
case 4:
|
case RIGHT:
|
||||||
upgrade = getUpgrade( TurtleSide.Right );
|
upgrade = getUpgrade( TurtleSide.Right );
|
||||||
break;
|
break;
|
||||||
case 5:
|
case LEFT:
|
||||||
upgrade = getUpgrade( TurtleSide.Left );
|
upgrade = getUpgrade( TurtleSide.Left );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -13,6 +13,7 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.turtle.*;
|
import dan200.computercraft.api.turtle.*;
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.TurtleUpgrades;
|
import dan200.computercraft.shared.TurtleUpgrades;
|
||||||
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
|
||||||
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
|
||||||
@ -827,15 +828,15 @@ public class TurtleBrain implements ITurtleAccess
|
|||||||
: 0.0f;
|
: 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int toDirection( TurtleSide side )
|
private static ComputerSide toDirection( TurtleSide side )
|
||||||
{
|
{
|
||||||
switch( side )
|
switch( side )
|
||||||
{
|
{
|
||||||
case Left:
|
case Left:
|
||||||
return 5;
|
return ComputerSide.LEFT;
|
||||||
case Right:
|
case Right:
|
||||||
default:
|
default:
|
||||||
return 4;
|
return ComputerSide.RIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.shared.util;
|
package dan200.computercraft.shared.util;
|
||||||
|
|
||||||
|
import dan200.computercraft.core.computer.ComputerSide;
|
||||||
import dan200.computercraft.shared.common.IDirectionalTile;
|
import dan200.computercraft.shared.common.IDirectionalTile;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
@ -14,38 +15,17 @@ public final class DirectionUtil
|
|||||||
{
|
{
|
||||||
private DirectionUtil() {}
|
private DirectionUtil() {}
|
||||||
|
|
||||||
public static int toLocal( IDirectionalTile directional, EnumFacing dir )
|
public static ComputerSide toLocal( IDirectionalTile directional, EnumFacing dir )
|
||||||
{
|
{
|
||||||
EnumFacing front = directional.getDirection();
|
EnumFacing front = directional.getDirection();
|
||||||
if( front.getAxis() == EnumFacing.Axis.Y ) front = EnumFacing.NORTH;
|
if( front.getAxis() == EnumFacing.Axis.Y ) front = EnumFacing.NORTH;
|
||||||
|
|
||||||
EnumFacing back = front.getOpposite();
|
if( dir == front ) return ComputerSide.FRONT;
|
||||||
EnumFacing left = front.rotateYCCW();
|
if( dir == front.getOpposite() ) return ComputerSide.BACK;
|
||||||
EnumFacing right = front.rotateY();
|
if( dir == front.rotateYCCW() ) return ComputerSide.LEFT;
|
||||||
if( dir == front )
|
if( dir == front.rotateY() ) return ComputerSide.RIGHT;
|
||||||
{
|
if( dir == EnumFacing.UP ) return ComputerSide.TOP;
|
||||||
return 3;
|
return ComputerSide.BOTTOM;
|
||||||
}
|
|
||||||
else if( dir == back )
|
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
else if( dir == left )
|
|
||||||
{
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
else if( dir == right )
|
|
||||||
{
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
else if( dir == EnumFacing.UP )
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumFacing fromEntityRot( EntityLivingBase player )
|
public static EnumFacing fromEntityRot( EntityLivingBase player )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user