1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 03:00:30 +00:00

Remove m_ (#658)

IT'S GONE!

Not looking forward to the merge conflicts on this one.
This commit is contained in:
Jonathan Coates 2021-01-15 16:35:49 +00:00
parent b90611b4b4
commit 9d1ee6f61d
57 changed files with 1397 additions and 1482 deletions

View File

@ -471,6 +471,7 @@ tasks.register('testInGame', JavaExec.class).configure {
jacoco.applyTo(it) jacoco.applyTo(it)
it.jacoco.setIncludes(["dan200.computercraft.*"]) it.jacoco.setIncludes(["dan200.computercraft.*"])
it.jacoco.setClassDumpDir(coverageOut) it.jacoco.setClassDumpDir(coverageOut)
it.outputs.dir(coverageOut)
// Older versions of modlauncher don't include a protection domain (and thus no code // Older versions of modlauncher don't include a protection domain (and thus no code
// source). Jacoco skips such classes by default, so we need to explicitly include them. // source). Jacoco skips such classes by default, so we need to explicitly include them.
it.jacoco.setIncludeNoLocationClasses(true) it.jacoco.setIncludeNoLocationClasses(true)

View File

@ -97,20 +97,11 @@
<module name="LambdaParameterName" /> <module name="LambdaParameterName" />
<module name="LocalFinalVariableName" /> <module name="LocalFinalVariableName" />
<module name="LocalVariableName" /> <module name="LocalVariableName" />
<!-- Allow an optional m_ on private members --> <module name="MemberName" />
<module name="MemberName">
<property name="applyToPrivate" value="false" />
<property name="applyToPackage" value="false" />
</module>
<module name="MemberName">
<property name="format" value="^(m_)?[a-z][a-zA-Z0-9]*$" />
<property name="applyToPrivate" value="true" />
<property name="applyToPackage" value="true" />
</module>
<module name="MethodName" /> <module name="MethodName" />
<module name="MethodTypeParameterName" /> <module name="MethodTypeParameterName" />
<module name="PackageName"> <module name="PackageName">
<property name="format" value="^dan200\.computercraf(\.[a-z][a-z0-9]*)*" /> <property name="format" value="^dan200\.computercraft(\.[a-z][a-z0-9]*)*" />
</module> </module>
<module name="ParameterName" /> <module name="ParameterName" />
<module name="StaticVariableName"> <module name="StaticVariableName">

View File

@ -25,7 +25,7 @@ public class ClientTableFormatter implements TableFormatter
{ {
public static final ClientTableFormatter INSTANCE = new ClientTableFormatter(); public static final ClientTableFormatter INSTANCE = new ClientTableFormatter();
private static Int2IntOpenHashMap lastHeights = new Int2IntOpenHashMap(); private static final Int2IntOpenHashMap lastHeights = new Int2IntOpenHashMap();
private static FontRenderer renderer() private static FontRenderer renderer()
{ {

View File

@ -24,11 +24,11 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
{ {
private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix(); private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix();
private final boolean m_book; private final boolean book;
private final int m_pages; private final int pages;
private final TextBuffer[] m_text; private final TextBuffer[] text;
private final TextBuffer[] m_colours; private final TextBuffer[] colours;
private int m_page; private int page;
public GuiPrintout( ContainerHeldItem container, PlayerInventory player, ITextComponent title ) public GuiPrintout( ContainerHeldItem container, PlayerInventory player, ITextComponent title )
{ {
@ -37,16 +37,16 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
imageHeight = Y_SIZE; imageHeight = Y_SIZE;
String[] text = ItemPrintout.getText( container.getStack() ); String[] text = ItemPrintout.getText( container.getStack() );
m_text = new TextBuffer[text.length]; this.text = new TextBuffer[text.length];
for( int i = 0; i < m_text.length; i++ ) m_text[i] = new TextBuffer( text[i] ); for( int i = 0; i < this.text.length; i++ ) this.text[i] = new TextBuffer( text[i] );
String[] colours = ItemPrintout.getColours( container.getStack() ); String[] colours = ItemPrintout.getColours( container.getStack() );
m_colours = new TextBuffer[colours.length]; this.colours = new TextBuffer[colours.length];
for( int i = 0; i < m_colours.length; i++ ) m_colours[i] = new TextBuffer( colours[i] ); for( int i = 0; i < this.colours.length; i++ ) this.colours[i] = new TextBuffer( colours[i] );
m_page = 0; page = 0;
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 ); pages = Math.max( this.text.length / ItemPrintout.LINES_PER_PAGE, 1 );
m_book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK; book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK;
} }
@Override @Override
@ -56,13 +56,13 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
if( key == GLFW.GLFW_KEY_RIGHT ) if( key == GLFW.GLFW_KEY_RIGHT )
{ {
if( m_page < m_pages - 1 ) m_page++; if( page < pages - 1 ) page++;
return true; return true;
} }
if( key == GLFW.GLFW_KEY_LEFT ) if( key == GLFW.GLFW_KEY_LEFT )
{ {
if( m_page > 0 ) m_page--; if( page > 0 ) page--;
return true; return true;
} }
@ -76,14 +76,14 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
if( delta < 0 ) if( delta < 0 )
{ {
// Scroll up goes to the next page // Scroll up goes to the next page
if( m_page < m_pages - 1 ) m_page++; if( page < pages - 1 ) page++;
return true; return true;
} }
if( delta > 0 ) if( delta > 0 )
{ {
// Scroll down goes to the previous page // Scroll down goes to the previous page
if( m_page > 0 ) m_page--; if( page > 0 ) page--;
return true; return true;
} }
@ -98,8 +98,8 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource(); IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource();
drawBorder( IDENTITY, renderer, leftPos, topPos, getBlitOffset(), m_page, m_pages, m_book ); drawBorder( IDENTITY, renderer, leftPos, topPos, getBlitOffset(), page, pages, book );
drawText( IDENTITY, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); drawText( IDENTITY, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours );
renderer.endBatch(); renderer.endBatch();
} }

View File

@ -20,13 +20,13 @@ import org.lwjgl.glfw.GLFW;
public class GuiTurtle extends ContainerScreen<ContainerTurtle> public class GuiTurtle extends ContainerScreen<ContainerTurtle>
{ {
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" ); private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_normal.png" );
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" ); private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_advanced.png" );
private ContainerTurtle m_container; private final ContainerTurtle container;
private final ComputerFamily m_family; private final ComputerFamily family;
private final ClientComputer m_computer; private final ClientComputer computer;
private WidgetTerminal terminal; private WidgetTerminal terminal;
private WidgetWrapper terminalWrapper; private WidgetWrapper terminalWrapper;
@ -35,9 +35,9 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
{ {
super( container, player, title ); super( container, player, title );
m_container = container; this.container = container;
m_family = container.getFamily(); family = container.getFamily();
m_computer = (ClientComputer) container.getComputer(); computer = (ClientComputer) container.getComputer();
imageWidth = 254; imageWidth = 254;
imageHeight = 217; imageHeight = 217;
@ -53,7 +53,7 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT; int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT;
terminal = new WidgetTerminal( terminal = new WidgetTerminal(
minecraft, () -> m_computer, minecraft, () -> computer,
ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermWidth,
ComputerCraft.turtleTermHeight, ComputerCraft.turtleTermHeight,
2, 2, 2, 2 2, 2, 2, 2
@ -95,7 +95,7 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
private void drawSelectionSlot( boolean advanced ) private void drawSelectionSlot( boolean advanced )
{ {
// Draw selection slot // Draw selection slot
int slot = m_container.getSelectedSlot(); int slot = container.getSelectedSlot();
if( slot >= 0 ) if( slot >= 0 )
{ {
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
@ -110,7 +110,7 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
protected void renderBg( float partialTicks, int mouseX, int mouseY ) protected void renderBg( float partialTicks, int mouseX, int mouseY )
{ {
// Draw term // Draw term
boolean advanced = m_family == ComputerFamily.ADVANCED; boolean advanced = family == ComputerFamily.ADVANCED;
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() ); terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
// Draw border/inventory // Draw border/inventory

View File

@ -23,22 +23,22 @@ import java.util.*;
public class TurtleMultiModel implements IBakedModel public class TurtleMultiModel implements IBakedModel
{ {
private final IBakedModel m_baseModel; private final IBakedModel baseModel;
private final IBakedModel m_overlayModel; private final IBakedModel overlayModel;
private final TransformationMatrix m_generalTransform; private final TransformationMatrix generalTransform;
private final TransformedModel m_leftUpgradeModel; private final TransformedModel leftUpgradeModel;
private final TransformedModel m_rightUpgradeModel; private final TransformedModel rightUpgradeModel;
private List<BakedQuad> m_generalQuads = null; private List<BakedQuad> generalQuads = null;
private Map<Direction, List<BakedQuad>> m_faceQuads = new EnumMap<>( Direction.class ); private final Map<Direction, List<BakedQuad>> faceQuads = new EnumMap<>( Direction.class );
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, TransformationMatrix generalTransform, TransformedModel leftUpgradeModel, TransformedModel rightUpgradeModel ) public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, TransformationMatrix generalTransform, TransformedModel leftUpgradeModel, TransformedModel rightUpgradeModel )
{ {
// Get the models // Get the models
m_baseModel = baseModel; this.baseModel = baseModel;
m_overlayModel = overlayModel; this.overlayModel = overlayModel;
m_leftUpgradeModel = leftUpgradeModel; this.leftUpgradeModel = leftUpgradeModel;
m_rightUpgradeModel = rightUpgradeModel; this.rightUpgradeModel = rightUpgradeModel;
m_generalTransform = generalTransform; this.generalTransform = generalTransform;
} }
@Nonnull @Nonnull
@ -55,13 +55,13 @@ public class TurtleMultiModel implements IBakedModel
{ {
if( side != null ) if( side != null )
{ {
if( !m_faceQuads.containsKey( side ) ) m_faceQuads.put( side, buildQuads( state, side, rand ) ); if( !faceQuads.containsKey( side ) ) faceQuads.put( side, buildQuads( state, side, rand ) );
return m_faceQuads.get( side ); return faceQuads.get( side );
} }
else else
{ {
if( m_generalQuads == null ) m_generalQuads = buildQuads( state, side, rand ); if( generalQuads == null ) generalQuads = buildQuads( state, side, rand );
return m_generalQuads; return generalQuads;
} }
} }
@ -70,20 +70,20 @@ public class TurtleMultiModel implements IBakedModel
ArrayList<BakedQuad> quads = new ArrayList<>(); ArrayList<BakedQuad> quads = new ArrayList<>();
transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform ); transformQuadsTo( quads, baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), generalTransform );
if( m_overlayModel != null ) if( overlayModel != null )
{ {
transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform ); transformQuadsTo( quads, overlayModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), generalTransform );
} }
if( m_leftUpgradeModel != null ) if( leftUpgradeModel != null )
{ {
TransformationMatrix upgradeTransform = m_generalTransform.compose( m_leftUpgradeModel.getMatrix() ); TransformationMatrix upgradeTransform = generalTransform.compose( leftUpgradeModel.getMatrix() );
transformQuadsTo( quads, m_leftUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform ); transformQuadsTo( quads, leftUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
} }
if( m_rightUpgradeModel != null ) if( rightUpgradeModel != null )
{ {
TransformationMatrix upgradeTransform = m_generalTransform.compose( m_rightUpgradeModel.getMatrix() ); TransformationMatrix upgradeTransform = generalTransform.compose( rightUpgradeModel.getMatrix() );
transformQuadsTo( quads, m_rightUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform ); transformQuadsTo( quads, rightUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
} }
quads.trimToSize(); quads.trimToSize();
return quads; return quads;
@ -92,25 +92,25 @@ public class TurtleMultiModel implements IBakedModel
@Override @Override
public boolean useAmbientOcclusion() public boolean useAmbientOcclusion()
{ {
return m_baseModel.useAmbientOcclusion(); return baseModel.useAmbientOcclusion();
} }
@Override @Override
public boolean isGui3d() public boolean isGui3d()
{ {
return m_baseModel.isGui3d(); return baseModel.isGui3d();
} }
@Override @Override
public boolean isCustomRenderer() public boolean isCustomRenderer()
{ {
return m_baseModel.isCustomRenderer(); return baseModel.isCustomRenderer();
} }
@Override @Override
public boolean usesBlockLight() public boolean usesBlockLight()
{ {
return m_baseModel.usesBlockLight(); return baseModel.usesBlockLight();
} }
@Nonnull @Nonnull
@ -118,7 +118,7 @@ public class TurtleMultiModel implements IBakedModel
@Deprecated @Deprecated
public TextureAtlasSprite getParticleIcon() public TextureAtlasSprite getParticleIcon()
{ {
return m_baseModel.getParticleIcon(); return baseModel.getParticleIcon();
} }
@Nonnull @Nonnull
@ -126,7 +126,7 @@ public class TurtleMultiModel implements IBakedModel
@Deprecated @Deprecated
public net.minecraft.client.renderer.model.ItemCameraTransforms getTransforms() public net.minecraft.client.renderer.model.ItemCameraTransforms getTransforms()
{ {
return m_baseModel.getTransforms(); return baseModel.getTransforms();
} }
@Nonnull @Nonnull

View File

@ -47,21 +47,21 @@ public class TurtleSmartItemModel implements IBakedModel
private static class TurtleModelCombination private static class TurtleModelCombination
{ {
final boolean m_colour; final boolean colour;
final ITurtleUpgrade m_leftUpgrade; final ITurtleUpgrade leftUpgrade;
final ITurtleUpgrade m_rightUpgrade; final ITurtleUpgrade rightUpgrade;
final ResourceLocation m_overlay; final ResourceLocation overlay;
final boolean m_christmas; final boolean christmas;
final boolean m_flip; final boolean flip;
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas, boolean flip ) TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas, boolean flip )
{ {
m_colour = colour; this.colour = colour;
m_leftUpgrade = leftUpgrade; this.leftUpgrade = leftUpgrade;
m_rightUpgrade = rightUpgrade; this.rightUpgrade = rightUpgrade;
m_overlay = overlay; this.overlay = overlay;
m_christmas = christmas; this.christmas = christmas;
m_flip = flip; this.flip = flip;
} }
@Override @Override
@ -71,12 +71,12 @@ public class TurtleSmartItemModel implements IBakedModel
if( !(other instanceof TurtleModelCombination) ) return false; if( !(other instanceof TurtleModelCombination) ) return false;
TurtleModelCombination otherCombo = (TurtleModelCombination) other; TurtleModelCombination otherCombo = (TurtleModelCombination) other;
return otherCombo.m_colour == m_colour && return otherCombo.colour == colour &&
otherCombo.m_leftUpgrade == m_leftUpgrade && otherCombo.leftUpgrade == leftUpgrade &&
otherCombo.m_rightUpgrade == m_rightUpgrade && otherCombo.rightUpgrade == rightUpgrade &&
Objects.equal( otherCombo.m_overlay, m_overlay ) && Objects.equal( otherCombo.overlay, overlay ) &&
otherCombo.m_christmas == m_christmas && otherCombo.christmas == christmas &&
otherCombo.m_flip == m_flip; otherCombo.flip == flip;
} }
@Override @Override
@ -84,12 +84,12 @@ public class TurtleSmartItemModel implements IBakedModel
{ {
final int prime = 31; final int prime = 31;
int result = 0; int result = 0;
result = prime * result + (m_colour ? 1 : 0); result = prime * result + (colour ? 1 : 0);
result = prime * result + (m_leftUpgrade != null ? m_leftUpgrade.hashCode() : 0); result = prime * result + (leftUpgrade != null ? leftUpgrade.hashCode() : 0);
result = prime * result + (m_rightUpgrade != null ? m_rightUpgrade.hashCode() : 0); result = prime * result + (rightUpgrade != null ? rightUpgrade.hashCode() : 0);
result = prime * result + (m_overlay != null ? m_overlay.hashCode() : 0); result = prime * result + (overlay != null ? overlay.hashCode() : 0);
result = prime * result + (m_christmas ? 1 : 0); result = prime * result + (christmas ? 1 : 0);
result = prime * result + (m_flip ? 1 : 0); result = prime * result + (flip ? 1 : 0);
return result; return result;
} }
} }
@ -97,15 +97,15 @@ public class TurtleSmartItemModel implements IBakedModel
private final IBakedModel familyModel; private final IBakedModel familyModel;
private final IBakedModel colourModel; private final IBakedModel colourModel;
private final HashMap<TurtleModelCombination, IBakedModel> m_cachedModels = new HashMap<>(); private final HashMap<TurtleModelCombination, IBakedModel> cachedModels = new HashMap<>();
private final ItemOverrideList m_overrides; private final ItemOverrideList overrides;
public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel ) public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel )
{ {
this.familyModel = familyModel; this.familyModel = familyModel;
this.colourModel = colourModel; this.colourModel = colourModel;
m_overrides = new ItemOverrideList() overrides = new ItemOverrideList()
{ {
@Nonnull @Nonnull
@Override @Override
@ -121,8 +121,8 @@ public class TurtleSmartItemModel implements IBakedModel
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )); boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip ); TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
IBakedModel model = m_cachedModels.get( combo ); IBakedModel model = cachedModels.get( combo );
if( model == null ) m_cachedModels.put( combo, model = buildModel( combo ) ); if( model == null ) cachedModels.put( combo, model = buildModel( combo ) );
return model; return model;
} }
}; };
@ -132,20 +132,20 @@ public class TurtleSmartItemModel implements IBakedModel
@Override @Override
public ItemOverrideList getOverrides() public ItemOverrideList getOverrides()
{ {
return m_overrides; return overrides;
} }
private IBakedModel buildModel( TurtleModelCombination combo ) private IBakedModel buildModel( TurtleModelCombination combo )
{ {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
ModelManager modelManager = mc.getItemRenderer().getItemModelShaper().getModelManager(); ModelManager modelManager = mc.getItemRenderer().getItemModelShaper().getModelManager();
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas ); ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
IBakedModel baseModel = combo.m_colour ? colourModel : familyModel; IBakedModel baseModel = combo.colour ? colourModel : familyModel;
IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null; IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
TransformationMatrix transform = combo.m_flip ? flip : identity; TransformationMatrix transform = combo.flip ? flip : identity;
TransformedModel leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.LEFT ) : null; TransformedModel leftModel = combo.leftUpgrade != null ? combo.leftUpgrade.getModel( null, TurtleSide.LEFT ) : null;
TransformedModel rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null; TransformedModel rightModel = combo.rightUpgrade != null ? combo.rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null;
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel ); return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel );
} }

View File

@ -19,22 +19,22 @@ import java.util.Set;
public abstract class ComputerAccess implements IComputerAccess public abstract class ComputerAccess implements IComputerAccess
{ {
private final IAPIEnvironment m_environment; private final IAPIEnvironment environment;
private final Set<String> m_mounts = new HashSet<>(); private final Set<String> mounts = new HashSet<>();
protected ComputerAccess( IAPIEnvironment environment ) protected ComputerAccess( IAPIEnvironment environment )
{ {
this.m_environment = environment; this.environment = environment;
} }
public void unmountAll() public void unmountAll()
{ {
FileSystem fileSystem = m_environment.getFileSystem(); FileSystem fileSystem = environment.getFileSystem();
for( String mount : m_mounts ) for( String mount : mounts )
{ {
fileSystem.unmount( mount ); fileSystem.unmount( mount );
} }
m_mounts.clear(); mounts.clear();
} }
@Override @Override
@ -46,7 +46,7 @@ public abstract class ComputerAccess implements IComputerAccess
// Mount the location // Mount the location
String location; String location;
FileSystem fileSystem = m_environment.getFileSystem(); FileSystem fileSystem = environment.getFileSystem();
if( fileSystem == null ) throw new IllegalStateException( "File system has not been created" ); if( fileSystem == null ) throw new IllegalStateException( "File system has not been created" );
synchronized( fileSystem ) synchronized( fileSystem )
@ -64,7 +64,7 @@ public abstract class ComputerAccess implements IComputerAccess
} }
} }
if( location != null ) m_mounts.add( location ); if( location != null ) mounts.add( location );
return location; return location;
} }
@ -77,7 +77,7 @@ public abstract class ComputerAccess implements IComputerAccess
// Mount the location // Mount the location
String location; String location;
FileSystem fileSystem = m_environment.getFileSystem(); FileSystem fileSystem = environment.getFileSystem();
if( fileSystem == null ) throw new IllegalStateException( "File system has not been created" ); if( fileSystem == null ) throw new IllegalStateException( "File system has not been created" );
synchronized( fileSystem ) synchronized( fileSystem )
@ -95,7 +95,7 @@ public abstract class ComputerAccess implements IComputerAccess
} }
} }
if( location != null ) m_mounts.add( location ); if( location != null ) mounts.add( location );
return location; return location;
} }
@ -103,37 +103,37 @@ public abstract class ComputerAccess implements IComputerAccess
public void unmount( String location ) public void unmount( String location )
{ {
if( location == null ) return; if( location == null ) return;
if( !m_mounts.contains( location ) ) throw new IllegalStateException( "You didn't mount this location" ); if( !mounts.contains( location ) ) throw new IllegalStateException( "You didn't mount this location" );
m_environment.getFileSystem().unmount( location ); environment.getFileSystem().unmount( location );
m_mounts.remove( location ); mounts.remove( location );
} }
@Override @Override
public int getID() public int getID()
{ {
return m_environment.getComputerID(); return environment.getComputerID();
} }
@Override @Override
public void queueEvent( @Nonnull String event, Object... arguments ) public void queueEvent( @Nonnull String event, Object... arguments )
{ {
Objects.requireNonNull( event, "event cannot be null" ); Objects.requireNonNull( event, "event cannot be null" );
m_environment.queueEvent( event, arguments ); environment.queueEvent( event, arguments );
} }
@Nonnull @Nonnull
@Override @Override
public IWorkMonitor getMainThreadMonitor() public IWorkMonitor getMainThreadMonitor()
{ {
return m_environment.getMainThreadMonitor(); return environment.getMainThreadMonitor();
} }
private String findFreeLocation( String desiredLoc ) private String findFreeLocation( String desiredLoc )
{ {
try try
{ {
FileSystem fileSystem = m_environment.getFileSystem(); FileSystem fileSystem = environment.getFileSystem();
if( !fileSystem.exists( desiredLoc ) ) return desiredLoc; if( !fileSystem.exists( desiredLoc ) ) return desiredLoc;
// We used to check foo2, foo3, foo4, etc here but the disk drive does this itself now // We used to check foo2, foo3, foo4, etc here but the disk drive does this itself now

View File

@ -34,7 +34,7 @@ import static dan200.computercraft.core.apis.TableHelper.*;
*/ */
public class HTTPAPI implements ILuaAPI public class HTTPAPI implements ILuaAPI
{ {
private final IAPIEnvironment m_apiEnvironment; private final IAPIEnvironment apiEnvironment;
private final ResourceGroup<CheckUrl> checkUrls = new ResourceGroup<>(); private final ResourceGroup<CheckUrl> checkUrls = new ResourceGroup<>();
private final ResourceGroup<HttpRequest> requests = new ResourceQueue<>( () -> ComputerCraft.httpMaxRequests ); private final ResourceGroup<HttpRequest> requests = new ResourceQueue<>( () -> ComputerCraft.httpMaxRequests );
@ -42,7 +42,7 @@ public class HTTPAPI implements ILuaAPI
public HTTPAPI( IAPIEnvironment environment ) public HTTPAPI( IAPIEnvironment environment )
{ {
m_apiEnvironment = environment; apiEnvironment = environment;
} }
@Override @Override
@ -123,7 +123,7 @@ public class HTTPAPI implements ILuaAPI
try try
{ {
URI uri = HttpRequest.checkUri( address ); URI uri = HttpRequest.checkUri( address );
HttpRequest request = new HttpRequest( requests, m_apiEnvironment, address, postString, headers, binary, redirect ); HttpRequest request = new HttpRequest( requests, apiEnvironment, address, postString, headers, binary, redirect );
// Make the request // Make the request
request.queue( r -> r.request( uri, httpMethod ) ); request.queue( r -> r.request( uri, httpMethod ) );
@ -142,7 +142,7 @@ public class HTTPAPI implements ILuaAPI
try try
{ {
URI uri = HttpRequest.checkUri( address ); URI uri = HttpRequest.checkUri( address );
new CheckUrl( checkUrls, m_apiEnvironment, address, uri ).queue( CheckUrl::run ); new CheckUrl( checkUrls, apiEnvironment, address, uri ).queue( CheckUrl::run );
return new Object[] { true }; return new Object[] { true };
} }
@ -165,7 +165,7 @@ public class HTTPAPI implements ILuaAPI
try try
{ {
URI uri = Websocket.checkUri( address ); URI uri = Websocket.checkUri( address );
if( !new Websocket( websockets, m_apiEnvironment, uri, address, headers ).queue( Websocket::connect ) ) if( !new Websocket( websockets, apiEnvironment, uri, address, headers ).queue( Websocket::connect ) )
{ {
throw new LuaException( "Too many websockets already open" ); throw new LuaException( "Too many websockets already open" );
} }

View File

@ -32,29 +32,29 @@ public class OSAPI implements ILuaAPI
{ {
private final IAPIEnvironment apiEnvironment; private final IAPIEnvironment apiEnvironment;
private final Int2ObjectMap<Alarm> m_alarms = new Int2ObjectOpenHashMap<>(); private final Int2ObjectMap<Alarm> alarms = new Int2ObjectOpenHashMap<>();
private int m_clock; private int clock;
private double m_time; private double time;
private int m_day; private int day;
private int m_nextAlarmToken = 0; private int nextAlarmToken = 0;
private static class Alarm implements Comparable<Alarm> private static class Alarm implements Comparable<Alarm>
{ {
final double m_time; final double time;
final int m_day; final int day;
Alarm( double time, int day ) Alarm( double time, int day )
{ {
m_time = time; this.time = time;
m_day = day; this.day = day;
} }
@Override @Override
public int compareTo( @Nonnull Alarm o ) public int compareTo( @Nonnull Alarm o )
{ {
double t = m_day * 24.0 + m_time; double t = day * 24.0 + time;
double ot = m_day * 24.0 + m_time; double ot = day * 24.0 + time;
return Double.compare( t, ot ); return Double.compare( t, ot );
} }
} }
@ -73,38 +73,38 @@ public class OSAPI implements ILuaAPI
@Override @Override
public void startup() public void startup()
{ {
m_time = apiEnvironment.getComputerEnvironment().getTimeOfDay(); time = apiEnvironment.getComputerEnvironment().getTimeOfDay();
m_day = apiEnvironment.getComputerEnvironment().getDay(); day = apiEnvironment.getComputerEnvironment().getDay();
m_clock = 0; clock = 0;
synchronized( m_alarms ) synchronized( alarms )
{ {
m_alarms.clear(); alarms.clear();
} }
} }
@Override @Override
public void update() public void update()
{ {
m_clock++; clock++;
// Wait for all of our alarms // Wait for all of our alarms
synchronized( m_alarms ) synchronized( alarms )
{ {
double previousTime = m_time; double previousTime = time;
int previousDay = m_day; int previousDay = day;
double time = apiEnvironment.getComputerEnvironment().getTimeOfDay(); double time = apiEnvironment.getComputerEnvironment().getTimeOfDay();
int day = apiEnvironment.getComputerEnvironment().getDay(); int day = apiEnvironment.getComputerEnvironment().getDay();
if( time > previousTime || day > previousDay ) if( time > previousTime || day > previousDay )
{ {
double now = m_day * 24.0 + m_time; double now = this.day * 24.0 + this.time;
Iterator<Int2ObjectMap.Entry<Alarm>> it = m_alarms.int2ObjectEntrySet().iterator(); Iterator<Int2ObjectMap.Entry<Alarm>> it = alarms.int2ObjectEntrySet().iterator();
while( it.hasNext() ) while( it.hasNext() )
{ {
Int2ObjectMap.Entry<Alarm> entry = it.next(); Int2ObjectMap.Entry<Alarm> entry = it.next();
Alarm alarm = entry.getValue(); Alarm alarm = entry.getValue();
double t = alarm.m_day * 24.0 + alarm.m_time; double t = alarm.day * 24.0 + alarm.time;
if( now >= t ) if( now >= t )
{ {
apiEnvironment.queueEvent( "alarm", entry.getIntKey() ); apiEnvironment.queueEvent( "alarm", entry.getIntKey() );
@ -113,17 +113,17 @@ public class OSAPI implements ILuaAPI
} }
} }
m_time = time; this.time = time;
m_day = day; this.day = day;
} }
} }
@Override @Override
public void shutdown() public void shutdown()
{ {
synchronized( m_alarms ) synchronized( alarms )
{ {
m_alarms.clear(); alarms.clear();
} }
} }
@ -219,11 +219,11 @@ public class OSAPI implements ILuaAPI
{ {
checkFinite( 0, time ); checkFinite( 0, time );
if( time < 0.0 || time >= 24.0 ) throw new LuaException( "Number out of range" ); if( time < 0.0 || time >= 24.0 ) throw new LuaException( "Number out of range" );
synchronized( m_alarms ) synchronized( alarms )
{ {
int day = time > m_time ? m_day : m_day + 1; int day = time > this.time ? this.day : this.day + 1;
m_alarms.put( m_nextAlarmToken, new Alarm( time, day ) ); alarms.put( nextAlarmToken, new Alarm( time, day ) );
return m_nextAlarmToken++; return nextAlarmToken++;
} }
} }
@ -237,9 +237,9 @@ public class OSAPI implements ILuaAPI
@LuaFunction @LuaFunction
public final void cancelAlarm( int token ) public final void cancelAlarm( int token )
{ {
synchronized( m_alarms ) synchronized( alarms )
{ {
m_alarms.remove( token ); alarms.remove( token );
} }
} }
@ -304,7 +304,7 @@ public class OSAPI implements ILuaAPI
@LuaFunction @LuaFunction
public final double clock() public final double clock()
{ {
return m_clock * 0.05; return clock * 0.05;
} }
/** /**
@ -341,7 +341,7 @@ public class OSAPI implements ILuaAPI
case "local": // Get Hour of day (local time) case "local": // Get Hour of day (local time)
return getTimeForCalendar( Calendar.getInstance() ); return getTimeForCalendar( Calendar.getInstance() );
case "ingame": // Get in-game hour case "ingame": // Get in-game hour
return m_time; return time;
default: default:
throw new LuaException( "Unsupported operation" ); throw new LuaException( "Unsupported operation" );
} }
@ -371,7 +371,7 @@ public class OSAPI implements ILuaAPI
case "local": // Get numbers of days since 1970-01-01 (local time) case "local": // Get numbers of days since 1970-01-01 (local time)
return getDayForCalendar( Calendar.getInstance() ); return getDayForCalendar( Calendar.getInstance() );
case "ingame":// Get game day case "ingame":// Get game day
return m_day; return day;
default: default:
throw new LuaException( "Unsupported operation" ); throw new LuaException( "Unsupported operation" );
} }
@ -410,9 +410,9 @@ public class OSAPI implements ILuaAPI
} }
case "ingame": case "ingame":
// Get in-game epoch // Get in-game epoch
synchronized( m_alarms ) synchronized( alarms )
{ {
return m_day * 86400000L + (long) (m_time * 3600000.0); return day * 86400000L + (long) (time * 3600000.0);
} }
default: default:
throw new LuaException( "Unsupported operation" ); throw new LuaException( "Unsupported operation" );

View File

@ -32,28 +32,28 @@ public class Computer
private static final int START_DELAY = 50; private static final int START_DELAY = 50;
// Various properties of the computer // Various properties of the computer
private int m_id; private int id;
private String m_label = null; private String label = null;
// Read-only fields about the computer // Read-only fields about the computer
private final IComputerEnvironment m_environment; private final IComputerEnvironment environment;
private final Terminal m_terminal; private final Terminal terminal;
private final ComputerExecutor executor; private final ComputerExecutor executor;
private final MainThreadExecutor serverExecutor; private final MainThreadExecutor serverExecutor;
// Additional state about the computer and its environment. // Additional state about the computer and its environment.
private boolean m_blinking = false; private boolean blinking = false;
private final Environment internalEnvironment = new Environment( this ); private final Environment internalEnvironment = new Environment( this );
private final AtomicBoolean externalOutputChanged = new AtomicBoolean(); private final AtomicBoolean externalOutputChanged = new AtomicBoolean();
private boolean startRequested; private boolean startRequested;
private int m_ticksSinceStart = -1; private int ticksSinceStart = -1;
public Computer( IComputerEnvironment environment, Terminal terminal, int id ) public Computer( IComputerEnvironment environment, Terminal terminal, int id )
{ {
m_id = id; this.id = id;
m_environment = environment; this.environment = environment;
m_terminal = terminal; this.terminal = terminal;
executor = new ComputerExecutor( this ); executor = new ComputerExecutor( this );
serverExecutor = new MainThreadExecutor( this ); serverExecutor = new MainThreadExecutor( this );
@ -61,7 +61,7 @@ public class Computer
IComputerEnvironment getComputerEnvironment() IComputerEnvironment getComputerEnvironment()
{ {
return m_environment; return environment;
} }
FileSystem getFileSystem() FileSystem getFileSystem()
@ -71,7 +71,7 @@ public class Computer
Terminal getTerminal() Terminal getTerminal()
{ {
return m_terminal; return terminal;
} }
public Environment getEnvironment() public Environment getEnvironment()
@ -132,33 +132,33 @@ public class Computer
public int getID() public int getID()
{ {
return m_id; return id;
} }
public int assignID() public int assignID()
{ {
if( m_id < 0 ) if( id < 0 )
{ {
m_id = m_environment.assignNewID(); id = environment.assignNewID();
} }
return m_id; return id;
} }
public void setID( int id ) public void setID( int id )
{ {
m_id = id; this.id = id;
} }
public String getLabel() public String getLabel()
{ {
return m_label; return label;
} }
public void setLabel( String label ) public void setLabel( String label )
{ {
if( !Objects.equal( label, m_label ) ) if( !Objects.equal( label, this.label ) )
{ {
m_label = label; this.label = label;
externalOutputChanged.set( true ); externalOutputChanged.set( true );
} }
} }
@ -166,14 +166,14 @@ public class Computer
public void tick() public void tick()
{ {
// We keep track of the number of ticks since the last start, only // We keep track of the number of ticks since the last start, only
if( m_ticksSinceStart >= 0 && m_ticksSinceStart <= START_DELAY ) m_ticksSinceStart++; if( ticksSinceStart >= 0 && ticksSinceStart <= START_DELAY ) ticksSinceStart++;
if( startRequested && (m_ticksSinceStart < 0 || m_ticksSinceStart > START_DELAY) ) if( startRequested && (ticksSinceStart < 0 || ticksSinceStart > START_DELAY) )
{ {
startRequested = false; startRequested = false;
if( !executor.isOn() ) if( !executor.isOn() )
{ {
m_ticksSinceStart = 0; ticksSinceStart = 0;
executor.queueStart(); executor.queueStart();
} }
} }
@ -187,12 +187,12 @@ public class Computer
if( internalEnvironment.updateOutput() ) externalOutputChanged.set( true ); if( internalEnvironment.updateOutput() ) externalOutputChanged.set( true );
// Set output changed if the terminal has changed from blinking to not // Set output changed if the terminal has changed from blinking to not
boolean blinking = m_terminal.getCursorBlink() && boolean blinking = terminal.getCursorBlink() &&
m_terminal.getCursorX() >= 0 && m_terminal.getCursorX() < m_terminal.getWidth() && terminal.getCursorX() >= 0 && terminal.getCursorX() < terminal.getWidth() &&
m_terminal.getCursorY() >= 0 && m_terminal.getCursorY() < m_terminal.getHeight(); terminal.getCursorY() >= 0 && terminal.getCursorY() < terminal.getHeight();
if( blinking != m_blinking ) if( blinking != this.blinking )
{ {
m_blinking = blinking; this.blinking = blinking;
externalOutputChanged.set( true ); externalOutputChanged.set( true );
} }
} }
@ -209,7 +209,7 @@ public class Computer
public boolean isBlinking() public boolean isBlinking()
{ {
return isOn() && m_blinking; return isOn() && blinking;
} }
public void addApi( ILuaAPI api ) public void addApi( ILuaAPI api )

View File

@ -19,11 +19,11 @@ import java.util.Set;
public class ComboMount implements IMount public class ComboMount implements IMount
{ {
private IMount[] m_parts; private final IMount[] parts;
public ComboMount( IMount[] parts ) public ComboMount( IMount[] parts )
{ {
m_parts = parts; this.parts = parts;
} }
// IMount implementation // IMount implementation
@ -31,9 +31,9 @@ public class ComboMount implements IMount
@Override @Override
public boolean exists( @Nonnull String path ) throws IOException public boolean exists( @Nonnull String path ) throws IOException
{ {
for( int i = m_parts.length - 1; i >= 0; --i ) for( int i = parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = parts[i];
if( part.exists( path ) ) if( part.exists( path ) )
{ {
return true; return true;
@ -45,9 +45,9 @@ public class ComboMount implements IMount
@Override @Override
public boolean isDirectory( @Nonnull String path ) throws IOException public boolean isDirectory( @Nonnull String path ) throws IOException
{ {
for( int i = m_parts.length - 1; i >= 0; --i ) for( int i = parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = parts[i];
if( part.isDirectory( path ) ) if( part.isDirectory( path ) )
{ {
return true; return true;
@ -62,9 +62,9 @@ public class ComboMount implements IMount
// Combine the lists from all the mounts // Combine the lists from all the mounts
List<String> foundFiles = null; List<String> foundFiles = null;
int foundDirs = 0; int foundDirs = 0;
for( int i = m_parts.length - 1; i >= 0; --i ) for( int i = parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = parts[i];
if( part.exists( path ) && part.isDirectory( path ) ) if( part.exists( path ) && part.isDirectory( path ) )
{ {
if( foundFiles == null ) if( foundFiles == null )
@ -102,9 +102,9 @@ public class ComboMount implements IMount
@Override @Override
public long getSize( @Nonnull String path ) throws IOException public long getSize( @Nonnull String path ) throws IOException
{ {
for( int i = m_parts.length - 1; i >= 0; --i ) for( int i = parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = parts[i];
if( part.exists( path ) ) if( part.exists( path ) )
{ {
return part.getSize( path ); return part.getSize( path );
@ -117,9 +117,9 @@ public class ComboMount implements IMount
@Override @Override
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
{ {
for( int i = m_parts.length - 1; i >= 0; --i ) for( int i = parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = parts[i];
if( part.exists( path ) && !part.isDirectory( path ) ) if( part.exists( path ) && !part.isDirectory( path ) )
{ {
return part.openForRead( path ); return part.openForRead( path );
@ -132,9 +132,9 @@ public class ComboMount implements IMount
@Override @Override
public BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException public BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
{ {
for( int i = m_parts.length - 1; i >= 0; --i ) for( int i = parts.length - 1; i >= 0; --i )
{ {
IMount part = m_parts[i]; IMount part = parts[i];
if( part.exists( path ) && !part.isDirectory( path ) ) if( part.exists( path ) && !part.isDirectory( path ) )
{ {
return part.getAttributes( path ); return part.getAttributes( path );

View File

@ -32,57 +32,57 @@ public class FileMount implements IWritableMount
private class WritableCountingChannel implements WritableByteChannel private class WritableCountingChannel implements WritableByteChannel
{ {
private final WritableByteChannel m_inner; private final WritableByteChannel inner;
long m_ignoredBytesLeft; long ignoredBytesLeft;
WritableCountingChannel( WritableByteChannel inner, long bytesToIgnore ) WritableCountingChannel( WritableByteChannel inner, long bytesToIgnore )
{ {
m_inner = inner; this.inner = inner;
m_ignoredBytesLeft = bytesToIgnore; ignoredBytesLeft = bytesToIgnore;
} }
@Override @Override
public int write( @Nonnull ByteBuffer b ) throws IOException public int write( @Nonnull ByteBuffer b ) throws IOException
{ {
count( b.remaining() ); count( b.remaining() );
return m_inner.write( b ); return inner.write( b );
} }
void count( long n ) throws IOException void count( long n ) throws IOException
{ {
m_ignoredBytesLeft -= n; ignoredBytesLeft -= n;
if( m_ignoredBytesLeft < 0 ) if( ignoredBytesLeft < 0 )
{ {
long newBytes = -m_ignoredBytesLeft; long newBytes = -ignoredBytesLeft;
m_ignoredBytesLeft = 0; ignoredBytesLeft = 0;
long bytesLeft = m_capacity - m_usedSpace; long bytesLeft = capacity - usedSpace;
if( newBytes > bytesLeft ) throw new IOException( "Out of space" ); if( newBytes > bytesLeft ) throw new IOException( "Out of space" );
m_usedSpace += newBytes; usedSpace += newBytes;
} }
} }
@Override @Override
public boolean isOpen() public boolean isOpen()
{ {
return m_inner.isOpen(); return inner.isOpen();
} }
@Override @Override
public void close() throws IOException public void close() throws IOException
{ {
m_inner.close(); inner.close();
} }
} }
private class SeekableCountingChannel extends WritableCountingChannel implements SeekableByteChannel private class SeekableCountingChannel extends WritableCountingChannel implements SeekableByteChannel
{ {
private final SeekableByteChannel m_inner; private final SeekableByteChannel inner;
SeekableCountingChannel( SeekableByteChannel inner, long bytesToIgnore ) SeekableCountingChannel( SeekableByteChannel inner, long bytesToIgnore )
{ {
super( inner, bytesToIgnore ); super( inner, bytesToIgnore );
m_inner = inner; this.inner = inner;
} }
@Override @Override
@ -94,17 +94,17 @@ public class FileMount implements IWritableMount
throw new IllegalArgumentException( "Cannot seek before the beginning of the stream" ); throw new IllegalArgumentException( "Cannot seek before the beginning of the stream" );
} }
long delta = newPosition - m_inner.position(); long delta = newPosition - inner.position();
if( delta < 0 ) if( delta < 0 )
{ {
m_ignoredBytesLeft -= delta; ignoredBytesLeft -= delta;
} }
else else
{ {
count( delta ); count( delta );
} }
return m_inner.position( newPosition ); return inner.position( newPosition );
} }
@Override @Override
@ -116,32 +116,32 @@ public class FileMount implements IWritableMount
@Override @Override
public int read( ByteBuffer dst ) throws ClosedChannelException public int read( ByteBuffer dst ) throws ClosedChannelException
{ {
if( !m_inner.isOpen() ) throw new ClosedChannelException(); if( !inner.isOpen() ) throw new ClosedChannelException();
throw new NonReadableChannelException(); throw new NonReadableChannelException();
} }
@Override @Override
public long position() throws IOException public long position() throws IOException
{ {
return m_inner.position(); return inner.position();
} }
@Override @Override
public long size() throws IOException public long size() throws IOException
{ {
return m_inner.size(); return inner.size();
} }
} }
private File m_rootPath; private final File rootPath;
private long m_capacity; private final long capacity;
private long m_usedSpace; private long usedSpace;
public FileMount( File rootPath, long capacity ) public FileMount( File rootPath, long capacity )
{ {
m_rootPath = rootPath; this.rootPath = rootPath;
m_capacity = capacity + MINIMUM_FILE_SIZE; this.capacity = capacity + MINIMUM_FILE_SIZE;
m_usedSpace = created() ? measureUsedSpace( m_rootPath ) : MINIMUM_FILE_SIZE; usedSpace = created() ? measureUsedSpace( this.rootPath ) : MINIMUM_FILE_SIZE;
} }
// IMount implementation // IMount implementation
@ -253,7 +253,7 @@ public class FileMount implements IWritableMount
if( file.mkdirs() ) if( file.mkdirs() )
{ {
m_usedSpace += dirsToCreate * MINIMUM_FILE_SIZE; usedSpace += dirsToCreate * MINIMUM_FILE_SIZE;
} }
else else
{ {
@ -290,7 +290,7 @@ public class FileMount implements IWritableMount
boolean success = file.delete(); boolean success = file.delete();
if( success ) if( success )
{ {
m_usedSpace -= Math.max( MINIMUM_FILE_SIZE, fileSize ); usedSpace -= Math.max( MINIMUM_FILE_SIZE, fileSize );
} }
else else
{ {
@ -308,13 +308,13 @@ public class FileMount implements IWritableMount
if( file.exists() ) if( file.exists() )
{ {
m_usedSpace -= Math.max( file.length(), MINIMUM_FILE_SIZE ); usedSpace -= Math.max( file.length(), MINIMUM_FILE_SIZE );
} }
else if( getRemainingSpace() < MINIMUM_FILE_SIZE ) else if( getRemainingSpace() < MINIMUM_FILE_SIZE )
{ {
throw new FileOperationException( path, "Out of space" ); throw new FileOperationException( path, "Out of space" );
} }
m_usedSpace += MINIMUM_FILE_SIZE; usedSpace += MINIMUM_FILE_SIZE;
return new SeekableCountingChannel( Files.newByteChannel( file.toPath(), WRITE_OPTIONS ), MINIMUM_FILE_SIZE ); return new SeekableCountingChannel( Files.newByteChannel( file.toPath(), WRITE_OPTIONS ), MINIMUM_FILE_SIZE );
} }
@ -342,31 +342,31 @@ public class FileMount implements IWritableMount
@Override @Override
public long getRemainingSpace() public long getRemainingSpace()
{ {
return Math.max( m_capacity - m_usedSpace, 0 ); return Math.max( capacity - usedSpace, 0 );
} }
@Nonnull @Nonnull
@Override @Override
public OptionalLong getCapacity() public OptionalLong getCapacity()
{ {
return OptionalLong.of( m_capacity - MINIMUM_FILE_SIZE ); return OptionalLong.of( capacity - MINIMUM_FILE_SIZE );
} }
private File getRealPath( String path ) private File getRealPath( String path )
{ {
return new File( m_rootPath, path ); return new File( rootPath, path );
} }
private boolean created() private boolean created()
{ {
return m_rootPath.exists(); return rootPath.exists();
} }
private void create() throws IOException private void create() throws IOException
{ {
if( !m_rootPath.exists() ) if( !rootPath.exists() )
{ {
boolean success = m_rootPath.mkdirs(); boolean success = rootPath.mkdirs();
if( !success ) if( !success )
{ {
throw new IOException( "Access denied" ); throw new IOException( "Access denied" );

View File

@ -37,11 +37,11 @@ public class FileSystem
*/ */
private static final int MAX_COPY_DEPTH = 128; private static final int MAX_COPY_DEPTH = 128;
private final FileSystemWrapperMount m_wrapper = new FileSystemWrapperMount( this ); private final FileSystemWrapperMount wrapper = new FileSystemWrapperMount( this );
private final Map<String, MountWrapper> mounts = new HashMap<>(); private final Map<String, MountWrapper> mounts = new HashMap<>();
private final HashMap<WeakReference<FileSystemWrapper<?>>, ChannelWrapper<?>> m_openFiles = new HashMap<>(); private final HashMap<WeakReference<FileSystemWrapper<?>>, ChannelWrapper<?>> openFiles = new HashMap<>();
private final ReferenceQueue<FileSystemWrapper<?>> m_openFileQueue = new ReferenceQueue<>(); private final ReferenceQueue<FileSystemWrapper<?>> openFileQueue = new ReferenceQueue<>();
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
{ {
@ -56,11 +56,11 @@ public class FileSystem
public void close() public void close()
{ {
// Close all dangling open files // Close all dangling open files
synchronized( m_openFiles ) synchronized( openFiles )
{ {
for( Closeable file : m_openFiles.values() ) IoUtil.closeQuietly( file ); for( Closeable file : openFiles.values() ) IoUtil.closeQuietly( file );
m_openFiles.clear(); openFiles.clear();
while( m_openFileQueue.poll() != null ) ; while( openFileQueue.poll() != null ) ;
} }
} }
@ -101,11 +101,11 @@ public class FileSystem
cleanup(); cleanup();
// Close any files which belong to this mount - don't want people writing to a disk after it's been ejected! // Close any files which belong to this mount - don't want people writing to a disk after it's been ejected!
// There's no point storing a Mount -> Wrapper[] map, as m_openFiles is small and unmount isn't called very // There's no point storing a Mount -> Wrapper[] map, as openFiles is small and unmount isn't called very
// often. // often.
synchronized( m_openFiles ) synchronized( openFiles )
{ {
for( Iterator<WeakReference<FileSystemWrapper<?>>> iterator = m_openFiles.keySet().iterator(); iterator.hasNext(); ) for( Iterator<WeakReference<FileSystemWrapper<?>>> iterator = openFiles.keySet().iterator(); iterator.hasNext(); )
{ {
WeakReference<FileSystemWrapper<?>> reference = iterator.next(); WeakReference<FileSystemWrapper<?>> reference = iterator.next();
FileSystemWrapper<?> wrapper = reference.get(); FileSystemWrapper<?> wrapper = reference.get();
@ -383,22 +383,22 @@ public class FileSystem
private void cleanup() private void cleanup()
{ {
synchronized( m_openFiles ) synchronized( openFiles )
{ {
Reference<?> ref; Reference<?> ref;
while( (ref = m_openFileQueue.poll()) != null ) while( (ref = openFileQueue.poll()) != null )
{ {
IoUtil.closeQuietly( m_openFiles.remove( ref ) ); IoUtil.closeQuietly( openFiles.remove( ref ) );
} }
} }
} }
private synchronized <T extends Closeable> FileSystemWrapper<T> openFile( @Nonnull MountWrapper mount, @Nonnull Channel channel, @Nonnull T file ) throws FileSystemException private synchronized <T extends Closeable> FileSystemWrapper<T> openFile( @Nonnull MountWrapper mount, @Nonnull Channel channel, @Nonnull T file ) throws FileSystemException
{ {
synchronized( m_openFiles ) synchronized( openFiles )
{ {
if( ComputerCraft.maximumFilesOpen > 0 && if( ComputerCraft.maximumFilesOpen > 0 &&
m_openFiles.size() >= ComputerCraft.maximumFilesOpen ) openFiles.size() >= ComputerCraft.maximumFilesOpen )
{ {
IoUtil.closeQuietly( file ); IoUtil.closeQuietly( file );
IoUtil.closeQuietly( channel ); IoUtil.closeQuietly( channel );
@ -406,17 +406,17 @@ public class FileSystem
} }
ChannelWrapper<T> channelWrapper = new ChannelWrapper<>( file, channel ); ChannelWrapper<T> channelWrapper = new ChannelWrapper<>( file, channel );
FileSystemWrapper<T> fsWrapper = new FileSystemWrapper<>( this, mount, channelWrapper, m_openFileQueue ); FileSystemWrapper<T> fsWrapper = new FileSystemWrapper<>( this, mount, channelWrapper, openFileQueue );
m_openFiles.put( fsWrapper.self, channelWrapper ); openFiles.put( fsWrapper.self, channelWrapper );
return fsWrapper; return fsWrapper;
} }
} }
void removeFile( FileSystemWrapper<?> handle ) void removeFile( FileSystemWrapper<?> handle )
{ {
synchronized( m_openFiles ) synchronized( openFiles )
{ {
m_openFiles.remove( handle.self ); openFiles.remove( handle.self );
} }
} }
@ -483,7 +483,7 @@ public class FileSystem
public IFileSystem getMountWrapper() public IFileSystem getMountWrapper()
{ {
return m_wrapper; return wrapper;
} }
private static String sanitizePath( String path ) private static String sanitizePath( String path )

View File

@ -17,11 +17,11 @@ import java.util.function.Function;
public class FileSystemWrapperMount implements IFileSystem public class FileSystemWrapperMount implements IFileSystem
{ {
private final FileSystem m_filesystem; private final FileSystem filesystem;
public FileSystemWrapperMount( FileSystem filesystem ) public FileSystemWrapperMount( FileSystem filesystem )
{ {
this.m_filesystem = filesystem; this.filesystem = filesystem;
} }
@Override @Override
@ -29,7 +29,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
m_filesystem.makeDir( path ); filesystem.makeDir( path );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -42,7 +42,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
m_filesystem.delete( path ); filesystem.delete( path );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -57,7 +57,7 @@ public class FileSystemWrapperMount implements IFileSystem
try try
{ {
// FIXME: Think of a better way of implementing this, so closing this will close on the computer. // FIXME: Think of a better way of implementing this, so closing this will close on the computer.
return m_filesystem.openForRead( path, Function.identity() ).get(); return filesystem.openForRead( path, Function.identity() ).get();
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -71,7 +71,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
return m_filesystem.openForWrite( path, false, Function.identity() ).get(); return filesystem.openForWrite( path, false, Function.identity() ).get();
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -85,7 +85,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
return m_filesystem.openForWrite( path, true, Function.identity() ).get(); return filesystem.openForWrite( path, true, Function.identity() ).get();
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -98,7 +98,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
return m_filesystem.getFreeSpace( "/" ); return filesystem.getFreeSpace( "/" );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -111,7 +111,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
return m_filesystem.exists( path ); return filesystem.exists( path );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -124,7 +124,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
return m_filesystem.isDir( path ); return filesystem.isDir( path );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -137,7 +137,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
Collections.addAll( contents, m_filesystem.list( path ) ); Collections.addAll( contents, filesystem.list( path ) );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -150,7 +150,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
return m_filesystem.getSize( path ); return filesystem.getSize( path );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -161,7 +161,7 @@ public class FileSystemWrapperMount implements IFileSystem
@Override @Override
public String combine( String path, String child ) public String combine( String path, String child )
{ {
return m_filesystem.combine( path, child ); return filesystem.combine( path, child );
} }
@Override @Override
@ -169,7 +169,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
m_filesystem.copy( from, to ); filesystem.copy( from, to );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {
@ -182,7 +182,7 @@ public class FileSystemWrapperMount implements IFileSystem
{ {
try try
{ {
m_filesystem.move( from, to ); filesystem.move( from, to );
} }
catch( FileSystemException e ) catch( FileSystemException e )
{ {

View File

@ -15,8 +15,8 @@ import java.util.List;
public class SubMount implements IMount public class SubMount implements IMount
{ {
private IMount parent; private final IMount parent;
private String subPath; private final String subPath;
public SubMount( IMount parent, String subPath ) public SubMount( IMount parent, String subPath )
{ {

View File

@ -50,29 +50,29 @@ public class CobaltLuaMachine implements ILuaMachine
private static final LuaMethod FUNCTION_METHOD = ( target, context, args ) -> ((ILuaFunction) target).call( args ); private static final LuaMethod FUNCTION_METHOD = ( target, context, args ) -> ((ILuaFunction) target).call( args );
private final Computer m_computer; private final Computer computer;
private final TimeoutState timeout; private final TimeoutState timeout;
private final TimeoutDebugHandler debug; private final TimeoutDebugHandler debug;
private final ILuaContext context = new CobaltLuaContext(); private final ILuaContext context = new CobaltLuaContext();
private LuaState m_state; private LuaState state;
private LuaTable m_globals; private LuaTable globals;
private LuaThread m_mainRoutine = null; private LuaThread mainRoutine = null;
private String m_eventFilter = null; private String eventFilter = null;
public CobaltLuaMachine( Computer computer, TimeoutState timeout ) public CobaltLuaMachine( Computer computer, TimeoutState timeout )
{ {
m_computer = computer; this.computer = computer;
this.timeout = timeout; this.timeout = timeout;
debug = new TimeoutDebugHandler(); debug = new TimeoutDebugHandler();
// Create an environment to run in // Create an environment to run in
LuaState state = m_state = LuaState.builder() LuaState state = this.state = LuaState.builder()
.resourceManipulator( new VoidResourceManipulator() ) .resourceManipulator( new VoidResourceManipulator() )
.debug( debug ) .debug( debug )
.coroutineExecutor( command -> { .coroutineExecutor( command -> {
Tracking.addValue( m_computer, TrackingField.COROUTINES_CREATED, 1 ); Tracking.addValue( this.computer, TrackingField.COROUTINES_CREATED, 1 );
COROUTINES.execute( () -> { COROUTINES.execute( () -> {
try try
{ {
@ -80,38 +80,38 @@ public class CobaltLuaMachine implements ILuaMachine
} }
finally finally
{ {
Tracking.addValue( m_computer, TrackingField.COROUTINES_DISPOSED, 1 ); Tracking.addValue( this.computer, TrackingField.COROUTINES_DISPOSED, 1 );
} }
} ); } );
} ) } )
.build(); .build();
m_globals = new LuaTable(); globals = new LuaTable();
state.setupThread( m_globals ); state.setupThread( globals );
// Add basic libraries // Add basic libraries
m_globals.load( state, new BaseLib() ); globals.load( state, new BaseLib() );
m_globals.load( state, new TableLib() ); globals.load( state, new TableLib() );
m_globals.load( state, new StringLib() ); globals.load( state, new StringLib() );
m_globals.load( state, new MathLib() ); globals.load( state, new MathLib() );
m_globals.load( state, new CoroutineLib() ); globals.load( state, new CoroutineLib() );
m_globals.load( state, new Bit32Lib() ); globals.load( state, new Bit32Lib() );
m_globals.load( state, new Utf8Lib() ); globals.load( state, new Utf8Lib() );
if( ComputerCraft.debugEnable ) m_globals.load( state, new DebugLib() ); if( ComputerCraft.debugEnable ) globals.load( state, new DebugLib() );
// Remove globals we don't want to expose // Remove globals we don't want to expose
m_globals.rawset( "collectgarbage", Constants.NIL ); globals.rawset( "collectgarbage", Constants.NIL );
m_globals.rawset( "dofile", Constants.NIL ); globals.rawset( "dofile", Constants.NIL );
m_globals.rawset( "loadfile", Constants.NIL ); globals.rawset( "loadfile", Constants.NIL );
m_globals.rawset( "print", Constants.NIL ); globals.rawset( "print", Constants.NIL );
// Add version globals // Add version globals
m_globals.rawset( "_VERSION", valueOf( "Lua 5.1" ) ); globals.rawset( "_VERSION", valueOf( "Lua 5.1" ) );
m_globals.rawset( "_HOST", valueOf( computer.getAPIEnvironment().getComputerEnvironment().getHostString() ) ); globals.rawset( "_HOST", valueOf( computer.getAPIEnvironment().getComputerEnvironment().getHostString() ) );
m_globals.rawset( "_CC_DEFAULT_SETTINGS", valueOf( ComputerCraft.defaultComputerSettings ) ); globals.rawset( "_CC_DEFAULT_SETTINGS", valueOf( ComputerCraft.defaultComputerSettings ) );
if( ComputerCraft.disableLua51Features ) if( ComputerCraft.disableLua51Features )
{ {
m_globals.rawset( "_CC_DISABLE_LUA51_FEATURES", Constants.TRUE ); globals.rawset( "_CC_DISABLE_LUA51_FEATURES", Constants.TRUE );
} }
} }
@ -127,19 +127,19 @@ public class CobaltLuaMachine implements ILuaMachine
} }
String[] names = api.getNames(); String[] names = api.getNames();
for( String name : names ) m_globals.rawset( name, table ); for( String name : names ) globals.rawset( name, table );
} }
@Override @Override
public MachineResult loadBios( @Nonnull InputStream bios ) public MachineResult loadBios( @Nonnull InputStream bios )
{ {
// Begin executing a file (ie, the bios) // Begin executing a file (ie, the bios)
if( m_mainRoutine != null ) return MachineResult.OK; if( mainRoutine != null ) return MachineResult.OK;
try try
{ {
LuaFunction value = LoadState.load( m_state, bios, "@bios.lua", m_globals ); LuaFunction value = LoadState.load( state, bios, "@bios.lua", globals );
m_mainRoutine = new LuaThread( m_state, value, m_globals ); mainRoutine = new LuaThread( state, value, globals );
return MachineResult.OK; return MachineResult.OK;
} }
catch( CompileException e ) catch( CompileException e )
@ -158,9 +158,9 @@ public class CobaltLuaMachine implements ILuaMachine
@Override @Override
public MachineResult handleEvent( String eventName, Object[] arguments ) public MachineResult handleEvent( String eventName, Object[] arguments )
{ {
if( m_mainRoutine == null ) return MachineResult.OK; if( mainRoutine == null ) return MachineResult.OK;
if( m_eventFilter != null && eventName != null && !eventName.equals( m_eventFilter ) && !eventName.equals( "terminate" ) ) if( eventFilter != null && eventName != null && !eventName.equals( eventFilter ) && !eventName.equals( "terminate" ) )
{ {
return MachineResult.OK; return MachineResult.OK;
} }
@ -178,17 +178,17 @@ public class CobaltLuaMachine implements ILuaMachine
} }
// Resume the current thread, or the main one when first starting off. // Resume the current thread, or the main one when first starting off.
LuaThread thread = m_state.getCurrentThread(); LuaThread thread = state.getCurrentThread();
if( thread == null || thread == m_state.getMainThread() ) thread = m_mainRoutine; if( thread == null || thread == state.getMainThread() ) thread = mainRoutine;
Varargs results = LuaThread.run( thread, resumeArgs ); Varargs results = LuaThread.run( thread, resumeArgs );
if( timeout.isHardAborted() ) throw HardAbortError.INSTANCE; if( timeout.isHardAborted() ) throw HardAbortError.INSTANCE;
if( results == null ) return MachineResult.PAUSE; if( results == null ) return MachineResult.PAUSE;
LuaValue filter = results.first(); LuaValue filter = results.first();
m_eventFilter = filter.isString() ? filter.toString() : null; eventFilter = filter.isString() ? filter.toString() : null;
if( m_mainRoutine.getStatus().equals( "dead" ) ) if( mainRoutine.getStatus().equals( "dead" ) )
{ {
close(); close();
return MachineResult.GENERIC_ERROR; return MachineResult.GENERIC_ERROR;
@ -214,13 +214,13 @@ public class CobaltLuaMachine implements ILuaMachine
@Override @Override
public void close() public void close()
{ {
LuaState state = m_state; LuaState state = this.state;
if( state == null ) return; if( state == null ) return;
state.abandon(); state.abandon();
m_mainRoutine = null; mainRoutine = null;
m_state = null; this.state = null;
m_globals = null; globals = null;
} }
@Nullable @Nullable
@ -457,7 +457,7 @@ public class CobaltLuaMachine implements ILuaMachine
if( (count = (count + 1) & 127) == 0 ) if( (count = (count + 1) & 127) == 0 )
{ {
// If we've been hard aborted or closed then abort. // If we've been hard aborted or closed then abort.
if( timeout.isHardAborted() || m_state == null ) throw HardAbortError.INSTANCE; if( timeout.isHardAborted() || state == null ) throw HardAbortError.INSTANCE;
timeout.refresh(); timeout.refresh();
if( timeout.isPaused() ) if( timeout.isPaused() )
@ -483,7 +483,7 @@ public class CobaltLuaMachine implements ILuaMachine
public void poll() throws LuaError public void poll() throws LuaError
{ {
// If we've been hard aborted or closed then abort. // If we've been hard aborted or closed then abort.
LuaState state = m_state; LuaState state = CobaltLuaMachine.this.state;
if( timeout.isHardAborted() || state == null ) throw HardAbortError.INSTANCE; if( timeout.isHardAborted() || state == null ) throw HardAbortError.INSTANCE;
timeout.refresh(); timeout.refresh();
@ -526,26 +526,26 @@ public class CobaltLuaMachine implements ILuaMachine
eventArguments[0] = taskID; eventArguments[0] = taskID;
eventArguments[1] = true; eventArguments[1] = true;
System.arraycopy( results, 0, eventArguments, 2, results.length ); System.arraycopy( results, 0, eventArguments, 2, results.length );
m_computer.queueEvent( "task_complete", eventArguments ); computer.queueEvent( "task_complete", eventArguments );
} }
else else
{ {
m_computer.queueEvent( "task_complete", new Object[] { taskID, true } ); computer.queueEvent( "task_complete", new Object[] { taskID, true } );
} }
} }
catch( LuaException e ) catch( LuaException e )
{ {
m_computer.queueEvent( "task_complete", new Object[] { taskID, false, e.getMessage() } ); computer.queueEvent( "task_complete", new Object[] { taskID, false, e.getMessage() } );
} }
catch( Throwable t ) catch( Throwable t )
{ {
if( ComputerCraft.logComputerErrors ) ComputerCraft.log.error( "Error running task", t ); if( ComputerCraft.logComputerErrors ) ComputerCraft.log.error( "Error running task", t );
m_computer.queueEvent( "task_complete", new Object[] { computer.queueEvent( "task_complete", new Object[] {
taskID, false, "Java Exception Thrown: " + t, taskID, false, "Java Exception Thrown: " + t,
} ); } );
} }
}; };
if( m_computer.queueMainThread( iTask ) ) if( computer.queueMainThread( iTask ) )
{ {
return taskID; return taskID;
} }

View File

@ -16,20 +16,20 @@ public class Terminal
{ {
private static final String base16 = "0123456789abcdef"; private static final String base16 = "0123456789abcdef";
private int m_cursorX = 0; private int cursorX = 0;
private int m_cursorY = 0; private int cursorY = 0;
private boolean m_cursorBlink = false; private boolean cursorBlink = false;
private int m_cursorColour = 0; private int cursorColour = 0;
private int m_cursorBackgroundColour = 15; private int cursorBackgroundColour = 15;
private int m_width; private int width;
private int m_height; private int height;
private TextBuffer[] m_text; private TextBuffer[] text;
private TextBuffer[] m_textColour; private TextBuffer[] textColour;
private TextBuffer[] m_backgroundColour; private TextBuffer[] backgroundColour;
private final Palette m_palette = new Palette(); private final Palette palette = new Palette();
private final Runnable onChanged; private final Runnable onChanged;
@ -40,84 +40,84 @@ public class Terminal
public Terminal( int width, int height, Runnable changedCallback ) public Terminal( int width, int height, Runnable changedCallback )
{ {
m_width = width; this.width = width;
m_height = height; this.height = height;
onChanged = changedCallback; onChanged = changedCallback;
m_text = new TextBuffer[m_height]; text = new TextBuffer[this.height];
m_textColour = new TextBuffer[m_height]; textColour = new TextBuffer[this.height];
m_backgroundColour = new TextBuffer[m_height]; backgroundColour = new TextBuffer[this.height];
for( int i = 0; i < m_height; i++ ) for( int i = 0; i < this.height; i++ )
{ {
m_text[i] = new TextBuffer( ' ', m_width ); text[i] = new TextBuffer( ' ', this.width );
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
} }
} }
public synchronized void reset() public synchronized void reset()
{ {
m_cursorColour = 0; cursorColour = 0;
m_cursorBackgroundColour = 15; cursorBackgroundColour = 15;
m_cursorX = 0; cursorX = 0;
m_cursorY = 0; cursorY = 0;
m_cursorBlink = false; cursorBlink = false;
clear(); clear();
setChanged(); setChanged();
m_palette.resetColours(); palette.resetColours();
} }
public int getWidth() public int getWidth()
{ {
return m_width; return width;
} }
public int getHeight() public int getHeight()
{ {
return m_height; return height;
} }
public synchronized void resize( int width, int height ) public synchronized void resize( int width, int height )
{ {
if( width == m_width && height == m_height ) if( width == this.width && height == this.height )
{ {
return; return;
} }
int oldHeight = m_height; int oldHeight = this.height;
int oldWidth = m_width; int oldWidth = this.width;
TextBuffer[] oldText = m_text; TextBuffer[] oldText = text;
TextBuffer[] oldTextColour = m_textColour; TextBuffer[] oldTextColour = textColour;
TextBuffer[] oldBackgroundColour = m_backgroundColour; TextBuffer[] oldBackgroundColour = backgroundColour;
m_width = width; this.width = width;
m_height = height; this.height = height;
m_text = new TextBuffer[m_height]; text = new TextBuffer[this.height];
m_textColour = new TextBuffer[m_height]; textColour = new TextBuffer[this.height];
m_backgroundColour = new TextBuffer[m_height]; backgroundColour = new TextBuffer[this.height];
for( int i = 0; i < m_height; i++ ) for( int i = 0; i < this.height; i++ )
{ {
if( i >= oldHeight ) if( i >= oldHeight )
{ {
m_text[i] = new TextBuffer( ' ', m_width ); text[i] = new TextBuffer( ' ', this.width );
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
} }
else if( m_width == oldWidth ) else if( this.width == oldWidth )
{ {
m_text[i] = oldText[i]; text[i] = oldText[i];
m_textColour[i] = oldTextColour[i]; textColour[i] = oldTextColour[i];
m_backgroundColour[i] = oldBackgroundColour[i]; backgroundColour[i] = oldBackgroundColour[i];
} }
else else
{ {
m_text[i] = new TextBuffer( ' ', m_width ); text[i] = new TextBuffer( ' ', this.width );
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
m_text[i].write( oldText[i] ); text[i].write( oldText[i] );
m_textColour[i].write( oldTextColour[i] ); textColour[i].write( oldTextColour[i] );
m_backgroundColour[i].write( oldBackgroundColour[i] ); backgroundColour[i].write( oldBackgroundColour[i] );
} }
} }
setChanged(); setChanged();
@ -125,94 +125,94 @@ public class Terminal
public void setCursorPos( int x, int y ) public void setCursorPos( int x, int y )
{ {
if( m_cursorX != x || m_cursorY != y ) if( cursorX != x || cursorY != y )
{ {
m_cursorX = x; cursorX = x;
m_cursorY = y; cursorY = y;
setChanged(); setChanged();
} }
} }
public void setCursorBlink( boolean blink ) public void setCursorBlink( boolean blink )
{ {
if( m_cursorBlink != blink ) if( cursorBlink != blink )
{ {
m_cursorBlink = blink; cursorBlink = blink;
setChanged(); setChanged();
} }
} }
public void setTextColour( int colour ) public void setTextColour( int colour )
{ {
if( m_cursorColour != colour ) if( cursorColour != colour )
{ {
m_cursorColour = colour; cursorColour = colour;
setChanged(); setChanged();
} }
} }
public void setBackgroundColour( int colour ) public void setBackgroundColour( int colour )
{ {
if( m_cursorBackgroundColour != colour ) if( cursorBackgroundColour != colour )
{ {
m_cursorBackgroundColour = colour; cursorBackgroundColour = colour;
setChanged(); setChanged();
} }
} }
public int getCursorX() public int getCursorX()
{ {
return m_cursorX; return cursorX;
} }
public int getCursorY() public int getCursorY()
{ {
return m_cursorY; return cursorY;
} }
public boolean getCursorBlink() public boolean getCursorBlink()
{ {
return m_cursorBlink; return cursorBlink;
} }
public int getTextColour() public int getTextColour()
{ {
return m_cursorColour; return cursorColour;
} }
public int getBackgroundColour() public int getBackgroundColour()
{ {
return m_cursorBackgroundColour; return cursorBackgroundColour;
} }
@Nonnull @Nonnull
public Palette getPalette() public Palette getPalette()
{ {
return m_palette; return palette;
} }
public synchronized void blit( String text, String textColour, String backgroundColour ) public synchronized void blit( String text, String textColour, String backgroundColour )
{ {
int x = m_cursorX; int x = cursorX;
int y = m_cursorY; int y = cursorY;
if( y >= 0 && y < m_height ) if( y >= 0 && y < height )
{ {
m_text[y].write( text, x ); this.text[y].write( text, x );
m_textColour[y].write( textColour, x ); this.textColour[y].write( textColour, x );
m_backgroundColour[y].write( backgroundColour, x ); this.backgroundColour[y].write( backgroundColour, x );
setChanged(); setChanged();
} }
} }
public synchronized void write( String text ) public synchronized void write( String text )
{ {
int x = m_cursorX; int x = cursorX;
int y = m_cursorY; int y = cursorY;
if( y >= 0 && y < m_height ) if( y >= 0 && y < height )
{ {
m_text[y].write( text, x ); this.text[y].write( text, x );
m_textColour[y].fill( base16.charAt( m_cursorColour ), x, x + text.length() ); textColour[y].fill( base16.charAt( cursorColour ), x, x + text.length() );
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() ); backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ), x, x + text.length() );
setChanged(); setChanged();
} }
} }
@ -221,86 +221,86 @@ public class Terminal
{ {
if( yDiff != 0 ) if( yDiff != 0 )
{ {
TextBuffer[] newText = new TextBuffer[m_height]; TextBuffer[] newText = new TextBuffer[height];
TextBuffer[] newTextColour = new TextBuffer[m_height]; TextBuffer[] newTextColour = new TextBuffer[height];
TextBuffer[] newBackgroundColour = new TextBuffer[m_height]; TextBuffer[] newBackgroundColour = new TextBuffer[height];
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
int oldY = y + yDiff; int oldY = y + yDiff;
if( oldY >= 0 && oldY < m_height ) if( oldY >= 0 && oldY < height )
{ {
newText[y] = m_text[oldY]; newText[y] = text[oldY];
newTextColour[y] = m_textColour[oldY]; newTextColour[y] = textColour[oldY];
newBackgroundColour[y] = m_backgroundColour[oldY]; newBackgroundColour[y] = backgroundColour[oldY];
} }
else else
{ {
newText[y] = new TextBuffer( ' ', m_width ); newText[y] = new TextBuffer( ' ', width );
newTextColour[y] = new TextBuffer( base16.charAt( m_cursorColour ), m_width ); newTextColour[y] = new TextBuffer( base16.charAt( cursorColour ), width );
newBackgroundColour[y] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width ); newBackgroundColour[y] = new TextBuffer( base16.charAt( cursorBackgroundColour ), width );
} }
} }
m_text = newText; text = newText;
m_textColour = newTextColour; textColour = newTextColour;
m_backgroundColour = newBackgroundColour; backgroundColour = newBackgroundColour;
setChanged(); setChanged();
} }
} }
public synchronized void clear() public synchronized void clear()
{ {
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
m_text[y].fill( ' ' ); text[y].fill( ' ' );
m_textColour[y].fill( base16.charAt( m_cursorColour ) ); textColour[y].fill( base16.charAt( cursorColour ) );
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) ); backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ) );
} }
setChanged(); setChanged();
} }
public synchronized void clearLine() public synchronized void clearLine()
{ {
int y = m_cursorY; int y = cursorY;
if( y >= 0 && y < m_height ) if( y >= 0 && y < height )
{ {
m_text[y].fill( ' ' ); text[y].fill( ' ' );
m_textColour[y].fill( base16.charAt( m_cursorColour ) ); textColour[y].fill( base16.charAt( cursorColour ) );
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) ); backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ) );
setChanged(); setChanged();
} }
} }
public synchronized TextBuffer getLine( int y ) public synchronized TextBuffer getLine( int y )
{ {
if( y >= 0 && y < m_height ) if( y >= 0 && y < height )
{ {
return m_text[y]; return text[y];
} }
return null; return null;
} }
public synchronized void setLine( int y, String text, String textColour, String backgroundColour ) public synchronized void setLine( int y, String text, String textColour, String backgroundColour )
{ {
m_text[y].write( text ); this.text[y].write( text );
m_textColour[y].write( textColour ); this.textColour[y].write( textColour );
m_backgroundColour[y].write( backgroundColour ); this.backgroundColour[y].write( backgroundColour );
setChanged(); setChanged();
} }
public synchronized TextBuffer getTextColourLine( int y ) public synchronized TextBuffer getTextColourLine( int y )
{ {
if( y >= 0 && y < m_height ) if( y >= 0 && y < height )
{ {
return m_textColour[y]; return textColour[y];
} }
return null; return null;
} }
public synchronized TextBuffer getBackgroundColourLine( int y ) public synchronized TextBuffer getBackgroundColourLine( int y )
{ {
if( y >= 0 && y < m_height ) if( y >= 0 && y < height )
{ {
return m_backgroundColour[y]; return backgroundColour[y];
} }
return null; return null;
} }
@ -312,18 +312,18 @@ public class Terminal
public synchronized void write( PacketBuffer buffer ) public synchronized void write( PacketBuffer buffer )
{ {
buffer.writeInt( m_cursorX ); buffer.writeInt( cursorX );
buffer.writeInt( m_cursorY ); buffer.writeInt( cursorY );
buffer.writeBoolean( m_cursorBlink ); buffer.writeBoolean( cursorBlink );
buffer.writeByte( m_cursorBackgroundColour << 4 | m_cursorColour ); buffer.writeByte( cursorBackgroundColour << 4 | cursorColour );
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
TextBuffer text = m_text[y]; TextBuffer text = this.text[y];
TextBuffer textColour = m_textColour[y]; TextBuffer textColour = this.textColour[y];
TextBuffer backColour = m_backgroundColour[y]; TextBuffer backColour = backgroundColour[y];
for( int x = 0; x < m_width; x++ ) for( int x = 0; x < width; x++ )
{ {
buffer.writeByte( text.charAt( x ) & 0xFF ); buffer.writeByte( text.charAt( x ) & 0xFF );
buffer.writeByte( getColour( buffer.writeByte( getColour(
@ -333,26 +333,26 @@ public class Terminal
} }
} }
m_palette.write( buffer ); palette.write( buffer );
} }
public synchronized void read( PacketBuffer buffer ) public synchronized void read( PacketBuffer buffer )
{ {
m_cursorX = buffer.readInt(); cursorX = buffer.readInt();
m_cursorY = buffer.readInt(); cursorY = buffer.readInt();
m_cursorBlink = buffer.readBoolean(); cursorBlink = buffer.readBoolean();
byte cursorColour = buffer.readByte(); byte cursorColour = buffer.readByte();
m_cursorBackgroundColour = (cursorColour >> 4) & 0xF; cursorBackgroundColour = (cursorColour >> 4) & 0xF;
m_cursorColour = cursorColour & 0xF; this.cursorColour = cursorColour & 0xF;
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
TextBuffer text = m_text[y]; TextBuffer text = this.text[y];
TextBuffer textColour = m_textColour[y]; TextBuffer textColour = this.textColour[y];
TextBuffer backColour = m_backgroundColour[y]; TextBuffer backColour = backgroundColour[y];
for( int x = 0; x < m_width; x++ ) for( int x = 0; x < width; x++ )
{ {
text.setChar( x, (char) (buffer.readByte() & 0xFF) ); text.setChar( x, (char) (buffer.readByte() & 0xFF) );
@ -362,56 +362,56 @@ public class Terminal
} }
} }
m_palette.read( buffer ); palette.read( buffer );
setChanged(); setChanged();
} }
public synchronized CompoundNBT writeToNBT( CompoundNBT nbt ) public synchronized CompoundNBT writeToNBT( CompoundNBT nbt )
{ {
nbt.putInt( "term_cursorX", m_cursorX ); nbt.putInt( "term_cursorX", cursorX );
nbt.putInt( "term_cursorY", m_cursorY ); nbt.putInt( "term_cursorY", cursorY );
nbt.putBoolean( "term_cursorBlink", m_cursorBlink ); nbt.putBoolean( "term_cursorBlink", cursorBlink );
nbt.putInt( "term_textColour", m_cursorColour ); nbt.putInt( "term_textColour", cursorColour );
nbt.putInt( "term_bgColour", m_cursorBackgroundColour ); nbt.putInt( "term_bgColour", cursorBackgroundColour );
for( int n = 0; n < m_height; n++ ) for( int n = 0; n < height; n++ )
{ {
nbt.putString( "term_text_" + n, m_text[n].toString() ); nbt.putString( "term_text_" + n, text[n].toString() );
nbt.putString( "term_textColour_" + n, m_textColour[n].toString() ); nbt.putString( "term_textColour_" + n, textColour[n].toString() );
nbt.putString( "term_textBgColour_" + n, m_backgroundColour[n].toString() ); nbt.putString( "term_textBgColour_" + n, backgroundColour[n].toString() );
} }
m_palette.writeToNBT( nbt ); palette.writeToNBT( nbt );
return nbt; return nbt;
} }
public synchronized void readFromNBT( CompoundNBT nbt ) public synchronized void readFromNBT( CompoundNBT nbt )
{ {
m_cursorX = nbt.getInt( "term_cursorX" ); cursorX = nbt.getInt( "term_cursorX" );
m_cursorY = nbt.getInt( "term_cursorY" ); cursorY = nbt.getInt( "term_cursorY" );
m_cursorBlink = nbt.getBoolean( "term_cursorBlink" ); cursorBlink = nbt.getBoolean( "term_cursorBlink" );
m_cursorColour = nbt.getInt( "term_textColour" ); cursorColour = nbt.getInt( "term_textColour" );
m_cursorBackgroundColour = nbt.getInt( "term_bgColour" ); cursorBackgroundColour = nbt.getInt( "term_bgColour" );
for( int n = 0; n < m_height; n++ ) for( int n = 0; n < height; n++ )
{ {
m_text[n].fill( ' ' ); text[n].fill( ' ' );
if( nbt.contains( "term_text_" + n ) ) if( nbt.contains( "term_text_" + n ) )
{ {
m_text[n].write( nbt.getString( "term_text_" + n ) ); text[n].write( nbt.getString( "term_text_" + n ) );
} }
m_textColour[n].fill( base16.charAt( m_cursorColour ) ); textColour[n].fill( base16.charAt( cursorColour ) );
if( nbt.contains( "term_textColour_" + n ) ) if( nbt.contains( "term_textColour_" + n ) )
{ {
m_textColour[n].write( nbt.getString( "term_textColour_" + n ) ); textColour[n].write( nbt.getString( "term_textColour_" + n ) );
} }
m_backgroundColour[n].fill( base16.charAt( m_cursorBackgroundColour ) ); backgroundColour[n].fill( base16.charAt( cursorBackgroundColour ) );
if( nbt.contains( "term_textBgColour_" + n ) ) if( nbt.contains( "term_textBgColour_" + n ) )
{ {
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) ); backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
} }
} }
m_palette.readFromNBT( nbt ); palette.readFromNBT( nbt );
setChanged(); setChanged();
} }

View File

@ -7,14 +7,14 @@ package dan200.computercraft.core.terminal;
public class TextBuffer public class TextBuffer
{ {
private final char[] m_text; private final char[] text;
public TextBuffer( char c, int length ) public TextBuffer( char c, int length )
{ {
m_text = new char[length]; text = new char[length];
for( int i = 0; i < length; i++ ) for( int i = 0; i < length; i++ )
{ {
m_text[i] = c; text[i] = c;
} }
} }
@ -26,12 +26,12 @@ public class TextBuffer
public TextBuffer( String text, int repetitions ) public TextBuffer( String text, int repetitions )
{ {
int textLength = text.length(); int textLength = text.length();
m_text = new char[textLength * repetitions]; this.text = new char[textLength * repetitions];
for( int i = 0; i < repetitions; i++ ) for( int i = 0; i < repetitions; i++ )
{ {
for( int j = 0; j < textLength; j++ ) for( int j = 0; j < textLength; j++ )
{ {
m_text[j + i * textLength] = text.charAt( j ); this.text[j + i * textLength] = text.charAt( j );
} }
} }
} }
@ -44,37 +44,37 @@ public class TextBuffer
public TextBuffer( TextBuffer text, int repetitions ) public TextBuffer( TextBuffer text, int repetitions )
{ {
int textLength = text.length(); int textLength = text.length();
m_text = new char[textLength * repetitions]; this.text = new char[textLength * repetitions];
for( int i = 0; i < repetitions; i++ ) for( int i = 0; i < repetitions; i++ )
{ {
for( int j = 0; j < textLength; j++ ) for( int j = 0; j < textLength; j++ )
{ {
m_text[j + i * textLength] = text.charAt( j ); this.text[j + i * textLength] = text.charAt( j );
} }
} }
} }
public int length() public int length()
{ {
return m_text.length; return text.length;
} }
public String read() public String read()
{ {
return read( 0, m_text.length ); return read( 0, text.length );
} }
public String read( int start ) public String read( int start )
{ {
return read( start, m_text.length ); return read( start, text.length );
} }
public String read( int start, int end ) public String read( int start, int end )
{ {
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, m_text.length ); end = Math.min( end, text.length );
int textLength = Math.max( end - start, 0 ); int textLength = Math.max( end - start, 0 );
return new String( m_text, start, textLength ); return new String( text, start, textLength );
} }
public void write( String text ) public void write( String text )
@ -92,10 +92,10 @@ public class TextBuffer
int pos = start; int pos = start;
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, pos + text.length() ); end = Math.min( end, pos + text.length() );
end = Math.min( end, m_text.length ); end = Math.min( end, this.text.length );
for( int i = start; i < end; i++ ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( i - pos ); this.text[i] = text.charAt( i - pos );
} }
} }
@ -114,94 +114,94 @@ public class TextBuffer
int pos = start; int pos = start;
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, pos + text.length() ); end = Math.min( end, pos + text.length() );
end = Math.min( end, m_text.length ); end = Math.min( end, this.text.length );
for( int i = start; i < end; i++ ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( i - pos ); this.text[i] = text.charAt( i - pos );
} }
} }
public void fill( char c ) public void fill( char c )
{ {
fill( c, 0, m_text.length ); fill( c, 0, text.length );
} }
public void fill( char c, int start ) public void fill( char c, int start )
{ {
fill( c, start, m_text.length ); fill( c, start, text.length );
} }
public void fill( char c, int start, int end ) public void fill( char c, int start, int end )
{ {
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, m_text.length ); end = Math.min( end, text.length );
for( int i = start; i < end; i++ ) for( int i = start; i < end; i++ )
{ {
m_text[i] = c; text[i] = c;
} }
} }
public void fill( String text ) public void fill( String text )
{ {
fill( text, 0, m_text.length ); fill( text, 0, this.text.length );
} }
public void fill( String text, int start ) public void fill( String text, int start )
{ {
fill( text, start, m_text.length ); fill( text, start, this.text.length );
} }
public void fill( String text, int start, int end ) public void fill( String text, int start, int end )
{ {
int pos = start; int pos = start;
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, m_text.length ); end = Math.min( end, this.text.length );
int textLength = text.length(); int textLength = text.length();
for( int i = start; i < end; i++ ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( (i - pos) % textLength ); this.text[i] = text.charAt( (i - pos) % textLength );
} }
} }
public void fill( TextBuffer text ) public void fill( TextBuffer text )
{ {
fill( text, 0, m_text.length ); fill( text, 0, this.text.length );
} }
public void fill( TextBuffer text, int start ) public void fill( TextBuffer text, int start )
{ {
fill( text, start, m_text.length ); fill( text, start, this.text.length );
} }
public void fill( TextBuffer text, int start, int end ) public void fill( TextBuffer text, int start, int end )
{ {
int pos = start; int pos = start;
start = Math.max( start, 0 ); start = Math.max( start, 0 );
end = Math.min( end, m_text.length ); end = Math.min( end, this.text.length );
int textLength = text.length(); int textLength = text.length();
for( int i = start; i < end; i++ ) for( int i = start; i < end; i++ )
{ {
m_text[i] = text.charAt( (i - pos) % textLength ); this.text[i] = text.charAt( (i - pos) % textLength );
} }
} }
public char charAt( int i ) public char charAt( int i )
{ {
return m_text[i]; return text[i];
} }
public void setChar( int i, char c ) public void setChar( int i, char c )
{ {
if( i >= 0 && i < m_text.length ) if( i >= 0 && i < text.length )
{ {
m_text[i] = c; text[i] = c;
} }
} }
public String toString() public String toString()
{ {
return new String( m_text ); return new String( text );
} }
} }

View File

@ -31,7 +31,7 @@ import static dan200.computercraft.shared.command.builder.HelpingArgumentBuilder
*/ */
public class CommandBuilder<S> implements CommandNodeBuilder<S, Command<S>> public class CommandBuilder<S> implements CommandNodeBuilder<S, Command<S>>
{ {
private List<ArgumentBuilder<S, ?>> args = new ArrayList<>(); private final List<ArgumentBuilder<S, ?>> args = new ArrayList<>();
private Predicate<S> requires; private Predicate<S> requires;
public static CommandBuilder<CommandSource> args() public static CommandBuilder<CommandSource> args()

View File

@ -10,21 +10,21 @@ import dan200.computercraft.shared.network.client.TerminalState;
public class ClientTerminal implements ITerminal public class ClientTerminal implements ITerminal
{ {
private boolean m_colour; private boolean colour;
private Terminal m_terminal; private Terminal terminal;
private boolean m_terminalChanged; private boolean terminalChanged;
public ClientTerminal( boolean colour ) public ClientTerminal( boolean colour )
{ {
m_colour = colour; this.colour = colour;
m_terminal = null; terminal = null;
m_terminalChanged = false; terminalChanged = false;
} }
public boolean pollTerminalChanged() public boolean pollTerminalChanged()
{ {
boolean changed = m_terminalChanged; boolean changed = terminalChanged;
m_terminalChanged = false; terminalChanged = false;
return changed; return changed;
} }
@ -33,22 +33,22 @@ public class ClientTerminal implements ITerminal
@Override @Override
public Terminal getTerminal() public Terminal getTerminal()
{ {
return m_terminal; return terminal;
} }
@Override @Override
public boolean isColour() public boolean isColour()
{ {
return m_colour; return colour;
} }
public void read( TerminalState state ) public void read( TerminalState state )
{ {
m_colour = state.colour; colour = state.colour;
if( state.hasTerminal() ) if( state.hasTerminal() )
{ {
resizeTerminal( state.width, state.height ); resizeTerminal( state.width, state.height );
state.apply( m_terminal ); state.apply( terminal );
} }
else else
{ {
@ -58,23 +58,23 @@ public class ClientTerminal implements ITerminal
private void resizeTerminal( int width, int height ) private void resizeTerminal( int width, int height )
{ {
if( m_terminal == null ) if( terminal == null )
{ {
m_terminal = new Terminal( width, height, () -> m_terminalChanged = true ); terminal = new Terminal( width, height, () -> terminalChanged = true );
m_terminalChanged = true; terminalChanged = true;
} }
else else
{ {
m_terminal.resize( width, height ); terminal.resize( width, height );
} }
} }
private void deleteTerminal() private void deleteTerminal()
{ {
if( m_terminal != null ) if( terminal != null )
{ {
m_terminal = null; terminal = null;
m_terminalChanged = true; terminalChanged = true;
} }
} }
} }

View File

@ -12,74 +12,74 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ServerTerminal implements ITerminal public class ServerTerminal implements ITerminal
{ {
private final boolean m_colour; private final boolean colour;
private Terminal m_terminal; private Terminal terminal;
private final AtomicBoolean m_terminalChanged = new AtomicBoolean( false ); private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
private boolean m_terminalChangedLastFrame = false; private boolean terminalChangedLastFrame = false;
public ServerTerminal( boolean colour ) public ServerTerminal( boolean colour )
{ {
m_colour = colour; this.colour = colour;
m_terminal = null; terminal = null;
} }
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight ) public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
{ {
m_colour = colour; this.colour = colour;
m_terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged ); terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
} }
protected void resize( int width, int height ) protected void resize( int width, int height )
{ {
if( m_terminal == null ) if( terminal == null )
{ {
m_terminal = new Terminal( width, height, this::markTerminalChanged ); terminal = new Terminal( width, height, this::markTerminalChanged );
markTerminalChanged(); markTerminalChanged();
} }
else else
{ {
m_terminal.resize( width, height ); terminal.resize( width, height );
} }
} }
public void delete() public void delete()
{ {
if( m_terminal != null ) if( terminal != null )
{ {
m_terminal = null; terminal = null;
markTerminalChanged(); markTerminalChanged();
} }
} }
protected void markTerminalChanged() protected void markTerminalChanged()
{ {
m_terminalChanged.set( true ); terminalChanged.set( true );
} }
public void update() public void update()
{ {
m_terminalChangedLastFrame = m_terminalChanged.getAndSet( false ); terminalChangedLastFrame = terminalChanged.getAndSet( false );
} }
public boolean hasTerminalChanged() public boolean hasTerminalChanged()
{ {
return m_terminalChangedLastFrame; return terminalChangedLastFrame;
} }
@Override @Override
public Terminal getTerminal() public Terminal getTerminal()
{ {
return m_terminal; return terminal;
} }
@Override @Override
public boolean isColour() public boolean isColour()
{ {
return m_colour; return colour;
} }
public TerminalState write() public TerminalState write()
{ {
return new TerminalState( m_colour, m_terminal ); return new TerminalState( colour, terminal );
} }
} }

View File

@ -33,7 +33,7 @@ public final class ComputerProxy
ServerComputer computer = tile.getServerComputer(); ServerComputer computer = tile.getServerComputer();
if( computer == null ) if( computer == null )
{ {
tile.m_startOn = true; tile.startOn = true;
} }
else else
{ {
@ -47,7 +47,7 @@ public final class ComputerProxy
ServerComputer computer = tile.getServerComputer(); ServerComputer computer = tile.getServerComputer();
if( computer == null ) if( computer == null )
{ {
tile.m_startOn = false; tile.startOn = false;
} }
else else
{ {
@ -61,7 +61,7 @@ public final class ComputerProxy
ServerComputer computer = tile.getServerComputer(); ServerComputer computer = tile.getServerComputer();
if( computer == null ) if( computer == null )
{ {
tile.m_startOn = true; tile.startOn = true;
} }
else else
{ {

View File

@ -52,12 +52,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
private static final String NBT_LABEL = "Label"; private static final String NBT_LABEL = "Label";
private static final String NBT_ON = "On"; private static final String NBT_ON = "On";
private int m_instanceID = -1; private int instanceID = -1;
private int m_computerID = -1; private int computerID = -1;
protected String label = null; protected String label = null;
private boolean m_on = false; private boolean on = false;
boolean m_startOn = false; boolean startOn = false;
private boolean m_fresh = false; private boolean fresh = false;
private final NonNullConsumer<LazyOptional<IPeripheral>>[] invalidate; private final NonNullConsumer<LazyOptional<IPeripheral>>[] invalidate;
private final ComputerFamily family; private final ComputerFamily family;
@ -78,10 +78,10 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
protected void unload() protected void unload()
{ {
if( m_instanceID >= 0 ) if( instanceID >= 0 )
{ {
if( !getLevel().isClientSide ) ComputerCraft.serverComputerRegistry.remove( m_instanceID ); if( !getLevel().isClientSide ) ComputerCraft.serverComputerRegistry.remove( instanceID );
m_instanceID = -1; instanceID = -1;
} }
} }
@ -162,18 +162,18 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
if( computer == null ) return; if( computer == null ) return;
// If the computer isn't on and should be, then turn it on // If the computer isn't on and should be, then turn it on
if( m_startOn || (m_fresh && m_on) ) if( startOn || (fresh && on) )
{ {
computer.turnOn(); computer.turnOn();
m_startOn = false; startOn = false;
} }
computer.keepAlive(); computer.keepAlive();
m_fresh = false; fresh = false;
m_computerID = computer.getID(); computerID = computer.getID();
label = computer.getLabel(); label = computer.getLabel();
m_on = computer.isOn(); on = computer.isOn();
if( computer.hasOutputChanged() ) updateOutput(); if( computer.hasOutputChanged() ) updateOutput();
@ -192,9 +192,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
public CompoundNBT save( @Nonnull CompoundNBT nbt ) public CompoundNBT save( @Nonnull CompoundNBT nbt )
{ {
// Save ID, label and power state // Save ID, label and power state
if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID ); if( computerID >= 0 ) nbt.putInt( NBT_ID, computerID );
if( label != null ) nbt.putString( NBT_LABEL, label ); if( label != null ) nbt.putString( NBT_LABEL, label );
nbt.putBoolean( NBT_ON, m_on ); nbt.putBoolean( NBT_ON, on );
return super.save( nbt ); return super.save( nbt );
} }
@ -205,9 +205,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
super.load( nbt ); super.load( nbt );
// Load ID, label and power state // Load ID, label and power state
m_computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
m_on = m_startOn = nbt.getBoolean( NBT_ON ); on = startOn = nbt.getBoolean( NBT_ON );
} }
protected boolean isPeripheralBlockedOnSide( ComputerSide localSide ) protected boolean isPeripheralBlockedOnSide( ComputerSide localSide )
@ -322,7 +322,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public final int getComputerID() public final int getComputerID()
{ {
return m_computerID; return computerID;
} }
@Override @Override
@ -334,11 +334,11 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public final void setComputerID( int id ) public final void setComputerID( int id )
{ {
if( getLevel().isClientSide || m_computerID == id ) return; if( getLevel().isClientSide || computerID == id ) return;
m_computerID = id; computerID = id;
ServerComputer computer = getServerComputer(); ServerComputer computer = getServerComputer();
if( computer != null ) computer.setID( m_computerID ); if( computer != null ) computer.setID( computerID );
setChanged(); setChanged();
} }
@ -364,16 +364,16 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
if( getLevel().isClientSide ) return null; if( getLevel().isClientSide ) return null;
boolean changed = false; boolean changed = false;
if( m_instanceID < 0 ) if( instanceID < 0 )
{ {
m_instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID(); instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID();
changed = true; changed = true;
} }
if( !ComputerCraft.serverComputerRegistry.contains( m_instanceID ) ) if( !ComputerCraft.serverComputerRegistry.contains( instanceID ) )
{ {
ServerComputer computer = createComputer( m_instanceID, m_computerID ); ServerComputer computer = createComputer( instanceID, computerID );
ComputerCraft.serverComputerRegistry.add( m_instanceID, computer ); ComputerCraft.serverComputerRegistry.add( instanceID, computer );
m_fresh = true; fresh = true;
changed = true; changed = true;
} }
if( changed ) if( changed )
@ -381,12 +381,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
updateBlock(); updateBlock();
updateInput(); updateInput();
} }
return ComputerCraft.serverComputerRegistry.get( m_instanceID ); return ComputerCraft.serverComputerRegistry.get( instanceID );
} }
public ServerComputer getServerComputer() public ServerComputer getServerComputer()
{ {
return getLevel().isClientSide ? null : ComputerCraft.serverComputerRegistry.get( m_instanceID ); return getLevel().isClientSide ? null : ComputerCraft.serverComputerRegistry.get( instanceID );
} }
// Networking stuff // Networking stuff
@ -396,7 +396,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
if( label != null ) nbt.putString( NBT_LABEL, label ); if( label != null ) nbt.putString( NBT_LABEL, label );
if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID ); if( computerID >= 0 ) nbt.putInt( NBT_ID, computerID );
} }
@Override @Override
@ -404,22 +404,22 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{ {
super.readDescription( nbt ); super.readDescription( nbt );
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
m_computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
} }
protected void transferStateFrom( TileComputerBase copy ) protected void transferStateFrom( TileComputerBase copy )
{ {
if( copy.m_computerID != m_computerID || copy.m_instanceID != m_instanceID ) if( copy.computerID != computerID || copy.instanceID != instanceID )
{ {
unload(); unload();
m_instanceID = copy.m_instanceID; instanceID = copy.instanceID;
m_computerID = copy.m_computerID; computerID = copy.computerID;
label = copy.label; label = copy.label;
m_on = copy.m_on; on = copy.on;
m_startOn = copy.m_startOn; startOn = copy.startOn;
updateBlock(); updateBlock();
} }
copy.m_instanceID = -1; copy.instanceID = -1;
} }
@Nonnull @Nonnull

View File

@ -12,22 +12,21 @@ import net.minecraft.nbt.CompoundNBT;
public class ClientComputer extends ClientTerminal implements IComputer public class ClientComputer extends ClientTerminal implements IComputer
{ {
private final int m_instanceID; private final int instanceID;
private boolean m_on = false;
private boolean m_blinking = false;
private CompoundNBT m_userData = null;
private boolean on = false;
private boolean blinking = false;
private CompoundNBT userData = null;
public ClientComputer( int instanceID ) public ClientComputer( int instanceID )
{ {
super( false ); super( false );
m_instanceID = instanceID; this.instanceID = instanceID;
} }
public CompoundNBT getUserData() public CompoundNBT getUserData()
{ {
return m_userData; return userData;
} }
public void requestState() public void requestState()
@ -41,89 +40,89 @@ public class ClientComputer extends ClientTerminal implements IComputer
@Override @Override
public int getInstanceID() public int getInstanceID()
{ {
return m_instanceID; return instanceID;
} }
@Override @Override
public boolean isOn() public boolean isOn()
{ {
return m_on; return on;
} }
@Override @Override
public boolean isCursorDisplayed() public boolean isCursorDisplayed()
{ {
return m_on && m_blinking; return on && blinking;
} }
@Override @Override
public void turnOn() public void turnOn()
{ {
// Send turnOn to server // Send turnOn to server
NetworkHandler.sendToServer( new ComputerActionServerMessage( m_instanceID, ComputerActionServerMessage.Action.TURN_ON ) ); NetworkHandler.sendToServer( new ComputerActionServerMessage( instanceID, ComputerActionServerMessage.Action.TURN_ON ) );
} }
@Override @Override
public void shutdown() public void shutdown()
{ {
// Send shutdown to server // Send shutdown to server
NetworkHandler.sendToServer( new ComputerActionServerMessage( m_instanceID, ComputerActionServerMessage.Action.SHUTDOWN ) ); NetworkHandler.sendToServer( new ComputerActionServerMessage( instanceID, ComputerActionServerMessage.Action.SHUTDOWN ) );
} }
@Override @Override
public void reboot() public void reboot()
{ {
// Send reboot to server // Send reboot to server
NetworkHandler.sendToServer( new ComputerActionServerMessage( m_instanceID, ComputerActionServerMessage.Action.REBOOT ) ); NetworkHandler.sendToServer( new ComputerActionServerMessage( instanceID, ComputerActionServerMessage.Action.REBOOT ) );
} }
@Override @Override
public void queueEvent( String event, Object[] arguments ) public void queueEvent( String event, Object[] arguments )
{ {
// Send event to server // Send event to server
NetworkHandler.sendToServer( new QueueEventServerMessage( m_instanceID, event, arguments ) ); NetworkHandler.sendToServer( new QueueEventServerMessage( instanceID, event, arguments ) );
} }
@Override @Override
public void keyDown( int key, boolean repeat ) public void keyDown( int key, boolean repeat )
{ {
NetworkHandler.sendToServer( new KeyEventServerMessage( m_instanceID, repeat ? KeyEventServerMessage.TYPE_REPEAT : KeyEventServerMessage.TYPE_DOWN, key ) ); NetworkHandler.sendToServer( new KeyEventServerMessage( instanceID, repeat ? KeyEventServerMessage.TYPE_REPEAT : KeyEventServerMessage.TYPE_DOWN, key ) );
} }
@Override @Override
public void keyUp( int key ) public void keyUp( int key )
{ {
NetworkHandler.sendToServer( new KeyEventServerMessage( m_instanceID, KeyEventServerMessage.TYPE_UP, key ) ); NetworkHandler.sendToServer( new KeyEventServerMessage( instanceID, KeyEventServerMessage.TYPE_UP, key ) );
} }
@Override @Override
public void mouseClick( int button, int x, int y ) public void mouseClick( int button, int x, int y )
{ {
NetworkHandler.sendToServer( new MouseEventServerMessage( m_instanceID, MouseEventServerMessage.TYPE_CLICK, button, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( instanceID, MouseEventServerMessage.TYPE_CLICK, button, x, y ) );
} }
@Override @Override
public void mouseUp( int button, int x, int y ) public void mouseUp( int button, int x, int y )
{ {
NetworkHandler.sendToServer( new MouseEventServerMessage( m_instanceID, MouseEventServerMessage.TYPE_UP, button, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( instanceID, MouseEventServerMessage.TYPE_UP, button, x, y ) );
} }
@Override @Override
public void mouseDrag( int button, int x, int y ) public void mouseDrag( int button, int x, int y )
{ {
NetworkHandler.sendToServer( new MouseEventServerMessage( m_instanceID, MouseEventServerMessage.TYPE_DRAG, button, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( instanceID, MouseEventServerMessage.TYPE_DRAG, button, x, y ) );
} }
@Override @Override
public void mouseScroll( int direction, int x, int y ) public void mouseScroll( int direction, int x, int y )
{ {
NetworkHandler.sendToServer( new MouseEventServerMessage( m_instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) );
} }
public void setState( ComputerState state, CompoundNBT userData ) public void setState( ComputerState state, CompoundNBT userData )
{ {
m_on = state != ComputerState.OFF; on = state != ComputerState.OFF;
m_blinking = state == ComputerState.BLINKING; blinking = state == ComputerState.BLINKING;
m_userData = userData; this.userData = userData;
} }
} }

View File

@ -12,38 +12,37 @@ import java.util.Random;
public class ComputerRegistry<T extends IComputer> public class ComputerRegistry<T extends IComputer>
{ {
private Map<Integer, T> m_computers; private final Map<Integer, T> computers = new HashMap<>();
private int m_nextUnusedInstanceID; private int nextUnusedInstanceID;
private int m_sessionID; private int sessionID;
protected ComputerRegistry() protected ComputerRegistry()
{ {
m_computers = new HashMap<>();
reset(); reset();
} }
public int getSessionID() public int getSessionID()
{ {
return m_sessionID; return sessionID;
} }
public int getUnusedInstanceID() public int getUnusedInstanceID()
{ {
return m_nextUnusedInstanceID++; return nextUnusedInstanceID++;
} }
public Collection<T> getComputers() public Collection<T> getComputers()
{ {
return m_computers.values(); return computers.values();
} }
public T get( int instanceID ) public T get( int instanceID )
{ {
if( instanceID >= 0 ) if( instanceID >= 0 )
{ {
if( m_computers.containsKey( instanceID ) ) if( computers.containsKey( instanceID ) )
{ {
return m_computers.get( instanceID ); return computers.get( instanceID );
} }
} }
return null; return null;
@ -51,28 +50,28 @@ public class ComputerRegistry<T extends IComputer>
public boolean contains( int instanceID ) public boolean contains( int instanceID )
{ {
return m_computers.containsKey( instanceID ); return computers.containsKey( instanceID );
} }
public void add( int instanceID, T computer ) public void add( int instanceID, T computer )
{ {
if( m_computers.containsKey( instanceID ) ) if( computers.containsKey( instanceID ) )
{ {
remove( instanceID ); remove( instanceID );
} }
m_computers.put( instanceID, computer ); computers.put( instanceID, computer );
m_nextUnusedInstanceID = Math.max( m_nextUnusedInstanceID, instanceID + 1 ); nextUnusedInstanceID = Math.max( nextUnusedInstanceID, instanceID + 1 );
} }
public void remove( int instanceID ) public void remove( int instanceID )
{ {
m_computers.remove( instanceID ); computers.remove( instanceID );
} }
public void reset() public void reset()
{ {
m_computers.clear(); computers.clear();
m_nextUnusedInstanceID = 0; nextUnusedInstanceID = 0;
m_sessionID = new Random().nextInt(); sessionID = new Random().nextInt();
} }
} }

View File

@ -37,116 +37,109 @@ import java.io.InputStream;
public class ServerComputer extends ServerTerminal implements IComputer, IComputerEnvironment public class ServerComputer extends ServerTerminal implements IComputer, IComputerEnvironment
{ {
private final int m_instanceID; private final int instanceID;
private World m_world; private World world;
private BlockPos m_position; private BlockPos position;
private final ComputerFamily m_family; private final ComputerFamily family;
private final Computer m_computer; private final Computer computer;
private CompoundNBT m_userData; private CompoundNBT userData;
private boolean m_changed; private boolean changed;
private boolean m_changedLastFrame; private boolean changedLastFrame;
private int m_ticksSincePing; private int ticksSincePing;
public ServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family, int terminalWidth, int terminalHeight ) public ServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family, int terminalWidth, int terminalHeight )
{ {
super( family != ComputerFamily.NORMAL, terminalWidth, terminalHeight ); super( family != ComputerFamily.NORMAL, terminalWidth, terminalHeight );
m_instanceID = instanceID; this.instanceID = instanceID;
m_world = world; this.world = world;
m_position = null; this.family = family;
computer = new Computer( this, getTerminal(), computerID );
m_family = family; computer.setLabel( label );
m_computer = new Computer( this, getTerminal(), computerID );
m_computer.setLabel( label );
m_userData = null;
m_changed = false;
m_changedLastFrame = false;
m_ticksSincePing = 0;
} }
public ComputerFamily getFamily() public ComputerFamily getFamily()
{ {
return m_family; return family;
} }
public World getWorld() public World getWorld()
{ {
return m_world; return world;
} }
public void setWorld( World world ) public void setWorld( World world )
{ {
m_world = world; this.world = world;
} }
public BlockPos getPosition() public BlockPos getPosition()
{ {
return m_position; return position;
} }
public void setPosition( BlockPos pos ) public void setPosition( BlockPos pos )
{ {
m_position = new BlockPos( pos ); position = new BlockPos( pos );
} }
public IAPIEnvironment getAPIEnvironment() public IAPIEnvironment getAPIEnvironment()
{ {
return m_computer.getAPIEnvironment(); return computer.getAPIEnvironment();
} }
public Computer getComputer() public Computer getComputer()
{ {
return m_computer; return computer;
} }
@Override @Override
public void update() public void update()
{ {
super.update(); super.update();
m_computer.tick(); computer.tick();
m_changedLastFrame = m_computer.pollAndResetChanged() || m_changed; changedLastFrame = computer.pollAndResetChanged() || changed;
m_changed = false; changed = false;
m_ticksSincePing++; ticksSincePing++;
} }
public void keepAlive() public void keepAlive()
{ {
m_ticksSincePing = 0; ticksSincePing = 0;
} }
public boolean hasTimedOut() public boolean hasTimedOut()
{ {
return m_ticksSincePing > 100; return ticksSincePing > 100;
} }
public boolean hasOutputChanged() public boolean hasOutputChanged()
{ {
return m_changedLastFrame; return changedLastFrame;
} }
public void unload() public void unload()
{ {
m_computer.unload(); computer.unload();
} }
public CompoundNBT getUserData() public CompoundNBT getUserData()
{ {
if( m_userData == null ) if( userData == null )
{ {
m_userData = new CompoundNBT(); userData = new CompoundNBT();
} }
return m_userData; return userData;
} }
public void updateUserData() public void updateUserData()
{ {
m_changed = true; changed = true;
} }
private NetworkMessage createComputerPacket() private NetworkMessage createComputerPacket()
@ -204,7 +197,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public void setID( int id ) public void setID( int id )
{ {
m_computer.setID( id ); computer.setID( id );
} }
// IComputer // IComputer
@ -212,97 +205,97 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
@Override @Override
public int getInstanceID() public int getInstanceID()
{ {
return m_instanceID; return instanceID;
} }
public int getID() public int getID()
{ {
return m_computer.getID(); return computer.getID();
} }
public String getLabel() public String getLabel()
{ {
return m_computer.getLabel(); return computer.getLabel();
} }
@Override @Override
public boolean isOn() public boolean isOn()
{ {
return m_computer.isOn(); return computer.isOn();
} }
@Override @Override
public boolean isCursorDisplayed() public boolean isCursorDisplayed()
{ {
return m_computer.isOn() && m_computer.isBlinking(); return computer.isOn() && computer.isBlinking();
} }
@Override @Override
public void turnOn() public void turnOn()
{ {
// Turn on // Turn on
m_computer.turnOn(); computer.turnOn();
} }
@Override @Override
public void shutdown() public void shutdown()
{ {
// Shutdown // Shutdown
m_computer.shutdown(); computer.shutdown();
} }
@Override @Override
public void reboot() public void reboot()
{ {
// Reboot // Reboot
m_computer.reboot(); computer.reboot();
} }
@Override @Override
public void queueEvent( String event, Object[] arguments ) public void queueEvent( String event, Object[] arguments )
{ {
// Queue event // Queue event
m_computer.queueEvent( event, arguments ); computer.queueEvent( event, arguments );
} }
public int getRedstoneOutput( ComputerSide side ) public int getRedstoneOutput( ComputerSide side )
{ {
return m_computer.getEnvironment().getExternalRedstoneOutput( side ); return computer.getEnvironment().getExternalRedstoneOutput( side );
} }
public void setRedstoneInput( ComputerSide side, int level ) public void setRedstoneInput( ComputerSide side, int level )
{ {
m_computer.getEnvironment().setRedstoneInput( side, level ); computer.getEnvironment().setRedstoneInput( side, level );
} }
public int getBundledRedstoneOutput( ComputerSide side ) public int getBundledRedstoneOutput( ComputerSide side )
{ {
return m_computer.getEnvironment().getExternalBundledRedstoneOutput( side ); return computer.getEnvironment().getExternalBundledRedstoneOutput( side );
} }
public void setBundledRedstoneInput( ComputerSide side, int combination ) public void setBundledRedstoneInput( ComputerSide side, int combination )
{ {
m_computer.getEnvironment().setBundledRedstoneInput( side, combination ); computer.getEnvironment().setBundledRedstoneInput( side, combination );
} }
public void addAPI( ILuaAPI api ) public void addAPI( ILuaAPI api )
{ {
m_computer.addApi( api ); computer.addApi( api );
} }
public void setPeripheral( ComputerSide side, IPeripheral peripheral ) public void setPeripheral( ComputerSide side, IPeripheral peripheral )
{ {
m_computer.getEnvironment().setPeripheral( side, peripheral ); computer.getEnvironment().setPeripheral( side, peripheral );
} }
public IPeripheral getPeripheral( ComputerSide side ) public IPeripheral getPeripheral( ComputerSide side )
{ {
return m_computer.getEnvironment().getPeripheral( side ); return computer.getEnvironment().getPeripheral( side );
} }
public void setLabel( String label ) public void setLabel( String label )
{ {
m_computer.setLabel( label ); computer.setLabel( label );
} }
// IComputerEnvironment implementation // IComputerEnvironment implementation
@ -310,19 +303,19 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
@Override @Override
public double getTimeOfDay() public double getTimeOfDay()
{ {
return (m_world.getDayTime() + 6000) % 24000 / 1000.0; return (world.getDayTime() + 6000) % 24000 / 1000.0;
} }
@Override @Override
public int getDay() public int getDay()
{ {
return (int) ((m_world.getDayTime() + 6000) / 24000) + 1; return (int) ((world.getDayTime() + 6000) / 24000) + 1;
} }
@Override @Override
public IWritableMount createSaveDirMount( String subPath, long capacity ) public IWritableMount createSaveDirMount( String subPath, long capacity )
{ {
return ComputerCraftAPI.createSaveDirMount( m_world, subPath, capacity ); return ComputerCraftAPI.createSaveDirMount( world, subPath, capacity );
} }
@Override @Override
@ -360,7 +353,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
@Override @Override
public int assignNewID() public int assignNewID()
{ {
return ComputerCraftAPI.createUniqueNumberedSaveDir( m_world, "computer" ); return ComputerCraftAPI.createUniqueNumberedSaveDir( world, "computer" );
} }
@Nullable @Nullable

View File

@ -10,8 +10,6 @@ import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.network.NetworkMessage; import dan200.computercraft.shared.network.NetworkMessage;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -80,7 +78,6 @@ public class ChatTableClientMessage implements NetworkMessage
} }
@Override @Override
@OnlyIn( Dist.CLIENT )
public void handle( NetworkEvent.Context context ) public void handle( NetworkEvent.Context context )
{ {
ClientTableFormatter.INSTANCE.display( table ); ClientTableFormatter.INSTANCE.display( table );

View File

@ -59,18 +59,18 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
ITextComponent customName; ITextComponent customName;
private final Map<IComputerAccess, MountInfo> m_computers = new HashMap<>(); private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
@Nonnull @Nonnull
private ItemStack m_diskStack = ItemStack.EMPTY; private ItemStack diskStack = ItemStack.EMPTY;
private LazyOptional<IItemHandlerModifiable> itemHandlerCap; private LazyOptional<IItemHandlerModifiable> itemHandlerCap;
private LazyOptional<IPeripheral> peripheralCap; private LazyOptional<IPeripheral> peripheralCap;
private IMount m_diskMount = null; private IMount diskMount = null;
private boolean m_recordQueued = false; private boolean recordQueued = false;
private boolean m_recordPlaying = false; private boolean recordPlaying = false;
private boolean m_restartRecord = false; private boolean restartRecord = false;
private boolean m_ejectQueued; private boolean ejectQueued;
public TileDiskDrive( TileEntityType<TileDiskDrive> type ) public TileDiskDrive( TileEntityType<TileDiskDrive> type )
{ {
@ -81,7 +81,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
public void destroy() public void destroy()
{ {
ejectContents( true ); ejectContents( true );
if( m_recordPlaying ) stopRecord(); if( recordPlaying ) stopRecord();
} }
@Override @Override
@ -129,8 +129,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
if( nbt.contains( NBT_ITEM ) ) if( nbt.contains( NBT_ITEM ) )
{ {
CompoundNBT item = nbt.getCompound( NBT_ITEM ); CompoundNBT item = nbt.getCompound( NBT_ITEM );
m_diskStack = ItemStack.of( item ); diskStack = ItemStack.of( item );
m_diskMount = null; diskMount = null;
} }
} }
@ -140,10 +140,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) );
if( !m_diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
CompoundNBT item = new CompoundNBT(); CompoundNBT item = new CompoundNBT();
m_diskStack.save( item ); diskStack.save( item );
nbt.put( NBT_ITEM, item ); nbt.put( NBT_ITEM, item );
} }
return super.save( nbt ); return super.save( nbt );
@ -153,36 +153,36 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
public void tick() public void tick()
{ {
// Ejection // Ejection
if( m_ejectQueued ) if( ejectQueued )
{ {
ejectContents( false ); ejectContents( false );
m_ejectQueued = false; ejectQueued = false;
} }
// Music // Music
synchronized( this ) synchronized( this )
{ {
if( !level.isClientSide && m_recordPlaying != m_recordQueued || m_restartRecord ) if( !level.isClientSide && recordPlaying != recordQueued || restartRecord )
{ {
m_restartRecord = false; restartRecord = false;
if( m_recordQueued ) if( recordQueued )
{ {
IMedia contents = getDiskMedia(); IMedia contents = getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( m_diskStack ) : null; SoundEvent record = contents != null ? contents.getAudio( diskStack ) : null;
if( record != null ) if( record != null )
{ {
m_recordPlaying = true; recordPlaying = true;
playRecord(); playRecord();
} }
else else
{ {
m_recordQueued = false; recordQueued = false;
} }
} }
else else
{ {
stopRecord(); stopRecord();
m_recordPlaying = false; recordPlaying = false;
} }
} }
} }
@ -199,23 +199,23 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
return m_diskStack.isEmpty(); return diskStack.isEmpty();
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack getItem( int slot ) public ItemStack getItem( int slot )
{ {
return m_diskStack; return diskStack;
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack removeItemNoUpdate( int slot ) public ItemStack removeItemNoUpdate( int slot )
{ {
ItemStack result = m_diskStack; ItemStack result = diskStack;
m_diskStack = ItemStack.EMPTY; diskStack = ItemStack.EMPTY;
m_diskMount = null; diskMount = null;
return result; return result;
} }
@ -224,17 +224,17 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
@Override @Override
public ItemStack removeItem( int slot, int count ) public ItemStack removeItem( int slot, int count )
{ {
if( m_diskStack.isEmpty() ) return ItemStack.EMPTY; if( diskStack.isEmpty() ) return ItemStack.EMPTY;
if( m_diskStack.getCount() <= count ) if( diskStack.getCount() <= count )
{ {
ItemStack disk = m_diskStack; ItemStack disk = diskStack;
setItem( slot, ItemStack.EMPTY ); setItem( slot, ItemStack.EMPTY );
return disk; return disk;
} }
ItemStack part = m_diskStack.split( count ); ItemStack part = diskStack.split( count );
setItem( slot, m_diskStack.isEmpty() ? ItemStack.EMPTY : m_diskStack ); setItem( slot, diskStack.isEmpty() ? ItemStack.EMPTY : diskStack );
return part; return part;
} }
@ -243,45 +243,45 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
if( getLevel().isClientSide ) if( getLevel().isClientSide )
{ {
m_diskStack = stack; diskStack = stack;
m_diskMount = null; diskMount = null;
setChanged(); setChanged();
return; return;
} }
synchronized( this ) synchronized( this )
{ {
if( InventoryUtil.areItemsStackable( stack, m_diskStack ) ) if( InventoryUtil.areItemsStackable( stack, diskStack ) )
{ {
m_diskStack = stack; diskStack = stack;
return; return;
} }
// Unmount old disk // Unmount old disk
if( !m_diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
// TODO: Is this iteration thread safe? // TODO: Is this iteration thread safe?
Set<IComputerAccess> computers = m_computers.keySet(); Set<IComputerAccess> computers = this.computers.keySet();
for( IComputerAccess computer : computers ) unmountDisk( computer ); for( IComputerAccess computer : computers ) unmountDisk( computer );
} }
// Stop music // Stop music
if( m_recordPlaying ) if( recordPlaying )
{ {
stopRecord(); stopRecord();
m_recordPlaying = false; recordPlaying = false;
m_recordQueued = false; recordQueued = false;
} }
// Swap disk over // Swap disk over
m_diskStack = stack; diskStack = stack;
m_diskMount = null; diskMount = null;
setChanged(); setChanged();
// Mount new disk // Mount new disk
if( !m_diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
Set<IComputerAccess> computers = m_computers.keySet(); Set<IComputerAccess> computers = this.computers.keySet();
for( IComputerAccess computer : computers ) mountDisk( computer ); for( IComputerAccess computer : computers ) mountDisk( computer );
} }
} }
@ -326,7 +326,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
MountInfo info = m_computers.get( computer ); MountInfo info = computers.get( computer );
return info != null ? info.mountPath : null; return info != null ? info.mountPath : null;
} }
} }
@ -335,7 +335,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
m_computers.put( computer, new MountInfo() ); computers.put( computer, new MountInfo() );
mountDisk( computer ); mountDisk( computer );
} }
} }
@ -345,7 +345,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
synchronized( this ) synchronized( this )
{ {
unmountDisk( computer ); unmountDisk( computer );
m_computers.remove( computer ); computers.remove( computer );
} }
} }
@ -354,10 +354,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
synchronized( this ) synchronized( this )
{ {
IMedia media = getDiskMedia(); IMedia media = getDiskMedia();
if( media != null && media.getAudioTitle( m_diskStack ) != null ) if( media != null && media.getAudioTitle( diskStack ) != null )
{ {
m_recordQueued = true; recordQueued = true;
m_restartRecord = m_recordPlaying; restartRecord = recordPlaying;
} }
} }
} }
@ -366,8 +366,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
m_recordQueued = false; recordQueued = false;
m_restartRecord = false; restartRecord = false;
} }
} }
@ -375,7 +375,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
m_ejectQueued = true; ejectQueued = true;
} }
} }
@ -383,25 +383,25 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private synchronized void mountDisk( IComputerAccess computer ) private synchronized void mountDisk( IComputerAccess computer )
{ {
if( !m_diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
MountInfo info = m_computers.get( computer ); MountInfo info = computers.get( computer );
IMedia contents = getDiskMedia(); IMedia contents = getDiskMedia();
if( contents != null ) if( contents != null )
{ {
if( m_diskMount == null ) if( diskMount == null )
{ {
m_diskMount = contents.createDataMount( m_diskStack, getLevel() ); diskMount = contents.createDataMount( diskStack, getLevel() );
} }
if( m_diskMount != null ) if( diskMount != null )
{ {
if( m_diskMount instanceof IWritableMount ) if( diskMount instanceof IWritableMount )
{ {
// Try mounting at the lowest numbered "disk" name we can // Try mounting at the lowest numbered "disk" name we can
int n = 1; int n = 1;
while( info.mountPath == null ) while( info.mountPath == null )
{ {
info.mountPath = computer.mountWritable( n == 1 ? "disk" : "disk" + n, (IWritableMount) m_diskMount ); info.mountPath = computer.mountWritable( n == 1 ? "disk" : "disk" + n, (IWritableMount) diskMount );
n++; n++;
} }
} }
@ -411,7 +411,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
int n = 1; int n = 1;
while( info.mountPath == null ) while( info.mountPath == null )
{ {
info.mountPath = computer.mount( n == 1 ? "disk" : "disk" + n, m_diskMount ); info.mountPath = computer.mount( n == 1 ? "disk" : "disk" + n, diskMount );
n++; n++;
} }
} }
@ -427,9 +427,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private synchronized void unmountDisk( IComputerAccess computer ) private synchronized void unmountDisk( IComputerAccess computer )
{ {
if( !m_diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
MountInfo info = m_computers.get( computer ); MountInfo info = computers.get( computer );
assert info != null; assert info != null;
if( info.mountPath != null ) if( info.mountPath != null )
{ {
@ -444,7 +444,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
if( remove ) return; if( remove ) return;
if( !m_diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
IMedia contents = getDiskMedia(); IMedia contents = getDiskMedia();
updateBlockState( contents != null ? DiskDriveState.FULL : DiskDriveState.INVALID ); updateBlockState( contents != null ? DiskDriveState.FULL : DiskDriveState.INVALID );
@ -465,10 +465,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private synchronized void ejectContents( boolean destroyed ) private synchronized void ejectContents( boolean destroyed )
{ {
if( getLevel().isClientSide || m_diskStack.isEmpty() ) return; if( getLevel().isClientSide || diskStack.isEmpty() ) return;
// Remove the disks from the inventory // Remove the disks from the inventory
ItemStack disks = m_diskStack; ItemStack disks = diskStack;
setDiskStack( ItemStack.EMPTY ); setDiskStack( ItemStack.EMPTY );
// Spawn the item in the world // Spawn the item in the world
@ -497,10 +497,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private void playRecord() private void playRecord()
{ {
IMedia contents = getDiskMedia(); IMedia contents = getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( m_diskStack ) : null; SoundEvent record = contents != null ? contents.getAudio( diskStack ) : null;
if( record != null ) if( record != null )
{ {
RecordUtil.playRecord( record, contents.getAudioTitle( m_diskStack ), getLevel(), getBlockPos() ); RecordUtil.playRecord( record, contents.getAudioTitle( diskStack ), getLevel(), getBlockPos() );
} }
else else
{ {

View File

@ -27,32 +27,32 @@ import java.util.Set;
*/ */
public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver
{ {
private IPacketNetwork m_network; private IPacketNetwork network;
private final Set<IComputerAccess> m_computers = new HashSet<>( 1 ); private final Set<IComputerAccess> computers = new HashSet<>( 1 );
private final ModemState m_state; private final ModemState state;
protected ModemPeripheral( ModemState state ) protected ModemPeripheral( ModemState state )
{ {
m_state = state; this.state = state;
} }
public ModemState getModemState() public ModemState getModemState()
{ {
return m_state; return state;
} }
private synchronized void setNetwork( IPacketNetwork network ) private synchronized void setNetwork( IPacketNetwork network )
{ {
if( m_network == network ) return; if( this.network == network ) return;
// Leave old network // Leave old network
if( m_network != null ) m_network.removeReceiver( this ); if( this.network != null ) this.network.removeReceiver( this );
// Set new network // Set new network
m_network = network; this.network = network;
// Join new network // Join new network
if( m_network != null ) m_network.addReceiver( this ); if( this.network != null ) this.network.addReceiver( this );
} }
public void destroy() public void destroy()
@ -63,11 +63,11 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@Override @Override
public void receiveSameDimension( @Nonnull Packet packet, double distance ) public void receiveSameDimension( @Nonnull Packet packet, double distance )
{ {
if( packet.getSender() == this || !m_state.isOpen( packet.getChannel() ) ) return; if( packet.getSender() == this || !state.isOpen( packet.getChannel() ) ) return;
synchronized( m_computers ) synchronized( computers )
{ {
for( IComputerAccess computer : m_computers ) for( IComputerAccess computer : computers )
{ {
computer.queueEvent( "modem_message", computer.queueEvent( "modem_message",
computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload(), distance ); computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload(), distance );
@ -78,11 +78,11 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@Override @Override
public void receiveDifferentDimension( @Nonnull Packet packet ) public void receiveDifferentDimension( @Nonnull Packet packet )
{ {
if( packet.getSender() == this || !m_state.isOpen( packet.getChannel() ) ) return; if( packet.getSender() == this || !state.isOpen( packet.getChannel() ) ) return;
synchronized( m_computers ) synchronized( computers )
{ {
for( IComputerAccess computer : m_computers ) for( IComputerAccess computer : computers )
{ {
computer.queueEvent( "modem_message", computer.queueEvent( "modem_message",
computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload() ); computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload() );
@ -116,7 +116,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final void open( int channel ) throws LuaException public final void open( int channel ) throws LuaException
{ {
m_state.open( parseChannel( channel ) ); state.open( parseChannel( channel ) );
} }
/** /**
@ -129,7 +129,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final boolean isOpen( int channel ) throws LuaException public final boolean isOpen( int channel ) throws LuaException
{ {
return m_state.isOpen( parseChannel( channel ) ); return state.isOpen( parseChannel( channel ) );
} }
/** /**
@ -141,7 +141,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final void close( int channel ) throws LuaException public final void close( int channel ) throws LuaException
{ {
m_state.close( parseChannel( channel ) ); state.close( parseChannel( channel ) );
} }
/** /**
@ -150,7 +150,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final void closeAll() public final void closeAll()
{ {
m_state.closeAll(); state.closeAll();
} }
/** /**
@ -172,7 +172,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
World world = getWorld(); World world = getWorld();
Vec3d position = getPosition(); Vec3d position = getPosition();
IPacketNetwork network = m_network; IPacketNetwork network = this.network;
if( world == null || position == null || network == null ) return; if( world == null || position == null || network == null ) return;
@ -198,16 +198,16 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final boolean isWireless() public final boolean isWireless()
{ {
IPacketNetwork network = m_network; IPacketNetwork network = this.network;
return network != null && network.isWireless(); return network != null && network.isWireless();
} }
@Override @Override
public synchronized void attach( @Nonnull IComputerAccess computer ) public synchronized void attach( @Nonnull IComputerAccess computer )
{ {
synchronized( m_computers ) synchronized( computers )
{ {
m_computers.add( computer ); computers.add( computer );
} }
setNetwork( getNetwork() ); setNetwork( getNetwork() );
@ -217,10 +217,10 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
public synchronized void detach( @Nonnull IComputerAccess computer ) public synchronized void detach( @Nonnull IComputerAccess computer )
{ {
boolean empty; boolean empty;
synchronized( m_computers ) synchronized( computers )
{ {
m_computers.remove( computer ); computers.remove( computer );
empty = m_computers.isEmpty(); empty = computers.isEmpty();
} }
if( empty ) setNetwork( null ); if( empty ) setNetwork( null );
@ -230,15 +230,15 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@Override @Override
public String getSenderID() public String getSenderID()
{ {
synchronized( m_computers ) synchronized( computers )
{ {
if( m_computers.size() != 1 ) if( computers.size() != 1 )
{ {
return "unknown"; return "unknown";
} }
else else
{ {
IComputerAccess computer = m_computers.iterator().next(); IComputerAccess computer = computers.iterator().next();
return computer.getID() + "_" + computer.getAttachmentName(); return computer.getID() + "_" + computer.getAttachmentName();
} }
} }

View File

@ -67,38 +67,38 @@ public class TileCable extends TileGeneric
@Override @Override
protected void attachPeripheral( String name, IPeripheral peripheral ) protected void attachPeripheral( String name, IPeripheral peripheral )
{ {
m_modem.attachPeripheral( name, peripheral ); modem.attachPeripheral( name, peripheral );
} }
@Override @Override
protected void detachPeripheral( String name ) protected void detachPeripheral( String name )
{ {
m_modem.detachPeripheral( name ); modem.detachPeripheral( name );
} }
} }
private boolean m_peripheralAccessAllowed; private boolean peripheralAccessAllowed;
private final WiredModemLocalPeripheral m_peripheral = new WiredModemLocalPeripheral( this::refreshPeripheral ); private final WiredModemLocalPeripheral peripheral = new WiredModemLocalPeripheral( this::refreshPeripheral );
private boolean m_destroyed = false; private boolean destroyed = false;
private Direction modemDirection = Direction.NORTH; private Direction modemDirection = Direction.NORTH;
private boolean hasModemDirection = false; private boolean hasModemDirection = false;
private boolean m_connectionsFormed = false; private boolean connectionsFormed = false;
private final WiredModemElement m_cable = new CableElement(); private final WiredModemElement cable = new CableElement();
private LazyOptional<IWiredElement> elementCap; private LazyOptional<IWiredElement> elementCap;
private final IWiredNode m_node = m_cable.getNode(); private final IWiredNode node = cable.getNode();
private final WiredModemPeripheral m_modem = new WiredModemPeripheral( private final WiredModemPeripheral modem = new WiredModemPeripheral(
new ModemState( () -> TickScheduler.schedule( this ) ), new ModemState( () -> TickScheduler.schedule( this ) ),
m_cable cable
) )
{ {
@Nonnull @Nonnull
@Override @Override
protected WiredModemLocalPeripheral getLocalPeripheral() protected WiredModemLocalPeripheral getLocalPeripheral()
{ {
return m_peripheral; return peripheral;
} }
@Nonnull @Nonnull
@ -129,18 +129,18 @@ public class TileCable extends TileGeneric
{ {
if( level == null || !level.isClientSide ) if( level == null || !level.isClientSide )
{ {
m_node.remove(); node.remove();
m_connectionsFormed = false; connectionsFormed = false;
} }
} }
@Override @Override
public void destroy() public void destroy()
{ {
if( !m_destroyed ) if( !destroyed )
{ {
m_destroyed = true; destroyed = true;
m_modem.destroy(); modem.destroy();
onRemove(); onRemove();
} }
} }
@ -236,7 +236,7 @@ public class TileCable extends TileGeneric
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{ {
super.onNeighbourTileEntityChange( neighbour ); super.onNeighbourTileEntityChange( neighbour );
if( !level.isClientSide && m_peripheralAccessAllowed ) if( !level.isClientSide && peripheralAccessAllowed )
{ {
Direction facing = getDirection(); Direction facing = getDirection();
if( getBlockPos().relative( facing ).equals( neighbour ) ) refreshPeripheral(); if( getBlockPos().relative( facing ).equals( neighbour ) ) refreshPeripheral();
@ -245,7 +245,7 @@ public class TileCable extends TileGeneric
private void refreshPeripheral() private void refreshPeripheral()
{ {
if( level != null && !isRemoved() && m_peripheral.attach( level, getBlockPos(), getDirection() ) ) if( level != null && !isRemoved() && peripheral.attach( level, getBlockPos(), getDirection() ) )
{ {
updateConnectedPeripherals(); updateConnectedPeripherals();
} }
@ -260,9 +260,9 @@ public class TileCable extends TileGeneric
if( getLevel().isClientSide ) return ActionResultType.SUCCESS; if( getLevel().isClientSide ) return ActionResultType.SUCCESS;
String oldName = m_peripheral.getConnectedName(); String oldName = peripheral.getConnectedName();
togglePeripheralAccess(); togglePeripheralAccess();
String newName = m_peripheral.getConnectedName(); String newName = peripheral.getConnectedName();
if( !Objects.equal( newName, oldName ) ) if( !Objects.equal( newName, oldName ) )
{ {
if( oldName != null ) if( oldName != null )
@ -284,16 +284,16 @@ public class TileCable extends TileGeneric
public void load( @Nonnull CompoundNBT nbt ) public void load( @Nonnull CompoundNBT nbt )
{ {
super.load( nbt ); super.load( nbt );
m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
m_peripheral.read( nbt, "" ); peripheral.read( nbt, "" );
} }
@Nonnull @Nonnull
@Override @Override
public CompoundNBT save( CompoundNBT nbt ) public CompoundNBT save( CompoundNBT nbt )
{ {
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, m_peripheralAccessAllowed ); nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed );
m_peripheral.write( nbt, "" ); peripheral.write( nbt, "" );
return super.save( nbt ); return super.save( nbt );
} }
@ -302,7 +302,7 @@ public class TileCable extends TileGeneric
BlockState state = getBlockState(); BlockState state = getBlockState();
CableModemVariant oldVariant = state.getValue( BlockCable.MODEM ); CableModemVariant oldVariant = state.getValue( BlockCable.MODEM );
CableModemVariant newVariant = CableModemVariant CableModemVariant newVariant = CableModemVariant
.from( oldVariant.getFacing(), m_modem.getModemState().isOpen(), m_peripheralAccessAllowed ); .from( oldVariant.getFacing(), modem.getModemState().isOpen(), peripheralAccessAllowed );
if( oldVariant != newVariant ) if( oldVariant != newVariant )
{ {
@ -324,16 +324,16 @@ public class TileCable extends TileGeneric
elementCap = CapabilityUtil.invalidate( elementCap ); elementCap = CapabilityUtil.invalidate( elementCap );
} }
if( m_modem.getModemState().pollChanged() ) updateBlockState(); if( modem.getModemState().pollChanged() ) updateBlockState();
if( !m_connectionsFormed ) if( !connectionsFormed )
{ {
m_connectionsFormed = true; connectionsFormed = true;
connectionsChanged(); connectionsChanged();
if( m_peripheralAccessAllowed ) if( peripheralAccessAllowed )
{ {
m_peripheral.attach( level, worldPosition, modemDirection ); peripheral.attach( level, worldPosition, modemDirection );
updateConnectedPeripherals(); updateConnectedPeripherals();
} }
} }
@ -359,12 +359,12 @@ public class TileCable extends TileGeneric
if( BlockCable.canConnectIn( state, facing ) ) if( BlockCable.canConnectIn( state, facing ) )
{ {
// If we can connect to it then do so // If we can connect to it then do so
m_node.connectTo( node ); this.node.connectTo( node );
} }
else if( m_node.getNetwork() == node.getNetwork() ) else if( this.node.getNetwork() == node.getNetwork() )
{ {
// Otherwise if we're on the same network then attempt to void it. // Otherwise if we're on the same network then attempt to void it.
m_node.disconnectFrom( node ); this.node.disconnectFrom( node );
} }
} }
} }
@ -378,11 +378,11 @@ public class TileCable extends TileGeneric
// If we can no longer attach peripherals, then detach any // If we can no longer attach peripherals, then detach any
// which may have existed // which may have existed
if( !canAttachPeripheral() && m_peripheralAccessAllowed ) if( !canAttachPeripheral() && peripheralAccessAllowed )
{ {
m_peripheralAccessAllowed = false; peripheralAccessAllowed = false;
m_peripheral.detach(); peripheral.detach();
m_node.updatePeripherals( Collections.emptyMap() ); node.updatePeripherals( Collections.emptyMap() );
setChanged(); setChanged();
updateBlockState(); updateBlockState();
} }
@ -390,20 +390,20 @@ public class TileCable extends TileGeneric
private void togglePeripheralAccess() private void togglePeripheralAccess()
{ {
if( !m_peripheralAccessAllowed ) if( !peripheralAccessAllowed )
{ {
m_peripheral.attach( level, getBlockPos(), getDirection() ); peripheral.attach( level, getBlockPos(), getDirection() );
if( !m_peripheral.hasPeripheral() ) return; if( !peripheral.hasPeripheral() ) return;
m_peripheralAccessAllowed = true; peripheralAccessAllowed = true;
m_node.updatePeripherals( m_peripheral.toMap() ); node.updatePeripherals( peripheral.toMap() );
} }
else else
{ {
m_peripheral.detach(); peripheral.detach();
m_peripheralAccessAllowed = false; peripheralAccessAllowed = false;
m_node.updatePeripherals( Collections.emptyMap() ); node.updatePeripherals( Collections.emptyMap() );
} }
updateBlockState(); updateBlockState();
@ -411,15 +411,15 @@ public class TileCable extends TileGeneric
private void updateConnectedPeripherals() private void updateConnectedPeripherals()
{ {
Map<String, IPeripheral> peripherals = m_peripheral.toMap(); Map<String, IPeripheral> peripherals = peripheral.toMap();
if( peripherals.isEmpty() ) if( peripherals.isEmpty() )
{ {
// If there are no peripherals then disable access and update the display state. // If there are no peripherals then disable access and update the display state.
m_peripheralAccessAllowed = false; peripheralAccessAllowed = false;
updateBlockState(); updateBlockState();
} }
m_node.updatePeripherals( peripherals ); node.updatePeripherals( peripherals );
} }
@Override @Override
@ -434,8 +434,8 @@ public class TileCable extends TileGeneric
{ {
if( capability == CAPABILITY_WIRED_ELEMENT ) if( capability == CAPABILITY_WIRED_ELEMENT )
{ {
if( m_destroyed || !BlockCable.canConnectIn( getBlockState(), side ) ) return LazyOptional.empty(); if( destroyed || !BlockCable.canConnectIn( getBlockState(), side ) ) return LazyOptional.empty();
if( elementCap == null ) elementCap = LazyOptional.of( () -> m_cable ); if( elementCap == null ) elementCap = LazyOptional.of( () -> cable );
return elementCap.cast(); return elementCap.cast();
} }
@ -443,7 +443,7 @@ public class TileCable extends TileGeneric
{ {
refreshDirection(); refreshDirection();
if( side != null && getMaybeDirection() != side ) return LazyOptional.empty(); if( side != null && getMaybeDirection() != side ) return LazyOptional.empty();
if( modemCap == null ) modemCap = LazyOptional.of( () -> m_modem ); if( modemCap == null ) modemCap = LazyOptional.of( () -> modem );
return modemCap.cast(); return modemCap.cast();
} }

View File

@ -49,11 +49,11 @@ public class TileWiredModemFull extends TileGeneric
private static final class FullElement extends WiredModemElement private static final class FullElement extends WiredModemElement
{ {
private final TileWiredModemFull m_entity; private final TileWiredModemFull entity;
private FullElement( TileWiredModemFull entity ) private FullElement( TileWiredModemFull entity )
{ {
m_entity = entity; this.entity = entity;
} }
@Override @Override
@ -61,7 +61,7 @@ public class TileWiredModemFull extends TileGeneric
{ {
for( int i = 0; i < 6; i++ ) for( int i = 0; i < 6; i++ )
{ {
WiredModemPeripheral modem = m_entity.modems[i]; WiredModemPeripheral modem = entity.modems[i];
if( modem != null ) modem.attachPeripheral( name, peripheral ); if( modem != null ) modem.attachPeripheral( name, peripheral );
} }
} }
@ -71,7 +71,7 @@ public class TileWiredModemFull extends TileGeneric
{ {
for( int i = 0; i < 6; i++ ) for( int i = 0; i < 6; i++ )
{ {
WiredModemPeripheral modem = m_entity.modems[i]; WiredModemPeripheral modem = entity.modems[i];
if( modem != null ) modem.detachPeripheral( name ); if( modem != null ) modem.detachPeripheral( name );
} }
} }
@ -80,14 +80,14 @@ public class TileWiredModemFull extends TileGeneric
@Override @Override
public World getWorld() public World getWorld()
{ {
return m_entity.getLevel(); return entity.getLevel();
} }
@Nonnull @Nonnull
@Override @Override
public Vec3d getPosition() public Vec3d getPosition()
{ {
BlockPos pos = m_entity.getBlockPos(); BlockPos pos = entity.getBlockPos();
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
} }
} }
@ -95,26 +95,26 @@ public class TileWiredModemFull extends TileGeneric
private final WiredModemPeripheral[] modems = new WiredModemPeripheral[6]; private final WiredModemPeripheral[] modems = new WiredModemPeripheral[6];
private final SidedCaps<IPeripheral> modemCaps = SidedCaps.ofNonNull( this::getPeripheral ); private final SidedCaps<IPeripheral> modemCaps = SidedCaps.ofNonNull( this::getPeripheral );
private boolean m_peripheralAccessAllowed = false; private boolean peripheralAccessAllowed = false;
private final WiredModemLocalPeripheral[] m_peripherals = new WiredModemLocalPeripheral[6]; private final WiredModemLocalPeripheral[] peripherals = new WiredModemLocalPeripheral[6];
private boolean m_destroyed = false; private boolean destroyed = false;
private boolean m_connectionsFormed = false; private boolean connectionsFormed = false;
private final ModemState m_modemState = new ModemState( () -> TickScheduler.schedule( this ) ); private final ModemState modemState = new ModemState( () -> TickScheduler.schedule( this ) );
private final WiredModemElement m_element = new FullElement( this ); private final WiredModemElement element = new FullElement( this );
private LazyOptional<IWiredElement> elementCap; private LazyOptional<IWiredElement> elementCap;
private final IWiredNode m_node = m_element.getNode(); private final IWiredNode node = element.getNode();
private final NonNullConsumer<LazyOptional<IWiredElement>> connectedNodeChanged = x -> connectionsChanged(); private final NonNullConsumer<LazyOptional<IWiredElement>> connectedNodeChanged = x -> connectionsChanged();
public TileWiredModemFull( TileEntityType<TileWiredModemFull> type ) public TileWiredModemFull( TileEntityType<TileWiredModemFull> type )
{ {
super( type ); super( type );
for( int i = 0; i < m_peripherals.length; i++ ) for( int i = 0; i < peripherals.length; i++ )
{ {
Direction facing = Direction.from3DDataValue( i ); Direction facing = Direction.from3DDataValue( i );
m_peripherals[i] = new WiredModemLocalPeripheral( () -> refreshPeripheral( facing ) ); peripherals[i] = new WiredModemLocalPeripheral( () -> refreshPeripheral( facing ) );
} }
} }
@ -122,17 +122,17 @@ public class TileWiredModemFull extends TileGeneric
{ {
if( level == null || !level.isClientSide ) if( level == null || !level.isClientSide )
{ {
m_node.remove(); node.remove();
m_connectionsFormed = false; connectionsFormed = false;
} }
} }
@Override @Override
public void destroy() public void destroy()
{ {
if( !m_destroyed ) if( !destroyed )
{ {
m_destroyed = true; destroyed = true;
doRemove(); doRemove();
} }
super.destroy(); super.destroy();
@ -169,7 +169,7 @@ public class TileWiredModemFull extends TileGeneric
@Override @Override
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{ {
if( !level.isClientSide && m_peripheralAccessAllowed ) if( !level.isClientSide && peripheralAccessAllowed )
{ {
for( Direction facing : DirectionUtil.FACINGS ) for( Direction facing : DirectionUtil.FACINGS )
{ {
@ -180,7 +180,7 @@ public class TileWiredModemFull extends TileGeneric
private void refreshPeripheral( @Nonnull Direction facing ) private void refreshPeripheral( @Nonnull Direction facing )
{ {
WiredModemLocalPeripheral peripheral = m_peripherals[facing.ordinal()]; WiredModemLocalPeripheral peripheral = peripherals[facing.ordinal()];
if( level != null && !isRemoved() && peripheral.attach( level, getBlockPos(), facing ) ) if( level != null && !isRemoved() && peripheral.attach( level, getBlockPos(), facing ) )
{ {
updateConnectedPeripherals(); updateConnectedPeripherals();
@ -228,23 +228,23 @@ public class TileWiredModemFull extends TileGeneric
public void load( @Nonnull CompoundNBT nbt ) public void load( @Nonnull CompoundNBT nbt )
{ {
super.load( nbt ); super.load( nbt );
m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
for( int i = 0; i < m_peripherals.length; i++ ) m_peripherals[i].read( nbt, Integer.toString( i ) ); for( int i = 0; i < peripherals.length; i++ ) peripherals[i].read( nbt, Integer.toString( i ) );
} }
@Nonnull @Nonnull
@Override @Override
public CompoundNBT save( CompoundNBT nbt ) public CompoundNBT save( CompoundNBT nbt )
{ {
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, m_peripheralAccessAllowed ); nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed );
for( int i = 0; i < m_peripherals.length; i++ ) m_peripherals[i].write( nbt, Integer.toString( i ) ); for( int i = 0; i < peripherals.length; i++ ) peripherals[i].write( nbt, Integer.toString( i ) );
return super.save( nbt ); return super.save( nbt );
} }
private void updateBlockState() private void updateBlockState()
{ {
BlockState state = getBlockState(); BlockState state = getBlockState();
boolean modemOn = m_modemState.isOpen(), peripheralOn = m_peripheralAccessAllowed; boolean modemOn = modemState.isOpen(), peripheralOn = peripheralAccessAllowed;
if( state.getValue( MODEM_ON ) == modemOn && state.getValue( PERIPHERAL_ON ) == peripheralOn ) return; if( state.getValue( MODEM_ON ) == modemOn && state.getValue( PERIPHERAL_ON ) == peripheralOn ) return;
getLevel().setBlockAndUpdate( getBlockPos(), state.setValue( MODEM_ON, modemOn ).setValue( PERIPHERAL_ON, peripheralOn ) ); getLevel().setBlockAndUpdate( getBlockPos(), state.setValue( MODEM_ON, modemOn ).setValue( PERIPHERAL_ON, peripheralOn ) );
@ -262,18 +262,18 @@ public class TileWiredModemFull extends TileGeneric
{ {
if( getLevel().isClientSide ) return; if( getLevel().isClientSide ) return;
if( m_modemState.pollChanged() ) updateBlockState(); if( modemState.pollChanged() ) updateBlockState();
if( !m_connectionsFormed ) if( !connectionsFormed )
{ {
m_connectionsFormed = true; connectionsFormed = true;
connectionsChanged(); connectionsChanged();
if( m_peripheralAccessAllowed ) if( peripheralAccessAllowed )
{ {
for( Direction facing : DirectionUtil.FACINGS ) for( Direction facing : DirectionUtil.FACINGS )
{ {
m_peripherals[facing.ordinal()].attach( level, getBlockPos(), facing ); peripherals[facing.ordinal()].attach( level, getBlockPos(), facing );
} }
updateConnectedPeripherals(); updateConnectedPeripherals();
} }
@ -295,33 +295,33 @@ public class TileWiredModemFull extends TileGeneric
if( !element.isPresent() ) continue; if( !element.isPresent() ) continue;
element.addListener( connectedNodeChanged ); element.addListener( connectedNodeChanged );
m_node.connectTo( element.orElseThrow( NullPointerException::new ).getNode() ); node.connectTo( element.orElseThrow( NullPointerException::new ).getNode() );
} }
} }
private void togglePeripheralAccess() private void togglePeripheralAccess()
{ {
if( !m_peripheralAccessAllowed ) if( !peripheralAccessAllowed )
{ {
boolean hasAny = false; boolean hasAny = false;
for( Direction facing : DirectionUtil.FACINGS ) for( Direction facing : DirectionUtil.FACINGS )
{ {
WiredModemLocalPeripheral peripheral = m_peripherals[facing.ordinal()]; WiredModemLocalPeripheral peripheral = peripherals[facing.ordinal()];
peripheral.attach( level, getBlockPos(), facing ); peripheral.attach( level, getBlockPos(), facing );
hasAny |= peripheral.hasPeripheral(); hasAny |= peripheral.hasPeripheral();
} }
if( !hasAny ) return; if( !hasAny ) return;
m_peripheralAccessAllowed = true; peripheralAccessAllowed = true;
m_node.updatePeripherals( getConnectedPeripherals() ); node.updatePeripherals( getConnectedPeripherals() );
} }
else else
{ {
m_peripheralAccessAllowed = false; peripheralAccessAllowed = false;
for( WiredModemLocalPeripheral peripheral : m_peripherals ) peripheral.detach(); for( WiredModemLocalPeripheral peripheral : peripherals ) peripheral.detach();
m_node.updatePeripherals( Collections.emptyMap() ); node.updatePeripherals( Collections.emptyMap() );
} }
updateBlockState(); updateBlockState();
@ -329,10 +329,10 @@ public class TileWiredModemFull extends TileGeneric
private Set<String> getConnectedPeripheralNames() private Set<String> getConnectedPeripheralNames()
{ {
if( !m_peripheralAccessAllowed ) return Collections.emptySet(); if( !peripheralAccessAllowed ) return Collections.emptySet();
Set<String> peripherals = new HashSet<>( 6 ); Set<String> peripherals = new HashSet<>( 6 );
for( WiredModemLocalPeripheral peripheral : m_peripherals ) for( WiredModemLocalPeripheral peripheral : this.peripherals )
{ {
String name = peripheral.getConnectedName(); String name = peripheral.getConnectedName();
if( name != null ) peripherals.add( name ); if( name != null ) peripherals.add( name );
@ -342,10 +342,10 @@ public class TileWiredModemFull extends TileGeneric
private Map<String, IPeripheral> getConnectedPeripherals() private Map<String, IPeripheral> getConnectedPeripherals()
{ {
if( !m_peripheralAccessAllowed ) return Collections.emptyMap(); if( !peripheralAccessAllowed ) return Collections.emptyMap();
Map<String, IPeripheral> peripherals = new HashMap<>( 6 ); Map<String, IPeripheral> peripherals = new HashMap<>( 6 );
for( WiredModemLocalPeripheral peripheral : m_peripherals ) peripheral.extendMap( peripherals ); for( WiredModemLocalPeripheral peripheral : this.peripherals ) peripheral.extendMap( peripherals );
return peripherals; return peripherals;
} }
@ -355,11 +355,11 @@ public class TileWiredModemFull extends TileGeneric
if( peripherals.isEmpty() ) if( peripherals.isEmpty() )
{ {
// If there are no peripherals then disable access and update the display state. // If there are no peripherals then disable access and update the display state.
m_peripheralAccessAllowed = false; peripheralAccessAllowed = false;
updateBlockState(); updateBlockState();
} }
m_node.updatePeripherals( peripherals ); node.updatePeripherals( peripherals );
} }
@Nonnull @Nonnull
@ -368,7 +368,7 @@ public class TileWiredModemFull extends TileGeneric
{ {
if( capability == CAPABILITY_WIRED_ELEMENT ) if( capability == CAPABILITY_WIRED_ELEMENT )
{ {
if( elementCap == null ) elementCap = LazyOptional.of( () -> m_element ); if( elementCap == null ) elementCap = LazyOptional.of( () -> element );
return elementCap.cast(); return elementCap.cast();
} }
@ -379,7 +379,7 @@ public class TileWiredModemFull extends TileGeneric
public IWiredElement getElement() public IWiredElement getElement()
{ {
return m_element; return element;
} }
private WiredModemPeripheral getPeripheral( @Nonnull Direction side ) private WiredModemPeripheral getPeripheral( @Nonnull Direction side )
@ -387,8 +387,8 @@ public class TileWiredModemFull extends TileGeneric
WiredModemPeripheral peripheral = modems[side.ordinal()]; WiredModemPeripheral peripheral = modems[side.ordinal()];
if( peripheral != null ) return peripheral; if( peripheral != null ) return peripheral;
WiredModemLocalPeripheral localPeripheral = m_peripherals[side.ordinal()]; WiredModemLocalPeripheral localPeripheral = peripherals[side.ordinal()];
return modems[side.ordinal()] = new WiredModemPeripheral( m_modemState, m_element ) return modems[side.ordinal()] = new WiredModemPeripheral( modemState, element )
{ {
@Nonnull @Nonnull
@Override @Override

View File

@ -14,24 +14,24 @@ import net.minecraft.world.World;
public abstract class WirelessModemPeripheral extends ModemPeripheral public abstract class WirelessModemPeripheral extends ModemPeripheral
{ {
private final boolean m_advanced; private final boolean advanced;
public WirelessModemPeripheral( ModemState state, boolean advanced ) public WirelessModemPeripheral( ModemState state, boolean advanced )
{ {
super( state ); super( state );
m_advanced = advanced; this.advanced = advanced;
} }
@Override @Override
public boolean isInterdimensional() public boolean isInterdimensional()
{ {
return m_advanced; return advanced;
} }
@Override @Override
public double getRange() public double getRange()
{ {
if( m_advanced ) if( advanced )
{ {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }

View File

@ -18,50 +18,47 @@ import java.util.concurrent.ConcurrentHashMap;
public class WirelessNetwork implements IPacketNetwork public class WirelessNetwork implements IPacketNetwork
{ {
private static WirelessNetwork s_universalNetwork = null; private static WirelessNetwork universalNetwork = null;
public static WirelessNetwork getUniversal() public static WirelessNetwork getUniversal()
{ {
if( s_universalNetwork == null ) if( universalNetwork == null ) universalNetwork = new WirelessNetwork();
{ return universalNetwork;
s_universalNetwork = new WirelessNetwork();
}
return s_universalNetwork;
} }
public static void resetNetworks() public static void resetNetworks()
{ {
s_universalNetwork = null; universalNetwork = null;
} }
private final Set<IPacketReceiver> m_receivers = Collections.newSetFromMap( new ConcurrentHashMap<>() ); private final Set<IPacketReceiver> receivers = Collections.newSetFromMap( new ConcurrentHashMap<>() );
@Override @Override
public void addReceiver( @Nonnull IPacketReceiver receiver ) public void addReceiver( @Nonnull IPacketReceiver receiver )
{ {
Objects.requireNonNull( receiver, "device cannot be null" ); Objects.requireNonNull( receiver, "device cannot be null" );
m_receivers.add( receiver ); receivers.add( receiver );
} }
@Override @Override
public void removeReceiver( @Nonnull IPacketReceiver receiver ) public void removeReceiver( @Nonnull IPacketReceiver receiver )
{ {
Objects.requireNonNull( receiver, "device cannot be null" ); Objects.requireNonNull( receiver, "device cannot be null" );
m_receivers.remove( receiver ); receivers.remove( receiver );
} }
@Override @Override
public void transmitSameDimension( @Nonnull Packet packet, double range ) public void transmitSameDimension( @Nonnull Packet packet, double range )
{ {
Objects.requireNonNull( packet, "packet cannot be null" ); Objects.requireNonNull( packet, "packet cannot be null" );
for( IPacketReceiver device : m_receivers ) tryTransmit( device, packet, range, false ); for( IPacketReceiver device : receivers ) tryTransmit( device, packet, range, false );
} }
@Override @Override
public void transmitInterdimensional( @Nonnull Packet packet ) public void transmitInterdimensional( @Nonnull Packet packet )
{ {
Objects.requireNonNull( packet, "packet cannot be null" ); Objects.requireNonNull( packet, "packet cannot be null" );
for( IPacketReceiver device : m_receivers ) tryTransmit( device, packet, 0, true ); for( IPacketReceiver device : receivers ) tryTransmit( device, packet, 0, true );
} }
private static void tryTransmit( IPacketReceiver receiver, Packet packet, double range, boolean interdimensional ) private static void tryTransmit( IPacketReceiver receiver, Packet packet, double range, boolean interdimensional )

View File

@ -49,23 +49,23 @@ public class TileMonitor extends TileGeneric
private final boolean advanced; private final boolean advanced;
private ServerMonitor m_serverMonitor; private ServerMonitor serverMonitor;
private ClientMonitor m_clientMonitor; private ClientMonitor clientMonitor;
private MonitorPeripheral peripheral; private MonitorPeripheral peripheral;
private LazyOptional<IPeripheral> peripheralCap; private LazyOptional<IPeripheral> peripheralCap;
private final Set<IComputerAccess> m_computers = new HashSet<>(); private final Set<IComputerAccess> computers = new HashSet<>();
private boolean m_destroyed = false; private boolean destroyed = false;
private boolean visiting = false; private boolean visiting = false;
// MonitorWatcher state. // MonitorWatcher state.
boolean enqueued; boolean enqueued;
TerminalState cached; TerminalState cached;
private int m_width = 1; private int width = 1;
private int m_height = 1; private int height = 1;
private int m_xIndex = 0; private int xIndex = 0;
private int m_yIndex = 0; private int yIndex = 0;
public TileMonitor( TileEntityType<? extends TileMonitor> type, boolean advanced ) public TileMonitor( TileEntityType<? extends TileMonitor> type, boolean advanced )
{ {
@ -84,8 +84,8 @@ public class TileMonitor extends TileGeneric
public void destroy() public void destroy()
{ {
// TODO: Call this before using the block // TODO: Call this before using the block
if( m_destroyed ) return; if( destroyed ) return;
m_destroyed = true; destroyed = true;
if( !getLevel().isClientSide ) contractNeighbours(); if( !getLevel().isClientSide ) contractNeighbours();
} }
@ -93,14 +93,14 @@ public class TileMonitor extends TileGeneric
public void setRemoved() public void setRemoved()
{ {
super.setRemoved(); super.setRemoved();
if( m_clientMonitor != null && m_xIndex == 0 && m_yIndex == 0 ) m_clientMonitor.destroy(); if( clientMonitor != null && xIndex == 0 && yIndex == 0 ) clientMonitor.destroy();
} }
@Override @Override
public void onChunkUnloaded() public void onChunkUnloaded()
{ {
super.onChunkUnloaded(); super.onChunkUnloaded();
if( m_clientMonitor != null && m_xIndex == 0 && m_yIndex == 0 ) m_clientMonitor.destroy(); if( clientMonitor != null && xIndex == 0 && yIndex == 0 ) clientMonitor.destroy();
} }
@Nonnull @Nonnull
@ -127,10 +127,10 @@ public class TileMonitor extends TileGeneric
@Override @Override
public CompoundNBT save( CompoundNBT tag ) public CompoundNBT save( CompoundNBT tag )
{ {
tag.putInt( NBT_X, m_xIndex ); tag.putInt( NBT_X, xIndex );
tag.putInt( NBT_Y, m_yIndex ); tag.putInt( NBT_Y, yIndex );
tag.putInt( NBT_WIDTH, m_width ); tag.putInt( NBT_WIDTH, width );
tag.putInt( NBT_HEIGHT, m_height ); tag.putInt( NBT_HEIGHT, height );
return super.save( tag ); return super.save( tag );
} }
@ -138,29 +138,29 @@ public class TileMonitor extends TileGeneric
public void load( @Nonnull CompoundNBT tag ) public void load( @Nonnull CompoundNBT tag )
{ {
super.load( tag ); super.load( tag );
m_xIndex = tag.getInt( NBT_X ); xIndex = tag.getInt( NBT_X );
m_yIndex = tag.getInt( NBT_Y ); yIndex = tag.getInt( NBT_Y );
m_width = tag.getInt( NBT_WIDTH ); width = tag.getInt( NBT_WIDTH );
m_height = tag.getInt( NBT_HEIGHT ); height = tag.getInt( NBT_HEIGHT );
} }
@Override @Override
public void blockTick() public void blockTick()
{ {
if( m_xIndex != 0 || m_yIndex != 0 || m_serverMonitor == null ) return; if( xIndex != 0 || yIndex != 0 || serverMonitor == null ) return;
m_serverMonitor.clearChanged(); serverMonitor.clearChanged();
if( m_serverMonitor.pollResized() ) if( serverMonitor.pollResized() )
{ {
for( int x = 0; x < m_width; x++ ) for( int x = 0; x < width; x++ )
{ {
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
TileMonitor monitor = getNeighbour( x, y ); TileMonitor monitor = getNeighbour( x, y );
if( monitor == null ) continue; if( monitor == null ) continue;
for( IComputerAccess computer : monitor.m_computers ) for( IComputerAccess computer : monitor.computers )
{ {
computer.queueEvent( "monitor_resize", computer.getAttachmentName() ); computer.queueEvent( "monitor_resize", computer.getAttachmentName() );
} }
@ -168,7 +168,7 @@ public class TileMonitor extends TileGeneric
} }
} }
if( m_serverMonitor.pollTerminalChanged() ) MonitorWatcher.enqueue( this ); if( serverMonitor.pollTerminalChanged() ) MonitorWatcher.enqueue( this );
} }
@Override @Override
@ -194,62 +194,62 @@ public class TileMonitor extends TileGeneric
public ServerMonitor getCachedServerMonitor() public ServerMonitor getCachedServerMonitor()
{ {
return m_serverMonitor; return serverMonitor;
} }
private ServerMonitor getServerMonitor() private ServerMonitor getServerMonitor()
{ {
if( m_serverMonitor != null ) return m_serverMonitor; if( serverMonitor != null ) return serverMonitor;
TileMonitor origin = getOrigin(); TileMonitor origin = getOrigin();
if( origin == null ) return null; if( origin == null ) return null;
return m_serverMonitor = origin.m_serverMonitor; return serverMonitor = origin.serverMonitor;
} }
private ServerMonitor createServerMonitor() private ServerMonitor createServerMonitor()
{ {
if( m_serverMonitor != null ) return m_serverMonitor; if( serverMonitor != null ) return serverMonitor;
if( m_xIndex == 0 && m_yIndex == 0 ) if( xIndex == 0 && yIndex == 0 )
{ {
// If we're the origin, set up the new monitor // If we're the origin, set up the new monitor
m_serverMonitor = new ServerMonitor( advanced, this ); serverMonitor = new ServerMonitor( advanced, this );
m_serverMonitor.rebuild(); serverMonitor.rebuild();
// And propagate it to child monitors // And propagate it to child monitors
for( int x = 0; x < m_width; x++ ) for( int x = 0; x < width; x++ )
{ {
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
TileMonitor monitor = getNeighbour( x, y ); TileMonitor monitor = getNeighbour( x, y );
if( monitor != null ) monitor.m_serverMonitor = m_serverMonitor; if( monitor != null ) monitor.serverMonitor = serverMonitor;
} }
} }
return m_serverMonitor; return serverMonitor;
} }
else else
{ {
// Otherwise fetch the origin and attempt to get its monitor // Otherwise fetch the origin and attempt to get its monitor
// Note this may load chunks, but we don't really have a choice here. // Note this may load chunks, but we don't really have a choice here.
BlockPos pos = getBlockPos(); BlockPos pos = getBlockPos();
TileEntity te = level.getBlockEntity( pos.relative( getRight(), -m_xIndex ).relative( getDown(), -m_yIndex ) ); TileEntity te = level.getBlockEntity( pos.relative( getRight(), -xIndex ).relative( getDown(), -yIndex ) );
if( !(te instanceof TileMonitor) ) return null; if( !(te instanceof TileMonitor) ) return null;
return m_serverMonitor = ((TileMonitor) te).createServerMonitor(); return serverMonitor = ((TileMonitor) te).createServerMonitor();
} }
} }
public ClientMonitor getClientMonitor() public ClientMonitor getClientMonitor()
{ {
if( m_clientMonitor != null ) return m_clientMonitor; if( clientMonitor != null ) return clientMonitor;
BlockPos pos = getBlockPos(); BlockPos pos = getBlockPos();
TileEntity te = level.getBlockEntity( pos.relative( getRight(), -m_xIndex ).relative( getDown(), -m_yIndex ) ); TileEntity te = level.getBlockEntity( pos.relative( getRight(), -xIndex ).relative( getDown(), -yIndex ) );
if( !(te instanceof TileMonitor) ) return null; if( !(te instanceof TileMonitor) ) return null;
return m_clientMonitor = ((TileMonitor) te).m_clientMonitor; return clientMonitor = ((TileMonitor) te).clientMonitor;
} }
// Networking stuff // Networking stuff
@ -258,10 +258,10 @@ public class TileMonitor extends TileGeneric
protected void writeDescription( @Nonnull CompoundNBT nbt ) protected void writeDescription( @Nonnull CompoundNBT nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
nbt.putInt( NBT_X, m_xIndex ); nbt.putInt( NBT_X, xIndex );
nbt.putInt( NBT_Y, m_yIndex ); nbt.putInt( NBT_Y, yIndex );
nbt.putInt( NBT_WIDTH, m_width ); nbt.putInt( NBT_WIDTH, width );
nbt.putInt( NBT_HEIGHT, m_height ); nbt.putInt( NBT_HEIGHT, height );
} }
@Override @Override
@ -269,32 +269,32 @@ public class TileMonitor extends TileGeneric
{ {
super.readDescription( nbt ); super.readDescription( nbt );
int oldXIndex = m_xIndex; int oldXIndex = xIndex;
int oldYIndex = m_yIndex; int oldYIndex = yIndex;
int oldWidth = m_width; int oldWidth = width;
int oldHeight = m_height; int oldHeight = height;
m_xIndex = nbt.getInt( NBT_X ); xIndex = nbt.getInt( NBT_X );
m_yIndex = nbt.getInt( NBT_Y ); yIndex = nbt.getInt( NBT_Y );
m_width = nbt.getInt( NBT_WIDTH ); width = nbt.getInt( NBT_WIDTH );
m_height = nbt.getInt( NBT_HEIGHT ); height = nbt.getInt( NBT_HEIGHT );
if( oldXIndex != m_xIndex || oldYIndex != m_yIndex ) if( oldXIndex != xIndex || oldYIndex != yIndex )
{ {
// If our index has changed then it's possible the origin monitor has changed. Thus // If our index has changed then it's possible the origin monitor has changed. Thus
// we'll clear our cache. If we're the origin then we'll need to remove the glList as well. // we'll clear our cache. If we're the origin then we'll need to remove the glList as well.
if( oldXIndex == 0 && oldYIndex == 0 && m_clientMonitor != null ) m_clientMonitor.destroy(); if( oldXIndex == 0 && oldYIndex == 0 && clientMonitor != null ) clientMonitor.destroy();
m_clientMonitor = null; clientMonitor = null;
} }
if( m_xIndex == 0 && m_yIndex == 0 ) if( xIndex == 0 && yIndex == 0 )
{ {
// If we're the origin terminal then create it. // If we're the origin terminal then create it.
if( m_clientMonitor == null ) m_clientMonitor = new ClientMonitor( advanced, this ); if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
} }
if( oldXIndex != m_xIndex || oldYIndex != m_yIndex || if( oldXIndex != xIndex || oldYIndex != yIndex ||
oldWidth != m_width || oldHeight != m_height ) oldWidth != width || oldHeight != height )
{ {
// One of our properties has changed, so ensure we redraw the block // One of our properties has changed, so ensure we redraw the block
updateBlock(); updateBlock();
@ -303,14 +303,14 @@ public class TileMonitor extends TileGeneric
public final void read( TerminalState state ) public final void read( TerminalState state )
{ {
if( m_xIndex != 0 || m_yIndex != 0 ) if( xIndex != 0 || yIndex != 0 )
{ {
ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", getBlockPos() ); ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", getBlockPos() );
return; return;
} }
if( m_clientMonitor == null ) m_clientMonitor = new ClientMonitor( advanced, this ); if( clientMonitor == null ) clientMonitor = new ClientMonitor( advanced, this );
m_clientMonitor.read( state ); clientMonitor.read( state );
} }
// Sizing and placement stuff // Sizing and placement stuff
@ -319,8 +319,8 @@ public class TileMonitor extends TileGeneric
{ {
getLevel().setBlock( getBlockPos(), getBlockState() getLevel().setBlock( getBlockPos(), getBlockState()
.setValue( BlockMonitor.STATE, MonitorEdgeState.fromConnections( .setValue( BlockMonitor.STATE, MonitorEdgeState.fromConnections(
m_yIndex < m_height - 1, m_yIndex > 0, yIndex < height - 1, yIndex > 0,
m_xIndex > 0, m_xIndex < m_width - 1 ) ), 2 ); xIndex > 0, xIndex < width - 1 ) ), 2 );
} }
// region Sizing and placement stuff // region Sizing and placement stuff
@ -358,22 +358,22 @@ public class TileMonitor extends TileGeneric
public int getWidth() public int getWidth()
{ {
return m_width; return width;
} }
public int getHeight() public int getHeight()
{ {
return m_height; return height;
} }
public int getXIndex() public int getXIndex()
{ {
return m_xIndex; return xIndex;
} }
public int getYIndex() public int getYIndex()
{ {
return m_yIndex; return yIndex;
} }
private TileMonitor getSimilarMonitorAt( BlockPos pos ) private TileMonitor getSimilarMonitorAt( BlockPos pos )
@ -388,7 +388,7 @@ public class TileMonitor extends TileGeneric
if( !(tile instanceof TileMonitor) ) return null; if( !(tile instanceof TileMonitor) ) return null;
TileMonitor monitor = (TileMonitor) tile; TileMonitor monitor = (TileMonitor) tile;
return !monitor.visiting && !monitor.m_destroyed && advanced == monitor.advanced return !monitor.visiting && !monitor.destroyed && advanced == monitor.advanced
&& getDirection() == monitor.getDirection() && getOrientation() == monitor.getOrientation() && getDirection() == monitor.getDirection() && getOrientation() == monitor.getOrientation()
? monitor : null; ? monitor : null;
} }
@ -398,8 +398,8 @@ public class TileMonitor extends TileGeneric
BlockPos pos = getBlockPos(); BlockPos pos = getBlockPos();
Direction right = getRight(); Direction right = getRight();
Direction down = getDown(); Direction down = getDown();
int xOffset = -m_xIndex + x; int xOffset = -xIndex + x;
int yOffset = -m_yIndex + y; int yOffset = -yIndex + y;
return getSimilarMonitorAt( pos.relative( right, xOffset ).relative( down, yOffset ) ); return getSimilarMonitorAt( pos.relative( right, xOffset ).relative( down, yOffset ) );
} }
@ -411,12 +411,12 @@ public class TileMonitor extends TileGeneric
private void resize( int width, int height ) private void resize( int width, int height )
{ {
// If we're not already the origin then we'll need to generate a new terminal. // If we're not already the origin then we'll need to generate a new terminal.
if( m_xIndex != 0 || m_yIndex != 0 ) m_serverMonitor = null; if( xIndex != 0 || yIndex != 0 ) serverMonitor = null;
m_xIndex = 0; xIndex = 0;
m_yIndex = 0; yIndex = 0;
m_width = width; this.width = width;
m_height = height; this.height = height;
// Determine if we actually need a monitor. In order to do this, simply check if // Determine if we actually need a monitor. In order to do this, simply check if
// any component monitor been wrapped as a peripheral. Whilst this flag may be // any component monitor been wrapped as a peripheral. Whilst this flag may be
@ -439,16 +439,16 @@ public class TileMonitor extends TileGeneric
// Either delete the current monitor or sync a new one. // Either delete the current monitor or sync a new one.
if( needsTerminal ) if( needsTerminal )
{ {
if( m_serverMonitor == null ) m_serverMonitor = new ServerMonitor( advanced, this ); if( serverMonitor == null ) serverMonitor = new ServerMonitor( advanced, this );
} }
else else
{ {
m_serverMonitor = null; serverMonitor = null;
} }
// Update the terminal's width and height and rebuild it. This ensures the monitor // Update the terminal's width and height and rebuild it. This ensures the monitor
// is consistent when syncing it to other monitors. // is consistent when syncing it to other monitors.
if( m_serverMonitor != null ) m_serverMonitor.rebuild(); if( serverMonitor != null ) serverMonitor.rebuild();
// Update the other monitors, setting coordinates, dimensions and the server terminal // Update the other monitors, setting coordinates, dimensions and the server terminal
for( int x = 0; x < width; x++ ) for( int x = 0; x < width; x++ )
@ -458,11 +458,11 @@ public class TileMonitor extends TileGeneric
TileMonitor monitor = getNeighbour( x, y ); TileMonitor monitor = getNeighbour( x, y );
if( monitor == null ) continue; if( monitor == null ) continue;
monitor.m_xIndex = x; monitor.xIndex = x;
monitor.m_yIndex = y; monitor.yIndex = y;
monitor.m_width = width; monitor.width = width;
monitor.m_height = height; monitor.height = height;
monitor.m_serverMonitor = m_serverMonitor; monitor.serverMonitor = serverMonitor;
monitor.updateBlockState(); monitor.updateBlockState();
monitor.updateBlock(); monitor.updateBlock();
} }
@ -472,41 +472,41 @@ public class TileMonitor extends TileGeneric
private boolean mergeLeft() private boolean mergeLeft()
{ {
TileMonitor left = getNeighbour( -1, 0 ); TileMonitor left = getNeighbour( -1, 0 );
if( left == null || left.m_yIndex != 0 || left.m_height != m_height ) return false; if( left == null || left.yIndex != 0 || left.height != height ) return false;
int width = left.m_width + m_width; int width = left.width + this.width;
if( width > ComputerCraft.monitorWidth ) return false; if( width > ComputerCraft.monitorWidth ) return false;
TileMonitor origin = left.getOrigin(); TileMonitor origin = left.getOrigin();
if( origin != null ) origin.resize( width, m_height ); if( origin != null ) origin.resize( width, height );
left.expand(); left.expand();
return true; return true;
} }
private boolean mergeRight() private boolean mergeRight()
{ {
TileMonitor right = getNeighbour( m_width, 0 ); TileMonitor right = getNeighbour( width, 0 );
if( right == null || right.m_yIndex != 0 || right.m_height != m_height ) return false; if( right == null || right.yIndex != 0 || right.height != height ) return false;
int width = m_width + right.m_width; int width = this.width + right.width;
if( width > ComputerCraft.monitorWidth ) return false; if( width > ComputerCraft.monitorWidth ) return false;
TileMonitor origin = getOrigin(); TileMonitor origin = getOrigin();
if( origin != null ) origin.resize( width, m_height ); if( origin != null ) origin.resize( width, height );
expand(); expand();
return true; return true;
} }
private boolean mergeUp() private boolean mergeUp()
{ {
TileMonitor above = getNeighbour( 0, m_height ); TileMonitor above = getNeighbour( 0, height );
if( above == null || above.m_xIndex != 0 || above.m_width != m_width ) return false; if( above == null || above.xIndex != 0 || above.width != width ) return false;
int height = above.m_height + m_height; int height = above.height + this.height;
if( height > ComputerCraft.monitorHeight ) return false; if( height > ComputerCraft.monitorHeight ) return false;
TileMonitor origin = getOrigin(); TileMonitor origin = getOrigin();
if( origin != null ) origin.resize( m_width, height ); if( origin != null ) origin.resize( width, height );
expand(); expand();
return true; return true;
} }
@ -514,13 +514,13 @@ public class TileMonitor extends TileGeneric
private boolean mergeDown() private boolean mergeDown()
{ {
TileMonitor below = getNeighbour( 0, -1 ); TileMonitor below = getNeighbour( 0, -1 );
if( below == null || below.m_xIndex != 0 || below.m_width != m_width ) return false; if( below == null || below.xIndex != 0 || below.width != width ) return false;
int height = m_height + below.m_height; int height = this.height + below.height;
if( height > ComputerCraft.monitorHeight ) return false; if( height > ComputerCraft.monitorHeight ) return false;
TileMonitor origin = below.getOrigin(); TileMonitor origin = below.getOrigin();
if( origin != null ) origin.resize( m_width, height ); if( origin != null ) origin.resize( width, height );
below.expand(); below.expand();
return true; return true;
} }
@ -534,24 +534,24 @@ public class TileMonitor extends TileGeneric
void contractNeighbours() void contractNeighbours()
{ {
visiting = true; visiting = true;
if( m_xIndex > 0 ) if( xIndex > 0 )
{ {
TileMonitor left = getNeighbour( m_xIndex - 1, m_yIndex ); TileMonitor left = getNeighbour( xIndex - 1, yIndex );
if( left != null ) left.contract(); if( left != null ) left.contract();
} }
if( m_xIndex + 1 < m_width ) if( xIndex + 1 < width )
{ {
TileMonitor right = getNeighbour( m_xIndex + 1, m_yIndex ); TileMonitor right = getNeighbour( xIndex + 1, yIndex );
if( right != null ) right.contract(); if( right != null ) right.contract();
} }
if( m_yIndex > 0 ) if( yIndex > 0 )
{ {
TileMonitor below = getNeighbour( m_xIndex, m_yIndex - 1 ); TileMonitor below = getNeighbour( xIndex, yIndex - 1 );
if( below != null ) below.contract(); if( below != null ) below.contract();
} }
if( m_yIndex + 1 < m_height ) if( yIndex + 1 < height )
{ {
TileMonitor above = getNeighbour( m_xIndex, m_yIndex + 1 ); TileMonitor above = getNeighbour( xIndex, yIndex + 1 );
if( above != null ) above.contract(); if( above != null ) above.contract();
} }
visiting = false; visiting = false;
@ -559,8 +559,8 @@ public class TileMonitor extends TileGeneric
void contract() void contract()
{ {
int height = m_height; int height = this.height;
int width = m_width; int width = this.width;
TileMonitor origin = getOrigin(); TileMonitor origin = getOrigin();
if( origin == null ) if( origin == null )
@ -624,9 +624,9 @@ public class TileMonitor extends TileGeneric
{ {
XYPair pair = XYPair XYPair pair = XYPair
.of( xPos, yPos, zPos, getDirection(), getOrientation() ) .of( xPos, yPos, zPos, getDirection(), getOrientation() )
.add( m_xIndex, m_height - m_yIndex - 1 ); .add( xIndex, height - yIndex - 1 );
if( pair.x > m_width - RENDER_BORDER || pair.y > m_height - RENDER_BORDER || pair.x < RENDER_BORDER || pair.y < RENDER_BORDER ) if( pair.x > width - RENDER_BORDER || pair.y > height - RENDER_BORDER || pair.x < RENDER_BORDER || pair.y < RENDER_BORDER )
{ {
return; return;
} }
@ -637,20 +637,20 @@ public class TileMonitor extends TileGeneric
Terminal originTerminal = serverTerminal.getTerminal(); Terminal originTerminal = serverTerminal.getTerminal();
if( originTerminal == null ) return; if( originTerminal == null ) return;
double xCharWidth = (m_width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth(); double xCharWidth = (width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth();
double yCharHeight = (m_height - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getHeight(); double yCharHeight = (height - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getHeight();
int xCharPos = (int) Math.min( originTerminal.getWidth(), Math.max( (pair.x - RENDER_BORDER - RENDER_MARGIN) / xCharWidth + 1.0, 1.0 ) ); int xCharPos = (int) Math.min( originTerminal.getWidth(), Math.max( (pair.x - RENDER_BORDER - RENDER_MARGIN) / xCharWidth + 1.0, 1.0 ) );
int yCharPos = (int) Math.min( originTerminal.getHeight(), Math.max( (pair.y - RENDER_BORDER - RENDER_MARGIN) / yCharHeight + 1.0, 1.0 ) ); int yCharPos = (int) Math.min( originTerminal.getHeight(), Math.max( (pair.y - RENDER_BORDER - RENDER_MARGIN) / yCharHeight + 1.0, 1.0 ) );
for( int y = 0; y < m_height; y++ ) for( int y = 0; y < height; y++ )
{ {
for( int x = 0; x < m_width; x++ ) for( int x = 0; x < width; x++ )
{ {
TileMonitor monitor = getNeighbour( x, y ); TileMonitor monitor = getNeighbour( x, y );
if( monitor == null ) continue; if( monitor == null ) continue;
for( IComputerAccess computer : monitor.m_computers ) for( IComputerAccess computer : monitor.computers )
{ {
computer.queueEvent( "monitor_touch", computer.getAttachmentName(), xCharPos, yCharPos ); computer.queueEvent( "monitor_touch", computer.getAttachmentName(), xCharPos, yCharPos );
} }
@ -661,12 +661,12 @@ public class TileMonitor extends TileGeneric
void addComputer( IComputerAccess computer ) void addComputer( IComputerAccess computer )
{ {
m_computers.add( computer ); computers.add( computer );
} }
void removeComputer( IComputerAccess computer ) void removeComputer( IComputerAccess computer )
{ {
m_computers.remove( computer ); computers.remove( computer );
} }
@Nonnull @Nonnull
@ -674,7 +674,7 @@ public class TileMonitor extends TileGeneric
public AxisAlignedBB getRenderBoundingBox() public AxisAlignedBB getRenderBoundingBox()
{ {
TileMonitor start = getNeighbour( 0, 0 ); TileMonitor start = getNeighbour( 0, 0 );
TileMonitor end = getNeighbour( m_width - 1, m_height - 1 ); TileMonitor end = getNeighbour( width - 1, height - 1 );
if( start != null && end != null ) if( start != null && end != null )
{ {
BlockPos startPos = start.getBlockPos(); BlockPos startPos = start.getBlockPos();

View File

@ -55,14 +55,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
ITextComponent customName; ITextComponent customName;
private final NonNullList<ItemStack> m_inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY ); private final NonNullList<ItemStack> inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY );
private final SidedCaps<IItemHandler> itemHandlerCaps = private final SidedCaps<IItemHandler> itemHandlerCaps =
SidedCaps.ofNullable( facing -> facing == null ? new InvWrapper( this ) : new SidedInvWrapper( this, facing ) ); SidedCaps.ofNullable( facing -> facing == null ? new InvWrapper( this ) : new SidedInvWrapper( this, facing ) );
private LazyOptional<IPeripheral> peripheralCap; private LazyOptional<IPeripheral> peripheralCap;
private final Terminal m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE ); private final Terminal page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
private String m_pageTitle = ""; private String pageTitle = "";
private boolean m_printing = false; private boolean printing = false;
public TilePrinter( TileEntityType<TilePrinter> type ) public TilePrinter( TileEntityType<TilePrinter> type )
{ {
@ -101,15 +101,15 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
// Read page // Read page
synchronized( m_page ) synchronized( page )
{ {
m_printing = nbt.getBoolean( NBT_PRINTING ); printing = nbt.getBoolean( NBT_PRINTING );
m_pageTitle = nbt.getString( NBT_PAGE_TITLE ); pageTitle = nbt.getString( NBT_PAGE_TITLE );
m_page.readFromNBT( nbt ); page.readFromNBT( nbt );
} }
// Read inventory // Read inventory
ItemStackHelper.loadAllItems( nbt, m_inventory ); ItemStackHelper.loadAllItems( nbt, inventory );
} }
@Nonnull @Nonnull
@ -119,35 +119,35 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) );
// Write page // Write page
synchronized( m_page ) synchronized( page )
{ {
nbt.putBoolean( NBT_PRINTING, m_printing ); nbt.putBoolean( NBT_PRINTING, printing );
nbt.putString( NBT_PAGE_TITLE, m_pageTitle ); nbt.putString( NBT_PAGE_TITLE, pageTitle );
m_page.writeToNBT( nbt ); page.writeToNBT( nbt );
} }
// Write inventory // Write inventory
ItemStackHelper.saveAllItems( nbt, m_inventory ); ItemStackHelper.saveAllItems( nbt, inventory );
return super.save( nbt ); return super.save( nbt );
} }
boolean isPrinting() boolean isPrinting()
{ {
return m_printing; return printing;
} }
// IInventory implementation // IInventory implementation
@Override @Override
public int getContainerSize() public int getContainerSize()
{ {
return m_inventory.size(); return inventory.size();
} }
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
for( ItemStack stack : m_inventory ) for( ItemStack stack : inventory )
{ {
if( !stack.isEmpty() ) return false; if( !stack.isEmpty() ) return false;
} }
@ -158,15 +158,15 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public ItemStack getItem( int slot ) public ItemStack getItem( int slot )
{ {
return m_inventory.get( slot ); return inventory.get( slot );
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack removeItemNoUpdate( int slot ) public ItemStack removeItemNoUpdate( int slot )
{ {
ItemStack result = m_inventory.get( slot ); ItemStack result = inventory.get( slot );
m_inventory.set( slot, ItemStack.EMPTY ); inventory.set( slot, ItemStack.EMPTY );
setChanged(); setChanged();
updateBlockState(); updateBlockState();
return result; return result;
@ -176,7 +176,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public ItemStack removeItem( int slot, int count ) public ItemStack removeItem( int slot, int count )
{ {
ItemStack stack = m_inventory.get( slot ); ItemStack stack = inventory.get( slot );
if( stack.isEmpty() ) return ItemStack.EMPTY; if( stack.isEmpty() ) return ItemStack.EMPTY;
if( stack.getCount() <= count ) if( stack.getCount() <= count )
@ -186,9 +186,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
ItemStack part = stack.split( count ); ItemStack part = stack.split( count );
if( m_inventory.get( slot ).isEmpty() ) if( inventory.get( slot ).isEmpty() )
{ {
m_inventory.set( slot, ItemStack.EMPTY ); inventory.set( slot, ItemStack.EMPTY );
updateBlockState(); updateBlockState();
} }
setChanged(); setChanged();
@ -198,7 +198,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public void setItem( int slot, @Nonnull ItemStack stack ) public void setItem( int slot, @Nonnull ItemStack stack )
{ {
m_inventory.set( slot, stack ); inventory.set( slot, stack );
setChanged(); setChanged();
updateBlockState(); updateBlockState();
} }
@ -206,7 +206,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public void clearContent() public void clearContent()
{ {
for( int i = 0; i < m_inventory.size(); i++ ) m_inventory.set( i, ItemStack.EMPTY ); for( int i = 0; i < inventory.size(); i++ ) inventory.set( i, ItemStack.EMPTY );
setChanged(); setChanged();
updateBlockState(); updateBlockState();
} }
@ -254,33 +254,33 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Nullable @Nullable
Terminal getCurrentPage() Terminal getCurrentPage()
{ {
synchronized( m_page ) synchronized( page )
{ {
return m_printing ? m_page : null; return printing ? page : null;
} }
} }
boolean startNewPage() boolean startNewPage()
{ {
synchronized( m_page ) synchronized( page )
{ {
if( !canInputPage() ) return false; if( !canInputPage() ) return false;
if( m_printing && !outputPage() ) return false; if( printing && !outputPage() ) return false;
return inputPage(); return inputPage();
} }
} }
boolean endCurrentPage() boolean endCurrentPage()
{ {
synchronized( m_page ) synchronized( page )
{ {
return m_printing && outputPage(); return printing && outputPage();
} }
} }
int getInkLevel() int getInkLevel()
{ {
ItemStack inkStack = m_inventory.get( 0 ); ItemStack inkStack = inventory.get( 0 );
return isInk( inkStack ) ? inkStack.getCount() : 0; return isInk( inkStack ) ? inkStack.getCount() : 0;
} }
@ -289,7 +289,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
int count = 0; int count = 0;
for( int i = 1; i < 7; i++ ) for( int i = 1; i < 7; i++ )
{ {
ItemStack paperStack = m_inventory.get( i ); ItemStack paperStack = inventory.get( i );
if( isPaper( paperStack ) ) count += paperStack.getCount(); if( isPaper( paperStack ) ) count += paperStack.getCount();
} }
return count; return count;
@ -297,9 +297,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
void setPageTitle( String title ) void setPageTitle( String title )
{ {
synchronized( m_page ) synchronized( page )
{ {
if( m_printing ) m_pageTitle = title; if( printing ) pageTitle = title;
} }
} }
@ -317,55 +317,55 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
private boolean canInputPage() private boolean canInputPage()
{ {
ItemStack inkStack = m_inventory.get( 0 ); ItemStack inkStack = inventory.get( 0 );
return !inkStack.isEmpty() && isInk( inkStack ) && getPaperLevel() > 0; return !inkStack.isEmpty() && isInk( inkStack ) && getPaperLevel() > 0;
} }
private boolean inputPage() private boolean inputPage()
{ {
ItemStack inkStack = m_inventory.get( 0 ); ItemStack inkStack = inventory.get( 0 );
DyeColor dye = ColourUtils.getStackColour( inkStack ); DyeColor dye = ColourUtils.getStackColour( inkStack );
if( dye == null ) return false; if( dye == null ) return false;
for( int i = 1; i < 7; i++ ) for( int i = 1; i < 7; i++ )
{ {
ItemStack paperStack = m_inventory.get( i ); ItemStack paperStack = inventory.get( i );
if( paperStack.isEmpty() || !isPaper( paperStack ) ) continue; if( paperStack.isEmpty() || !isPaper( paperStack ) ) continue;
// Setup the new page // Setup the new page
m_page.setTextColour( dye.getId() ); page.setTextColour( dye.getId() );
m_page.clear(); page.clear();
if( paperStack.getItem() instanceof ItemPrintout ) if( paperStack.getItem() instanceof ItemPrintout )
{ {
m_pageTitle = ItemPrintout.getTitle( paperStack ); pageTitle = ItemPrintout.getTitle( paperStack );
String[] text = ItemPrintout.getText( paperStack ); String[] text = ItemPrintout.getText( paperStack );
String[] textColour = ItemPrintout.getColours( paperStack ); String[] textColour = ItemPrintout.getColours( paperStack );
for( int y = 0; y < m_page.getHeight(); y++ ) for( int y = 0; y < page.getHeight(); y++ )
{ {
m_page.setLine( y, text[y], textColour[y], "" ); page.setLine( y, text[y], textColour[y], "" );
} }
} }
else else
{ {
m_pageTitle = ""; pageTitle = "";
} }
m_page.setCursorPos( 0, 0 ); page.setCursorPos( 0, 0 );
// Decrement ink // Decrement ink
inkStack.shrink( 1 ); inkStack.shrink( 1 );
if( inkStack.isEmpty() ) m_inventory.set( 0, ItemStack.EMPTY ); if( inkStack.isEmpty() ) inventory.set( 0, ItemStack.EMPTY );
// Decrement paper // Decrement paper
paperStack.shrink( 1 ); paperStack.shrink( 1 );
if( paperStack.isEmpty() ) if( paperStack.isEmpty() )
{ {
m_inventory.set( i, ItemStack.EMPTY ); inventory.set( i, ItemStack.EMPTY );
updateBlockState(); updateBlockState();
} }
setChanged(); setChanged();
m_printing = true; printing = true;
return true; return true;
} }
return false; return false;
@ -373,22 +373,22 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
private boolean outputPage() private boolean outputPage()
{ {
int height = m_page.getHeight(); int height = page.getHeight();
String[] lines = new String[height]; String[] lines = new String[height];
String[] colours = new String[height]; String[] colours = new String[height];
for( int i = 0; i < height; i++ ) for( int i = 0; i < height; i++ )
{ {
lines[i] = m_page.getLine( i ).toString(); lines[i] = page.getLine( i ).toString();
colours[i] = m_page.getTextColourLine( i ).toString(); colours[i] = page.getTextColourLine( i ).toString();
} }
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( m_pageTitle, lines, colours ); ItemStack stack = ItemPrintout.createSingleFromTitleAndText( pageTitle, lines, colours );
for( int slot : BOTTOM_SLOTS ) for( int slot : BOTTOM_SLOTS )
{ {
if( m_inventory.get( slot ).isEmpty() ) if( inventory.get( slot ).isEmpty() )
{ {
setItem( slot, stack ); setItem( slot, stack );
m_printing = false; printing = false;
return true; return true;
} }
} }
@ -399,7 +399,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
{ {
for( int i = 0; i < 13; i++ ) for( int i = 0; i < 13; i++ )
{ {
ItemStack stack = m_inventory.get( i ); ItemStack stack = inventory.get( i );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
// Remove the stack from the inventory // Remove the stack from the inventory
@ -416,7 +416,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
boolean top = false, bottom = false; boolean top = false, bottom = false;
for( int i = 1; i < 7; i++ ) for( int i = 1; i < 7; i++ )
{ {
ItemStack stack = m_inventory.get( i ); ItemStack stack = inventory.get( i );
if( !stack.isEmpty() && isPaper( stack ) ) if( !stack.isEmpty() && isPaper( stack ) )
{ {
top = true; top = true;
@ -425,7 +425,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
for( int i = 7; i < 13; i++ ) for( int i = 7; i < 13; i++ )
{ {
ItemStack stack = m_inventory.get( i ); ItemStack stack = inventory.get( i );
if( !stack.isEmpty() && isPaper( stack ) ) if( !stack.isEmpty() && isPaper( stack ) )
{ {
bottom = true; bottom = true;

View File

@ -32,14 +32,14 @@ import static dan200.computercraft.api.lua.LuaValues.checkFinite;
*/ */
public abstract class SpeakerPeripheral implements IPeripheral public abstract class SpeakerPeripheral implements IPeripheral
{ {
private long m_clock = 0; private long clock = 0;
private long m_lastPlayTime = 0; private long lastPlayTime = 0;
private final AtomicInteger m_notesThisTick = new AtomicInteger(); private final AtomicInteger notesThisTick = new AtomicInteger();
public void update() public void update()
{ {
m_clock++; clock++;
m_notesThisTick.set( 0 ); notesThisTick.set( 0 );
} }
public abstract World getWorld(); public abstract World getWorld();
@ -48,7 +48,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
public boolean madeSound( long ticks ) public boolean madeSound( long ticks )
{ {
return m_clock - m_lastPlayTime <= ticks; return clock - lastPlayTime <= ticks;
} }
@Nonnull @Nonnull
@ -129,14 +129,14 @@ public abstract class SpeakerPeripheral implements IPeripheral
// If the resource location for note block notes changes, this method call will need to be updated // If the resource location for note block notes changes, this method call will need to be updated
boolean success = playSound( context, instrument.getSoundEvent().getRegistryName(), volume, (float) Math.pow( 2.0, (pitch - 12.0) / 12.0 ), true ); boolean success = playSound( context, instrument.getSoundEvent().getRegistryName(), volume, (float) Math.pow( 2.0, (pitch - 12.0) / 12.0 ), true );
if( success ) m_notesThisTick.incrementAndGet(); if( success ) notesThisTick.incrementAndGet();
return success; return success;
} }
private synchronized boolean playSound( ILuaContext context, ResourceLocation name, float volume, float pitch, boolean isNote ) throws LuaException private synchronized boolean playSound( ILuaContext context, ResourceLocation name, float volume, float pitch, boolean isNote ) throws LuaException
{ {
if( m_clock - m_lastPlayTime < TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS && if( clock - lastPlayTime < TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS &&
(!isNote || m_clock - m_lastPlayTime != 0 || m_notesThisTick.get() >= ComputerCraft.maxNotesPerTick) ) (!isNote || clock - lastPlayTime != 0 || notesThisTick.get() >= ComputerCraft.maxNotesPerTick) )
{ {
// Rate limiting occurs when we've already played a sound within the last tick, or we've // Rate limiting occurs when we've already played a sound within the last tick, or we've
// played more notes than allowable within the current tick. // played more notes than allowable within the current tick.
@ -158,7 +158,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
return null; return null;
} ); } );
m_lastPlayTime = m_clock; lastPlayTime = clock;
return true; return true;
} }
} }

View File

@ -35,9 +35,9 @@ import static dan200.computercraft.shared.pocket.items.ItemPocketComputer.NBT_LI
public class PocketServerComputer extends ServerComputer implements IPocketAccess public class PocketServerComputer extends ServerComputer implements IPocketAccess
{ {
private IPocketUpgrade m_upgrade; private IPocketUpgrade upgrade;
private Entity m_entity; private Entity entity;
private ItemStack m_stack; private ItemStack stack;
public PocketServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family ) public PocketServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family )
{ {
@ -48,18 +48,18 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public Entity getEntity() public Entity getEntity()
{ {
Entity entity = m_entity; Entity entity = this.entity;
if( entity == null || m_stack == null || !entity.isAlive() ) return null; if( entity == null || stack == null || !entity.isAlive() ) return null;
if( entity instanceof PlayerEntity ) if( entity instanceof PlayerEntity )
{ {
PlayerInventory inventory = ((PlayerEntity) entity).inventory; PlayerInventory inventory = ((PlayerEntity) entity).inventory;
return inventory.items.contains( m_stack ) || inventory.offhand.contains( m_stack ) ? entity : null; return inventory.items.contains( stack ) || inventory.offhand.contains( stack ) ? entity : null;
} }
else if( entity instanceof LivingEntity ) else if( entity instanceof LivingEntity )
{ {
LivingEntity living = (LivingEntity) entity; LivingEntity living = (LivingEntity) entity;
return living.getMainHandItem() == m_stack || living.getOffhandItem() == m_stack ? entity : null; return living.getMainHandItem() == stack || living.getOffhandItem() == stack ? entity : null;
} }
else else
{ {
@ -70,13 +70,13 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public int getColour() public int getColour()
{ {
return IColouredItem.getColourBasic( m_stack ); return IColouredItem.getColourBasic( stack );
} }
@Override @Override
public void setColour( int colour ) public void setColour( int colour )
{ {
IColouredItem.setColourBasic( m_stack, colour ); IColouredItem.setColourBasic( stack, colour );
updateUpgradeNBTData(); updateUpgradeNBTData();
} }
@ -110,19 +110,19 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public CompoundNBT getUpgradeNBTData() public CompoundNBT getUpgradeNBTData()
{ {
return ItemPocketComputer.getUpgradeInfo( m_stack ); return ItemPocketComputer.getUpgradeInfo( stack );
} }
@Override @Override
public void updateUpgradeNBTData() public void updateUpgradeNBTData()
{ {
if( m_entity instanceof PlayerEntity ) ((PlayerEntity) m_entity).inventory.setChanged(); if( entity instanceof PlayerEntity ) ((PlayerEntity) entity).inventory.setChanged();
} }
@Override @Override
public void invalidatePeripheral() public void invalidatePeripheral()
{ {
IPeripheral peripheral = m_upgrade == null ? null : m_upgrade.createPeripheral( this ); IPeripheral peripheral = upgrade == null ? null : upgrade.createPeripheral( this );
setPeripheral( ComputerSide.BACK, peripheral ); setPeripheral( ComputerSide.BACK, peripheral );
} }
@ -130,12 +130,12 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public Map<ResourceLocation, IPeripheral> getUpgrades() public Map<ResourceLocation, IPeripheral> getUpgrades()
{ {
return m_upgrade == null ? Collections.emptyMap() : Collections.singletonMap( m_upgrade.getUpgradeID(), getPeripheral( ComputerSide.BACK ) ); return upgrade == null ? Collections.emptyMap() : Collections.singletonMap( upgrade.getUpgradeID(), getPeripheral( ComputerSide.BACK ) );
} }
public IPocketUpgrade getUpgrade() public IPocketUpgrade getUpgrade()
{ {
return m_upgrade; return upgrade;
} }
/** /**
@ -147,13 +147,13 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
*/ */
public void setUpgrade( IPocketUpgrade upgrade ) public void setUpgrade( IPocketUpgrade upgrade )
{ {
if( m_upgrade == upgrade ) return; if( this.upgrade == upgrade ) return;
synchronized( this ) synchronized( this )
{ {
ItemPocketComputer.setUpgrade( m_stack, upgrade ); ItemPocketComputer.setUpgrade( stack, upgrade );
updateUpgradeNBTData(); updateUpgradeNBTData();
m_upgrade = upgrade; this.upgrade = upgrade;
invalidatePeripheral(); invalidatePeripheral();
} }
} }
@ -167,14 +167,14 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
} }
// If a new entity has picked it up then rebroadcast the terminal to them // If a new entity has picked it up then rebroadcast the terminal to them
if( entity != m_entity && entity instanceof ServerPlayerEntity ) markTerminalChanged(); if( entity != this.entity && entity instanceof ServerPlayerEntity ) markTerminalChanged();
m_entity = entity; this.entity = entity;
m_stack = stack; this.stack = stack;
if( m_upgrade != upgrade ) if( this.upgrade != upgrade )
{ {
m_upgrade = upgrade; this.upgrade = upgrade;
invalidatePeripheral(); invalidatePeripheral();
} }
} }
@ -184,10 +184,10 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
{ {
super.broadcastState( force ); super.broadcastState( force );
if( (hasTerminalChanged() || force) && m_entity instanceof ServerPlayerEntity ) if( (hasTerminalChanged() || force) && entity instanceof ServerPlayerEntity )
{ {
// Broadcast the state to the current entity if they're not already interacting with it. // Broadcast the state to the current entity if they're not already interacting with it.
ServerPlayerEntity player = (ServerPlayerEntity) m_entity; ServerPlayerEntity player = (ServerPlayerEntity) entity;
if( player.connection != null && !isInteracting( player ) ) if( player.connection != null && !isInteracting( player ) )
{ {
NetworkHandler.sendToPlayer( player, createTerminalPacket() ); NetworkHandler.sendToPlayer( player, createTerminalPacket() );

View File

@ -38,8 +38,6 @@ import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -361,14 +359,12 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
stack.getOrCreateTag().putInt( NBT_SESSION, sessionID ); stack.getOrCreateTag().putInt( NBT_SESSION, sessionID );
} }
@OnlyIn( Dist.CLIENT )
public static ComputerState getState( @Nonnull ItemStack stack ) public static ComputerState getState( @Nonnull ItemStack stack )
{ {
ClientComputer computer = getClientComputer( stack ); ClientComputer computer = getClientComputer( stack );
return computer == null ? ComputerState.OFF : computer.getState(); return computer == null ? ComputerState.OFF : computer.getState();
} }
@OnlyIn( Dist.CLIENT )
public static int getLightState( @Nonnull ItemStack stack ) public static int getLightState( @Nonnull ItemStack stack )
{ {
ClientComputer computer = getClientComputer( stack ); ClientComputer computer = getClientComputer( stack );

View File

@ -63,13 +63,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
MOVED MOVED
} }
private final NonNullList<ItemStack> m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY ); private final NonNullList<ItemStack> inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
private final NonNullList<ItemStack> m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY ); private final NonNullList<ItemStack> previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY );
private final IItemHandlerModifiable m_itemHandler = new InvWrapper( this ); private final IItemHandlerModifiable itemHandler = new InvWrapper( this );
private LazyOptional<IItemHandlerModifiable> itemHandlerCap; private LazyOptional<IItemHandlerModifiable> itemHandlerCap;
private boolean m_inventoryChanged = false; private boolean inventoryChanged = false;
private TurtleBrain m_brain = new TurtleBrain( this ); private TurtleBrain brain = new TurtleBrain( this );
private MoveState m_moveState = MoveState.NOT_MOVED; private MoveState moveState = MoveState.NOT_MOVED;
private LazyOptional<IPeripheral> peripheral; private LazyOptional<IPeripheral> peripheral;
public TileTurtle( TileEntityType<? extends TileGeneric> type, ComputerFamily family ) public TileTurtle( TileEntityType<? extends TileGeneric> type, ComputerFamily family )
@ -79,7 +79,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
private boolean hasMoved() private boolean hasMoved()
{ {
return m_moveState == MoveState.MOVED; return moveState == MoveState.MOVED;
} }
@Override @Override
@ -91,13 +91,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
); );
computer.setPosition( getBlockPos() ); computer.setPosition( getBlockPos() );
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) ); computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) );
m_brain.setupComputer( computer ); brain.setupComputer( computer );
return computer; return computer;
} }
public ComputerProxy createProxy() public ComputerProxy createProxy()
{ {
return m_brain.getProxy(); return brain.getProxy();
} }
@Override @Override
@ -163,9 +163,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
if( !getLevel().isClientSide ) if( !getLevel().isClientSide )
{ {
DyeColor dye = ((DyeItem) currentItem.getItem()).getDyeColor(); DyeColor dye = ((DyeItem) currentItem.getItem()).getDyeColor();
if( m_brain.getDyeColour() != dye ) if( brain.getDyeColour() != dye )
{ {
m_brain.setDyeColour( dye ); brain.setDyeColour( dye );
if( !player.isCreative() ) if( !player.isCreative() )
{ {
currentItem.shrink( 1 ); currentItem.shrink( 1 );
@ -174,14 +174,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
} }
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getColour() != -1 ) else if( currentItem.getItem() == Items.WATER_BUCKET && brain.getColour() != -1 )
{ {
// Water to remove turtle colour // Water to remove turtle colour
if( !getLevel().isClientSide ) if( !getLevel().isClientSide )
{ {
if( m_brain.getColour() != -1 ) if( brain.getColour() != -1 )
{ {
m_brain.setColour( -1 ); brain.setColour( -1 );
if( !player.isCreative() ) if( !player.isCreative() )
{ {
player.setItemInHand( hand, new ItemStack( Items.BUCKET ) ); player.setItemInHand( hand, new ItemStack( Items.BUCKET ) );
@ -213,16 +213,16 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public void tick() public void tick()
{ {
super.tick(); super.tick();
m_brain.update(); brain.update();
if( !getLevel().isClientSide && m_inventoryChanged ) if( !getLevel().isClientSide && inventoryChanged )
{ {
ServerComputer computer = getServerComputer(); ServerComputer computer = getServerComputer();
if( computer != null ) computer.queueEvent( "turtle_inventory" ); if( computer != null ) computer.queueEvent( "turtle_inventory" );
m_inventoryChanged = false; inventoryChanged = false;
for( int n = 0; n < getContainerSize(); n++ ) for( int n = 0; n < getContainerSize(); n++ )
{ {
m_previousInventory.set( n, getItem( n ).copy() ); previousInventory.set( n, getItem( n ).copy() );
} }
} }
} }
@ -235,24 +235,24 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public void onNeighbourChange( @Nonnull BlockPos neighbour ) public void onNeighbourChange( @Nonnull BlockPos neighbour )
{ {
if( m_moveState == MoveState.NOT_MOVED ) super.onNeighbourChange( neighbour ); if( moveState == MoveState.NOT_MOVED ) super.onNeighbourChange( neighbour );
} }
@Override @Override
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{ {
if( m_moveState == MoveState.NOT_MOVED ) super.onNeighbourTileEntityChange( neighbour ); if( moveState == MoveState.NOT_MOVED ) super.onNeighbourTileEntityChange( neighbour );
} }
public void notifyMoveStart() public void notifyMoveStart()
{ {
if( m_moveState == MoveState.NOT_MOVED ) m_moveState = MoveState.IN_PROGRESS; if( moveState == MoveState.NOT_MOVED ) moveState = MoveState.IN_PROGRESS;
} }
public void notifyMoveEnd() public void notifyMoveEnd()
{ {
// MoveState.MOVED is final // MoveState.MOVED is final
if( m_moveState == MoveState.IN_PROGRESS ) m_moveState = MoveState.NOT_MOVED; if( moveState == MoveState.IN_PROGRESS ) moveState = MoveState.NOT_MOVED;
} }
@Override @Override
@ -262,21 +262,21 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Read inventory // Read inventory
ListNBT nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND ); ListNBT nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND );
m_inventory.clear(); inventory.clear();
m_previousInventory.clear(); previousInventory.clear();
for( int i = 0; i < nbttaglist.size(); i++ ) for( int i = 0; i < nbttaglist.size(); i++ )
{ {
CompoundNBT tag = nbttaglist.getCompound( i ); CompoundNBT tag = nbttaglist.getCompound( i );
int slot = tag.getByte( "Slot" ) & 0xff; int slot = tag.getByte( "Slot" ) & 0xff;
if( slot < getContainerSize() ) if( slot < getContainerSize() )
{ {
m_inventory.set( slot, ItemStack.of( tag ) ); inventory.set( slot, ItemStack.of( tag ) );
m_previousInventory.set( slot, m_inventory.get( slot ).copy() ); previousInventory.set( slot, inventory.get( slot ).copy() );
} }
} }
// Read state // Read state
m_brain.readFromNBT( nbt ); brain.readFromNBT( nbt );
} }
@Nonnull @Nonnull
@ -287,18 +287,18 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
ListNBT nbttaglist = new ListNBT(); ListNBT nbttaglist = new ListNBT();
for( int i = 0; i < INVENTORY_SIZE; i++ ) for( int i = 0; i < INVENTORY_SIZE; i++ )
{ {
if( !m_inventory.get( i ).isEmpty() ) if( !inventory.get( i ).isEmpty() )
{ {
CompoundNBT tag = new CompoundNBT(); CompoundNBT tag = new CompoundNBT();
tag.putByte( "Slot", (byte) i ); tag.putByte( "Slot", (byte) i );
m_inventory.get( i ).save( tag ); inventory.get( i ).save( tag );
nbttaglist.add( tag ); nbttaglist.add( tag );
} }
} }
nbt.put( "Items", nbttaglist ); nbt.put( "Items", nbttaglist );
// Write brain // Write brain
nbt = m_brain.writeToNBT( nbt ); nbt = brain.writeToNBT( nbt );
return super.save( nbt ); return super.save( nbt );
} }
@ -331,48 +331,48 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public ITurtleUpgrade getUpgrade( TurtleSide side ) public ITurtleUpgrade getUpgrade( TurtleSide side )
{ {
return m_brain.getUpgrade( side ); return brain.getUpgrade( side );
} }
@Override @Override
public int getColour() public int getColour()
{ {
return m_brain.getColour(); return brain.getColour();
} }
@Override @Override
public ResourceLocation getOverlay() public ResourceLocation getOverlay()
{ {
return m_brain.getOverlay(); return brain.getOverlay();
} }
@Override @Override
public ITurtleAccess getAccess() public ITurtleAccess getAccess()
{ {
return m_brain; return brain;
} }
@Override @Override
public Vec3d getRenderOffset( float f ) public Vec3d getRenderOffset( float f )
{ {
return m_brain.getRenderOffset( f ); return brain.getRenderOffset( f );
} }
@Override @Override
public float getRenderYaw( float f ) public float getRenderYaw( float f )
{ {
return m_brain.getVisualYaw( f ); return brain.getVisualYaw( f );
} }
@Override @Override
public float getToolRenderAngle( TurtleSide side, float f ) public float getToolRenderAngle( TurtleSide side, float f )
{ {
return m_brain.getToolRenderAngle( side, f ); return brain.getToolRenderAngle( side, f );
} }
void setOwningPlayer( GameProfile player ) void setOwningPlayer( GameProfile player )
{ {
m_brain.setOwningPlayer( player ); brain.setOwningPlayer( player );
setChanged(); setChanged();
} }
@ -387,7 +387,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
for( ItemStack stack : m_inventory ) for( ItemStack stack : inventory )
{ {
if( !stack.isEmpty() ) return false; if( !stack.isEmpty() ) return false;
} }
@ -398,7 +398,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public ItemStack getItem( int slot ) public ItemStack getItem( int slot )
{ {
return slot >= 0 && slot < INVENTORY_SIZE ? m_inventory.get( slot ) : ItemStack.EMPTY; return slot >= 0 && slot < INVENTORY_SIZE ? inventory.get( slot ) : ItemStack.EMPTY;
} }
@Nonnull @Nonnull
@ -433,9 +433,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public void setItem( int i, @Nonnull ItemStack stack ) public void setItem( int i, @Nonnull ItemStack stack )
{ {
if( i >= 0 && i < INVENTORY_SIZE && !InventoryUtil.areItemsEqual( stack, m_inventory.get( i ) ) ) if( i >= 0 && i < INVENTORY_SIZE && !InventoryUtil.areItemsEqual( stack, inventory.get( i ) ) )
{ {
m_inventory.set( i, stack ); inventory.set( i, stack );
onInventoryDefinitelyChanged(); onInventoryDefinitelyChanged();
} }
} }
@ -446,9 +446,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
boolean changed = false; boolean changed = false;
for( int i = 0; i < INVENTORY_SIZE; i++ ) for( int i = 0; i < INVENTORY_SIZE; i++ )
{ {
if( !m_inventory.get( i ).isEmpty() ) if( !inventory.get( i ).isEmpty() )
{ {
m_inventory.set( i, ItemStack.EMPTY ); inventory.set( i, ItemStack.EMPTY );
changed = true; changed = true;
} }
} }
@ -460,13 +460,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public void setChanged() public void setChanged()
{ {
super.setChanged(); super.setChanged();
if( !m_inventoryChanged ) if( !inventoryChanged )
{ {
for( int n = 0; n < getContainerSize(); n++ ) for( int n = 0; n < getContainerSize(); n++ )
{ {
if( !ItemStack.matches( getItem( n ), m_previousInventory.get( n ) ) ) if( !ItemStack.matches( getItem( n ), previousInventory.get( n ) ) )
{ {
m_inventoryChanged = true; inventoryChanged = true;
break; break;
} }
} }
@ -482,7 +482,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
private void onInventoryDefinitelyChanged() private void onInventoryDefinitelyChanged()
{ {
super.setChanged(); super.setChanged();
m_inventoryChanged = true; inventoryChanged = true;
} }
public void onTileEntityChange() public void onTileEntityChange()
@ -496,14 +496,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
protected void writeDescription( @Nonnull CompoundNBT nbt ) protected void writeDescription( @Nonnull CompoundNBT nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
m_brain.writeDescription( nbt ); brain.writeDescription( nbt );
} }
@Override @Override
protected void readDescription( @Nonnull CompoundNBT nbt ) protected void readDescription( @Nonnull CompoundNBT nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
m_brain.readDescription( nbt ); brain.readDescription( nbt );
} }
// Privates // Privates
@ -528,20 +528,20 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public void transferStateFrom( TileTurtle copy ) public void transferStateFrom( TileTurtle copy )
{ {
super.transferStateFrom( copy ); super.transferStateFrom( copy );
Collections.copy( m_inventory, copy.m_inventory ); Collections.copy( inventory, copy.inventory );
Collections.copy( m_previousInventory, copy.m_previousInventory ); Collections.copy( previousInventory, copy.previousInventory );
m_inventoryChanged = copy.m_inventoryChanged; inventoryChanged = copy.inventoryChanged;
m_brain = copy.m_brain; brain = copy.brain;
m_brain.setOwner( this ); brain.setOwner( this );
// Mark the other turtle as having moved, and so its peripheral is dead. // Mark the other turtle as having moved, and so its peripheral is dead.
copy.m_moveState = MoveState.MOVED; copy.moveState = MoveState.MOVED;
copy.peripheral = CapabilityUtil.invalidate( copy.peripheral ); copy.peripheral = CapabilityUtil.invalidate( copy.peripheral );
} }
public IItemHandlerModifiable getItemHandler() public IItemHandlerModifiable getItemHandler()
{ {
return m_itemHandler; return itemHandler;
} }
@Nonnull @Nonnull
@ -571,6 +571,6 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ) public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
{ {
return new ContainerTurtle( id, inventory, m_brain ); return new ContainerTurtle( id, inventory, brain );
} }
} }

View File

@ -65,55 +65,55 @@ public class TurtleBrain implements ITurtleAccess
private static final int ANIM_DURATION = 8; private static final int ANIM_DURATION = 8;
private TileTurtle m_owner; private TileTurtle owner;
private ComputerProxy m_proxy; private ComputerProxy proxy;
private GameProfile m_owningPlayer; private GameProfile owningPlayer;
private final IInventory m_inventory = (InventoryDelegate) () -> m_owner; private final IInventory inventory = (InventoryDelegate) () -> owner;
private final IItemHandlerModifiable m_inventoryWrapper = new InvWrapper( m_inventory ); private final IItemHandlerModifiable inventoryWrapper = new InvWrapper( inventory );
private final Queue<TurtleCommandQueueEntry> m_commandQueue = new ArrayDeque<>(); private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>();
private int m_commandsIssued = 0; private int commandsIssued = 0;
private final Map<TurtleSide, ITurtleUpgrade> m_upgrades = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, ITurtleUpgrade> upgrades = new EnumMap<>( TurtleSide.class );
private final Map<TurtleSide, IPeripheral> peripherals = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, IPeripheral> peripherals = new EnumMap<>( TurtleSide.class );
private final Map<TurtleSide, CompoundNBT> m_upgradeNBTData = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, CompoundNBT> upgradeNBTData = new EnumMap<>( TurtleSide.class );
private int m_selectedSlot = 0; private int selectedSlot = 0;
private int m_fuelLevel = 0; private int fuelLevel = 0;
private int m_colourHex = -1; private int colourHex = -1;
private ResourceLocation m_overlay = null; private ResourceLocation overlay = null;
private TurtleAnimation m_animation = TurtleAnimation.NONE; private TurtleAnimation animation = TurtleAnimation.NONE;
private int m_animationProgress = 0; private int animationProgress = 0;
private int m_lastAnimationProgress = 0; private int lastAnimationProgress = 0;
TurtlePlayer m_cachedPlayer; TurtlePlayer cachedPlayer;
public TurtleBrain( TileTurtle turtle ) public TurtleBrain( TileTurtle turtle )
{ {
m_owner = turtle; owner = turtle;
} }
public void setOwner( TileTurtle owner ) public void setOwner( TileTurtle owner )
{ {
m_owner = owner; this.owner = owner;
} }
public TileTurtle getOwner() public TileTurtle getOwner()
{ {
return m_owner; return owner;
} }
public ComputerProxy getProxy() public ComputerProxy getProxy()
{ {
if( m_proxy == null ) m_proxy = new ComputerProxy( () -> m_owner ); if( proxy == null ) proxy = new ComputerProxy( () -> owner );
return m_proxy; return proxy;
} }
public ComputerFamily getFamily() public ComputerFamily getFamily()
{ {
return m_owner.getFamily(); return owner.getFamily();
} }
public void setupComputer( ServerComputer computer ) public void setupComputer( ServerComputer computer )
@ -131,16 +131,16 @@ public class TurtleBrain implements ITurtleAccess
// The block may have been broken while the command was executing (for instance, if a block explodes // The block may have been broken while the command was executing (for instance, if a block explodes
// when being mined). If so, abort. // when being mined). If so, abort.
if( m_owner.isRemoved() ) return; if( owner.isRemoved() ) return;
} }
// Advance animation // Advance animation
updateAnimation(); updateAnimation();
// Advance upgrades // Advance upgrades
if( !m_upgrades.isEmpty() ) if( !upgrades.isEmpty() )
{ {
for( Map.Entry<TurtleSide, ITurtleUpgrade> entry : m_upgrades.entrySet() ) for( Map.Entry<TurtleSide, ITurtleUpgrade> entry : upgrades.entrySet() )
{ {
entry.getValue().update( this, entry.getKey() ); entry.getValue().update( this, entry.getKey() );
} }
@ -155,31 +155,31 @@ public class TurtleBrain implements ITurtleAccess
private void readCommon( CompoundNBT nbt ) private void readCommon( CompoundNBT nbt )
{ {
// Read fields // Read fields
m_colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1; colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1;
m_fuelLevel = nbt.contains( NBT_FUEL ) ? nbt.getInt( NBT_FUEL ) : 0; fuelLevel = nbt.contains( NBT_FUEL ) ? nbt.getInt( NBT_FUEL ) : 0;
m_overlay = nbt.contains( NBT_OVERLAY ) ? new ResourceLocation( nbt.getString( NBT_OVERLAY ) ) : null; overlay = nbt.contains( NBT_OVERLAY ) ? new ResourceLocation( nbt.getString( NBT_OVERLAY ) ) : null;
// Read upgrades // Read upgrades
setUpgrade( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null ); setUpgrade( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null );
setUpgrade( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null ); setUpgrade( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null );
// NBT // NBT
m_upgradeNBTData.clear(); upgradeNBTData.clear();
if( nbt.contains( NBT_LEFT_UPGRADE_DATA ) ) if( nbt.contains( NBT_LEFT_UPGRADE_DATA ) )
{ {
m_upgradeNBTData.put( TurtleSide.LEFT, nbt.getCompound( NBT_LEFT_UPGRADE_DATA ).copy() ); upgradeNBTData.put( TurtleSide.LEFT, nbt.getCompound( NBT_LEFT_UPGRADE_DATA ).copy() );
} }
if( nbt.contains( NBT_RIGHT_UPGRADE_DATA ) ) if( nbt.contains( NBT_RIGHT_UPGRADE_DATA ) )
{ {
m_upgradeNBTData.put( TurtleSide.RIGHT, nbt.getCompound( NBT_RIGHT_UPGRADE_DATA ).copy() ); upgradeNBTData.put( TurtleSide.RIGHT, nbt.getCompound( NBT_RIGHT_UPGRADE_DATA ).copy() );
} }
} }
private void writeCommon( CompoundNBT nbt ) private void writeCommon( CompoundNBT nbt )
{ {
nbt.putInt( NBT_FUEL, m_fuelLevel ); nbt.putInt( NBT_FUEL, fuelLevel );
if( m_colourHex != -1 ) nbt.putInt( NBT_COLOUR, m_colourHex ); if( colourHex != -1 ) nbt.putInt( NBT_COLOUR, colourHex );
if( m_overlay != null ) nbt.putString( NBT_OVERLAY, m_overlay.toString() ); if( overlay != null ) nbt.putString( NBT_OVERLAY, overlay.toString() );
// Write upgrades // Write upgrades
String leftUpgradeId = getUpgradeId( getUpgrade( TurtleSide.LEFT ) ); String leftUpgradeId = getUpgradeId( getUpgrade( TurtleSide.LEFT ) );
@ -188,11 +188,11 @@ public class TurtleBrain implements ITurtleAccess
if( rightUpgradeId != null ) nbt.putString( NBT_RIGHT_UPGRADE, rightUpgradeId ); if( rightUpgradeId != null ) nbt.putString( NBT_RIGHT_UPGRADE, rightUpgradeId );
// Write upgrade NBT // Write upgrade NBT
if( m_upgradeNBTData.containsKey( TurtleSide.LEFT ) ) if( upgradeNBTData.containsKey( TurtleSide.LEFT ) )
{ {
nbt.put( NBT_LEFT_UPGRADE_DATA, getUpgradeNBTData( TurtleSide.LEFT ).copy() ); nbt.put( NBT_LEFT_UPGRADE_DATA, getUpgradeNBTData( TurtleSide.LEFT ).copy() );
} }
if( m_upgradeNBTData.containsKey( TurtleSide.RIGHT ) ) if( upgradeNBTData.containsKey( TurtleSide.RIGHT ) )
{ {
nbt.put( NBT_RIGHT_UPGRADE_DATA, getUpgradeNBTData( TurtleSide.RIGHT ).copy() ); nbt.put( NBT_RIGHT_UPGRADE_DATA, getUpgradeNBTData( TurtleSide.RIGHT ).copy() );
} }
@ -203,20 +203,20 @@ public class TurtleBrain implements ITurtleAccess
readCommon( nbt ); readCommon( nbt );
// Read state // Read state
m_selectedSlot = nbt.getInt( NBT_SLOT ); selectedSlot = nbt.getInt( NBT_SLOT );
// Read owner // Read owner
if( nbt.contains( "Owner", Constants.NBT.TAG_COMPOUND ) ) if( nbt.contains( "Owner", Constants.NBT.TAG_COMPOUND ) )
{ {
CompoundNBT owner = nbt.getCompound( "Owner" ); CompoundNBT owner = nbt.getCompound( "Owner" );
m_owningPlayer = new GameProfile( owningPlayer = new GameProfile(
new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ), new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ),
owner.getString( "Name" ) owner.getString( "Name" )
); );
} }
else else
{ {
m_owningPlayer = null; owningPlayer = null;
} }
} }
@ -225,17 +225,17 @@ public class TurtleBrain implements ITurtleAccess
writeCommon( nbt ); writeCommon( nbt );
// Write state // Write state
nbt.putInt( NBT_SLOT, m_selectedSlot ); nbt.putInt( NBT_SLOT, selectedSlot );
// Write owner // Write owner
if( m_owningPlayer != null ) if( owningPlayer != null )
{ {
CompoundNBT owner = new CompoundNBT(); CompoundNBT owner = new CompoundNBT();
nbt.put( "Owner", owner ); nbt.put( "Owner", owner );
owner.putLong( "UpperId", m_owningPlayer.getId().getMostSignificantBits() ); owner.putLong( "UpperId", owningPlayer.getId().getMostSignificantBits() );
owner.putLong( "LowerId", m_owningPlayer.getId().getLeastSignificantBits() ); owner.putLong( "LowerId", owningPlayer.getId().getLeastSignificantBits() );
owner.putString( "Name", m_owningPlayer.getName() ); owner.putString( "Name", owningPlayer.getName() );
} }
return nbt; return nbt;
@ -252,35 +252,35 @@ public class TurtleBrain implements ITurtleAccess
// Animation // Animation
TurtleAnimation anim = TurtleAnimation.values()[nbt.getInt( "Animation" )]; TurtleAnimation anim = TurtleAnimation.values()[nbt.getInt( "Animation" )];
if( anim != m_animation && if( anim != animation &&
anim != TurtleAnimation.WAIT && anim != TurtleAnimation.WAIT &&
anim != TurtleAnimation.SHORT_WAIT && anim != TurtleAnimation.SHORT_WAIT &&
anim != TurtleAnimation.NONE ) anim != TurtleAnimation.NONE )
{ {
m_animation = anim; animation = anim;
m_animationProgress = 0; animationProgress = 0;
m_lastAnimationProgress = 0; lastAnimationProgress = 0;
} }
} }
public void writeDescription( CompoundNBT nbt ) public void writeDescription( CompoundNBT nbt )
{ {
writeCommon( nbt ); writeCommon( nbt );
nbt.putInt( "Animation", m_animation.ordinal() ); nbt.putInt( "Animation", animation.ordinal() );
} }
@Nonnull @Nonnull
@Override @Override
public World getWorld() public World getWorld()
{ {
return m_owner.getLevel(); return owner.getLevel();
} }
@Nonnull @Nonnull
@Override @Override
public BlockPos getPosition() public BlockPos getPosition()
{ {
return m_owner.getBlockPos(); return owner.getBlockPos();
} }
@Override @Override
@ -293,9 +293,9 @@ public class TurtleBrain implements ITurtleAccess
// Cache info about the old turtle (so we don't access this after we delete ourselves) // Cache info about the old turtle (so we don't access this after we delete ourselves)
World oldWorld = getWorld(); World oldWorld = getWorld();
TileTurtle oldOwner = m_owner; TileTurtle oldOwner = owner;
BlockPos oldPos = m_owner.getBlockPos(); BlockPos oldPos = owner.getBlockPos();
BlockState oldBlock = m_owner.getBlockState(); BlockState oldBlock = owner.getBlockState();
if( oldWorld == world && oldPos.equals( pos ) ) if( oldWorld == world && oldPos.equals( pos ) )
{ {
@ -365,7 +365,7 @@ public class TurtleBrain implements ITurtleAccess
public Vec3d getVisualPosition( float f ) public Vec3d getVisualPosition( float f )
{ {
Vec3d offset = getRenderOffset( f ); Vec3d offset = getRenderOffset( f );
BlockPos pos = m_owner.getBlockPos(); BlockPos pos = owner.getBlockPos();
return new Vec3d( return new Vec3d(
pos.getX() + 0.5 + offset.x, pos.getX() + 0.5 + offset.x,
pos.getY() + 0.5 + offset.y, pos.getY() + 0.5 + offset.y,
@ -377,7 +377,7 @@ public class TurtleBrain implements ITurtleAccess
public float getVisualYaw( float f ) public float getVisualYaw( float f )
{ {
float yaw = getDirection().toYRot(); float yaw = getDirection().toYRot();
switch( m_animation ) switch( animation )
{ {
case TURN_LEFT: case TURN_LEFT:
{ {
@ -405,19 +405,19 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public Direction getDirection() public Direction getDirection()
{ {
return m_owner.getDirection(); return owner.getDirection();
} }
@Override @Override
public void setDirection( @Nonnull Direction dir ) public void setDirection( @Nonnull Direction dir )
{ {
m_owner.setDirection( dir ); owner.setDirection( dir );
} }
@Override @Override
public int getSelectedSlot() public int getSelectedSlot()
{ {
return m_selectedSlot; return selectedSlot;
} }
@Override @Override
@ -425,10 +425,10 @@ public class TurtleBrain implements ITurtleAccess
{ {
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot set the slot on the client" ); if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot set the slot on the client" );
if( slot >= 0 && slot < m_owner.getContainerSize() ) if( slot >= 0 && slot < owner.getContainerSize() )
{ {
m_selectedSlot = slot; selectedSlot = slot;
m_owner.onTileEntityChange(); owner.onTileEntityChange();
} }
} }
@ -436,14 +436,14 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public IInventory getInventory() public IInventory getInventory()
{ {
return m_inventory; return inventory;
} }
@Nonnull @Nonnull
@Override @Override
public IItemHandlerModifiable getItemHandler() public IItemHandlerModifiable getItemHandler()
{ {
return m_inventoryWrapper; return inventoryWrapper;
} }
@Override @Override
@ -455,20 +455,20 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public int getFuelLevel() public int getFuelLevel()
{ {
return Math.min( m_fuelLevel, getFuelLimit() ); return Math.min( fuelLevel, getFuelLimit() );
} }
@Override @Override
public void setFuelLevel( int level ) public void setFuelLevel( int level )
{ {
m_fuelLevel = Math.min( level, getFuelLimit() ); fuelLevel = Math.min( level, getFuelLimit() );
m_owner.onTileEntityChange(); owner.onTileEntityChange();
} }
@Override @Override
public int getFuelLimit() public int getFuelLimit()
{ {
if( m_owner.getFamily() == ComputerFamily.ADVANCED ) if( owner.getFamily() == ComputerFamily.ADVANCED )
{ {
return ComputerCraft.advancedTurtleFuelLimit; return ComputerCraft.advancedTurtleFuelLimit;
} }
@ -505,8 +505,8 @@ public class TurtleBrain implements ITurtleAccess
private int issueCommand( ITurtleCommand command ) private int issueCommand( ITurtleCommand command )
{ {
m_commandQueue.offer( new TurtleCommandQueueEntry( ++m_commandsIssued, command ) ); commandQueue.offer( new TurtleCommandQueueEntry( ++commandsIssued, command ) );
return m_commandsIssued; return commandsIssued;
} }
@Nonnull @Nonnull
@ -525,38 +525,38 @@ public class TurtleBrain implements ITurtleAccess
{ {
if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot play animations on the client" ); if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot play animations on the client" );
m_animation = animation; this.animation = animation;
if( m_animation == TurtleAnimation.SHORT_WAIT ) if( this.animation == TurtleAnimation.SHORT_WAIT )
{ {
m_animationProgress = ANIM_DURATION / 2; animationProgress = ANIM_DURATION / 2;
m_lastAnimationProgress = ANIM_DURATION / 2; lastAnimationProgress = ANIM_DURATION / 2;
} }
else else
{ {
m_animationProgress = 0; animationProgress = 0;
m_lastAnimationProgress = 0; lastAnimationProgress = 0;
} }
m_owner.updateBlock(); owner.updateBlock();
} }
public ResourceLocation getOverlay() public ResourceLocation getOverlay()
{ {
return m_overlay; return overlay;
} }
public void setOverlay( ResourceLocation overlay ) public void setOverlay( ResourceLocation overlay )
{ {
if( !Objects.equal( m_overlay, overlay ) ) if( !Objects.equal( this.overlay, overlay ) )
{ {
m_overlay = overlay; this.overlay = overlay;
m_owner.updateBlock(); owner.updateBlock();
} }
} }
public DyeColor getDyeColour() public DyeColor getDyeColour()
{ {
if( m_colourHex == -1 ) return null; if( colourHex == -1 ) return null;
Colour colour = Colour.fromHex( m_colourHex ); Colour colour = Colour.fromHex( colourHex );
return colour == null ? null : DyeColor.byId( 15 - colour.ordinal() ); return colour == null ? null : DyeColor.byId( 15 - colour.ordinal() );
} }
@ -567,10 +567,10 @@ public class TurtleBrain implements ITurtleAccess
{ {
newColour = Colour.values()[15 - dyeColour.getId()].getHex(); newColour = Colour.values()[15 - dyeColour.getId()].getHex();
} }
if( m_colourHex != newColour ) if( colourHex != newColour )
{ {
m_colourHex = newColour; colourHex = newColour;
m_owner.updateBlock(); owner.updateBlock();
} }
} }
@ -579,67 +579,67 @@ public class TurtleBrain implements ITurtleAccess
{ {
if( colour >= 0 && colour <= 0xFFFFFF ) if( colour >= 0 && colour <= 0xFFFFFF )
{ {
if( m_colourHex != colour ) if( colourHex != colour )
{ {
m_colourHex = colour; colourHex = colour;
m_owner.updateBlock(); owner.updateBlock();
} }
} }
else if( m_colourHex != -1 ) else if( colourHex != -1 )
{ {
m_colourHex = -1; colourHex = -1;
m_owner.updateBlock(); owner.updateBlock();
} }
} }
@Override @Override
public int getColour() public int getColour()
{ {
return m_colourHex; return colourHex;
} }
public void setOwningPlayer( GameProfile profile ) public void setOwningPlayer( GameProfile profile )
{ {
m_owningPlayer = profile; owningPlayer = profile;
} }
@Nullable @Nullable
@Override @Override
public GameProfile getOwningPlayer() public GameProfile getOwningPlayer()
{ {
return m_owningPlayer; return owningPlayer;
} }
@Override @Override
public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side ) public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side )
{ {
return m_upgrades.get( side ); return upgrades.get( side );
} }
@Override @Override
public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade ) public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade upgrade )
{ {
// Remove old upgrade // Remove old upgrade
if( m_upgrades.containsKey( side ) ) if( upgrades.containsKey( side ) )
{ {
if( m_upgrades.get( side ) == upgrade ) return; if( upgrades.get( side ) == upgrade ) return;
m_upgrades.remove( side ); upgrades.remove( side );
} }
else else
{ {
if( upgrade == null ) return; if( upgrade == null ) return;
} }
m_upgradeNBTData.remove( side ); upgradeNBTData.remove( side );
// Set new upgrade // Set new upgrade
if( upgrade != null ) m_upgrades.put( side, upgrade ); if( upgrade != null ) upgrades.put( side, upgrade );
// Notify clients and create peripherals // Notify clients and create peripherals
if( m_owner.getLevel() != null ) if( owner.getLevel() != null )
{ {
updatePeripherals( m_owner.createServerComputer() ); updatePeripherals( owner.createServerComputer() );
m_owner.updateBlock(); owner.updateBlock();
} }
} }
@ -653,20 +653,20 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public CompoundNBT getUpgradeNBTData( TurtleSide side ) public CompoundNBT getUpgradeNBTData( TurtleSide side )
{ {
CompoundNBT nbt = m_upgradeNBTData.get( side ); CompoundNBT nbt = upgradeNBTData.get( side );
if( nbt == null ) m_upgradeNBTData.put( side, nbt = new CompoundNBT() ); if( nbt == null ) upgradeNBTData.put( side, nbt = new CompoundNBT() );
return nbt; return nbt;
} }
@Override @Override
public void updateUpgradeNBTData( @Nonnull TurtleSide side ) public void updateUpgradeNBTData( @Nonnull TurtleSide side )
{ {
m_owner.updateBlock(); owner.updateBlock();
} }
public Vec3d getRenderOffset( float f ) public Vec3d getRenderOffset( float f )
{ {
switch( m_animation ) switch( animation )
{ {
case MOVE_FORWARD: case MOVE_FORWARD:
case MOVE_BACK: case MOVE_BACK:
@ -675,7 +675,7 @@ public class TurtleBrain implements ITurtleAccess
{ {
// Get direction // Get direction
Direction dir; Direction dir;
switch( m_animation ) switch( animation )
{ {
case MOVE_FORWARD: case MOVE_FORWARD:
default: default:
@ -708,8 +708,8 @@ public class TurtleBrain implements ITurtleAccess
public float getToolRenderAngle( TurtleSide side, float f ) public float getToolRenderAngle( TurtleSide side, float f )
{ {
return (side == TurtleSide.LEFT && m_animation == TurtleAnimation.SWING_LEFT_TOOL) || return (side == TurtleSide.LEFT && animation == TurtleAnimation.SWING_LEFT_TOOL) ||
(side == TurtleSide.RIGHT && m_animation == TurtleAnimation.SWING_RIGHT_TOOL) (side == TurtleSide.RIGHT && animation == TurtleAnimation.SWING_RIGHT_TOOL)
? 45.0f * (float) Math.sin( getAnimationFraction( f ) * Math.PI ) ? 45.0f * (float) Math.sin( getAnimationFraction( f ) * Math.PI )
: 0.0f; : 0.0f;
} }
@ -759,14 +759,14 @@ public class TurtleBrain implements ITurtleAccess
private void updateCommands() private void updateCommands()
{ {
if( m_animation != TurtleAnimation.NONE || m_commandQueue.isEmpty() ) return; if( animation != TurtleAnimation.NONE || commandQueue.isEmpty() ) return;
// If we've got a computer, ensure that we're allowed to perform work. // If we've got a computer, ensure that we're allowed to perform work.
ServerComputer computer = m_owner.getServerComputer(); ServerComputer computer = owner.getServerComputer();
if( computer != null && !computer.getComputer().getMainThreadMonitor().canWork() ) return; if( computer != null && !computer.getComputer().getMainThreadMonitor().canWork() ) return;
// Pull a new command // Pull a new command
TurtleCommandQueueEntry nextCommand = m_commandQueue.poll(); TurtleCommandQueueEntry nextCommand = commandQueue.poll();
if( nextCommand == null ) return; if( nextCommand == null ) return;
// Execute the command // Execute the command
@ -808,21 +808,21 @@ public class TurtleBrain implements ITurtleAccess
private void updateAnimation() private void updateAnimation()
{ {
if( m_animation != TurtleAnimation.NONE ) if( animation != TurtleAnimation.NONE )
{ {
World world = getWorld(); World world = getWorld();
if( ComputerCraft.turtlesCanPush ) if( ComputerCraft.turtlesCanPush )
{ {
// Advance entity pushing // Advance entity pushing
if( m_animation == TurtleAnimation.MOVE_FORWARD || if( animation == TurtleAnimation.MOVE_FORWARD ||
m_animation == TurtleAnimation.MOVE_BACK || animation == TurtleAnimation.MOVE_BACK ||
m_animation == TurtleAnimation.MOVE_UP || animation == TurtleAnimation.MOVE_UP ||
m_animation == TurtleAnimation.MOVE_DOWN ) animation == TurtleAnimation.MOVE_DOWN )
{ {
BlockPos pos = getPosition(); BlockPos pos = getPosition();
Direction moveDir; Direction moveDir;
switch( m_animation ) switch( animation )
{ {
case MOVE_FORWARD: case MOVE_FORWARD:
default: default:
@ -846,7 +846,7 @@ public class TurtleBrain implements ITurtleAccess
double maxY = minY + 1.0; double maxY = minY + 1.0;
double maxZ = minZ + 1.0; double maxZ = minZ + 1.0;
float pushFrac = 1.0f - (float) (m_animationProgress + 1) / ANIM_DURATION; float pushFrac = 1.0f - (float) (animationProgress + 1) / ANIM_DURATION;
float push = Math.max( pushFrac + 0.0125f, 0.0f ); float push = Math.max( pushFrac + 0.0125f, 0.0f );
if( moveDir.getStepX() < 0 ) if( moveDir.getStepX() < 0 )
{ {
@ -892,7 +892,7 @@ public class TurtleBrain implements ITurtleAccess
} }
// Advance valentines day easter egg // Advance valentines day easter egg
if( world.isClientSide && m_animation == TurtleAnimation.MOVE_FORWARD && m_animationProgress == 4 ) if( world.isClientSide && animation == TurtleAnimation.MOVE_FORWARD && animationProgress == 4 )
{ {
// Spawn love pfx if valentines day // Spawn love pfx if valentines day
Holiday currentHoliday = HolidayUtil.getCurrentHoliday(); Holiday currentHoliday = HolidayUtil.getCurrentHoliday();
@ -915,20 +915,20 @@ public class TurtleBrain implements ITurtleAccess
} }
// Wait for anim completion // Wait for anim completion
m_lastAnimationProgress = m_animationProgress; lastAnimationProgress = animationProgress;
if( ++m_animationProgress >= ANIM_DURATION ) if( ++animationProgress >= ANIM_DURATION )
{ {
m_animation = TurtleAnimation.NONE; animation = TurtleAnimation.NONE;
m_animationProgress = 0; animationProgress = 0;
m_lastAnimationProgress = 0; lastAnimationProgress = 0;
} }
} }
} }
private float getAnimationFraction( float f ) private float getAnimationFraction( float f )
{ {
float next = (float) m_animationProgress / ANIM_DURATION; float next = (float) animationProgress / ANIM_DURATION;
float previous = (float) m_lastAnimationProgress / ANIM_DURATION; float previous = (float) lastAnimationProgress / ANIM_DURATION;
return previous + (next - previous) * f; return previous + (next - previous) * f;
} }

View File

@ -23,11 +23,11 @@ import java.util.List;
public class TurtleCompareCommand implements ITurtleCommand public class TurtleCompareCommand implements ITurtleCommand
{ {
private final InteractDirection m_direction; private final InteractDirection direction;
public TurtleCompareCommand( InteractDirection direction ) public TurtleCompareCommand( InteractDirection direction )
{ {
m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@ -35,7 +35,7 @@ public class TurtleCompareCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
// Get world direction from direction // Get world direction from direction
Direction direction = m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Get currently selected stack // Get currently selected stack
ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() ); ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() );

View File

@ -15,11 +15,11 @@ import javax.annotation.Nonnull;
public class TurtleCompareToCommand implements ITurtleCommand public class TurtleCompareToCommand implements ITurtleCommand
{ {
private final int m_slot; private final int slot;
public TurtleCompareToCommand( int slot ) public TurtleCompareToCommand( int slot )
{ {
m_slot = slot; this.slot = slot;
} }
@Nonnull @Nonnull
@ -27,14 +27,9 @@ public class TurtleCompareToCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() ); ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() );
ItemStack stack = turtle.getInventory().getItem( m_slot ); ItemStack stack = turtle.getInventory().getItem( slot );
if( InventoryUtil.areItemsStackable( selectedStack, stack ) ) return InventoryUtil.areItemsStackable( selectedStack, stack )
{ ? TurtleCommandResult.success()
return TurtleCommandResult.success(); : TurtleCommandResult.failure();
}
else
{
return TurtleCommandResult.failure();
}
} }
} }

View File

@ -17,11 +17,11 @@ import javax.annotation.Nonnull;
public class TurtleDetectCommand implements ITurtleCommand public class TurtleDetectCommand implements ITurtleCommand
{ {
private final InteractDirection m_direction; private final InteractDirection direction;
public TurtleDetectCommand( InteractDirection direction ) public TurtleDetectCommand( InteractDirection direction )
{ {
m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@ -29,7 +29,7 @@ public class TurtleDetectCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
// Get world direction from direction // Get world direction from direction
Direction direction = m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Check if thing in front is air or not // Check if thing in front is air or not
World world = turtle.getWorld(); World world = turtle.getWorld();

View File

@ -23,13 +23,13 @@ import javax.annotation.Nonnull;
public class TurtleDropCommand implements ITurtleCommand public class TurtleDropCommand implements ITurtleCommand
{ {
private final InteractDirection m_direction; private final InteractDirection direction;
private final int m_quantity; private final int quantity;
public TurtleDropCommand( InteractDirection direction, int quantity ) public TurtleDropCommand( InteractDirection direction, int quantity )
{ {
m_direction = direction; this.direction = direction;
m_quantity = quantity; this.quantity = quantity;
} }
@Nonnull @Nonnull
@ -37,17 +37,17 @@ public class TurtleDropCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
// Dropping nothing is easy // Dropping nothing is easy
if( m_quantity == 0 ) if( quantity == 0 )
{ {
turtle.playAnimation( TurtleAnimation.WAIT ); turtle.playAnimation( TurtleAnimation.WAIT );
return TurtleCommandResult.success(); return TurtleCommandResult.success();
} }
// Get world direction from direction // Get world direction from direction
Direction direction = m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Get things to drop // Get things to drop
ItemStack stack = InventoryUtil.takeItems( m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() ); ItemStack stack = InventoryUtil.takeItems( quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );
if( stack.isEmpty() ) if( stack.isEmpty() )
{ {
return TurtleCommandResult.failure( "No items to drop" ); return TurtleCommandResult.failure( "No items to drop" );

View File

@ -20,11 +20,11 @@ import javax.annotation.Nonnull;
public class TurtleEquipCommand implements ITurtleCommand public class TurtleEquipCommand implements ITurtleCommand
{ {
private final TurtleSide m_side; private final TurtleSide side;
public TurtleEquipCommand( TurtleSide side ) public TurtleEquipCommand( TurtleSide side )
{ {
m_side = side; this.side = side;
} }
@Nonnull @Nonnull
@ -53,7 +53,7 @@ public class TurtleEquipCommand implements ITurtleCommand
// Determine the upgrade to replace // Determine the upgrade to replace
ItemStack oldUpgradeStack; ItemStack oldUpgradeStack;
ITurtleUpgrade oldUpgrade = turtle.getUpgrade( m_side ); ITurtleUpgrade oldUpgrade = turtle.getUpgrade( side );
if( oldUpgrade != null ) if( oldUpgrade != null )
{ {
ItemStack craftingItem = oldUpgrade.getCraftingItem(); ItemStack craftingItem = oldUpgrade.getCraftingItem();
@ -87,7 +87,7 @@ public class TurtleEquipCommand implements ITurtleCommand
WorldUtil.dropItemStack( remainder, turtle.getWorld(), position, turtle.getDirection() ); WorldUtil.dropItemStack( remainder, turtle.getWorld(), position, turtle.getDirection() );
} }
} }
turtle.setUpgrade( m_side, newUpgrade ); turtle.setUpgrade( side, newUpgrade );
// Animate // Animate
if( newUpgrade != null || oldUpgrade != null ) if( newUpgrade != null || oldUpgrade != null )

View File

@ -28,11 +28,11 @@ import java.util.List;
public class TurtleMoveCommand implements ITurtleCommand public class TurtleMoveCommand implements ITurtleCommand
{ {
private final MoveDirection m_direction; private final MoveDirection direction;
public TurtleMoveCommand( MoveDirection direction ) public TurtleMoveCommand( MoveDirection direction )
{ {
m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@ -40,7 +40,7 @@ public class TurtleMoveCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
// Get world direction from direction // Get world direction from direction
Direction direction = m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Check if we can move // Check if we can move
World oldWorld = turtle.getWorld(); World oldWorld = turtle.getWorld();
@ -72,7 +72,7 @@ public class TurtleMoveCommand implements ITurtleCommand
if( !oldWorld.isUnobstructed( null, collision ) ) if( !oldWorld.isUnobstructed( null, collision ) )
{ {
if( !ComputerCraft.turtlesCanPush || m_direction == MoveDirection.UP || m_direction == MoveDirection.DOWN ) if( !ComputerCraft.turtlesCanPush || this.direction == MoveDirection.UP || this.direction == MoveDirection.DOWN )
{ {
return TurtleCommandResult.failure( "Movement obstructed" ); return TurtleCommandResult.failure( "Movement obstructed" );
} }
@ -112,7 +112,7 @@ public class TurtleMoveCommand implements ITurtleCommand
turtle.consumeFuel( 1 ); turtle.consumeFuel( 1 );
// Animate // Animate
switch( m_direction ) switch( this.direction )
{ {
case FORWARD: case FORWARD:
default: default:

View File

@ -42,13 +42,13 @@ import java.util.List;
public class TurtlePlaceCommand implements ITurtleCommand public class TurtlePlaceCommand implements ITurtleCommand
{ {
private final InteractDirection m_direction; private final InteractDirection direction;
private final Object[] m_extraArguments; private final Object[] extraArguments;
public TurtlePlaceCommand( InteractDirection direction, Object[] arguments ) public TurtlePlaceCommand( InteractDirection direction, Object[] arguments )
{ {
m_direction = direction; this.direction = direction;
m_extraArguments = arguments; extraArguments = arguments;
} }
@Nonnull @Nonnull
@ -63,7 +63,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
} }
// Remember old block // Remember old block
Direction direction = m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
BlockPos coordinates = turtle.getPosition().relative( direction ); BlockPos coordinates = turtle.getPosition().relative( direction );
// Create a fake player, and orient it appropriately // Create a fake player, and orient it appropriately
@ -78,7 +78,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
// Do the deploying // Do the deploying
String[] errorMessage = new String[1]; String[] errorMessage = new String[1];
ItemStack remainder = deploy( stack, turtle, turtlePlayer, direction, m_extraArguments, errorMessage ); ItemStack remainder = deploy( stack, turtle, turtlePlayer, direction, extraArguments, errorMessage );
if( remainder != stack ) if( remainder != stack )
{ {
// Put the remaining items back // Put the remaining items back

View File

@ -95,11 +95,11 @@ public final class TurtlePlayer extends FakePlayer
if( !(access instanceof TurtleBrain) ) return create( access ); if( !(access instanceof TurtleBrain) ) return create( access );
TurtleBrain brain = (TurtleBrain) access; TurtleBrain brain = (TurtleBrain) access;
TurtlePlayer player = brain.m_cachedPlayer; TurtlePlayer player = brain.cachedPlayer;
if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() ) if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() )
|| player.getCommandSenderWorld() != access.getWorld() ) || player.getCommandSenderWorld() != access.getWorld() )
{ {
player = brain.m_cachedPlayer = create( brain ); player = brain.cachedPlayer = create( brain );
} }
else else
{ {

View File

@ -26,13 +26,13 @@ import java.util.List;
public class TurtleSuckCommand implements ITurtleCommand public class TurtleSuckCommand implements ITurtleCommand
{ {
private final InteractDirection m_direction; private final InteractDirection direction;
private final int m_quantity; private final int quantity;
public TurtleSuckCommand( InteractDirection direction, int quantity ) public TurtleSuckCommand( InteractDirection direction, int quantity )
{ {
m_direction = direction; this.direction = direction;
m_quantity = quantity; this.quantity = quantity;
} }
@Nonnull @Nonnull
@ -40,14 +40,14 @@ public class TurtleSuckCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
// Sucking nothing is easy // Sucking nothing is easy
if( m_quantity == 0 ) if( quantity == 0 )
{ {
turtle.playAnimation( TurtleAnimation.WAIT ); turtle.playAnimation( TurtleAnimation.WAIT );
return TurtleCommandResult.success(); return TurtleCommandResult.success();
} }
// Get world direction from direction // Get world direction from direction
Direction direction = m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Get inventory for thing in front // Get inventory for thing in front
World world = turtle.getWorld(); World world = turtle.getWorld();
@ -68,7 +68,7 @@ public class TurtleSuckCommand implements ITurtleCommand
if( inventory != null ) if( inventory != null )
{ {
// Take from inventory of thing in front // Take from inventory of thing in front
ItemStack stack = InventoryUtil.takeItems( m_quantity, inventory ); ItemStack stack = InventoryUtil.takeItems( quantity, inventory );
if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to take" ); if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to take" );
// Try to place into the turtle // Try to place into the turtle
@ -107,9 +107,9 @@ public class TurtleSuckCommand implements ITurtleCommand
ItemStack storeStack; ItemStack storeStack;
ItemStack leaveStack; ItemStack leaveStack;
if( stack.getCount() > m_quantity ) if( stack.getCount() > quantity )
{ {
storeStack = stack.split( m_quantity ); storeStack = stack.split( quantity );
leaveStack = stack; leaveStack = stack;
} }
else else

View File

@ -16,13 +16,13 @@ import javax.annotation.Nonnull;
public class TurtleTransferToCommand implements ITurtleCommand public class TurtleTransferToCommand implements ITurtleCommand
{ {
private final int m_slot; private final int slot;
private final int m_quantity; private final int quantity;
public TurtleTransferToCommand( int slot, int limit ) public TurtleTransferToCommand( int slot, int limit )
{ {
m_slot = slot; this.slot = slot;
m_quantity = limit; quantity = limit;
} }
@Nonnull @Nonnull
@ -30,7 +30,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
{ {
// Take stack // Take stack
ItemStack stack = InventoryUtil.takeItems( m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() ); ItemStack stack = InventoryUtil.takeItems( quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );
if( stack.isEmpty() ) if( stack.isEmpty() )
{ {
turtle.playAnimation( TurtleAnimation.WAIT ); turtle.playAnimation( TurtleAnimation.WAIT );
@ -38,7 +38,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
} }
// Store stack // Store stack
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), m_slot, 1, m_slot ); ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), slot, 1, slot );
if( !remainder.isEmpty() ) if( !remainder.isEmpty() )
{ {
// Put the remainder back // Put the remainder back

View File

@ -17,11 +17,11 @@ import javax.annotation.Nonnull;
public class TurtleTurnCommand implements ITurtleCommand public class TurtleTurnCommand implements ITurtleCommand
{ {
private final TurnDirection m_direction; private final TurnDirection direction;
public TurtleTurnCommand( TurnDirection direction ) public TurtleTurnCommand( TurnDirection direction )
{ {
m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@ -34,7 +34,7 @@ public class TurtleTurnCommand implements ITurtleCommand
return TurtleCommandResult.failure( event.getFailureMessage() ); return TurtleCommandResult.failure( event.getFailureMessage() );
} }
switch( m_direction ) switch( direction )
{ {
case LEFT: case LEFT:
{ {

View File

@ -21,11 +21,8 @@ import javax.annotation.Nonnull;
public class TurtleCraftingTable extends AbstractTurtleUpgrade public class TurtleCraftingTable extends AbstractTurtleUpgrade
{ {
@OnlyIn( Dist.CLIENT ) private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_left", "inventory" );
private ModelResourceLocation m_leftModel; private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_right", "inventory" );
@OnlyIn( Dist.CLIENT )
private ModelResourceLocation m_rightModel;
public TurtleCraftingTable( ResourceLocation id ) public TurtleCraftingTable( ResourceLocation id )
{ {
@ -38,22 +35,11 @@ public class TurtleCraftingTable extends AbstractTurtleUpgrade
return new CraftingTablePeripheral( turtle ); return new CraftingTablePeripheral( turtle );
} }
@OnlyIn( Dist.CLIENT )
private void loadModelLocations()
{
if( m_leftModel == null )
{
m_leftModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_left", "inventory" );
m_rightModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_right", "inventory" );
}
}
@Nonnull @Nonnull
@Override @Override
@OnlyIn( Dist.CLIENT ) @OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{ {
loadModelLocations(); return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel );
return TransformedModel.of( side == TurtleSide.LEFT ? m_leftModel : m_rightModel );
} }
} }

View File

@ -27,9 +27,9 @@ import java.util.List;
public class TurtleInventoryCrafting extends CraftingInventory public class TurtleInventoryCrafting extends CraftingInventory
{ {
private ITurtleAccess m_turtle; private final ITurtleAccess turtle;
private int m_xStart; private int xStart = 0;
private int m_yStart; private int yStart = 0;
@SuppressWarnings( "ConstantConditions" ) @SuppressWarnings( "ConstantConditions" )
public TurtleInventoryCrafting( ITurtleAccess turtle ) public TurtleInventoryCrafting( ITurtleAccess turtle )
@ -37,26 +37,24 @@ public class TurtleInventoryCrafting extends CraftingInventory
// Passing null in here is evil, but we don't have a container present. We override most methods in order to // Passing null in here is evil, but we don't have a container present. We override most methods in order to
// avoid throwing any NPEs. // avoid throwing any NPEs.
super( null, 0, 0 ); super( null, 0, 0 );
m_turtle = turtle; this.turtle = turtle;
m_xStart = 0;
m_yStart = 0;
} }
@Nullable @Nullable
private IRecipe<CraftingInventory> tryCrafting( int xStart, int yStart ) private IRecipe<CraftingInventory> tryCrafting( int xStart, int yStart )
{ {
m_xStart = xStart; this.xStart = xStart;
m_yStart = yStart; this.yStart = yStart;
// Check the non-relevant parts of the inventory are empty // Check the non-relevant parts of the inventory are empty
for( int x = 0; x < TileTurtle.INVENTORY_WIDTH; x++ ) for( int x = 0; x < TileTurtle.INVENTORY_WIDTH; x++ )
{ {
for( int y = 0; y < TileTurtle.INVENTORY_HEIGHT; y++ ) for( int y = 0; y < TileTurtle.INVENTORY_HEIGHT; y++ )
{ {
if( x < m_xStart || x >= m_xStart + 3 || if( x < this.xStart || x >= this.xStart + 3 ||
y < m_yStart || y >= m_yStart + 3 ) y < this.yStart || y >= this.yStart + 3 )
{ {
if( !m_turtle.getInventory().getItem( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() ) if( !turtle.getInventory().getItem( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() )
{ {
return null; return null;
} }
@ -65,7 +63,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
} }
// Check the actual crafting // Check the actual crafting
return m_turtle.getWorld().getRecipeManager().getRecipeFor( IRecipeType.CRAFTING, this, m_turtle.getWorld() ).orElse( null ); return turtle.getWorld().getRecipeManager().getRecipeFor( IRecipeType.CRAFTING, this, turtle.getWorld() ).orElse( null );
} }
@Nullable @Nullable
@ -83,7 +81,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
// Special case: craft(0) just returns an empty list if crafting was possible // Special case: craft(0) just returns an empty list if crafting was possible
if( maxCount == 0 ) return Collections.emptyList(); if( maxCount == 0 ) return Collections.emptyList();
TurtlePlayer player = TurtlePlayer.get( m_turtle ); TurtlePlayer player = TurtlePlayer.get( turtle );
ArrayList<ItemStack> results = new ArrayList<>(); ArrayList<ItemStack> results = new ArrayList<>();
for( int i = 0; i < maxCount && recipe.matches( this, world ); i++ ) for( int i = 0; i < maxCount && recipe.matches( this, world ); i++ )
@ -147,8 +145,8 @@ public class TurtleInventoryCrafting extends CraftingInventory
private int modifyIndex( int index ) private int modifyIndex( int index )
{ {
int x = m_xStart + index % getWidth(); int x = xStart + index % getWidth();
int y = m_yStart + index / getHeight(); int y = yStart + index / getHeight();
return x >= 0 && x < TileTurtle.INVENTORY_WIDTH && y >= 0 && y < TileTurtle.INVENTORY_HEIGHT return x >= 0 && x < TileTurtle.INVENTORY_WIDTH && y >= 0 && y < TileTurtle.INVENTORY_HEIGHT
? x + y * TileTurtle.INVENTORY_WIDTH ? x + y * TileTurtle.INVENTORY_WIDTH
: -1; : -1;
@ -167,7 +165,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public ItemStack getItem( int i ) public ItemStack getItem( int i )
{ {
i = modifyIndex( i ); i = modifyIndex( i );
return m_turtle.getInventory().getItem( i ); return turtle.getInventory().getItem( i );
} }
@Nonnull @Nonnull
@ -175,7 +173,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public ItemStack removeItemNoUpdate( int i ) public ItemStack removeItemNoUpdate( int i )
{ {
i = modifyIndex( i ); i = modifyIndex( i );
return m_turtle.getInventory().removeItemNoUpdate( i ); return turtle.getInventory().removeItemNoUpdate( i );
} }
@Nonnull @Nonnull
@ -183,26 +181,26 @@ public class TurtleInventoryCrafting extends CraftingInventory
public ItemStack removeItem( int i, int size ) public ItemStack removeItem( int i, int size )
{ {
i = modifyIndex( i ); i = modifyIndex( i );
return m_turtle.getInventory().removeItem( i, size ); return turtle.getInventory().removeItem( i, size );
} }
@Override @Override
public void setItem( int i, @Nonnull ItemStack stack ) public void setItem( int i, @Nonnull ItemStack stack )
{ {
i = modifyIndex( i ); i = modifyIndex( i );
m_turtle.getInventory().setItem( i, stack ); turtle.getInventory().setItem( i, stack );
} }
@Override @Override
public int getMaxStackSize() public int getMaxStackSize()
{ {
return m_turtle.getInventory().getMaxStackSize(); return turtle.getInventory().getMaxStackSize();
} }
@Override @Override
public void setChanged() public void setChanged()
{ {
m_turtle.getInventory().setChanged(); turtle.getInventory().setChanged();
} }
@Override @Override
@ -215,7 +213,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public boolean canPlaceItem( int i, @Nonnull ItemStack stack ) public boolean canPlaceItem( int i, @Nonnull ItemStack stack )
{ {
i = modifyIndex( i ); i = modifyIndex( i );
return m_turtle.getInventory().canPlaceItem( i, stack ); return turtle.getInventory().canPlaceItem( i, stack );
} }
@Override @Override
@ -224,7 +222,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
for( int i = 0; i < getContainerSize(); i++ ) for( int i = 0; i < getContainerSize(); i++ )
{ {
int j = modifyIndex( i ); int j = modifyIndex( i );
m_turtle.getInventory().setItem( j, ItemStack.EMPTY ); turtle.getInventory().setItem( j, ItemStack.EMPTY );
} }
} }
} }

View File

@ -63,17 +63,10 @@ public class TurtleModem extends AbstractTurtleUpgrade
private final boolean advanced; private final boolean advanced;
@OnlyIn( Dist.CLIENT ) private final ModelResourceLocation leftOffModel;
private ModelResourceLocation m_leftOffModel; private final ModelResourceLocation rightOffModel;
private final ModelResourceLocation leftOnModel;
@OnlyIn( Dist.CLIENT ) private final ModelResourceLocation rightOnModel;
private ModelResourceLocation m_rightOffModel;
@OnlyIn( Dist.CLIENT )
private ModelResourceLocation m_leftOnModel;
@OnlyIn( Dist.CLIENT )
private ModelResourceLocation m_rightOnModel;
public TurtleModem( boolean advanced, ResourceLocation id ) public TurtleModem( boolean advanced, ResourceLocation id )
{ {
@ -84,6 +77,21 @@ public class TurtleModem extends AbstractTurtleUpgrade
: Registry.ModBlocks.WIRELESS_MODEM_NORMAL : Registry.ModBlocks.WIRELESS_MODEM_NORMAL
); );
this.advanced = advanced; this.advanced = advanced;
if( advanced )
{
leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" );
rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" );
leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" );
rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" );
}
else
{
leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" );
rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" );
leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" );
rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" );
}
} }
@Override @Override
@ -99,35 +107,11 @@ public class TurtleModem extends AbstractTurtleUpgrade
return TurtleCommandResult.failure(); return TurtleCommandResult.failure();
} }
@OnlyIn( Dist.CLIENT )
private void loadModelLocations()
{
if( m_leftOffModel == null )
{
if( advanced )
{
m_leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" );
m_rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" );
m_leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" );
m_rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" );
}
else
{
m_leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" );
m_rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" );
m_leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" );
m_rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" );
}
}
}
@Nonnull @Nonnull
@Override @Override
@OnlyIn( Dist.CLIENT ) @OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{ {
loadModelLocations();
boolean active = false; boolean active = false;
if( turtle != null ) if( turtle != null )
{ {
@ -136,8 +120,8 @@ public class TurtleModem extends AbstractTurtleUpgrade
} }
return side == TurtleSide.LEFT return side == TurtleSide.LEFT
? TransformedModel.of( active ? m_leftOnModel : m_leftOffModel ) ? TransformedModel.of( active ? leftOnModel : leftOffModel )
: TransformedModel.of( active ? m_rightOnModel : m_rightOffModel ); : TransformedModel.of( active ? rightOnModel : rightOffModel );
} }
@Override @Override

View File

@ -25,6 +25,9 @@ import javax.annotation.Nonnull;
public class TurtleSpeaker extends AbstractTurtleUpgrade public class TurtleSpeaker extends AbstractTurtleUpgrade
{ {
private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" );
private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" );
private static class Peripheral extends SpeakerPeripheral private static class Peripheral extends SpeakerPeripheral
{ {
ITurtleAccess turtle; ITurtleAccess turtle;
@ -54,12 +57,6 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
} }
} }
@OnlyIn( Dist.CLIENT )
private ModelResourceLocation m_leftModel;
@OnlyIn( Dist.CLIENT )
private ModelResourceLocation m_rightModel;
public TurtleSpeaker( ResourceLocation id ) public TurtleSpeaker( ResourceLocation id )
{ {
super( id, TurtleUpgradeType.PERIPHERAL, Registry.ModBlocks.SPEAKER ); super( id, TurtleUpgradeType.PERIPHERAL, Registry.ModBlocks.SPEAKER );
@ -71,33 +68,18 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
return new TurtleSpeaker.Peripheral( turtle ); return new TurtleSpeaker.Peripheral( turtle );
} }
@OnlyIn( Dist.CLIENT )
private void loadModelLocations()
{
if( m_leftModel == null )
{
m_leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" );
m_rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" );
}
}
@Nonnull @Nonnull
@Override @Override
@OnlyIn( Dist.CLIENT ) @OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{ {
loadModelLocations(); return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel );
return TransformedModel.of( side == TurtleSide.LEFT ? m_leftModel : m_rightModel );
} }
@Override @Override
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide ) public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide )
{ {
IPeripheral turtlePeripheral = turtle.getPeripheral( turtleSide ); IPeripheral turtlePeripheral = turtle.getPeripheral( turtleSide );
if( turtlePeripheral instanceof Peripheral ) if( turtlePeripheral instanceof Peripheral ) ((Peripheral) turtlePeripheral).update();
{
Peripheral peripheral = (Peripheral) turtlePeripheral;
peripheral.update();
}
} }
} }

View File

@ -9,8 +9,6 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.Registry; import dan200.computercraft.shared.Registry;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -23,7 +21,6 @@ public class CreativeTabMain extends ItemGroup
@Nonnull @Nonnull
@Override @Override
@OnlyIn( Dist.CLIENT )
public ItemStack makeIcon() public ItemStack makeIcon()
{ {
return new ItemStack( Registry.ModBlocks.COMPUTER_NORMAL.get() ); return new ItemStack( Registry.ModBlocks.COMPUTER_NORMAL.get() );