1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-30 00:57:55 +00:00

No more m_ nice guy

This commit is contained in:
Jonathan Coates
2021-06-09 08:55:11 +01:00
parent a198a5241d
commit 59266fe6e9
39 changed files with 1234 additions and 1211 deletions

View File

@@ -25,11 +25,11 @@ import static dan200.computercraft.client.render.PrintoutRenderer.*;
public class GuiPrintout extends HandledScreen<ContainerHeldItem> public class GuiPrintout extends HandledScreen<ContainerHeldItem>
{ {
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, Text title ) public GuiPrintout( ContainerHeldItem container, PlayerInventory player, Text title )
{ {
@@ -38,22 +38,22 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
this.backgroundHeight = Y_SIZE; this.backgroundHeight = Y_SIZE;
String[] text = ItemPrintout.getText( container.getStack() ); String[] text = ItemPrintout.getText( container.getStack() );
this.m_text = new TextBuffer[text.length]; this.text = new TextBuffer[text.length];
for( int i = 0; i < this.m_text.length; i++ ) for( int i = 0; i < this.text.length; i++ )
{ {
this.m_text[i] = new TextBuffer( text[i] ); this.text[i] = new TextBuffer( text[i] );
} }
String[] colours = ItemPrintout.getColours( container.getStack() ); String[] colours = ItemPrintout.getColours( container.getStack() );
this.m_colours = new TextBuffer[colours.length]; this.colours = new TextBuffer[colours.length];
for( int i = 0; i < this.m_colours.length; i++ ) for( int i = 0; i < this.colours.length; i++ )
{ {
this.m_colours[i] = new TextBuffer( colours[i] ); this.colours[i] = new TextBuffer( colours[i] );
} }
this.m_page = 0; this.page = 0;
this.m_pages = Math.max( this.m_text.length / ItemPrintout.LINES_PER_PAGE, 1 ); this.pages = Math.max( this.text.length / ItemPrintout.LINES_PER_PAGE, 1 );
this.m_book = ((ItemPrintout) container.getStack() this.book = ((ItemPrintout) container.getStack()
.getItem()).getType() == ItemPrintout.Type.BOOK; .getItem()).getType() == ItemPrintout.Type.BOOK;
} }
@@ -67,9 +67,9 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
if( delta < 0 ) if( delta < 0 )
{ {
// Scroll up goes to the next page // Scroll up goes to the next page
if( this.m_page < this.m_pages - 1 ) if( this.page < this.pages - 1 )
{ {
this.m_page++; this.page++;
} }
return true; return true;
} }
@@ -77,9 +77,9 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
if( delta > 0 ) if( delta > 0 )
{ {
// Scroll down goes to the previous page // Scroll down goes to the previous page
if( this.m_page > 0 ) if( this.page > 0 )
{ {
this.m_page--; this.page--;
} }
return true; return true;
} }
@@ -116,8 +116,8 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
.getEntityVertexConsumers(); .getEntityVertexConsumers();
Matrix4f matrix = transform.peek() Matrix4f matrix = transform.peek()
.getModel(); .getModel();
drawBorder( matrix, renderer, this.x, this.y, this.getZOffset(), this.m_page, this.m_pages, this.m_book ); drawBorder( matrix, renderer, this.x, this.y, this.getZOffset(), this.page, this.pages, this.book );
drawText( matrix, renderer, this.x + X_TEXT_MARGIN, this.y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * this.m_page, this.m_text, this.m_colours ); drawText( matrix, renderer, this.x + X_TEXT_MARGIN, this.y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * this.page, this.text, this.colours );
renderer.draw(); renderer.draw();
} }
@@ -131,18 +131,18 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
if( key == GLFW.GLFW_KEY_RIGHT ) if( key == GLFW.GLFW_KEY_RIGHT )
{ {
if( this.m_page < this.m_pages - 1 ) if( this.page < this.pages - 1 )
{ {
this.m_page++; this.page++;
} }
return true; return true;
} }
if( key == GLFW.GLFW_KEY_LEFT ) if( key == GLFW.GLFW_KEY_LEFT )
{ {
if( this.m_page > 0 ) if( this.page > 0 )
{ {
this.m_page--; this.page--;
} }
return true; return true;
} }

View File

@@ -26,9 +26,9 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
{ {
private static final Identifier BACKGROUND_NORMAL = new Identifier( "computercraft", "textures/gui/turtle_normal.png" ); private static final Identifier BACKGROUND_NORMAL = new Identifier( "computercraft", "textures/gui/turtle_normal.png" );
private static final Identifier BACKGROUND_ADVANCED = new Identifier( "computercraft", "textures/gui/turtle_advanced.png" ); private static final Identifier BACKGROUND_ADVANCED = new Identifier( "computercraft", "textures/gui/turtle_advanced.png" );
private final ComputerFamily m_family; private final ComputerFamily family;
private final ClientComputer m_computer; private final ClientComputer computer;
private ContainerTurtle m_container; private final ContainerTurtle container;
private WidgetTerminal terminal; private WidgetTerminal terminal;
private WidgetWrapper terminalWrapper; private WidgetWrapper terminalWrapper;
@@ -36,9 +36,9 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
{ {
super( container, player, title ); super( container, player, title );
this.m_container = container; this.container = container;
this.m_family = container.getFamily(); this.family = container.getFamily();
this.m_computer = (ClientComputer) container.getComputer(); this.computer = (ClientComputer) container.getComputer();
this.backgroundWidth = 254; this.backgroundWidth = 254;
this.backgroundHeight = 217; this.backgroundHeight = 217;
@@ -53,7 +53,7 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH; int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH;
int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT; int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT;
this.terminal = new WidgetTerminal( this.client, () -> this.m_computer, ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight, 2, 2, 2, 2 ); this.terminal = new WidgetTerminal( this.client, () -> this.computer, ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight, 2, 2, 2, 2 );
this.terminalWrapper = new WidgetWrapper( this.terminal, 2 + 8 + this.x, 2 + 8 + this.y, termPxWidth, termPxHeight ); this.terminalWrapper = new WidgetWrapper( this.terminal, 2 + 8 + this.x, 2 + 8 + this.y, termPxWidth, termPxHeight );
this.children.add( this.terminalWrapper ); this.children.add( this.terminalWrapper );
@@ -78,7 +78,7 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
{ {
// Draw term // Draw term
Identifier texture = this.m_family == ComputerFamily.ADVANCED ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL; Identifier texture = this.family == ComputerFamily.ADVANCED ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL;
this.terminal.draw( this.terminalWrapper.getX(), this.terminalWrapper.getY() ); this.terminal.draw( this.terminalWrapper.getX(), this.terminalWrapper.getY() );
// Draw border/inventory // Draw border/inventory
@@ -88,7 +88,7 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
this.drawTexture( transform, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight ); this.drawTexture( transform, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight );
// Draw selection slot // Draw selection slot
int slot = this.m_container.getSelectedSlot(); int slot = this.container.getSelectedSlot();
if( slot >= 0 ) if( slot >= 0 )
{ {
int slotX = slot % 4; int slotX = slot % 4;

View File

@@ -23,23 +23,23 @@ import java.util.*;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
public class TurtleMultiModel implements BakedModel public class TurtleMultiModel implements BakedModel
{ {
private final BakedModel m_baseModel; private final BakedModel baseModel;
private final BakedModel m_overlayModel; private final BakedModel overlayModel;
private final AffineTransformation m_generalTransform; private final AffineTransformation 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 Map<Direction, List<BakedQuad>> faceQuads = new EnumMap<>( Direction.class );
public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, AffineTransformation generalTransform, TransformedModel leftUpgradeModel, public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, AffineTransformation generalTransform, TransformedModel leftUpgradeModel,
TransformedModel rightUpgradeModel ) TransformedModel rightUpgradeModel )
{ {
// Get the models // Get the models
this.m_baseModel = baseModel; this.baseModel = baseModel;
this.m_overlayModel = overlayModel; this.overlayModel = overlayModel;
this.m_leftUpgradeModel = leftUpgradeModel; this.leftUpgradeModel = leftUpgradeModel;
this.m_rightUpgradeModel = rightUpgradeModel; this.rightUpgradeModel = rightUpgradeModel;
this.m_generalTransform = generalTransform; this.generalTransform = generalTransform;
} }
@Nonnull @Nonnull
@@ -48,19 +48,19 @@ public class TurtleMultiModel implements BakedModel
{ {
if( side != null ) if( side != null )
{ {
if( !this.m_faceQuads.containsKey( side ) ) if( !this.faceQuads.containsKey( side ) )
{ {
this.m_faceQuads.put( side, this.buildQuads( state, side, rand ) ); this.faceQuads.put( side, this.buildQuads( state, side, rand ) );
} }
return this.m_faceQuads.get( side ); return this.faceQuads.get( side );
} }
else else
{ {
if( this.m_generalQuads == null ) if( this.generalQuads == null )
{ {
this.m_generalQuads = this.buildQuads( state, side, rand ); this.generalQuads = this.buildQuads( state, side, rand );
} }
return this.m_generalQuads; return this.generalQuads;
} }
} }
@@ -69,22 +69,22 @@ public class TurtleMultiModel implements BakedModel
ArrayList<BakedQuad> quads = new ArrayList<>(); ArrayList<BakedQuad> quads = new ArrayList<>();
ModelTransformer.transformQuadsTo( quads, this.m_baseModel.getQuads( state, side, rand ), this.m_generalTransform.getMatrix() ); ModelTransformer.transformQuadsTo( quads, this.baseModel.getQuads( state, side, rand ), this.generalTransform.getMatrix() );
if( this.m_overlayModel != null ) if( this.overlayModel != null )
{ {
ModelTransformer.transformQuadsTo( quads, this.m_overlayModel.getQuads( state, side, rand ), this.m_generalTransform.getMatrix() ); ModelTransformer.transformQuadsTo( quads, this.overlayModel.getQuads( state, side, rand ), this.generalTransform.getMatrix() );
} }
if( this.m_leftUpgradeModel != null ) if( this.leftUpgradeModel != null )
{ {
AffineTransformation upgradeTransform = this.m_generalTransform.multiply( this.m_leftUpgradeModel.getMatrix() ); AffineTransformation upgradeTransform = this.generalTransform.multiply( this.leftUpgradeModel.getMatrix() );
ModelTransformer.transformQuadsTo( quads, this.m_leftUpgradeModel.getModel() ModelTransformer.transformQuadsTo( quads, this.leftUpgradeModel.getModel()
.getQuads( state, side, rand ), .getQuads( state, side, rand ),
upgradeTransform.getMatrix() ); upgradeTransform.getMatrix() );
} }
if( this.m_rightUpgradeModel != null ) if( this.rightUpgradeModel != null )
{ {
AffineTransformation upgradeTransform = this.m_generalTransform.multiply( this.m_rightUpgradeModel.getMatrix() ); AffineTransformation upgradeTransform = this.generalTransform.multiply( this.rightUpgradeModel.getMatrix() );
ModelTransformer.transformQuadsTo( quads, this.m_rightUpgradeModel.getModel() ModelTransformer.transformQuadsTo( quads, this.rightUpgradeModel.getModel()
.getQuads( state, side, rand ), .getQuads( state, side, rand ),
upgradeTransform.getMatrix() ); upgradeTransform.getMatrix() );
} }
@@ -95,25 +95,25 @@ public class TurtleMultiModel implements BakedModel
@Override @Override
public boolean useAmbientOcclusion() public boolean useAmbientOcclusion()
{ {
return this.m_baseModel.useAmbientOcclusion(); return this.baseModel.useAmbientOcclusion();
} }
@Override @Override
public boolean hasDepth() public boolean hasDepth()
{ {
return this.m_baseModel.hasDepth(); return this.baseModel.hasDepth();
} }
@Override @Override
public boolean isSideLit() public boolean isSideLit()
{ {
return this.m_baseModel.isSideLit(); return this.baseModel.isSideLit();
} }
@Override @Override
public boolean isBuiltin() public boolean isBuiltin()
{ {
return this.m_baseModel.isBuiltin(); return this.baseModel.isBuiltin();
} }
@Nonnull @Nonnull
@@ -121,7 +121,7 @@ public class TurtleMultiModel implements BakedModel
@Deprecated @Deprecated
public Sprite getSprite() public Sprite getSprite()
{ {
return this.m_baseModel.getSprite(); return this.baseModel.getSprite();
} }
@Nonnull @Nonnull
@@ -129,7 +129,7 @@ public class TurtleMultiModel implements BakedModel
@Deprecated @Deprecated
public net.minecraft.client.render.model.json.ModelTransformation getTransformation() public net.minecraft.client.render.model.json.ModelTransformation getTransformation()
{ {
return this.m_baseModel.getTransformation(); return this.baseModel.getTransformation();
} }
@Nonnull @Nonnull

View File

@@ -57,8 +57,8 @@ public class TurtleSmartItemModel implements BakedModel
private final BakedModel familyModel; private final BakedModel familyModel;
private final BakedModel colourModel; private final BakedModel colourModel;
private final HashMap<TurtleModelCombination, BakedModel> m_cachedModels = new HashMap<>(); private final HashMap<TurtleModelCombination, BakedModel> cachedModels = new HashMap<>();
private final ModelOverrideList m_overrides; private final ModelOverrideList overrides;
public TurtleSmartItemModel( BakedModel familyModel, BakedModel colourModel ) public TurtleSmartItemModel( BakedModel familyModel, BakedModel colourModel )
{ {
@@ -66,7 +66,7 @@ public class TurtleSmartItemModel implements BakedModel
this.colourModel = colourModel; this.colourModel = colourModel;
// this actually works I think, trust me // this actually works I think, trust me
this.m_overrides = new ModelOverrideList( null, null, null, Collections.emptyList() ) this.overrides = new ModelOverrideList( null, null, null, Collections.emptyList() )
{ {
@Nonnull @Nonnull
@Override @Override
@@ -85,10 +85,10 @@ public class TurtleSmartItemModel implements BakedModel
boolean flip = false; boolean flip = false;
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip ); TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
BakedModel model = TurtleSmartItemModel.this.m_cachedModels.get( combo ); BakedModel model = TurtleSmartItemModel.this.cachedModels.get( combo );
if( model == null ) if( model == null )
{ {
TurtleSmartItemModel.this.m_cachedModels.put( combo, model = TurtleSmartItemModel.this.buildModel( combo ) ); TurtleSmartItemModel.this.cachedModels.put( combo, model = TurtleSmartItemModel.this.buildModel( combo ) );
} }
return model; return model;
} }
@@ -101,13 +101,13 @@ public class TurtleSmartItemModel implements BakedModel
BakedModelManager modelManager = mc.getItemRenderer() BakedModelManager modelManager = mc.getItemRenderer()
.getModels() .getModels()
.getModelManager(); .getModelManager();
ModelIdentifier overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas ); ModelIdentifier overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
BakedModel baseModel = combo.m_colour ? this.colourModel : this.familyModel; BakedModel baseModel = combo.colour ? this.colourModel : this.familyModel;
BakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null; BakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
AffineTransformation transform = combo.m_flip ? flip : identity; AffineTransformation 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 );
} }
@@ -163,27 +163,27 @@ public class TurtleSmartItemModel implements BakedModel
@Override @Override
public ModelOverrideList getOverrides() public ModelOverrideList getOverrides()
{ {
return this.m_overrides; return this.overrides;
} }
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 Identifier m_overlay; final Identifier overlay;
final boolean m_christmas; final boolean christmas;
final boolean m_flip; final boolean flip;
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, Identifier overlay, boolean christmas, TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, Identifier overlay, boolean christmas,
boolean flip ) boolean flip )
{ {
this.m_colour = colour; this.colour = colour;
this.m_leftUpgrade = leftUpgrade; this.leftUpgrade = leftUpgrade;
this.m_rightUpgrade = rightUpgrade; this.rightUpgrade = rightUpgrade;
this.m_overlay = overlay; this.overlay = overlay;
this.m_christmas = christmas; this.christmas = christmas;
this.m_flip = flip; this.flip = flip;
} }
@Override @Override
@@ -191,12 +191,12 @@ public class TurtleSmartItemModel implements BakedModel
{ {
final int prime = 31; final int prime = 31;
int result = 0; int result = 0;
result = prime * result + (this.m_colour ? 1 : 0); result = prime * result + (this.colour ? 1 : 0);
result = prime * result + (this.m_leftUpgrade != null ? this.m_leftUpgrade.hashCode() : 0); result = prime * result + (this.leftUpgrade != null ? this.leftUpgrade.hashCode() : 0);
result = prime * result + (this.m_rightUpgrade != null ? this.m_rightUpgrade.hashCode() : 0); result = prime * result + (this.rightUpgrade != null ? this.rightUpgrade.hashCode() : 0);
result = prime * result + (this.m_overlay != null ? this.m_overlay.hashCode() : 0); result = prime * result + (this.overlay != null ? this.overlay.hashCode() : 0);
result = prime * result + (this.m_christmas ? 1 : 0); result = prime * result + (this.christmas ? 1 : 0);
result = prime * result + (this.m_flip ? 1 : 0); result = prime * result + (this.flip ? 1 : 0);
return result; return result;
} }
@@ -213,8 +213,8 @@ public class TurtleSmartItemModel implements BakedModel
} }
TurtleModelCombination otherCombo = (TurtleModelCombination) other; TurtleModelCombination otherCombo = (TurtleModelCombination) other;
return otherCombo.m_colour == this.m_colour && otherCombo.m_leftUpgrade == this.m_leftUpgrade && otherCombo.m_rightUpgrade == this.m_rightUpgrade && Objects.equal( return otherCombo.colour == this.colour && otherCombo.leftUpgrade == this.leftUpgrade && otherCombo.rightUpgrade == this.rightUpgrade && Objects.equal(
otherCombo.m_overlay, this.m_overlay ) && otherCombo.m_christmas == this.m_christmas && otherCombo.m_flip == this.m_flip; otherCombo.overlay, this.overlay ) && otherCombo.christmas == this.christmas && otherCombo.flip == this.flip;
} }
} }

View File

@@ -12,21 +12,21 @@ import net.minecraft.nbt.CompoundTag;
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 )
{ {
this.m_colour = colour; this.colour = colour;
this.m_terminal = null; this.terminal = null;
this.m_terminalChanged = false; this.terminalChanged = false;
} }
public boolean pollTerminalChanged() public boolean pollTerminalChanged()
{ {
boolean changed = this.m_terminalChanged; boolean changed = this.terminalChanged;
this.m_terminalChanged = false; this.terminalChanged = false;
return changed; return changed;
} }
@@ -35,22 +35,22 @@ public class ClientTerminal implements ITerminal
@Override @Override
public Terminal getTerminal() public Terminal getTerminal()
{ {
return this.m_terminal; return this.terminal;
} }
@Override @Override
public boolean isColour() public boolean isColour()
{ {
return this.m_colour; return this.colour;
} }
public void read( TerminalState state ) public void read( TerminalState state )
{ {
this.m_colour = state.colour; this.colour = state.colour;
if( state.hasTerminal() ) if( state.hasTerminal() )
{ {
this.resizeTerminal( state.width, state.height ); this.resizeTerminal( state.width, state.height );
state.apply( this.m_terminal ); state.apply( this.terminal );
} }
else else
{ {
@@ -60,34 +60,34 @@ public class ClientTerminal implements ITerminal
private void resizeTerminal( int width, int height ) private void resizeTerminal( int width, int height )
{ {
if( this.m_terminal == null ) if( this.terminal == null )
{ {
this.m_terminal = new Terminal( width, height, () -> this.m_terminalChanged = true ); this.terminal = new Terminal( width, height, () -> this.terminalChanged = true );
this.m_terminalChanged = true; this.terminalChanged = true;
} }
else else
{ {
this.m_terminal.resize( width, height ); this.terminal.resize( width, height );
} }
} }
private void deleteTerminal() private void deleteTerminal()
{ {
if( this.m_terminal != null ) if( this.terminal != null )
{ {
this.m_terminal = null; this.terminal = null;
this.m_terminalChanged = true; this.terminalChanged = true;
} }
} }
public void readDescription( CompoundTag nbt ) public void readDescription( CompoundTag nbt )
{ {
this.m_colour = nbt.getBoolean( "colour" ); this.colour = nbt.getBoolean( "colour" );
if( nbt.contains( "terminal" ) ) if( nbt.contains( "terminal" ) )
{ {
CompoundTag terminal = nbt.getCompound( "terminal" ); CompoundTag terminal = nbt.getCompound( "terminal" );
this.resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) ); this.resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
this.m_terminal.readFromNBT( terminal ); this.terminal.readFromNBT( terminal );
} }
else else
{ {

View File

@@ -14,86 +14,86 @@ 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 final AtomicBoolean m_terminalChanged = new AtomicBoolean( false ); private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
private Terminal m_terminal; private Terminal terminal;
private boolean m_terminalChangedLastFrame = false; private boolean terminalChangedLastFrame = false;
public ServerTerminal( boolean colour ) public ServerTerminal( boolean colour )
{ {
this.m_colour = colour; this.colour = colour;
this.m_terminal = null; this.terminal = null;
} }
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight ) public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
{ {
this.m_colour = colour; this.colour = colour;
this.m_terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged ); this.terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
} }
protected void markTerminalChanged() protected void markTerminalChanged()
{ {
this.m_terminalChanged.set( true ); this.terminalChanged.set( true );
} }
protected void resize( int width, int height ) protected void resize( int width, int height )
{ {
if( this.m_terminal == null ) if( this.terminal == null )
{ {
this.m_terminal = new Terminal( width, height, this::markTerminalChanged ); this.terminal = new Terminal( width, height, this::markTerminalChanged );
this.markTerminalChanged(); this.markTerminalChanged();
} }
else else
{ {
this.m_terminal.resize( width, height ); this.terminal.resize( width, height );
} }
} }
public void delete() public void delete()
{ {
if( this.m_terminal != null ) if( this.terminal != null )
{ {
this.m_terminal = null; this.terminal = null;
this.markTerminalChanged(); this.markTerminalChanged();
} }
} }
public void update() public void update()
{ {
this.m_terminalChangedLastFrame = this.m_terminalChanged.getAndSet( false ); this.terminalChangedLastFrame = this.terminalChanged.getAndSet( false );
} }
public boolean hasTerminalChanged() public boolean hasTerminalChanged()
{ {
return this.m_terminalChangedLastFrame; return this.terminalChangedLastFrame;
} }
@Override @Override
public Terminal getTerminal() public Terminal getTerminal()
{ {
return this.m_terminal; return this.terminal;
} }
@Override @Override
public boolean isColour() public boolean isColour()
{ {
return this.m_colour; return this.colour;
} }
public TerminalState write() public TerminalState write()
{ {
return new TerminalState( this.m_colour, this.m_terminal ); return new TerminalState( this.colour, this.terminal );
} }
public void writeDescription( CompoundTag nbt ) public void writeDescription( CompoundTag nbt )
{ {
nbt.putBoolean( "colour", this.m_colour ); nbt.putBoolean( "colour", this.colour );
if( this.m_terminal != null ) if( this.terminal != null )
{ {
CompoundTag terminal = new CompoundTag(); CompoundTag terminal = new CompoundTag();
terminal.putInt( "term_width", this.m_terminal.getWidth() ); terminal.putInt( "term_width", this.terminal.getWidth() );
terminal.putInt( "term_height", this.m_terminal.getHeight() ); terminal.putInt( "term_height", this.terminal.getHeight() );
this.m_terminal.writeToNBT( terminal ); this.terminal.writeToNBT( terminal );
nbt.put( "terminal", terminal ); nbt.put( "terminal", terminal );
} }
} }

View File

@@ -29,7 +29,7 @@ public 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
{ {
@@ -48,7 +48,7 @@ public 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
{ {
@@ -62,7 +62,7 @@ public 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

@@ -56,11 +56,11 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
private static final String NBT_ON = "On"; private static final String NBT_ON = "On";
private final ComputerFamily family; private final ComputerFamily family;
protected String label = null; protected String label = null;
boolean m_startOn = false; boolean startOn = false;
private int m_instanceID = -1; private int instanceID = -1;
private int m_computerID = -1; private int computerID = -1;
private boolean m_on = false; private boolean on = false;
private boolean m_fresh = false; private boolean fresh = false;
public TileComputerBase( BlockEntityType<? extends TileGeneric> type, ComputerFamily family ) public TileComputerBase( BlockEntityType<? extends TileGeneric> type, ComputerFamily family )
{ {
@@ -86,13 +86,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
protected void unload() protected void unload()
{ {
if( this.m_instanceID >= 0 ) if( this.instanceID >= 0 )
{ {
if( !this.getWorld().isClient ) if( !this.getWorld().isClient )
{ {
ComputerCraft.serverComputerRegistry.remove( this.m_instanceID ); ComputerCraft.serverComputerRegistry.remove( this.instanceID );
} }
this.m_instanceID = -1; this.instanceID = -1;
} }
} }
@@ -139,16 +139,16 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
boolean changed = false; boolean changed = false;
if( this.m_instanceID < 0 ) if( this.instanceID < 0 )
{ {
this.m_instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID(); this.instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID();
changed = true; changed = true;
} }
if( !ComputerCraft.serverComputerRegistry.contains( this.m_instanceID ) ) if( !ComputerCraft.serverComputerRegistry.contains( this.instanceID ) )
{ {
ServerComputer computer = this.createComputer( this.m_instanceID, this.m_computerID ); ServerComputer computer = this.createComputer( this.instanceID, this.computerID );
ComputerCraft.serverComputerRegistry.add( this.m_instanceID, computer ); ComputerCraft.serverComputerRegistry.add( this.instanceID, computer );
this.m_fresh = true; this.fresh = true;
changed = true; changed = true;
} }
if( changed ) if( changed )
@@ -156,12 +156,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
this.updateBlock(); this.updateBlock();
this.updateInput(); this.updateInput();
} }
return ComputerCraft.serverComputerRegistry.get( this.m_instanceID ); return ComputerCraft.serverComputerRegistry.get( this.instanceID );
} }
public ServerComputer getServerComputer() public ServerComputer getServerComputer()
{ {
return this.getWorld().isClient ? null : ComputerCraft.serverComputerRegistry.get( this.m_instanceID ); return this.getWorld().isClient ? null : ComputerCraft.serverComputerRegistry.get( this.instanceID );
} }
protected abstract ServerComputer createComputer( int instanceID, int id ); protected abstract ServerComputer createComputer( int instanceID, int id );
@@ -255,7 +255,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{ {
super.readDescription( nbt ); super.readDescription( nbt );
this.label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; this.label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
this.m_computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; this.computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
} }
@Override @Override
@@ -266,9 +266,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{ {
nbt.putString( NBT_LABEL, this.label ); nbt.putString( NBT_LABEL, this.label );
} }
if( this.m_computerID >= 0 ) if( this.computerID >= 0 )
{ {
nbt.putInt( NBT_ID, this.m_computerID ); nbt.putInt( NBT_ID, this.computerID );
} }
} }
@@ -284,18 +284,18 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
// 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( this.m_startOn || (this.m_fresh && this.m_on) ) if( this.startOn || (this.fresh && this.on) )
{ {
computer.turnOn(); computer.turnOn();
this.m_startOn = false; this.startOn = false;
} }
computer.keepAlive(); computer.keepAlive();
this.m_fresh = false; this.fresh = false;
this.m_computerID = computer.getID(); this.computerID = computer.getID();
this.label = computer.getLabel(); this.label = computer.getLabel();
this.m_on = computer.isOn(); this.on = computer.isOn();
if( computer.hasOutputChanged() ) if( computer.hasOutputChanged() )
{ {
@@ -331,9 +331,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
super.fromTag( state, nbt ); super.fromTag( state, nbt );
// Load ID, label and power state // Load ID, label and power state
this.m_computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; this.computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
this.label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; this.label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
this.m_on = this.m_startOn = nbt.getBoolean( NBT_ON ); this.on = this.startOn = nbt.getBoolean( NBT_ON );
} }
@Nonnull @Nonnull
@@ -341,15 +341,15 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
public CompoundTag toTag( @Nonnull CompoundTag nbt ) public CompoundTag toTag( @Nonnull CompoundTag nbt )
{ {
// Save ID, label and power state // Save ID, label and power state
if( this.m_computerID >= 0 ) if( this.computerID >= 0 )
{ {
nbt.putInt( NBT_ID, this.m_computerID ); nbt.putInt( NBT_ID, this.computerID );
} }
if( this.label != null ) if( this.label != null )
{ {
nbt.putString( NBT_LABEL, this.label ); nbt.putString( NBT_LABEL, this.label );
} }
nbt.putBoolean( NBT_ON, this.m_on ); nbt.putBoolean( NBT_ON, this.on );
return super.toTag( nbt ); return super.toTag( nbt );
} }
@@ -407,22 +407,22 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public final int getComputerID() public final int getComputerID()
{ {
return this.m_computerID; return this.computerID;
} }
@Override @Override
public final void setComputerID( int id ) public final void setComputerID( int id )
{ {
if( this.getWorld().isClient || this.m_computerID == id ) if( this.getWorld().isClient || this.computerID == id )
{ {
return; return;
} }
this.m_computerID = id; this.computerID = id;
ServerComputer computer = this.getServerComputer(); ServerComputer computer = this.getServerComputer();
if( computer != null ) if( computer != null )
{ {
computer.setID( this.m_computerID ); computer.setID( this.computerID );
} }
this.markDirty(); this.markDirty();
} }
@@ -460,17 +460,17 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
protected void transferStateFrom( TileComputerBase copy ) protected void transferStateFrom( TileComputerBase copy )
{ {
if( copy.m_computerID != this.m_computerID || copy.m_instanceID != this.m_instanceID ) if( copy.computerID != this.computerID || copy.instanceID != this.instanceID )
{ {
this.unload(); this.unload();
this.m_instanceID = copy.m_instanceID; this.instanceID = copy.instanceID;
this.m_computerID = copy.m_computerID; this.computerID = copy.computerID;
this.label = copy.label; this.label = copy.label;
this.m_on = copy.m_on; this.on = copy.on;
this.m_startOn = copy.m_startOn; this.startOn = copy.startOn;
this.updateBlock(); this.updateBlock();
} }
copy.m_instanceID = -1; copy.instanceID = -1;
} }
@Nonnull @Nonnull

View File

@@ -13,22 +13,22 @@ import net.minecraft.nbt.CompoundTag;
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 on = false;
private boolean m_blinking = false; private boolean blinking = false;
private CompoundTag m_userData = null; private CompoundTag userData = null;
public ClientComputer( int instanceID ) public ClientComputer( int instanceID )
{ {
super( false ); super( false );
this.m_instanceID = instanceID; this.instanceID = instanceID;
} }
public CompoundTag getUserData() public CompoundTag getUserData()
{ {
return this.m_userData; return this.userData;
} }
public void requestState() public void requestState()
@@ -42,53 +42,53 @@ public class ClientComputer extends ClientTerminal implements IComputer
@Override @Override
public int getInstanceID() public int getInstanceID()
{ {
return this.m_instanceID; return this.instanceID;
} }
@Override @Override
public void turnOn() public void turnOn()
{ {
// Send turnOn to server // Send turnOn to server
NetworkHandler.sendToServer( new ComputerActionServerMessage( this.m_instanceID, ComputerActionServerMessage.Action.TURN_ON ) ); NetworkHandler.sendToServer( new ComputerActionServerMessage( this.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( this.m_instanceID, ComputerActionServerMessage.Action.SHUTDOWN ) ); NetworkHandler.sendToServer( new ComputerActionServerMessage( this.instanceID, ComputerActionServerMessage.Action.SHUTDOWN ) );
} }
@Override @Override
public void reboot() public void reboot()
{ {
// Send reboot to server // Send reboot to server
NetworkHandler.sendToServer( new ComputerActionServerMessage( this.m_instanceID, ComputerActionServerMessage.Action.REBOOT ) ); NetworkHandler.sendToServer( new ComputerActionServerMessage( this.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( this.m_instanceID, event, arguments ) ); NetworkHandler.sendToServer( new QueueEventServerMessage( this.instanceID, event, arguments ) );
} }
@Override @Override
public boolean isOn() public boolean isOn()
{ {
return this.m_on; return this.on;
} }
@Override @Override
public boolean isCursorDisplayed() public boolean isCursorDisplayed()
{ {
return this.m_on && this.m_blinking; return this.on && this.blinking;
} }
@Override @Override
public void keyDown( int key, boolean repeat ) public void keyDown( int key, boolean repeat )
{ {
NetworkHandler.sendToServer( new KeyEventServerMessage( this.m_instanceID, NetworkHandler.sendToServer( new KeyEventServerMessage( this.instanceID,
repeat ? KeyEventServerMessage.TYPE_REPEAT : KeyEventServerMessage.TYPE_DOWN, repeat ? KeyEventServerMessage.TYPE_REPEAT : KeyEventServerMessage.TYPE_DOWN,
key ) ); key ) );
} }
@@ -96,37 +96,37 @@ public class ClientComputer extends ClientTerminal implements IComputer
@Override @Override
public void keyUp( int key ) public void keyUp( int key )
{ {
NetworkHandler.sendToServer( new KeyEventServerMessage( this.m_instanceID, KeyEventServerMessage.TYPE_UP, key ) ); NetworkHandler.sendToServer( new KeyEventServerMessage( this.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( this.m_instanceID, MouseEventServerMessage.TYPE_CLICK, button, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( this.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( this.m_instanceID, MouseEventServerMessage.TYPE_UP, button, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( this.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( this.m_instanceID, MouseEventServerMessage.TYPE_DRAG, button, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( this.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( this.m_instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( this.instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) );
} }
public void setState( ComputerState state, CompoundTag userData ) public void setState( ComputerState state, CompoundTag userData )
{ {
this.m_on = state != ComputerState.OFF; this.on = state != ComputerState.OFF;
this.m_blinking = state == ComputerState.BLINKING; this.blinking = state == ComputerState.BLINKING;
this.m_userData = userData; this.userData = userData;
} }
} }

View File

@@ -13,45 +13,45 @@ 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;
private int m_nextUnusedInstanceID; private int nextUnusedInstanceID;
private int m_sessionID; private int sessionID;
protected ComputerRegistry() protected ComputerRegistry()
{ {
this.m_computers = new HashMap<>(); this.computers = new HashMap<>();
this.reset(); this.reset();
} }
public void reset() public void reset()
{ {
this.m_computers.clear(); this.computers.clear();
this.m_nextUnusedInstanceID = 0; this.nextUnusedInstanceID = 0;
this.m_sessionID = new Random().nextInt(); this.sessionID = new Random().nextInt();
} }
public int getSessionID() public int getSessionID()
{ {
return this.m_sessionID; return this.sessionID;
} }
public int getUnusedInstanceID() public int getUnusedInstanceID()
{ {
return this.m_nextUnusedInstanceID++; return this.nextUnusedInstanceID++;
} }
public Collection<T> getComputers() public Collection<T> getComputers()
{ {
return this.m_computers.values(); return this.computers.values();
} }
public T get( int instanceID ) public T get( int instanceID )
{ {
if( instanceID >= 0 ) if( instanceID >= 0 )
{ {
if( this.m_computers.containsKey( instanceID ) ) if( this.computers.containsKey( instanceID ) )
{ {
return this.m_computers.get( instanceID ); return this.computers.get( instanceID );
} }
} }
return null; return null;
@@ -59,21 +59,21 @@ public class ComputerRegistry<T extends IComputer>
public boolean contains( int instanceID ) public boolean contains( int instanceID )
{ {
return this.m_computers.containsKey( instanceID ); return this.computers.containsKey( instanceID );
} }
public void add( int instanceID, T computer ) public void add( int instanceID, T computer )
{ {
if( this.m_computers.containsKey( instanceID ) ) if( this.computers.containsKey( instanceID ) )
{ {
this.remove( instanceID ); this.remove( instanceID );
} }
this.m_computers.put( instanceID, computer ); this.computers.put( instanceID, computer );
this.m_nextUnusedInstanceID = Math.max( this.m_nextUnusedInstanceID, instanceID + 1 ); this.nextUnusedInstanceID = Math.max( this.nextUnusedInstanceID, instanceID + 1 );
} }
public void remove( int instanceID ) public void remove( int instanceID )
{ {
this.m_computers.remove( instanceID ); this.computers.remove( instanceID );
} }
} }

View File

@@ -37,109 +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 final ComputerFamily m_family; private final ComputerFamily family;
private final Computer m_computer; private final Computer computer;
private World m_world; private World world;
private BlockPos m_position; private BlockPos position;
private CompoundTag m_userData; private CompoundTag 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 );
this.m_instanceID = instanceID; this.instanceID = instanceID;
this.m_world = world; this.world = world;
this.m_position = null; this.position = null;
this.m_family = family; this.family = family;
this.m_computer = new Computer( this, this.getTerminal(), computerID ); this.computer = new Computer( this, this.getTerminal(), computerID );
this.m_computer.setLabel( label ); this.computer.setLabel( label );
this.m_userData = null; this.userData = null;
this.m_changed = false; this.changed = false;
this.m_changedLastFrame = false; this.changedLastFrame = false;
this.m_ticksSincePing = 0; this.ticksSincePing = 0;
} }
public ComputerFamily getFamily() public ComputerFamily getFamily()
{ {
return this.m_family; return this.family;
} }
public World getWorld() public World getWorld()
{ {
return this.m_world; return this.world;
} }
public void setWorld( World world ) public void setWorld( World world )
{ {
this.m_world = world; this.world = world;
} }
public BlockPos getPosition() public BlockPos getPosition()
{ {
return this.m_position; return this.position;
} }
public void setPosition( BlockPos pos ) public void setPosition( BlockPos pos )
{ {
this.m_position = new BlockPos( pos ); this.position = new BlockPos( pos );
} }
public IAPIEnvironment getAPIEnvironment() public IAPIEnvironment getAPIEnvironment()
{ {
return this.m_computer.getAPIEnvironment(); return this.computer.getAPIEnvironment();
} }
public Computer getComputer() public Computer getComputer()
{ {
return this.m_computer; return this.computer;
} }
@Override @Override
public void update() public void update()
{ {
super.update(); super.update();
this.m_computer.tick(); this.computer.tick();
this.m_changedLastFrame = this.m_computer.pollAndResetChanged() || this.m_changed; this.changedLastFrame = this.computer.pollAndResetChanged() || this.changed;
this.m_changed = false; this.changed = false;
this.m_ticksSincePing++; this.ticksSincePing++;
} }
public void keepAlive() public void keepAlive()
{ {
this.m_ticksSincePing = 0; this.ticksSincePing = 0;
} }
public boolean hasTimedOut() public boolean hasTimedOut()
{ {
return this.m_ticksSincePing > 100; return this.ticksSincePing > 100;
} }
public void unload() public void unload()
{ {
this.m_computer.unload(); this.computer.unload();
} }
public CompoundTag getUserData() public CompoundTag getUserData()
{ {
if( this.m_userData == null ) if( this.userData == null )
{ {
this.m_userData = new CompoundTag(); this.userData = new CompoundTag();
} }
return this.m_userData; return this.userData;
} }
public void updateUserData() public void updateUserData()
{ {
this.m_changed = true; this.changed = true;
} }
public void broadcastState( boolean force ) public void broadcastState( boolean force )
@@ -180,7 +180,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public boolean hasOutputChanged() public boolean hasOutputChanged()
{ {
return this.m_changedLastFrame; return this.changedLastFrame;
} }
private NetworkMessage createComputerPacket() private NetworkMessage createComputerPacket()
@@ -219,14 +219,14 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
@Override @Override
public int getInstanceID() public int getInstanceID()
{ {
return this.m_instanceID; return this.instanceID;
} }
@Override @Override
public void turnOn() public void turnOn()
{ {
// Turn on // Turn on
this.m_computer.turnOn(); this.computer.turnOn();
} }
// IComputer // IComputer
@@ -235,33 +235,33 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public void shutdown() public void shutdown()
{ {
// Shutdown // Shutdown
this.m_computer.shutdown(); this.computer.shutdown();
} }
@Override @Override
public void reboot() public void reboot()
{ {
// Reboot // Reboot
this.m_computer.reboot(); this.computer.reboot();
} }
@Override @Override
public void queueEvent( String event, Object[] arguments ) public void queueEvent( String event, Object[] arguments )
{ {
// Queue event // Queue event
this.m_computer.queueEvent( event, arguments ); this.computer.queueEvent( event, arguments );
} }
@Override @Override
public boolean isOn() public boolean isOn()
{ {
return this.m_computer.isOn(); return this.computer.isOn();
} }
@Override @Override
public boolean isCursorDisplayed() public boolean isCursorDisplayed()
{ {
return this.m_computer.isOn() && this.m_computer.isBlinking(); return this.computer.isOn() && this.computer.isBlinking();
} }
public void sendComputerState( PlayerEntity player ) public void sendComputerState( PlayerEntity player )
@@ -288,77 +288,77 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
public int getID() public int getID()
{ {
return this.m_computer.getID(); return this.computer.getID();
} }
public void setID( int id ) public void setID( int id )
{ {
this.m_computer.setID( id ); this.computer.setID( id );
} }
public String getLabel() public String getLabel()
{ {
return this.m_computer.getLabel(); return this.computer.getLabel();
} }
public void setLabel( String label ) public void setLabel( String label )
{ {
this.m_computer.setLabel( label ); this.computer.setLabel( label );
} }
public int getRedstoneOutput( ComputerSide side ) public int getRedstoneOutput( ComputerSide side )
{ {
return this.m_computer.getEnvironment() return this.computer.getEnvironment()
.getExternalRedstoneOutput( side ); .getExternalRedstoneOutput( side );
} }
public void setRedstoneInput( ComputerSide side, int level ) public void setRedstoneInput( ComputerSide side, int level )
{ {
this.m_computer.getEnvironment() this.computer.getEnvironment()
.setRedstoneInput( side, level ); .setRedstoneInput( side, level );
} }
public int getBundledRedstoneOutput( ComputerSide side ) public int getBundledRedstoneOutput( ComputerSide side )
{ {
return this.m_computer.getEnvironment() return this.computer.getEnvironment()
.getExternalBundledRedstoneOutput( side ); .getExternalBundledRedstoneOutput( side );
} }
public void setBundledRedstoneInput( ComputerSide side, int combination ) public void setBundledRedstoneInput( ComputerSide side, int combination )
{ {
this.m_computer.getEnvironment() this.computer.getEnvironment()
.setBundledRedstoneInput( side, combination ); .setBundledRedstoneInput( side, combination );
} }
public void addAPI( ILuaAPI api ) public void addAPI( ILuaAPI api )
{ {
this.m_computer.addApi( api ); this.computer.addApi( api );
} }
// IComputerEnvironment implementation // IComputerEnvironment implementation
public void setPeripheral( ComputerSide side, IPeripheral peripheral ) public void setPeripheral( ComputerSide side, IPeripheral peripheral )
{ {
this.m_computer.getEnvironment() this.computer.getEnvironment()
.setPeripheral( side, peripheral ); .setPeripheral( side, peripheral );
} }
public IPeripheral getPeripheral( ComputerSide side ) public IPeripheral getPeripheral( ComputerSide side )
{ {
return this.m_computer.getEnvironment() return this.computer.getEnvironment()
.getPeripheral( side ); .getPeripheral( side );
} }
@Override @Override
public int getDay() public int getDay()
{ {
return (int) ((this.m_world.getTimeOfDay() + 6000) / 24000) + 1; return (int) ((this.world.getTimeOfDay() + 6000) / 24000) + 1;
} }
@Override @Override
public double getTimeOfDay() public double getTimeOfDay()
{ {
return (this.m_world.getTimeOfDay() + 6000) % 24000 / 1000.0; return (this.world.getTimeOfDay() + 6000) % 24000 / 1000.0;
} }
@Override @Override
@@ -384,13 +384,13 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
@Override @Override
public int assignNewID() public int assignNewID()
{ {
return ComputerCraftAPI.createUniqueNumberedSaveDir( this.m_world, "computer" ); return ComputerCraftAPI.createUniqueNumberedSaveDir( this.world, "computer" );
} }
@Override @Override
public IWritableMount createSaveDirMount( String subPath, long capacity ) public IWritableMount createSaveDirMount( String subPath, long capacity )
{ {
return ComputerCraftAPI.createSaveDirMount( this.m_world, subPath, capacity ); return ComputerCraftAPI.createSaveDirMount( this.world, subPath, capacity );
} }
@Override @Override

View File

@@ -47,15 +47,15 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
private static final String NBT_NAME = "CustomName"; private static final String NBT_NAME = "CustomName";
private static final String NBT_ITEM = "Item"; private static final String NBT_ITEM = "Item";
private final Map<IComputerAccess, MountInfo> m_computers = new HashMap<>(); private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
Text customName; Text customName;
@Nonnull @Nonnull
private ItemStack m_diskStack = ItemStack.EMPTY; private ItemStack diskStack = ItemStack.EMPTY;
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( BlockEntityType<TileDiskDrive> type ) public TileDiskDrive( BlockEntityType<TileDiskDrive> type )
{ {
@@ -66,7 +66,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
public void destroy() public void destroy()
{ {
this.ejectContents( true ); this.ejectContents( true );
if( this.m_recordPlaying ) if( this.recordPlaying )
{ {
this.stopRecord(); this.stopRecord();
} }
@@ -115,8 +115,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
if( nbt.contains( NBT_ITEM ) ) if( nbt.contains( NBT_ITEM ) )
{ {
CompoundTag item = nbt.getCompound( NBT_ITEM ); CompoundTag item = nbt.getCompound( NBT_ITEM );
this.m_diskStack = ItemStack.fromTag( item ); this.diskStack = ItemStack.fromTag( item );
this.m_diskMount = null; this.diskMount = null;
} }
} }
@@ -129,10 +129,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
nbt.putString( NBT_NAME, Text.Serializer.toJson( this.customName ) ); nbt.putString( NBT_NAME, Text.Serializer.toJson( this.customName ) );
} }
if( !this.m_diskStack.isEmpty() ) if( !this.diskStack.isEmpty() )
{ {
CompoundTag item = new CompoundTag(); CompoundTag item = new CompoundTag();
this.m_diskStack.toTag( item ); this.diskStack.toTag( item );
nbt.put( NBT_ITEM, item ); nbt.put( NBT_ITEM, item );
} }
return super.toTag( nbt ); return super.toTag( nbt );
@@ -152,36 +152,36 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
public void tick() public void tick()
{ {
// Ejection // Ejection
if( this.m_ejectQueued ) if( this.ejectQueued )
{ {
this.ejectContents( false ); this.ejectContents( false );
this.m_ejectQueued = false; this.ejectQueued = false;
} }
// Music // Music
synchronized( this ) synchronized( this )
{ {
if( !this.world.isClient && this.m_recordPlaying != this.m_recordQueued || this.m_restartRecord ) if( !this.world.isClient && this.recordPlaying != this.recordQueued || this.restartRecord )
{ {
this.m_restartRecord = false; this.restartRecord = false;
if( this.m_recordQueued ) if( this.recordQueued )
{ {
IMedia contents = this.getDiskMedia(); IMedia contents = this.getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( this.m_diskStack ) : null; SoundEvent record = contents != null ? contents.getAudio( this.diskStack ) : null;
if( record != null ) if( record != null )
{ {
this.m_recordPlaying = true; this.recordPlaying = true;
this.playRecord(); this.playRecord();
} }
else else
{ {
this.m_recordQueued = false; this.recordQueued = false;
} }
} }
else else
{ {
this.stopRecord(); this.stopRecord();
this.m_recordPlaying = false; this.recordPlaying = false;
} }
} }
} }
@@ -198,34 +198,34 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
return this.m_diskStack.isEmpty(); return this.diskStack.isEmpty();
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack getStack( int slot ) public ItemStack getStack( int slot )
{ {
return this.m_diskStack; return this.diskStack;
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack removeStack( int slot, int count ) public ItemStack removeStack( int slot, int count )
{ {
if( this.m_diskStack.isEmpty() ) if( this.diskStack.isEmpty() )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if( this.m_diskStack.getCount() <= count ) if( this.diskStack.getCount() <= count )
{ {
ItemStack disk = this.m_diskStack; ItemStack disk = this.diskStack;
this.setStack( slot, ItemStack.EMPTY ); this.setStack( slot, ItemStack.EMPTY );
return disk; return disk;
} }
ItemStack part = this.m_diskStack.split( count ); ItemStack part = this.diskStack.split( count );
this.setStack( slot, this.m_diskStack.isEmpty() ? ItemStack.EMPTY : this.m_diskStack ); this.setStack( slot, this.diskStack.isEmpty() ? ItemStack.EMPTY : this.diskStack );
return part; return part;
} }
@@ -233,9 +233,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
@Override @Override
public ItemStack removeStack( int slot ) public ItemStack removeStack( int slot )
{ {
ItemStack result = this.m_diskStack; ItemStack result = this.diskStack;
this.m_diskStack = ItemStack.EMPTY; this.diskStack = ItemStack.EMPTY;
this.m_diskMount = null; this.diskMount = null;
return result; return result;
} }
@@ -245,25 +245,25 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
if( this.getWorld().isClient ) if( this.getWorld().isClient )
{ {
this.m_diskStack = stack; this.diskStack = stack;
this.m_diskMount = null; this.diskMount = null;
this.markDirty(); this.markDirty();
return; return;
} }
synchronized( this ) synchronized( this )
{ {
if( InventoryUtil.areItemsStackable( stack, this.m_diskStack ) ) if( InventoryUtil.areItemsStackable( stack, this.diskStack ) )
{ {
this.m_diskStack = stack; this.diskStack = stack;
return; return;
} }
// Unmount old disk // Unmount old disk
if( !this.m_diskStack.isEmpty() ) if( !this.diskStack.isEmpty() )
{ {
// TODO: Is this iteration thread safe? // TODO: Is this iteration thread safe?
Set<IComputerAccess> computers = this.m_computers.keySet(); Set<IComputerAccess> computers = this.computers.keySet();
for( IComputerAccess computer : computers ) for( IComputerAccess computer : computers )
{ {
this.unmountDisk( computer ); this.unmountDisk( computer );
@@ -271,22 +271,22 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
} }
// Stop music // Stop music
if( this.m_recordPlaying ) if( this.recordPlaying )
{ {
this.stopRecord(); this.stopRecord();
this.m_recordPlaying = false; this.recordPlaying = false;
this.m_recordQueued = false; this.recordQueued = false;
} }
// Swap disk over // Swap disk over
this.m_diskStack = stack; this.diskStack = stack;
this.m_diskMount = null; this.diskMount = null;
this.markDirty(); this.markDirty();
// Mount new disk // Mount new disk
if( !this.m_diskStack.isEmpty() ) if( !this.diskStack.isEmpty() )
{ {
Set<IComputerAccess> computers = this.m_computers.keySet(); Set<IComputerAccess> computers = this.computers.keySet();
for( IComputerAccess computer : computers ) for( IComputerAccess computer : computers )
{ {
this.mountDisk( computer ); this.mountDisk( computer );
@@ -318,7 +318,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
MountInfo info = this.m_computers.get( computer ); MountInfo info = this.computers.get( computer );
return info != null ? info.mountPath : null; return info != null ? info.mountPath : null;
} }
} }
@@ -327,32 +327,32 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
this.m_computers.put( computer, new MountInfo() ); this.computers.put( computer, new MountInfo() );
this.mountDisk( computer ); this.mountDisk( computer );
} }
} }
private synchronized void mountDisk( IComputerAccess computer ) private synchronized void mountDisk( IComputerAccess computer )
{ {
if( !this.m_diskStack.isEmpty() ) if( !this.diskStack.isEmpty() )
{ {
MountInfo info = this.m_computers.get( computer ); MountInfo info = this.computers.get( computer );
IMedia contents = this.getDiskMedia(); IMedia contents = this.getDiskMedia();
if( contents != null ) if( contents != null )
{ {
if( this.m_diskMount == null ) if( this.diskMount == null )
{ {
this.m_diskMount = contents.createDataMount( this.m_diskStack, this.getWorld() ); this.diskMount = contents.createDataMount( this.diskStack, this.getWorld() );
} }
if( this.m_diskMount != null ) if( this.diskMount != null )
{ {
if( this.m_diskMount instanceof IWritableMount ) if( this.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) this.m_diskMount ); info.mountPath = computer.mountWritable( n == 1 ? "disk" : "disk" + n, (IWritableMount) this.diskMount );
n++; n++;
} }
} }
@@ -362,7 +362,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, this.m_diskMount ); info.mountPath = computer.mount( n == 1 ? "disk" : "disk" + n, this.diskMount );
n++; n++;
} }
} }
@@ -397,15 +397,15 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
synchronized( this ) synchronized( this )
{ {
this.unmountDisk( computer ); this.unmountDisk( computer );
this.m_computers.remove( computer ); this.computers.remove( computer );
} }
} }
private synchronized void unmountDisk( IComputerAccess computer ) private synchronized void unmountDisk( IComputerAccess computer )
{ {
if( !this.m_diskStack.isEmpty() ) if( !this.diskStack.isEmpty() )
{ {
MountInfo info = this.m_computers.get( computer ); MountInfo info = this.computers.get( computer );
assert info != null; assert info != null;
if( info.mountPath != null ) if( info.mountPath != null )
{ {
@@ -421,10 +421,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
synchronized( this ) synchronized( this )
{ {
IMedia media = this.getDiskMedia(); IMedia media = this.getDiskMedia();
if( media != null && media.getAudioTitle( this.m_diskStack ) != null ) if( media != null && media.getAudioTitle( this.diskStack ) != null )
{ {
this.m_recordQueued = true; this.recordQueued = true;
this.m_restartRecord = this.m_recordPlaying; this.restartRecord = this.recordPlaying;
} }
} }
} }
@@ -433,8 +433,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
this.m_recordQueued = false; this.recordQueued = false;
this.m_restartRecord = false; this.restartRecord = false;
} }
} }
@@ -444,7 +444,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
{ {
synchronized( this ) synchronized( this )
{ {
this.m_ejectQueued = true; this.ejectQueued = true;
} }
} }
@@ -455,7 +455,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
return; return;
} }
if( !this.m_diskStack.isEmpty() ) if( !this.diskStack.isEmpty() )
{ {
IMedia contents = this.getDiskMedia(); IMedia contents = this.getDiskMedia();
this.updateBlockState( contents != null ? DiskDriveState.FULL : DiskDriveState.INVALID ); this.updateBlockState( contents != null ? DiskDriveState.FULL : DiskDriveState.INVALID );
@@ -479,13 +479,13 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private synchronized void ejectContents( boolean destroyed ) private synchronized void ejectContents( boolean destroyed )
{ {
if( this.getWorld().isClient || this.m_diskStack.isEmpty() ) if( this.getWorld().isClient || this.diskStack.isEmpty() )
{ {
return; return;
} }
// Remove the disks from the inventory // Remove the disks from the inventory
ItemStack disks = this.m_diskStack; ItemStack disks = this.diskStack;
this.setDiskStack( ItemStack.EMPTY ); this.setDiskStack( ItemStack.EMPTY );
// Spawn the item in the world // Spawn the item in the world
@@ -515,10 +515,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private void playRecord() private void playRecord()
{ {
IMedia contents = this.getDiskMedia(); IMedia contents = this.getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( this.m_diskStack ) : null; SoundEvent record = contents != null ? contents.getAudio( this.diskStack ) : null;
if( record != null ) if( record != null )
{ {
RecordUtil.playRecord( record, contents.getAudioTitle( this.m_diskStack ), this.getWorld(), this.getPos() ); RecordUtil.playRecord( record, contents.getAudioTitle( this.diskStack ), this.getWorld(), this.getPos() );
} }
else else
{ {

View File

@@ -28,18 +28,18 @@ import java.util.Set;
*/ */
public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver
{ {
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;
private IPacketNetwork m_network; private IPacketNetwork network;
protected ModemPeripheral( ModemState state ) protected ModemPeripheral( ModemState state )
{ {
this.m_state = state; this.state = state;
} }
public ModemState getModemState() public ModemState getModemState()
{ {
return this.m_state; return this.state;
} }
public void destroy() public void destroy()
@@ -50,14 +50,14 @@ 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 || !this.m_state.isOpen( packet.getChannel() ) ) if( packet.getSender() == this || !this.state.isOpen( packet.getChannel() ) )
{ {
return; return;
} }
synchronized( this.m_computers ) synchronized( this.computers )
{ {
for( IComputerAccess computer : this.m_computers ) for( IComputerAccess computer : this.computers )
{ {
computer.queueEvent( "modem_message", computer.queueEvent( "modem_message",
computer.getAttachmentName(), computer.getAttachmentName(),
@@ -72,14 +72,14 @@ 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 || !this.m_state.isOpen( packet.getChannel() ) ) if( packet.getSender() == this || !this.state.isOpen( packet.getChannel() ) )
{ {
return; return;
} }
synchronized( this.m_computers ) synchronized( this.computers )
{ {
for( IComputerAccess computer : this.m_computers ) for( IComputerAccess computer : this.computers )
{ {
computer.queueEvent( "modem_message", computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload() ); computer.queueEvent( "modem_message", computer.getAttachmentName(), packet.getChannel(), packet.getReplyChannel(), packet.getPayload() );
} }
@@ -96,9 +96,9 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@Override @Override
public synchronized void attach( @Nonnull IComputerAccess computer ) public synchronized void attach( @Nonnull IComputerAccess computer )
{ {
synchronized( this.m_computers ) synchronized( this.computers )
{ {
this.m_computers.add( computer ); this.computers.add( computer );
} }
this.setNetwork( this.getNetwork() ); this.setNetwork( this.getNetwork() );
@@ -108,24 +108,24 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
private synchronized void setNetwork( IPacketNetwork network ) private synchronized void setNetwork( IPacketNetwork network )
{ {
if( this.m_network == network ) if( this.network == network )
{ {
return; return;
} }
// Leave old network // Leave old network
if( this.m_network != null ) if( this.network != null )
{ {
this.m_network.removeReceiver( this ); this.network.removeReceiver( this );
} }
// Set new network // Set new network
this.m_network = network; this.network = network;
// Join new network // Join new network
if( this.m_network != null ) if( this.network != null )
{ {
this.m_network.addReceiver( this ); this.network.addReceiver( this );
} }
} }
@@ -133,10 +133,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( this.m_computers ) synchronized( this.computers )
{ {
this.m_computers.remove( computer ); this.computers.remove( computer );
empty = this.m_computers.isEmpty(); empty = this.computers.isEmpty();
} }
if( empty ) if( empty )
@@ -155,7 +155,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
{ {
this.m_state.open( parseChannel( channel ) ); this.state.open( parseChannel( channel ) );
} }
private static int parseChannel( int channel ) throws LuaException private static int parseChannel( int channel ) throws LuaException
@@ -177,7 +177,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 this.m_state.isOpen( parseChannel( channel ) ); return this.state.isOpen( parseChannel( channel ) );
} }
/** /**
@@ -189,7 +189,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
{ {
this.m_state.close( parseChannel( channel ) ); this.state.close( parseChannel( channel ) );
} }
/** /**
@@ -198,7 +198,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final void closeAll() public final void closeAll()
{ {
this.m_state.closeAll(); this.state.closeAll();
} }
/** /**
@@ -219,7 +219,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
World world = this.getWorld(); World world = this.getWorld();
Vec3d position = this.getPosition(); Vec3d position = this.getPosition();
IPacketNetwork network = this.m_network; IPacketNetwork network = this.network;
if( world == null || position == null || network == null ) if( world == null || position == null || network == null )
{ {
@@ -247,7 +247,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@LuaFunction @LuaFunction
public final boolean isWireless() public final boolean isWireless()
{ {
IPacketNetwork network = this.m_network; IPacketNetwork network = this.network;
return network != null && network.isWireless(); return network != null && network.isWireless();
} }
@@ -255,15 +255,15 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
@Override @Override
public String getSenderID() public String getSenderID()
{ {
synchronized( this.m_computers ) synchronized( this.computers )
{ {
if( this.m_computers.size() != 1 ) if( this.computers.size() != 1 )
{ {
return "unknown"; return "unknown";
} }
else else
{ {
IComputerAccess computer = this.m_computers.iterator() IComputerAccess computer = this.computers.iterator()
.next(); .next();
return computer.getID() + "_" + computer.getAttachmentName(); return computer.getID() + "_" + computer.getAttachmentName();
} }

View File

@@ -41,19 +41,19 @@ import java.util.Map;
public class TileCable extends TileGeneric implements IPeripheralTile public class TileCable extends TileGeneric implements IPeripheralTile
{ {
private static final String NBT_PERIPHERAL_ENABLED = "PeirpheralAccess"; private static final String NBT_PERIPHERAL_ENABLED = "PeirpheralAccess";
private final WiredModemLocalPeripheral m_peripheral = new WiredModemLocalPeripheral(); private final WiredModemLocalPeripheral peripheral = new WiredModemLocalPeripheral();
private final WiredModemElement m_cable = new CableElement(); private final WiredModemElement cable = new CableElement();
private final IWiredNode m_node = this.m_cable.getNode(); private final IWiredNode node = this.cable.getNode();
private boolean m_peripheralAccessAllowed; private boolean peripheralAccessAllowed;
private boolean m_destroyed = false; private boolean destroyed = false;
private Direction modemDirection = Direction.NORTH; private Direction modemDirection = Direction.NORTH;
private final WiredModemPeripheral m_modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), this.m_cable ) private final WiredModemPeripheral modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), this.cable )
{ {
@Nonnull @Nonnull
@Override @Override
protected WiredModemLocalPeripheral getLocalPeripheral() protected WiredModemLocalPeripheral getLocalPeripheral()
{ {
return TileCable.this.m_peripheral; return TileCable.this.peripheral;
} }
@Nonnull @Nonnull
@@ -72,7 +72,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
} }
}; };
private boolean hasModemDirection = false; private boolean hasModemDirection = false;
private boolean m_connectionsFormed = false; private boolean connectionsFormed = false;
public TileCable( BlockEntityType<? extends TileCable> type ) public TileCable( BlockEntityType<? extends TileCable> type )
{ {
@@ -82,10 +82,10 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override @Override
public void destroy() public void destroy()
{ {
if( !this.m_destroyed ) if( !this.destroyed )
{ {
this.m_destroyed = true; this.destroyed = true;
this.m_modem.destroy(); this.modem.destroy();
this.onRemove(); this.onRemove();
} }
} }
@@ -101,8 +101,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile
{ {
if( this.world == null || !this.world.isClient ) if( this.world == null || !this.world.isClient )
{ {
this.m_node.remove(); this.node.remove();
this.m_connectionsFormed = false; this.connectionsFormed = false;
} }
} }
@@ -124,9 +124,9 @@ public class TileCable extends TileGeneric implements IPeripheralTile
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
String oldName = this.m_peripheral.getConnectedName(); String oldName = this.peripheral.getConnectedName();
this.togglePeripheralAccess(); this.togglePeripheralAccess();
String newName = this.m_peripheral.getConnectedName(); String newName = this.peripheral.getConnectedName();
if( !Objects.equal( newName, oldName ) ) if( !Objects.equal( newName, oldName ) )
{ {
if( oldName != null ) if( oldName != null )
@@ -200,11 +200,11 @@ public class TileCable extends TileGeneric implements IPeripheralTile
// 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( !this.canAttachPeripheral() && this.m_peripheralAccessAllowed ) if( !this.canAttachPeripheral() && this.peripheralAccessAllowed )
{ {
this.m_peripheralAccessAllowed = false; this.peripheralAccessAllowed = false;
this.m_peripheral.detach(); this.peripheral.detach();
this.m_node.updatePeripherals( Collections.emptyMap() ); this.node.updatePeripherals( Collections.emptyMap() );
this.markDirty(); this.markDirty();
this.updateBlockState(); this.updateBlockState();
} }
@@ -233,17 +233,17 @@ public class TileCable extends TileGeneric implements IPeripheralTile
{ {
// TODO Figure out why this crashes. // TODO Figure out why this crashes.
IWiredNode node = element.getNode(); IWiredNode node = element.getNode();
if( node != null && this.m_node != null ) if( node != null && this.node != null )
{ {
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
this.m_node.connectTo( node ); this.node.connectTo( node );
} }
else if( this.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.
this.m_node.disconnectFrom( node ); this.node.disconnectFrom( node );
} }
} }
} }
@@ -259,8 +259,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile
{ {
BlockState state = this.getCachedState(); BlockState state = this.getCachedState();
CableModemVariant oldVariant = state.get( BlockCable.MODEM ); CableModemVariant oldVariant = state.get( BlockCable.MODEM );
CableModemVariant newVariant = CableModemVariant.from( oldVariant.getFacing(), this.m_modem.getModemState() CableModemVariant newVariant = CableModemVariant.from( oldVariant.getFacing(), this.modem.getModemState()
.isOpen(), this.m_peripheralAccessAllowed ); .isOpen(), this.peripheralAccessAllowed );
if( oldVariant != newVariant ) if( oldVariant != newVariant )
{ {
@@ -270,7 +270,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
private void refreshPeripheral() private void refreshPeripheral()
{ {
if( this.world != null && !this.isRemoved() && this.m_peripheral.attach( this.world, this.getPos(), this.getDirection() ) ) if( this.world != null && !this.isRemoved() && this.peripheral.attach( this.world, this.getPos(), this.getDirection() ) )
{ {
this.updateConnectedPeripherals(); this.updateConnectedPeripherals();
} }
@@ -278,22 +278,22 @@ public class TileCable extends TileGeneric implements IPeripheralTile
private void updateConnectedPeripherals() private void updateConnectedPeripherals()
{ {
Map<String, IPeripheral> peripherals = this.m_peripheral.toMap(); Map<String, IPeripheral> peripherals = this.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.
this.m_peripheralAccessAllowed = false; this.peripheralAccessAllowed = false;
this.updateBlockState(); this.updateBlockState();
} }
this.m_node.updatePeripherals( peripherals ); this.node.updatePeripherals( peripherals );
} }
@Override @Override
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{ {
super.onNeighbourTileEntityChange( neighbour ); super.onNeighbourTileEntityChange( neighbour );
if( !this.world.isClient && this.m_peripheralAccessAllowed ) if( !this.world.isClient && this.peripheralAccessAllowed )
{ {
Direction facing = this.getDirection(); Direction facing = this.getDirection();
if( this.getPos().offset( facing ) if( this.getPos().offset( facing )
@@ -314,20 +314,20 @@ public class TileCable extends TileGeneric implements IPeripheralTile
this.refreshDirection(); this.refreshDirection();
if( this.m_modem.getModemState() if( this.modem.getModemState()
.pollChanged() ) .pollChanged() )
{ {
this.updateBlockState(); this.updateBlockState();
} }
if( !this.m_connectionsFormed ) if( !this.connectionsFormed )
{ {
this.m_connectionsFormed = true; this.connectionsFormed = true;
this.connectionsChanged(); this.connectionsChanged();
if( this.m_peripheralAccessAllowed ) if( this.peripheralAccessAllowed )
{ {
this.m_peripheral.attach( this.world, this.pos, this.modemDirection ); this.peripheral.attach( this.world, this.pos, this.modemDirection );
this.updateConnectedPeripherals(); this.updateConnectedPeripherals();
} }
} }
@@ -335,23 +335,23 @@ public class TileCable extends TileGeneric implements IPeripheralTile
private void togglePeripheralAccess() private void togglePeripheralAccess()
{ {
if( !this.m_peripheralAccessAllowed ) if( !this.peripheralAccessAllowed )
{ {
this.m_peripheral.attach( this.world, this.getPos(), this.getDirection() ); this.peripheral.attach( this.world, this.getPos(), this.getDirection() );
if( !this.m_peripheral.hasPeripheral() ) if( !this.peripheral.hasPeripheral() )
{ {
return; return;
} }
this.m_peripheralAccessAllowed = true; this.peripheralAccessAllowed = true;
this.m_node.updatePeripherals( this.m_peripheral.toMap() ); this.node.updatePeripherals( this.peripheral.toMap() );
} }
else else
{ {
this.m_peripheral.detach(); this.peripheral.detach();
this.m_peripheralAccessAllowed = false; this.peripheralAccessAllowed = false;
this.m_node.updatePeripherals( Collections.emptyMap() ); this.node.updatePeripherals( Collections.emptyMap() );
} }
this.updateBlockState(); this.updateBlockState();
@@ -380,16 +380,16 @@ public class TileCable extends TileGeneric implements IPeripheralTile
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt )
{ {
super.fromTag( state, nbt ); super.fromTag( state, nbt );
this.m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); this.peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
this.m_peripheral.read( nbt, "" ); this.peripheral.read( nbt, "" );
} }
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( CompoundTag nbt ) public CompoundTag toTag( CompoundTag nbt )
{ {
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.m_peripheralAccessAllowed ); nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.peripheralAccessAllowed );
this.m_peripheral.write( nbt, "" ); this.peripheral.write( nbt, "" );
return super.toTag( nbt ); return super.toTag( nbt );
} }
@@ -422,14 +422,14 @@ public class TileCable extends TileGeneric implements IPeripheralTile
public IWiredElement getElement( Direction facing ) public IWiredElement getElement( Direction facing )
{ {
return BlockCable.canConnectIn( this.getCachedState(), facing ) ? this.m_cable : null; return BlockCable.canConnectIn( this.getCachedState(), facing ) ? this.cable : null;
} }
@Nonnull @Nonnull
@Override @Override
public IPeripheral getPeripheral( Direction side ) public IPeripheral getPeripheral( Direction side )
{ {
return !this.m_destroyed && this.hasModem() && side == this.getDirection() ? this.m_modem : null; return !this.destroyed && this.hasModem() && side == this.getDirection() ? this.modem : null;
} }
private class CableElement extends WiredModemElement private class CableElement extends WiredModemElement
@@ -452,13 +452,13 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override @Override
protected void attachPeripheral( String name, IPeripheral peripheral ) protected void attachPeripheral( String name, IPeripheral peripheral )
{ {
TileCable.this.m_modem.attachPeripheral( name, peripheral ); TileCable.this.modem.attachPeripheral( name, peripheral );
} }
@Override @Override
protected void detachPeripheral( String name ) protected void detachPeripheral( String name )
{ {
TileCable.this.m_modem.detachPeripheral( name ); TileCable.this.modem.detachPeripheral( name );
} }
} }
} }

View File

@@ -41,30 +41,30 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
{ {
private static final String NBT_PERIPHERAL_ENABLED = "PeripheralAccess"; private static final String NBT_PERIPHERAL_ENABLED = "PeripheralAccess";
private final WiredModemPeripheral[] modems = new WiredModemPeripheral[6]; private final WiredModemPeripheral[] modems = new WiredModemPeripheral[6];
private final WiredModemLocalPeripheral[] m_peripherals = new WiredModemLocalPeripheral[6]; private final WiredModemLocalPeripheral[] peripherals = new WiredModemLocalPeripheral[6];
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 final IWiredNode m_node = this.m_element.getNode(); private final IWiredNode node = this.element.getNode();
private boolean m_peripheralAccessAllowed = false; private boolean peripheralAccessAllowed = false;
private boolean m_destroyed = false; private boolean destroyed = false;
private boolean m_connectionsFormed = false; private boolean connectionsFormed = false;
public TileWiredModemFull( BlockEntityType<TileWiredModemFull> type ) public TileWiredModemFull( BlockEntityType<TileWiredModemFull> type )
{ {
super( type ); super( type );
for( int i = 0; i < this.m_peripherals.length; i++ ) for( int i = 0; i < this.peripherals.length; i++ )
{ {
Direction facing = Direction.byId( i ); Direction facing = Direction.byId( i );
this.m_peripherals[i] = new WiredModemLocalPeripheral(); this.peripherals[i] = new WiredModemLocalPeripheral();
} }
} }
@Override @Override
public void destroy() public void destroy()
{ {
if( !this.m_destroyed ) if( !this.destroyed )
{ {
this.m_destroyed = true; this.destroyed = true;
this.doRemove(); this.doRemove();
} }
super.destroy(); super.destroy();
@@ -81,8 +81,8 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
{ {
if( this.world == null || !this.world.isClient ) if( this.world == null || !this.world.isClient )
{ {
this.m_node.remove(); this.node.remove();
this.m_connectionsFormed = false; this.connectionsFormed = false;
} }
} }
@@ -118,7 +118,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Override @Override
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{ {
if( !this.world.isClient && this.m_peripheralAccessAllowed ) if( !this.world.isClient && this.peripheralAccessAllowed )
{ {
for( Direction facing : DirectionUtil.FACINGS ) for( Direction facing : DirectionUtil.FACINGS )
{ {
@@ -139,21 +139,21 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
return; return;
} }
if( this.m_modemState.pollChanged() ) if( this.modemState.pollChanged() )
{ {
this.updateBlockState(); this.updateBlockState();
} }
if( !this.m_connectionsFormed ) if( !this.connectionsFormed )
{ {
this.m_connectionsFormed = true; this.connectionsFormed = true;
this.connectionsChanged(); this.connectionsChanged();
if( this.m_peripheralAccessAllowed ) if( this.peripheralAccessAllowed )
{ {
for( Direction facing : DirectionUtil.FACINGS ) for( Direction facing : DirectionUtil.FACINGS )
{ {
this.m_peripherals[facing.ordinal()].attach( this.world, this.getPos(), facing ); this.peripherals[facing.ordinal()].attach( this.world, this.getPos(), facing );
} }
this.updateConnectedPeripherals(); this.updateConnectedPeripherals();
} }
@@ -183,13 +183,13 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
continue; continue;
} }
this.m_node.connectTo( element.getNode() ); this.node.connectTo( element.getNode() );
} }
} }
private void refreshPeripheral( @Nonnull Direction facing ) private void refreshPeripheral( @Nonnull Direction facing )
{ {
WiredModemLocalPeripheral peripheral = this.m_peripherals[facing.ordinal()]; WiredModemLocalPeripheral peripheral = this.peripherals[facing.ordinal()];
if( this.world != null && !this.isRemoved() && peripheral.attach( this.world, this.getPos(), facing ) ) if( this.world != null && !this.isRemoved() && peripheral.attach( this.world, this.getPos(), facing ) )
{ {
this.updateConnectedPeripherals(); this.updateConnectedPeripherals();
@@ -202,22 +202,22 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
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.
this.m_peripheralAccessAllowed = false; this.peripheralAccessAllowed = false;
this.updateBlockState(); this.updateBlockState();
} }
this.m_node.updatePeripherals( peripherals ); this.node.updatePeripherals( peripherals );
} }
private Map<String, IPeripheral> getConnectedPeripherals() private Map<String, IPeripheral> getConnectedPeripherals()
{ {
if( !this.m_peripheralAccessAllowed ) if( !this.peripheralAccessAllowed )
{ {
return Collections.emptyMap(); return Collections.emptyMap();
} }
Map<String, IPeripheral> peripherals = new HashMap<>( 6 ); Map<String, IPeripheral> peripherals = new HashMap<>( 6 );
for( WiredModemLocalPeripheral peripheral : this.m_peripherals ) for( WiredModemLocalPeripheral peripheral : this.peripherals )
{ {
peripheral.extendMap( peripherals ); peripheral.extendMap( peripherals );
} }
@@ -227,7 +227,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
private void updateBlockState() private void updateBlockState()
{ {
BlockState state = this.getCachedState(); BlockState state = this.getCachedState();
boolean modemOn = this.m_modemState.isOpen(), peripheralOn = this.m_peripheralAccessAllowed; boolean modemOn = this.modemState.isOpen(), peripheralOn = this.peripheralAccessAllowed;
if( state.get( MODEM_ON ) == modemOn && state.get( PERIPHERAL_ON ) == peripheralOn ) if( state.get( MODEM_ON ) == modemOn && state.get( PERIPHERAL_ON ) == peripheralOn )
{ {
return; return;
@@ -240,13 +240,13 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
private Set<String> getConnectedPeripheralNames() private Set<String> getConnectedPeripheralNames()
{ {
if( !this.m_peripheralAccessAllowed ) if( !this.peripheralAccessAllowed )
{ {
return Collections.emptySet(); return Collections.emptySet();
} }
Set<String> peripherals = new HashSet<>( 6 ); Set<String> peripherals = new HashSet<>( 6 );
for( WiredModemLocalPeripheral peripheral : this.m_peripherals ) for( WiredModemLocalPeripheral peripheral : this.peripherals )
{ {
String name = peripheral.getConnectedName(); String name = peripheral.getConnectedName();
if( name != null ) if( name != null )
@@ -259,12 +259,12 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
private void togglePeripheralAccess() private void togglePeripheralAccess()
{ {
if( !this.m_peripheralAccessAllowed ) if( !this.peripheralAccessAllowed )
{ {
boolean hasAny = false; boolean hasAny = false;
for( Direction facing : DirectionUtil.FACINGS ) for( Direction facing : DirectionUtil.FACINGS )
{ {
WiredModemLocalPeripheral peripheral = this.m_peripherals[facing.ordinal()]; WiredModemLocalPeripheral peripheral = this.peripherals[facing.ordinal()];
peripheral.attach( this.world, this.getPos(), facing ); peripheral.attach( this.world, this.getPos(), facing );
hasAny |= peripheral.hasPeripheral(); hasAny |= peripheral.hasPeripheral();
} }
@@ -274,18 +274,18 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
return; return;
} }
this.m_peripheralAccessAllowed = true; this.peripheralAccessAllowed = true;
this.m_node.updatePeripherals( this.getConnectedPeripherals() ); this.node.updatePeripherals( this.getConnectedPeripherals() );
} }
else else
{ {
this.m_peripheralAccessAllowed = false; this.peripheralAccessAllowed = false;
for( WiredModemLocalPeripheral peripheral : this.m_peripherals ) for( WiredModemLocalPeripheral peripheral : this.peripherals )
{ {
peripheral.detach(); peripheral.detach();
} }
this.m_node.updatePeripherals( Collections.emptyMap() ); this.node.updatePeripherals( Collections.emptyMap() );
} }
this.updateBlockState(); this.updateBlockState();
@@ -318,10 +318,10 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt )
{ {
super.fromTag( state, nbt ); super.fromTag( state, nbt );
this.m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); this.peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
for( int i = 0; i < this.m_peripherals.length; i++ ) for( int i = 0; i < this.peripherals.length; i++ )
{ {
this.m_peripherals[i].read( nbt, Integer.toString( i ) ); this.peripherals[i].read( nbt, Integer.toString( i ) );
} }
} }
@@ -329,10 +329,10 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Override @Override
public CompoundTag toTag( CompoundTag nbt ) public CompoundTag toTag( CompoundTag nbt )
{ {
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.m_peripheralAccessAllowed ); nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.peripheralAccessAllowed );
for( int i = 0; i < this.m_peripherals.length; i++ ) for( int i = 0; i < this.peripherals.length; i++ )
{ {
this.m_peripherals[i].write( nbt, Integer.toString( i ) ); this.peripherals[i].write( nbt, Integer.toString( i ) );
} }
return super.toTag( nbt ); return super.toTag( nbt );
} }
@@ -353,7 +353,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
public IWiredElement getElement() public IWiredElement getElement()
{ {
return this.m_element; return this.element;
} }
@Nonnull @Nonnull
@@ -366,8 +366,8 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
return peripheral; return peripheral;
} }
WiredModemLocalPeripheral localPeripheral = this.m_peripherals[side.ordinal()]; WiredModemLocalPeripheral localPeripheral = this.peripherals[side.ordinal()];
return this.modems[side.ordinal()] = new WiredModemPeripheral( this.m_modemState, this.m_element ) return this.modems[side.ordinal()] = new WiredModemPeripheral( this.modemState, this.element )
{ {
@Nonnull @Nonnull
@Override @Override
@@ -395,11 +395,11 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
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 )
{ {
this.m_entity = entity; this.entity = entity;
} }
@Override @Override
@@ -407,7 +407,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
{ {
for( int i = 0; i < 6; i++ ) for( int i = 0; i < 6; i++ )
{ {
WiredModemPeripheral modem = this.m_entity.modems[i]; WiredModemPeripheral modem = this.entity.modems[i];
if( modem != null ) if( modem != null )
{ {
modem.detachPeripheral( name ); modem.detachPeripheral( name );
@@ -420,7 +420,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
{ {
for( int i = 0; i < 6; i++ ) for( int i = 0; i < 6; i++ )
{ {
WiredModemPeripheral modem = this.m_entity.modems[i]; WiredModemPeripheral modem = this.entity.modems[i];
if( modem != null ) if( modem != null )
{ {
modem.attachPeripheral( name, peripheral ); modem.attachPeripheral( name, peripheral );
@@ -432,14 +432,14 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Override @Override
public World getWorld() public World getWorld()
{ {
return this.m_entity.getWorld(); return this.entity.getWorld();
} }
@Nonnull @Nonnull
@Override @Override
public Vec3d getPosition() public Vec3d getPosition()
{ {
BlockPos pos = this.m_entity.getPos(); BlockPos pos = this.entity.getPos();
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 );
} }
} }

View File

@@ -15,18 +15,18 @@ 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 );
this.m_advanced = advanced; this.advanced = advanced;
} }
@Override @Override
public double getRange() public double getRange()
{ {
if( this.m_advanced ) if( this.advanced )
{ {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
@@ -56,7 +56,7 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral
@Override @Override
public boolean isInterdimensional() public boolean isInterdimensional()
{ {
return this.m_advanced; return this.advanced;
} }
@Override @Override

View File

@@ -19,35 +19,35 @@ 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;
private final Set<IPacketReceiver> m_receivers = Collections.newSetFromMap( new ConcurrentHashMap<>() ); private final Set<IPacketReceiver> receivers = Collections.newSetFromMap( new ConcurrentHashMap<>() );
public static WirelessNetwork getUniversal() public static WirelessNetwork getUniversal()
{ {
if( s_universalNetwork == null ) if( universalNetwork == null )
{ {
s_universalNetwork = new WirelessNetwork(); universalNetwork = new WirelessNetwork();
} }
return s_universalNetwork; return universalNetwork;
} }
public static void resetNetworks() public static void resetNetworks()
{ {
s_universalNetwork = null; universalNetwork = null;
} }
@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" );
this.m_receivers.add( receiver ); this.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" );
this.m_receivers.remove( receiver ); this.receivers.remove( receiver );
} }
@Override @Override
@@ -60,7 +60,7 @@ public class WirelessNetwork implements IPacketNetwork
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 : this.m_receivers ) for( IPacketReceiver device : this.receivers )
{ {
tryTransmit( device, packet, range, false ); tryTransmit( device, packet, range, false );
} }
@@ -70,7 +70,7 @@ public class WirelessNetwork implements IPacketNetwork
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 : this.m_receivers ) for( IPacketReceiver device : this.receivers )
{ {
tryTransmit( device, packet, 0, true ); tryTransmit( device, packet, 0, true );
} }

View File

@@ -43,20 +43,20 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private static final String NBT_HEIGHT = "Height"; private static final String NBT_HEIGHT = "Height";
private final boolean advanced; private final boolean advanced;
private final Set<IComputerAccess> m_computers = new HashSet<>(); private final Set<IComputerAccess> computers = new HashSet<>();
// MonitorWatcher state. // MonitorWatcher state.
boolean enqueued; boolean enqueued;
TerminalState cached; TerminalState cached;
private ServerMonitor m_serverMonitor; private ServerMonitor serverMonitor;
private ClientMonitor m_clientMonitor; private ClientMonitor clientMonitor;
private MonitorPeripheral peripheral; private MonitorPeripheral peripheral;
private boolean needsUpdate = false; private boolean needsUpdate = false;
private boolean m_destroyed = false; private boolean destroyed = false;
private boolean visiting = false; private boolean visiting = false;
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( BlockEntityType<? extends TileMonitor> type, boolean advanced ) public TileMonitor( BlockEntityType<? extends TileMonitor> type, boolean advanced )
{ {
@@ -68,11 +68,11 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
public void destroy() public void destroy()
{ {
// TODO: Call this before using the block // TODO: Call this before using the block
if( this.m_destroyed ) if( this.destroyed )
{ {
return; return;
} }
this.m_destroyed = true; this.destroyed = true;
if( !this.getWorld().isClient ) if( !this.getWorld().isClient )
{ {
this.contractNeighbours(); this.contractNeighbours();
@@ -83,9 +83,9 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
public void markRemoved() public void markRemoved()
{ {
super.markRemoved(); super.markRemoved();
if( this.m_clientMonitor != null && this.m_xIndex == 0 && this.m_yIndex == 0 ) if( this.clientMonitor != null && this.xIndex == 0 && this.yIndex == 0 )
{ {
this.m_clientMonitor.destroy(); this.clientMonitor.destroy();
} }
} }
@@ -93,11 +93,11 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
public void onChunkUnloaded() public void onChunkUnloaded()
{ {
super.onChunkUnloaded(); super.onChunkUnloaded();
if( this.m_clientMonitor != null && this.m_xIndex == 0 && this.m_yIndex == 0 ) if( this.clientMonitor != null && this.xIndex == 0 && this.yIndex == 0 )
{ {
this.m_clientMonitor.destroy(); this.clientMonitor.destroy();
} }
this.m_clientMonitor = null; this.clientMonitor = null;
} }
@Nonnull @Nonnull
@@ -130,18 +130,18 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
updateNeighbors(); updateNeighbors();
} }
if( this.m_xIndex != 0 || this.m_yIndex != 0 || this.m_serverMonitor == null ) if( this.xIndex != 0 || this.yIndex != 0 || this.serverMonitor == null )
{ {
return; return;
} }
this.m_serverMonitor.clearChanged(); this.serverMonitor.clearChanged();
if( this.m_serverMonitor.pollResized() ) if( this.serverMonitor.pollResized() )
{ {
for( int x = 0; x < this.m_width; x++ ) for( int x = 0; x < this.width; x++ )
{ {
for( int y = 0; y < this.m_height; y++ ) for( int y = 0; y < this.height; y++ )
{ {
TileMonitor monitor = this.getNeighbour( x, y ); TileMonitor monitor = this.getNeighbour( x, y );
if( monitor == null ) if( monitor == null )
@@ -149,7 +149,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
continue; continue;
} }
for( IComputerAccess computer : monitor.m_computers ) for( IComputerAccess computer : monitor.computers )
{ {
computer.queueEvent( "monitor_resize", computer.getAttachmentName() ); computer.queueEvent( "monitor_resize", computer.getAttachmentName() );
} }
@@ -157,7 +157,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
} }
} }
if( this.m_serverMonitor.pollTerminalChanged() ) if( this.serverMonitor.pollTerminalChanged() )
{ {
this.updateBlock(); this.updateBlock();
} }
@@ -168,38 +168,38 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
{ {
super.readDescription( nbt ); super.readDescription( nbt );
int oldXIndex = this.m_xIndex; int oldXIndex = this.xIndex;
int oldYIndex = this.m_yIndex; int oldYIndex = this.yIndex;
int oldWidth = this.m_width; int oldWidth = this.width;
int oldHeight = this.m_height; int oldHeight = this.height;
this.m_xIndex = nbt.getInt( NBT_X ); this.xIndex = nbt.getInt( NBT_X );
this.m_yIndex = nbt.getInt( NBT_Y ); this.yIndex = nbt.getInt( NBT_Y );
this.m_width = nbt.getInt( NBT_WIDTH ); this.width = nbt.getInt( NBT_WIDTH );
this.m_height = nbt.getInt( NBT_HEIGHT ); this.height = nbt.getInt( NBT_HEIGHT );
if( oldXIndex != this.m_xIndex || oldYIndex != this.m_yIndex ) if( oldXIndex != this.xIndex || oldYIndex != this.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 && this.m_clientMonitor != null ) if( oldXIndex == 0 && oldYIndex == 0 && this.clientMonitor != null )
{ {
this.m_clientMonitor.destroy(); this.clientMonitor.destroy();
} }
this.m_clientMonitor = null; this.clientMonitor = null;
} }
if( this.m_xIndex == 0 && this.m_yIndex == 0 ) if( this.xIndex == 0 && this.yIndex == 0 )
{ {
// If we're the origin terminal then create it. // If we're the origin terminal then create it.
if( this.m_clientMonitor == null ) if( this.clientMonitor == null )
{ {
this.m_clientMonitor = new ClientMonitor( this.advanced, this ); this.clientMonitor = new ClientMonitor( this.advanced, this );
} }
this.m_clientMonitor.readDescription( nbt ); this.clientMonitor.readDescription( nbt );
} }
if( oldXIndex != this.m_xIndex || oldYIndex != this.m_yIndex || oldWidth != this.m_width || oldHeight != this.m_height ) if( oldXIndex != this.xIndex || oldYIndex != this.yIndex || oldWidth != this.width || oldHeight != this.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
this.updateBlock(); this.updateBlock();
@@ -210,14 +210,14 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
protected void writeDescription( @Nonnull CompoundTag nbt ) protected void writeDescription( @Nonnull CompoundTag nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
nbt.putInt( NBT_X, this.m_xIndex ); nbt.putInt( NBT_X, this.xIndex );
nbt.putInt( NBT_Y, this.m_yIndex ); nbt.putInt( NBT_Y, this.yIndex );
nbt.putInt( NBT_WIDTH, this.m_width ); nbt.putInt( NBT_WIDTH, this.width );
nbt.putInt( NBT_HEIGHT, this.m_height ); nbt.putInt( NBT_HEIGHT, this.height );
if( this.m_xIndex == 0 && this.m_yIndex == 0 && this.m_serverMonitor != null ) if( this.xIndex == 0 && this.yIndex == 0 && this.serverMonitor != null )
{ {
this.m_serverMonitor.writeDescription( nbt ); this.serverMonitor.writeDescription( nbt );
} }
} }
@@ -226,8 +226,8 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
BlockPos pos = this.getPos(); BlockPos pos = this.getPos();
Direction right = this.getRight(); Direction right = this.getRight();
Direction down = this.getDown(); Direction down = this.getDown();
int xOffset = -this.m_xIndex + x; int xOffset = -this.xIndex + x;
int yOffset = -this.m_yIndex + y; int yOffset = -this.yIndex + y;
return this.getSimilarMonitorAt( pos.offset( right, xOffset ) return this.getSimilarMonitorAt( pos.offset( right, xOffset )
.offset( down, yOffset ) ); .offset( down, yOffset ) );
} }
@@ -268,7 +268,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
} }
TileMonitor monitor = (TileMonitor) tile; TileMonitor monitor = (TileMonitor) tile;
return !monitor.visiting && !monitor.m_destroyed && this.advanced == monitor.advanced && this.getDirection() == monitor.getDirection() && this.getOrientation() == monitor.getOrientation() ? monitor : null; return !monitor.visiting && !monitor.destroyed && this.advanced == monitor.advanced && this.getDirection() == monitor.getDirection() && this.getOrientation() == monitor.getOrientation() ? monitor : null;
} }
// region Sizing and placement stuff // region Sizing and placement stuff
@@ -290,10 +290,10 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
{ {
super.fromTag( state, nbt ); super.fromTag( state, nbt );
this.m_xIndex = nbt.getInt( NBT_X ); this.xIndex = nbt.getInt( NBT_X );
this.m_yIndex = nbt.getInt( NBT_Y ); this.yIndex = nbt.getInt( NBT_Y );
this.m_width = nbt.getInt( NBT_WIDTH ); this.width = nbt.getInt( NBT_WIDTH );
this.m_height = nbt.getInt( NBT_HEIGHT ); this.height = nbt.getInt( NBT_HEIGHT );
} }
// Networking stuff // Networking stuff
@@ -302,10 +302,10 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
@Override @Override
public CompoundTag toTag( CompoundTag tag ) public CompoundTag toTag( CompoundTag tag )
{ {
tag.putInt( NBT_X, this.m_xIndex ); tag.putInt( NBT_X, this.xIndex );
tag.putInt( NBT_Y, this.m_yIndex ); tag.putInt( NBT_Y, this.yIndex );
tag.putInt( NBT_WIDTH, this.m_width ); tag.putInt( NBT_WIDTH, this.width );
tag.putInt( NBT_HEIGHT, this.m_height ); tag.putInt( NBT_HEIGHT, this.height );
return super.toTag( tag ); return super.toTag( tag );
} }
@@ -338,14 +338,14 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
public ServerMonitor getCachedServerMonitor() public ServerMonitor getCachedServerMonitor()
{ {
return this.m_serverMonitor; return this.serverMonitor;
} }
private ServerMonitor getServerMonitor() private ServerMonitor getServerMonitor()
{ {
if( this.m_serverMonitor != null ) if( this.serverMonitor != null )
{ {
return this.m_serverMonitor; return this.serverMonitor;
} }
TileMonitor origin = this.getOrigin(); TileMonitor origin = this.getOrigin();
@@ -354,92 +354,92 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
return null; return null;
} }
return this.m_serverMonitor = origin.m_serverMonitor; return this.serverMonitor = origin.serverMonitor;
} }
private ServerMonitor createServerMonitor() private ServerMonitor createServerMonitor()
{ {
if( this.m_serverMonitor != null ) if( this.serverMonitor != null )
{ {
return this.m_serverMonitor; return this.serverMonitor;
} }
if( this.m_xIndex == 0 && this.m_yIndex == 0 ) if( this.xIndex == 0 && this.yIndex == 0 )
{ {
// If we're the origin, set up the new monitor // If we're the origin, set up the new monitor
this.m_serverMonitor = new ServerMonitor( this.advanced, this ); this.serverMonitor = new ServerMonitor( this.advanced, this );
this.m_serverMonitor.rebuild(); this.serverMonitor.rebuild();
// And propagate it to child monitors // And propagate it to child monitors
for( int x = 0; x < this.m_width; x++ ) for( int x = 0; x < this.width; x++ )
{ {
for( int y = 0; y < this.m_height; y++ ) for( int y = 0; y < this.height; y++ )
{ {
TileMonitor monitor = this.getNeighbour( x, y ); TileMonitor monitor = this.getNeighbour( x, y );
if( monitor != null ) if( monitor != null )
{ {
monitor.m_serverMonitor = this.m_serverMonitor; monitor.serverMonitor = this.serverMonitor;
} }
} }
} }
return this.m_serverMonitor; return this.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 = this.getPos(); BlockPos pos = this.getPos();
BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.m_xIndex ) BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.xIndex )
.offset( this.getDown(), -this.m_yIndex ) ); .offset( this.getDown(), -this.yIndex ) );
if( !(te instanceof TileMonitor) ) if( !(te instanceof TileMonitor) )
{ {
return null; return null;
} }
return this.m_serverMonitor = ((TileMonitor) te).createServerMonitor(); return this.serverMonitor = ((TileMonitor) te).createServerMonitor();
} }
} }
public ClientMonitor getClientMonitor() public ClientMonitor getClientMonitor()
{ {
if( this.m_clientMonitor != null ) if( this.clientMonitor != null )
{ {
return this.m_clientMonitor; return this.clientMonitor;
} }
BlockPos pos = this.getPos(); BlockPos pos = this.getPos();
BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.m_xIndex ) BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.xIndex )
.offset( this.getDown(), -this.m_yIndex ) ); .offset( this.getDown(), -this.yIndex ) );
if( !(te instanceof TileMonitor) ) if( !(te instanceof TileMonitor) )
{ {
return null; return null;
} }
return this.m_clientMonitor = ((TileMonitor) te).m_clientMonitor; return this.clientMonitor = ((TileMonitor) te).clientMonitor;
} }
public final void read( TerminalState state ) public final void read( TerminalState state )
{ {
if( this.m_xIndex != 0 || this.m_yIndex != 0 ) if( this.xIndex != 0 || this.yIndex != 0 )
{ {
ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", this.getPos() ); ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", this.getPos() );
return; return;
} }
if( this.m_clientMonitor == null ) if( this.clientMonitor == null )
{ {
this.m_clientMonitor = new ClientMonitor( this.advanced, this ); this.clientMonitor = new ClientMonitor( this.advanced, this );
} }
this.m_clientMonitor.read( state ); this.clientMonitor.read( state );
} }
private void updateBlockState() private void updateBlockState()
{ {
this.getWorld().setBlockState( this.getPos(), this.getWorld().setBlockState( this.getPos(),
this.getCachedState().with( BlockMonitor.STATE, this.getCachedState().with( BlockMonitor.STATE,
MonitorEdgeState.fromConnections( this.m_yIndex < this.m_height - 1, MonitorEdgeState.fromConnections( this.yIndex < this.height - 1,
this.m_yIndex > 0, this.m_xIndex > 0, this.m_xIndex < this.m_width - 1 ) ), this.yIndex > 0, this.xIndex > 0, this.xIndex < this.width - 1 ) ),
2 ); 2 );
} }
@@ -451,22 +451,22 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
public int getWidth() public int getWidth()
{ {
return this.m_width; return this.width;
} }
public int getHeight() public int getHeight()
{ {
return this.m_height; return this.height;
} }
public int getXIndex() public int getXIndex()
{ {
return this.m_xIndex; return this.xIndex;
} }
public int getYIndex() public int getYIndex()
{ {
return this.m_yIndex; return this.yIndex;
} }
private TileMonitor getOrigin() private TileMonitor getOrigin()
@@ -477,15 +477,15 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
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( this.m_xIndex != 0 || this.m_yIndex != 0 ) if( this.xIndex != 0 || this.yIndex != 0 )
{ {
this.m_serverMonitor = null; this.serverMonitor = null;
} }
this.m_xIndex = 0; this.xIndex = 0;
this.m_yIndex = 0; this.yIndex = 0;
this.m_width = width; this.width = width;
this.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
@@ -508,21 +508,21 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
// 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( this.m_serverMonitor == null ) if( this.serverMonitor == null )
{ {
this.m_serverMonitor = new ServerMonitor( this.advanced, this ); this.serverMonitor = new ServerMonitor( this.advanced, this );
} }
} }
else else
{ {
this.m_serverMonitor = null; this.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( this.m_serverMonitor != null ) if( this.serverMonitor != null )
{ {
this.m_serverMonitor.rebuild(); this.serverMonitor.rebuild();
} }
// Update the other monitors, setting coordinates, dimensions and the server terminal // Update the other monitors, setting coordinates, dimensions and the server terminal
@@ -536,11 +536,11 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
continue; 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 = this.m_serverMonitor; monitor.serverMonitor = this.serverMonitor;
monitor.updateBlockState(); monitor.updateBlockState();
monitor.updateBlock(); monitor.updateBlock();
} }
@@ -550,12 +550,12 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private boolean mergeLeft() private boolean mergeLeft()
{ {
TileMonitor left = this.getNeighbour( -1, 0 ); TileMonitor left = this.getNeighbour( -1, 0 );
if( left == null || left.m_yIndex != 0 || left.m_height != this.m_height ) if( left == null || left.yIndex != 0 || left.height != this.height )
{ {
return false; return false;
} }
int width = left.m_width + this.m_width; int width = left.width + this.width;
if( width > ComputerCraft.monitorWidth ) if( width > ComputerCraft.monitorWidth )
{ {
return false; return false;
@@ -564,7 +564,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
TileMonitor origin = left.getOrigin(); TileMonitor origin = left.getOrigin();
if( origin != null ) if( origin != null )
{ {
origin.resize( width, this.m_height ); origin.resize( width, this.height );
} }
left.expand(); left.expand();
return true; return true;
@@ -572,13 +572,13 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private boolean mergeRight() private boolean mergeRight()
{ {
TileMonitor right = this.getNeighbour( this.m_width, 0 ); TileMonitor right = this.getNeighbour( this.width, 0 );
if( right == null || right.m_yIndex != 0 || right.m_height != this.m_height ) if( right == null || right.yIndex != 0 || right.height != this.height )
{ {
return false; return false;
} }
int width = this.m_width + right.m_width; int width = this.width + right.width;
if( width > ComputerCraft.monitorWidth ) if( width > ComputerCraft.monitorWidth )
{ {
return false; return false;
@@ -587,7 +587,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
TileMonitor origin = this.getOrigin(); TileMonitor origin = this.getOrigin();
if( origin != null ) if( origin != null )
{ {
origin.resize( width, this.m_height ); origin.resize( width, this.height );
} }
this.expand(); this.expand();
return true; return true;
@@ -595,13 +595,13 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private boolean mergeUp() private boolean mergeUp()
{ {
TileMonitor above = this.getNeighbour( 0, this.m_height ); TileMonitor above = this.getNeighbour( 0, this.height );
if( above == null || above.m_xIndex != 0 || above.m_width != this.m_width ) if( above == null || above.xIndex != 0 || above.width != this.width )
{ {
return false; return false;
} }
int height = above.m_height + this.m_height; int height = above.height + this.height;
if( height > ComputerCraft.monitorHeight ) if( height > ComputerCraft.monitorHeight )
{ {
return false; return false;
@@ -610,7 +610,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
TileMonitor origin = this.getOrigin(); TileMonitor origin = this.getOrigin();
if( origin != null ) if( origin != null )
{ {
origin.resize( this.m_width, height ); origin.resize( this.width, height );
} }
this.expand(); this.expand();
return true; return true;
@@ -619,12 +619,12 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private boolean mergeDown() private boolean mergeDown()
{ {
TileMonitor below = this.getNeighbour( 0, -1 ); TileMonitor below = this.getNeighbour( 0, -1 );
if( below == null || below.m_xIndex != 0 || below.m_width != this.m_width ) if( below == null || below.xIndex != 0 || below.width != this.width )
{ {
return false; return false;
} }
int height = this.m_height + below.m_height; int height = this.height + below.height;
if( height > ComputerCraft.monitorHeight ) if( height > ComputerCraft.monitorHeight )
{ {
return false; return false;
@@ -633,7 +633,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
TileMonitor origin = below.getOrigin(); TileMonitor origin = below.getOrigin();
if( origin != null ) if( origin != null )
{ {
origin.resize( this.m_width, height ); origin.resize( this.width, height );
} }
below.expand(); below.expand();
return true; return true;
@@ -662,33 +662,33 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
void contractNeighbours() void contractNeighbours()
{ {
this.visiting = true; this.visiting = true;
if( this.m_xIndex > 0 ) if( this.xIndex > 0 )
{ {
TileMonitor left = this.getNeighbour( this.m_xIndex - 1, this.m_yIndex ); TileMonitor left = this.getNeighbour( this.xIndex - 1, this.yIndex );
if( left != null ) if( left != null )
{ {
left.contract(); left.contract();
} }
} }
if( this.m_xIndex + 1 < this.m_width ) if( this.xIndex + 1 < this.width )
{ {
TileMonitor right = this.getNeighbour( this.m_xIndex + 1, this.m_yIndex ); TileMonitor right = this.getNeighbour( this.xIndex + 1, this.yIndex );
if( right != null ) if( right != null )
{ {
right.contract(); right.contract();
} }
} }
if( this.m_yIndex > 0 ) if( this.yIndex > 0 )
{ {
TileMonitor below = this.getNeighbour( this.m_xIndex, this.m_yIndex - 1 ); TileMonitor below = this.getNeighbour( this.xIndex, this.yIndex - 1 );
if( below != null ) if( below != null )
{ {
below.contract(); below.contract();
} }
} }
if( this.m_yIndex + 1 < this.m_height ) if( this.yIndex + 1 < this.height )
{ {
TileMonitor above = this.getNeighbour( this.m_xIndex, this.m_yIndex + 1 ); TileMonitor above = this.getNeighbour( this.xIndex, this.yIndex + 1 );
if( above != null ) if( above != null )
{ {
above.contract(); above.contract();
@@ -699,8 +699,8 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
void contract() void contract()
{ {
int height = this.m_height; int height = this.height;
int width = this.m_width; int width = this.width;
TileMonitor origin = this.getOrigin(); TileMonitor origin = this.getOrigin();
if( origin == null ) if( origin == null )
@@ -791,9 +791,9 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private void monitorTouched( float xPos, float yPos, float zPos ) private void monitorTouched( float xPos, float yPos, float zPos )
{ {
XYPair pair = XYPair.of( xPos, yPos, zPos, this.getDirection(), this.getOrientation() ) XYPair pair = XYPair.of( xPos, yPos, zPos, this.getDirection(), this.getOrientation() )
.add( this.m_xIndex, this.m_height - this.m_yIndex - 1 ); .add( this.xIndex, this.height - this.yIndex - 1 );
if( pair.x > this.m_width - RENDER_BORDER || pair.y > this.m_height - RENDER_BORDER || pair.x < RENDER_BORDER || pair.y < RENDER_BORDER ) if( pair.x > this.width - RENDER_BORDER || pair.y > this.height - RENDER_BORDER || pair.x < RENDER_BORDER || pair.y < RENDER_BORDER )
{ {
return; return;
} }
@@ -810,15 +810,15 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
return; return;
} }
double xCharWidth = (this.m_width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth(); double xCharWidth = (this.width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth();
double yCharHeight = (this.m_height - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getHeight(); double yCharHeight = (this.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 < this.m_height; y++ ) for( int y = 0; y < this.height; y++ )
{ {
for( int x = 0; x < this.m_width; x++ ) for( int x = 0; x < this.width; x++ )
{ {
TileMonitor monitor = this.getNeighbour( x, y ); TileMonitor monitor = this.getNeighbour( x, y );
if( monitor == null ) if( monitor == null )
@@ -826,7 +826,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
continue; 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 );
} }
@@ -836,7 +836,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
void addComputer( IComputerAccess computer ) void addComputer( IComputerAccess computer )
{ {
this.m_computers.add( computer ); this.computers.add( computer );
} }
// @Nonnull // @Nonnull
@@ -866,6 +866,6 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
void removeComputer( IComputerAccess computer ) void removeComputer( IComputerAccess computer )
{ {
this.m_computers.remove( computer ); this.computers.remove( computer );
} }
} }

View File

@@ -63,12 +63,12 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
6 6
}; };
private static final int[] SIDE_SLOTS = new int[] { 0 }; private static final int[] SIDE_SLOTS = new int[] { 0 };
private final DefaultedList<ItemStack> m_inventory = DefaultedList.ofSize( SLOTS, ItemStack.EMPTY ); private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize( SLOTS, ItemStack.EMPTY );
private final ItemStorage m_itemHandlerAll = ItemStorage.wrap( this ); private final ItemStorage itemHandlerAll = ItemStorage.wrap( this );
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 );
Text customName; Text customName;
private String m_pageTitle = ""; private String pageTitle = "";
private boolean m_printing = false; private boolean printing = false;
public TilePrinter( BlockEntityType<TilePrinter> type ) public TilePrinter( BlockEntityType<TilePrinter> type )
{ {
@@ -101,7 +101,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 = this.m_inventory.get( i ); ItemStack stack = this.inventory.get( i );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
// Remove the stack from the inventory // Remove the stack from the inventory
@@ -120,7 +120,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 = this.m_inventory.get( i ); ItemStack stack = this.inventory.get( i );
if( !stack.isEmpty() && isPaper( stack ) ) if( !stack.isEmpty() && isPaper( stack ) )
{ {
top = true; top = true;
@@ -129,7 +129,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 = this.m_inventory.get( i ); ItemStack stack = this.inventory.get( i );
if( !stack.isEmpty() && isPaper( stack ) ) if( !stack.isEmpty() && isPaper( stack ) )
{ {
bottom = true; bottom = true;
@@ -172,15 +172,15 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
this.customName = nbt.contains( NBT_NAME ) ? Text.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; this.customName = nbt.contains( NBT_NAME ) ? Text.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
// Read page // Read page
synchronized( this.m_page ) synchronized( this.page )
{ {
this.m_printing = nbt.getBoolean( NBT_PRINTING ); this.printing = nbt.getBoolean( NBT_PRINTING );
this.m_pageTitle = nbt.getString( NBT_PAGE_TITLE ); this.pageTitle = nbt.getString( NBT_PAGE_TITLE );
this.m_page.readFromNBT( nbt ); this.page.readFromNBT( nbt );
} }
// Read inventory // Read inventory
Inventories.fromTag( nbt, this.m_inventory ); Inventories.fromTag( nbt, this.inventory );
} }
@Nonnull @Nonnull
@@ -193,35 +193,35 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
// Write page // Write page
synchronized( this.m_page ) synchronized( this.page )
{ {
nbt.putBoolean( NBT_PRINTING, this.m_printing ); nbt.putBoolean( NBT_PRINTING, this.printing );
nbt.putString( NBT_PAGE_TITLE, this.m_pageTitle ); nbt.putString( NBT_PAGE_TITLE, this.pageTitle );
this.m_page.writeToNBT( nbt ); this.page.writeToNBT( nbt );
} }
// Write inventory // Write inventory
Inventories.toTag( nbt, this.m_inventory ); Inventories.toTag( nbt, this.inventory );
return super.toTag( nbt ); return super.toTag( nbt );
} }
boolean isPrinting() boolean isPrinting()
{ {
return this.m_printing; return this.printing;
} }
// IInventory implementation // IInventory implementation
@Override @Override
public int size() public int size()
{ {
return this.m_inventory.size(); return this.inventory.size();
} }
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
for( ItemStack stack : this.m_inventory ) for( ItemStack stack : this.inventory )
{ {
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
@@ -235,14 +235,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public ItemStack getStack( int slot ) public ItemStack getStack( int slot )
{ {
return this.m_inventory.get( slot ); return this.inventory.get( slot );
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack removeStack( int slot, int count ) public ItemStack removeStack( int slot, int count )
{ {
ItemStack stack = this.m_inventory.get( slot ); ItemStack stack = this.inventory.get( slot );
if( stack.isEmpty() ) if( stack.isEmpty() )
{ {
return ItemStack.EMPTY; return ItemStack.EMPTY;
@@ -255,10 +255,10 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
ItemStack part = stack.split( count ); ItemStack part = stack.split( count );
if( this.m_inventory.get( slot ) if( this.inventory.get( slot )
.isEmpty() ) .isEmpty() )
{ {
this.m_inventory.set( slot, ItemStack.EMPTY ); this.inventory.set( slot, ItemStack.EMPTY );
this.updateBlockState(); this.updateBlockState();
} }
this.markDirty(); this.markDirty();
@@ -269,8 +269,8 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public ItemStack removeStack( int slot ) public ItemStack removeStack( int slot )
{ {
ItemStack result = this.m_inventory.get( slot ); ItemStack result = this.inventory.get( slot );
this.m_inventory.set( slot, ItemStack.EMPTY ); this.inventory.set( slot, ItemStack.EMPTY );
this.markDirty(); this.markDirty();
this.updateBlockState(); this.updateBlockState();
return result; return result;
@@ -281,7 +281,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public void setStack( int slot, @Nonnull ItemStack stack ) public void setStack( int slot, @Nonnull ItemStack stack )
{ {
this.m_inventory.set( slot, stack ); this.inventory.set( slot, stack );
this.markDirty(); this.markDirty();
this.updateBlockState(); this.updateBlockState();
} }
@@ -295,9 +295,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Override @Override
public void clear() public void clear()
{ {
for( int i = 0; i < this.m_inventory.size(); i++ ) for( int i = 0; i < this.inventory.size(); i++ )
{ {
this.m_inventory.set( i, ItemStack.EMPTY ); this.inventory.set( i, ItemStack.EMPTY );
} }
this.markDirty(); this.markDirty();
this.updateBlockState(); this.updateBlockState();
@@ -350,21 +350,21 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
@Nullable @Nullable
Terminal getCurrentPage() Terminal getCurrentPage()
{ {
synchronized( this.m_page ) synchronized( this.page )
{ {
return this.m_printing ? this.m_page : null; return this.printing ? this.page : null;
} }
} }
boolean startNewPage() boolean startNewPage()
{ {
synchronized( this.m_page ) synchronized( this.page )
{ {
if( !this.canInputPage() ) if( !this.canInputPage() )
{ {
return false; return false;
} }
if( this.m_printing && !this.outputPage() ) if( this.printing && !this.outputPage() )
{ {
return false; return false;
} }
@@ -374,33 +374,33 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
boolean endCurrentPage() boolean endCurrentPage()
{ {
synchronized( this.m_page ) synchronized( this.page )
{ {
return this.m_printing && this.outputPage(); return this.printing && this.outputPage();
} }
} }
private boolean outputPage() private boolean outputPage()
{ {
int height = this.m_page.getHeight(); int height = this.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] = this.m_page.getLine( i ) lines[i] = this.page.getLine( i )
.toString(); .toString();
colours[i] = this.m_page.getTextColourLine( i ) colours[i] = this.page.getTextColourLine( i )
.toString(); .toString();
} }
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( this.m_pageTitle, lines, colours ); ItemStack stack = ItemPrintout.createSingleFromTitleAndText( this.pageTitle, lines, colours );
for( int slot : BOTTOM_SLOTS ) for( int slot : BOTTOM_SLOTS )
{ {
if( this.m_inventory.get( slot ) if( this.inventory.get( slot )
.isEmpty() ) .isEmpty() )
{ {
this.setStack( slot, stack ); this.setStack( slot, stack );
this.m_printing = false; this.printing = false;
return true; return true;
} }
} }
@@ -409,7 +409,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
int getInkLevel() int getInkLevel()
{ {
ItemStack inkStack = this.m_inventory.get( 0 ); ItemStack inkStack = this.inventory.get( 0 );
return isInk( inkStack ) ? inkStack.getCount() : 0; return isInk( inkStack ) ? inkStack.getCount() : 0;
} }
@@ -418,7 +418,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 = this.m_inventory.get( i ); ItemStack paperStack = this.inventory.get( i );
if( isPaper( paperStack ) ) if( isPaper( paperStack ) )
{ {
count += paperStack.getCount(); count += paperStack.getCount();
@@ -429,72 +429,72 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
void setPageTitle( String title ) void setPageTitle( String title )
{ {
synchronized( this.m_page ) synchronized( this.page )
{ {
if( this.m_printing ) if( this.printing )
{ {
this.m_pageTitle = title; this.pageTitle = title;
} }
} }
} }
private boolean canInputPage() private boolean canInputPage()
{ {
ItemStack inkStack = this.m_inventory.get( 0 ); ItemStack inkStack = this.inventory.get( 0 );
return !inkStack.isEmpty() && isInk( inkStack ) && this.getPaperLevel() > 0; return !inkStack.isEmpty() && isInk( inkStack ) && this.getPaperLevel() > 0;
} }
private boolean inputPage() private boolean inputPage()
{ {
ItemStack inkStack = this.m_inventory.get( 0 ); ItemStack inkStack = this.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 = this.m_inventory.get( i ); ItemStack paperStack = this.inventory.get( i );
if( paperStack.isEmpty() || !isPaper( paperStack ) ) if( paperStack.isEmpty() || !isPaper( paperStack ) )
{ {
continue; continue;
} }
// Setup the new page // Setup the new page
m_page.setTextColour( dye.getId() ); page.setTextColour( dye.getId() );
this.m_page.clear(); this.page.clear();
if( paperStack.getItem() instanceof ItemPrintout ) if( paperStack.getItem() instanceof ItemPrintout )
{ {
this.m_pageTitle = ItemPrintout.getTitle( paperStack ); this.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 < this.m_page.getHeight(); y++ ) for( int y = 0; y < this.page.getHeight(); y++ )
{ {
this.m_page.setLine( y, text[y], textColour[y], "" ); this.page.setLine( y, text[y], textColour[y], "" );
} }
} }
else else
{ {
this.m_pageTitle = ""; this.pageTitle = "";
} }
this.m_page.setCursorPos( 0, 0 ); this.page.setCursorPos( 0, 0 );
// Decrement ink // Decrement ink
inkStack.decrement( 1 ); inkStack.decrement( 1 );
if( inkStack.isEmpty() ) if( inkStack.isEmpty() )
{ {
this.m_inventory.set( 0, ItemStack.EMPTY ); this.inventory.set( 0, ItemStack.EMPTY );
} }
// Decrement paper // Decrement paper
paperStack.decrement( 1 ); paperStack.decrement( 1 );
if( paperStack.isEmpty() ) if( paperStack.isEmpty() )
{ {
this.m_inventory.set( i, ItemStack.EMPTY ); this.inventory.set( i, ItemStack.EMPTY );
this.updateBlockState(); this.updateBlockState();
} }
this.markDirty(); this.markDirty();
this.m_printing = true; this.printing = true;
return true; return true;
} }
return false; return false;

View File

@@ -34,19 +34,19 @@ import static dan200.computercraft.api.lua.LuaValues.checkFinite;
*/ */
public abstract class SpeakerPeripheral implements IPeripheral public abstract class SpeakerPeripheral implements IPeripheral
{ {
private final AtomicInteger m_notesThisTick = new AtomicInteger(); private final AtomicInteger notesThisTick = new AtomicInteger();
private long m_clock = 0; private long clock = 0;
private long m_lastPlayTime = 0; private long lastPlayTime = 0;
public void update() public void update()
{ {
this.m_clock++; this.clock++;
this.m_notesThisTick.set( 0 ); this.notesThisTick.set( 0 );
} }
public boolean madeSound( long ticks ) public boolean madeSound( long ticks )
{ {
return this.m_clock - this.m_lastPlayTime <= ticks; return this.clock - this.lastPlayTime <= ticks;
} }
@Nonnull @Nonnull
@@ -90,7 +90,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
private synchronized boolean playSound( ILuaContext context, Identifier name, float volume, float pitch, boolean isNote ) throws LuaException private synchronized boolean playSound( ILuaContext context, Identifier name, float volume, float pitch, boolean isNote ) throws LuaException
{ {
if( this.m_clock - this.m_lastPlayTime < TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS && (!isNote || this.m_clock - this.m_lastPlayTime != 0 || this.m_notesThisTick.get() >= ComputerCraft.maxNotesPerTick) ) if( this.clock - this.lastPlayTime < TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS && (!isNote || this.clock - this.lastPlayTime != 0 || this.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.
@@ -119,7 +119,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
return null; return null;
} ); } );
this.m_lastPlayTime = this.m_clock; this.lastPlayTime = this.clock;
return true; return true;
} }
@@ -173,7 +173,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
true ); true );
if( success ) if( success )
{ {
this.m_notesThisTick.incrementAndGet(); this.notesThisTick.incrementAndGet();
} }
return success; return success;
} }

View File

@@ -36,9 +36,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 )
{ {
@@ -49,8 +49,8 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public Entity getEntity() public Entity getEntity()
{ {
Entity entity = this.m_entity; Entity entity = this.entity;
if( entity == null || this.m_stack == null || !entity.isAlive() ) if( entity == null || this.stack == null || !entity.isAlive() )
{ {
return null; return null;
} }
@@ -58,12 +58,12 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
if( entity instanceof PlayerEntity ) if( entity instanceof PlayerEntity )
{ {
PlayerInventory inventory = ((PlayerEntity) entity).inventory; PlayerInventory inventory = ((PlayerEntity) entity).inventory;
return inventory.main.contains( this.m_stack ) || inventory.offHand.contains( this.m_stack ) ? entity : null; return inventory.main.contains( this.stack ) || inventory.offHand.contains( this.stack ) ? entity : null;
} }
else if( entity instanceof LivingEntity ) else if( entity instanceof LivingEntity )
{ {
LivingEntity living = (LivingEntity) entity; LivingEntity living = (LivingEntity) entity;
return living.getMainHandStack() == this.m_stack || living.getOffHandStack() == this.m_stack ? entity : null; return living.getMainHandStack() == this.stack || living.getOffHandStack() == this.stack ? entity : null;
} }
else else
{ {
@@ -74,13 +74,13 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public int getColour() public int getColour()
{ {
return IColouredItem.getColourBasic( this.m_stack ); return IColouredItem.getColourBasic( this.stack );
} }
@Override @Override
public void setColour( int colour ) public void setColour( int colour )
{ {
IColouredItem.setColourBasic( this.m_stack, colour ); IColouredItem.setColourBasic( this.stack, colour );
this.updateUpgradeNBTData(); this.updateUpgradeNBTData();
} }
@@ -114,22 +114,22 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public CompoundTag getUpgradeNBTData() public CompoundTag getUpgradeNBTData()
{ {
return ItemPocketComputer.getUpgradeInfo( this.m_stack ); return ItemPocketComputer.getUpgradeInfo( this.stack );
} }
@Override @Override
public void updateUpgradeNBTData() public void updateUpgradeNBTData()
{ {
if( this.m_entity instanceof PlayerEntity ) if( this.entity instanceof PlayerEntity )
{ {
((PlayerEntity) this.m_entity).inventory.markDirty(); ((PlayerEntity) this.entity).inventory.markDirty();
} }
} }
@Override @Override
public void invalidatePeripheral() public void invalidatePeripheral()
{ {
IPeripheral peripheral = this.m_upgrade == null ? null : this.m_upgrade.createPeripheral( this ); IPeripheral peripheral = this.upgrade == null ? null : this.upgrade.createPeripheral( this );
this.setPeripheral( ComputerSide.BACK, peripheral ); this.setPeripheral( ComputerSide.BACK, peripheral );
} }
@@ -137,12 +137,12 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public Map<Identifier, IPeripheral> getUpgrades() public Map<Identifier, IPeripheral> getUpgrades()
{ {
return this.m_upgrade == null ? Collections.emptyMap() : Collections.singletonMap( this.m_upgrade.getUpgradeID(), this.getPeripheral( ComputerSide.BACK ) ); return this.upgrade == null ? Collections.emptyMap() : Collections.singletonMap( this.upgrade.getUpgradeID(), this.getPeripheral( ComputerSide.BACK ) );
} }
public IPocketUpgrade getUpgrade() public IPocketUpgrade getUpgrade()
{ {
return this.m_upgrade; return this.upgrade;
} }
/** /**
@@ -154,16 +154,16 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
*/ */
public void setUpgrade( IPocketUpgrade upgrade ) public void setUpgrade( IPocketUpgrade upgrade )
{ {
if( this.m_upgrade == upgrade ) if( this.upgrade == upgrade )
{ {
return; return;
} }
synchronized( this ) synchronized( this )
{ {
ItemPocketComputer.setUpgrade( this.m_stack, upgrade ); ItemPocketComputer.setUpgrade( this.stack, upgrade );
this.updateUpgradeNBTData(); this.updateUpgradeNBTData();
this.m_upgrade = upgrade; this.upgrade = upgrade;
this.invalidatePeripheral(); this.invalidatePeripheral();
} }
} }
@@ -177,17 +177,17 @@ 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 != this.m_entity && entity instanceof ServerPlayerEntity ) if( entity != this.entity && entity instanceof ServerPlayerEntity )
{ {
this.markTerminalChanged(); this.markTerminalChanged();
} }
this.m_entity = entity; this.entity = entity;
this.m_stack = stack; this.stack = stack;
if( this.m_upgrade != upgrade ) if( this.upgrade != upgrade )
{ {
this.m_upgrade = upgrade; this.upgrade = upgrade;
this.invalidatePeripheral(); this.invalidatePeripheral();
} }
} }
@@ -197,10 +197,10 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
{ {
super.broadcastState( force ); super.broadcastState( force );
if( (this.hasTerminalChanged() || force) && this.m_entity instanceof ServerPlayerEntity ) if( (this.hasTerminalChanged() || force) && this.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) this.m_entity; ServerPlayerEntity player = (ServerPlayerEntity) this.entity;
if( player.networkHandler != null && !this.isInteracting( player ) ) if( player.networkHandler != null && !this.isInteracting( player ) )
{ {
NetworkHandler.sendToPlayer( player, this.createTerminalPacket() ); NetworkHandler.sendToPlayer( player, this.createTerminalPacket() );

View File

@@ -51,11 +51,11 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public static final int INVENTORY_SIZE = 16; public static final int INVENTORY_SIZE = 16;
public static final int INVENTORY_WIDTH = 4; public static final int INVENTORY_WIDTH = 4;
public static final int INVENTORY_HEIGHT = 4; public static final int INVENTORY_HEIGHT = 4;
private final DefaultedList<ItemStack> m_inventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY ); private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY );
private final DefaultedList<ItemStack> m_previousInventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY ); private final DefaultedList<ItemStack> previousInventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY );
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;
public TileTurtle( BlockEntityType<? extends TileGeneric> type, ComputerFamily family ) public TileTurtle( BlockEntityType<? extends TileGeneric> type, ComputerFamily family )
{ {
@@ -105,7 +105,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
private boolean hasMoved() private boolean hasMoved()
{ {
return this.m_moveState == MoveState.MOVED; return this.moveState == MoveState.MOVED;
} }
@Override @Override
@@ -117,7 +117,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public boolean isEmpty() public boolean isEmpty()
{ {
for( ItemStack stack : this.m_inventory ) for( ItemStack stack : this.inventory )
{ {
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
@@ -131,7 +131,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public ItemStack getStack( int slot ) public ItemStack getStack( int slot )
{ {
return slot >= 0 && slot < INVENTORY_SIZE ? this.m_inventory.get( slot ) : ItemStack.EMPTY; return slot >= 0 && slot < INVENTORY_SIZE ? this.inventory.get( slot ) : ItemStack.EMPTY;
} }
@Nonnull @Nonnull
@@ -172,9 +172,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public void setStack( int i, @Nonnull ItemStack stack ) public void setStack( int i, @Nonnull ItemStack stack )
{ {
if( i >= 0 && i < INVENTORY_SIZE && !InventoryUtil.areItemsEqual( stack, this.m_inventory.get( i ) ) ) if( i >= 0 && i < INVENTORY_SIZE && !InventoryUtil.areItemsEqual( stack, this.inventory.get( i ) ) )
{ {
this.m_inventory.set( i, stack ); this.inventory.set( i, stack );
this.onInventoryDefinitelyChanged(); this.onInventoryDefinitelyChanged();
} }
} }
@@ -188,7 +188,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
private void onInventoryDefinitelyChanged() private void onInventoryDefinitelyChanged()
{ {
super.markDirty(); super.markDirty();
this.m_inventoryChanged = true; this.inventoryChanged = true;
} }
@Override @Override
@@ -211,9 +211,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
if( !this.getWorld().isClient ) if( !this.getWorld().isClient )
{ {
DyeColor dye = ((DyeItem) currentItem.getItem()).getColor(); DyeColor dye = ((DyeItem) currentItem.getItem()).getColor();
if( this.m_brain.getDyeColour() != dye ) if( this.brain.getDyeColour() != dye )
{ {
this.m_brain.setDyeColour( dye ); this.brain.setDyeColour( dye );
if( !player.isCreative() ) if( !player.isCreative() )
{ {
currentItem.decrement( 1 ); currentItem.decrement( 1 );
@@ -222,14 +222,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
} }
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
else if( currentItem.getItem() == Items.WATER_BUCKET && this.m_brain.getColour() != -1 ) else if( currentItem.getItem() == Items.WATER_BUCKET && this.brain.getColour() != -1 )
{ {
// Water to remove turtle colour // Water to remove turtle colour
if( !this.getWorld().isClient ) if( !this.getWorld().isClient )
{ {
if( this.m_brain.getColour() != -1 ) if( this.brain.getColour() != -1 )
{ {
this.m_brain.setColour( -1 ); this.brain.setColour( -1 );
if( !player.isCreative() ) if( !player.isCreative() )
{ {
player.setStackInHand( hand, new ItemStack( Items.BUCKET ) ); player.setStackInHand( hand, new ItemStack( Items.BUCKET ) );
@@ -248,7 +248,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public void onNeighbourChange( @Nonnull BlockPos neighbour ) public void onNeighbourChange( @Nonnull BlockPos neighbour )
{ {
if( this.m_moveState == MoveState.NOT_MOVED ) if( this.moveState == MoveState.NOT_MOVED )
{ {
super.onNeighbourChange( neighbour ); super.onNeighbourChange( neighbour );
} }
@@ -257,7 +257,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override @Override
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
{ {
if( this.m_moveState == MoveState.NOT_MOVED ) if( this.moveState == MoveState.NOT_MOVED )
{ {
super.onNeighbourTileEntityChange( neighbour ); super.onNeighbourTileEntityChange( neighbour );
} }
@@ -267,8 +267,8 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public void tick() public void tick()
{ {
super.tick(); super.tick();
this.m_brain.update(); this.brain.update();
if( !this.getWorld().isClient && this.m_inventoryChanged ) if( !this.getWorld().isClient && this.inventoryChanged )
{ {
ServerComputer computer = this.getServerComputer(); ServerComputer computer = this.getServerComputer();
if( computer != null ) if( computer != null )
@@ -276,10 +276,10 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
computer.queueEvent( "turtle_inventory" ); computer.queueEvent( "turtle_inventory" );
} }
this.m_inventoryChanged = false; this.inventoryChanged = false;
for( int n = 0; n < this.size(); n++ ) for( int n = 0; n < this.size(); n++ )
{ {
this.m_previousInventory.set( n, this.previousInventory.set( n,
this.getStack( n ).copy() ); this.getStack( n ).copy() );
} }
} }
@@ -298,12 +298,12 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
ListTag nbttaglist = new ListTag(); ListTag nbttaglist = new ListTag();
for( int i = 0; i < INVENTORY_SIZE; i++ ) for( int i = 0; i < INVENTORY_SIZE; i++ )
{ {
if( !this.m_inventory.get( i ) if( !this.inventory.get( i )
.isEmpty() ) .isEmpty() )
{ {
CompoundTag tag = new CompoundTag(); CompoundTag tag = new CompoundTag();
tag.putByte( "Slot", (byte) i ); tag.putByte( "Slot", (byte) i );
this.m_inventory.get( i ) this.inventory.get( i )
.toTag( tag ); .toTag( tag );
nbttaglist.add( tag ); nbttaglist.add( tag );
} }
@@ -311,7 +311,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
nbt.put( "Items", nbttaglist ); nbt.put( "Items", nbttaglist );
// Write brain // Write brain
nbt = this.m_brain.writeToNBT( nbt ); nbt = this.brain.writeToNBT( nbt );
return super.toTag( nbt ); return super.toTag( nbt );
} }
@@ -325,22 +325,22 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Read inventory // Read inventory
ListTag nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND ); ListTag nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND );
this.m_inventory.clear(); this.inventory.clear();
this.m_previousInventory.clear(); this.previousInventory.clear();
for( int i = 0; i < nbttaglist.size(); i++ ) for( int i = 0; i < nbttaglist.size(); i++ )
{ {
CompoundTag tag = nbttaglist.getCompound( i ); CompoundTag tag = nbttaglist.getCompound( i );
int slot = tag.getByte( "Slot" ) & 0xff; int slot = tag.getByte( "Slot" ) & 0xff;
if( slot < this.size() ) if( slot < this.size() )
{ {
this.m_inventory.set( slot, ItemStack.fromTag( tag ) ); this.inventory.set( slot, ItemStack.fromTag( tag ) );
this.m_previousInventory.set( slot, this.m_inventory.get( slot ) this.previousInventory.set( slot, this.inventory.get( slot )
.copy() ); .copy() );
} }
} }
// Read state // Read state
this.m_brain.readFromNBT( nbt ); this.brain.readFromNBT( nbt );
} }
@Override @Override
@@ -367,7 +367,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
ComputerCraft.turtleTermHeight ); ComputerCraft.turtleTermHeight );
computer.setPosition( this.getPos() ); computer.setPosition( this.getPos() );
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), this.getAccess() ) ); computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), this.getAccess() ) );
this.m_brain.setupComputer( computer ); this.brain.setupComputer( computer );
return computer; return computer;
} }
@@ -375,20 +375,20 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
protected void writeDescription( @Nonnull CompoundTag nbt ) protected void writeDescription( @Nonnull CompoundTag nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
this.m_brain.writeDescription( nbt ); this.brain.writeDescription( nbt );
} }
@Override @Override
protected void readDescription( @Nonnull CompoundTag nbt ) protected void readDescription( @Nonnull CompoundTag nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
this.m_brain.readDescription( nbt ); this.brain.readDescription( nbt );
} }
@Override @Override
public ComputerProxy createProxy() public ComputerProxy createProxy()
{ {
return this.m_brain.getProxy(); return this.brain.getProxy();
} }
public void setDirection( Direction dir ) public void setDirection( Direction dir )
@@ -437,66 +437,66 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public void notifyMoveStart() public void notifyMoveStart()
{ {
if( this.m_moveState == MoveState.NOT_MOVED ) if( this.moveState == MoveState.NOT_MOVED )
{ {
this.m_moveState = MoveState.IN_PROGRESS; this.moveState = MoveState.IN_PROGRESS;
} }
} }
public void notifyMoveEnd() public void notifyMoveEnd()
{ {
// MoveState.MOVED is final // MoveState.MOVED is final
if( this.m_moveState == MoveState.IN_PROGRESS ) if( this.moveState == MoveState.IN_PROGRESS )
{ {
this.m_moveState = MoveState.NOT_MOVED; this.moveState = MoveState.NOT_MOVED;
} }
} }
@Override @Override
public int getColour() public int getColour()
{ {
return this.m_brain.getColour(); return this.brain.getColour();
} }
@Override @Override
public Identifier getOverlay() public Identifier getOverlay()
{ {
return this.m_brain.getOverlay(); return this.brain.getOverlay();
} }
@Override @Override
public ITurtleUpgrade getUpgrade( TurtleSide side ) public ITurtleUpgrade getUpgrade( TurtleSide side )
{ {
return this.m_brain.getUpgrade( side ); return this.brain.getUpgrade( side );
} }
@Override @Override
public ITurtleAccess getAccess() public ITurtleAccess getAccess()
{ {
return this.m_brain; return this.brain;
} }
@Override @Override
public Vec3d getRenderOffset( float f ) public Vec3d getRenderOffset( float f )
{ {
return this.m_brain.getRenderOffset( f ); return this.brain.getRenderOffset( f );
} }
@Override @Override
public float getRenderYaw( float f ) public float getRenderYaw( float f )
{ {
return this.m_brain.getVisualYaw( f ); return this.brain.getVisualYaw( f );
} }
@Override @Override
public float getToolRenderAngle( TurtleSide side, float f ) public float getToolRenderAngle( TurtleSide side, float f )
{ {
return this.m_brain.getToolRenderAngle( side, f ); return this.brain.getToolRenderAngle( side, f );
} }
void setOwningPlayer( GameProfile player ) void setOwningPlayer( GameProfile player )
{ {
this.m_brain.setOwningPlayer( player ); this.brain.setOwningPlayer( player );
this.markDirty(); this.markDirty();
} }
@@ -506,13 +506,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
public void markDirty() public void markDirty()
{ {
super.markDirty(); super.markDirty();
if( !this.m_inventoryChanged ) if( !this.inventoryChanged )
{ {
for( int n = 0; n < this.size(); n++ ) for( int n = 0; n < this.size(); n++ )
{ {
if( !ItemStack.areEqual( this.getStack( n ), this.m_previousInventory.get( n ) ) ) if( !ItemStack.areEqual( this.getStack( n ), this.previousInventory.get( n ) ) )
{ {
this.m_inventoryChanged = true; this.inventoryChanged = true;
break; break;
} }
} }
@@ -525,10 +525,10 @@ 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( !this.m_inventory.get( i ) if( !this.inventory.get( i )
.isEmpty() ) .isEmpty() )
{ {
this.m_inventory.set( i, ItemStack.EMPTY ); this.inventory.set( i, ItemStack.EMPTY );
changed = true; changed = true;
} }
} }
@@ -544,21 +544,21 @@ 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( this.m_inventory, copy.m_inventory ); Collections.copy( this.inventory, copy.inventory );
Collections.copy( this.m_previousInventory, copy.m_previousInventory ); Collections.copy( this.previousInventory, copy.previousInventory );
this.m_inventoryChanged = copy.m_inventoryChanged; this.inventoryChanged = copy.inventoryChanged;
this.m_brain = copy.m_brain; this.brain = copy.brain;
this.m_brain.setOwner( this ); 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;
} }
@Nullable @Nullable
@Override @Override
public ScreenHandler createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ) public ScreenHandler createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player )
{ {
return new ContainerTurtle( id, inventory, this.m_brain ); return new ContainerTurtle( id, inventory, this.brain );
} }
enum MoveState enum MoveState

View File

@@ -59,51 +59,51 @@ public class TurtleBrain implements ITurtleAccess
private static final String NBT_SLOT = "Slot"; private static final String NBT_SLOT = "Slot";
private static final int ANIM_DURATION = 8; private static final int ANIM_DURATION = 8;
private final Queue<TurtleCommandQueueEntry> m_commandQueue = new ArrayDeque<>(); private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>();
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, CompoundTag> m_upgradeNBTData = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, CompoundTag> upgradeNBTData = new EnumMap<>( TurtleSide.class );
TurtlePlayer m_cachedPlayer; TurtlePlayer cachedPlayer;
private TileTurtle m_owner; private TileTurtle owner;
private final Inventory m_inventory = (InventoryDelegate) () -> this.m_owner; private final Inventory inventory = (InventoryDelegate) () -> this.owner;
private ComputerProxy m_proxy; private ComputerProxy proxy;
private GameProfile m_owningPlayer; private GameProfile owningPlayer;
private int m_commandsIssued = 0; private int commandsIssued = 0;
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 Identifier m_overlay = null; private Identifier 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;
public TurtleBrain( TileTurtle turtle ) public TurtleBrain( TileTurtle turtle )
{ {
this.m_owner = turtle; this.owner = turtle;
} }
public TileTurtle getOwner() public TileTurtle getOwner()
{ {
return this.m_owner; return this.owner;
} }
public void setOwner( TileTurtle owner ) public void setOwner( TileTurtle owner )
{ {
this.m_owner = owner; this.owner = owner;
} }
public ComputerProxy getProxy() public ComputerProxy getProxy()
{ {
if( this.m_proxy == null ) if( this.proxy == null )
{ {
this.m_proxy = new ComputerProxy( () -> this.m_owner ); this.proxy = new ComputerProxy( () -> this.owner );
} }
return this.m_proxy; return this.proxy;
} }
public ComputerFamily getFamily() public ComputerFamily getFamily()
{ {
return this.m_owner.getFamily(); return this.owner.getFamily();
} }
public void setupComputer( ServerComputer computer ) public void setupComputer( ServerComputer computer )
@@ -168,16 +168,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
this.updateAnimation(); this.updateAnimation();
// Advance upgrades // Advance upgrades
if( !this.m_upgrades.isEmpty() ) if( !this.upgrades.isEmpty() )
{ {
for( Map.Entry<TurtleSide, ITurtleUpgrade> entry : this.m_upgrades.entrySet() ) for( Map.Entry<TurtleSide, ITurtleUpgrade> entry : this.upgrades.entrySet() )
{ {
entry.getValue() entry.getValue()
.update( this, entry.getKey() ); .update( this, entry.getKey() );
@@ -189,14 +189,14 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public World getWorld() public World getWorld()
{ {
return this.m_owner.getWorld(); return this.owner.getWorld();
} }
@Nonnull @Nonnull
@Override @Override
public BlockPos getPosition() public BlockPos getPosition()
{ {
return this.m_owner.getPos(); return this.owner.getPos();
} }
@Override @Override
@@ -209,9 +209,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 = this.getWorld(); World oldWorld = this.getWorld();
TileTurtle oldOwner = this.m_owner; TileTurtle oldOwner = this.owner;
BlockPos oldPos = this.m_owner.getPos(); BlockPos oldPos = this.owner.getPos();
BlockState oldBlock = this.m_owner.getCachedState(); BlockState oldBlock = this.owner.getCachedState();
if( oldWorld == world && oldPos.equals( pos ) ) if( oldWorld == world && oldPos.equals( pos ) )
{ {
@@ -292,7 +292,7 @@ public class TurtleBrain implements ITurtleAccess
public Vec3d getVisualPosition( float f ) public Vec3d getVisualPosition( float f )
{ {
Vec3d offset = this.getRenderOffset( f ); Vec3d offset = this.getRenderOffset( f );
BlockPos pos = this.m_owner.getPos(); BlockPos pos = this.owner.getPos();
return new Vec3d( pos.getX() + 0.5 + offset.x, pos.getY() + 0.5 + offset.y, pos.getZ() + 0.5 + offset.z ); return new Vec3d( pos.getX() + 0.5 + offset.x, pos.getY() + 0.5 + offset.y, pos.getZ() + 0.5 + offset.z );
} }
@@ -300,7 +300,7 @@ public class TurtleBrain implements ITurtleAccess
public float getVisualYaw( float f ) public float getVisualYaw( float f )
{ {
float yaw = this.getDirection().asRotation(); float yaw = this.getDirection().asRotation();
switch( this.m_animation ) switch( this.animation )
{ {
case TURN_LEFT: case TURN_LEFT:
{ {
@@ -328,19 +328,19 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public Direction getDirection() public Direction getDirection()
{ {
return this.m_owner.getDirection(); return this.owner.getDirection();
} }
@Override @Override
public void setDirection( @Nonnull Direction dir ) public void setDirection( @Nonnull Direction dir )
{ {
this.m_owner.setDirection( dir ); this.owner.setDirection( dir );
} }
@Override @Override
public int getSelectedSlot() public int getSelectedSlot()
{ {
return this.m_selectedSlot; return this.selectedSlot;
} }
@Override @Override
@@ -351,17 +351,17 @@ public class TurtleBrain implements ITurtleAccess
throw new UnsupportedOperationException( "Cannot set the slot on the client" ); throw new UnsupportedOperationException( "Cannot set the slot on the client" );
} }
if( slot >= 0 && slot < this.m_owner.size() ) if( slot >= 0 && slot < this.owner.size() )
{ {
this.m_selectedSlot = slot; this.selectedSlot = slot;
this.m_owner.onTileEntityChange(); this.owner.onTileEntityChange();
} }
} }
@Override @Override
public int getColour() public int getColour()
{ {
return this.m_colourHex; return this.colourHex;
} }
@Override @Override
@@ -369,16 +369,16 @@ public class TurtleBrain implements ITurtleAccess
{ {
if( colour >= 0 && colour <= 0xFFFFFF ) if( colour >= 0 && colour <= 0xFFFFFF )
{ {
if( this.m_colourHex != colour ) if( this.colourHex != colour )
{ {
this.m_colourHex = colour; this.colourHex = colour;
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
} }
else if( this.m_colourHex != -1 ) else if( this.colourHex != -1 )
{ {
this.m_colourHex = -1; this.colourHex = -1;
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
} }
@@ -386,7 +386,7 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public GameProfile getOwningPlayer() public GameProfile getOwningPlayer()
{ {
return this.m_owningPlayer; return this.owningPlayer;
} }
@Override @Override
@@ -398,20 +398,20 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public int getFuelLevel() public int getFuelLevel()
{ {
return Math.min( this.m_fuelLevel, this.getFuelLimit() ); return Math.min( this.fuelLevel, this.getFuelLimit() );
} }
@Override @Override
public void setFuelLevel( int level ) public void setFuelLevel( int level )
{ {
this.m_fuelLevel = Math.min( level, this.getFuelLimit() ); this.fuelLevel = Math.min( level, this.getFuelLimit() );
this.m_owner.onTileEntityChange(); this.owner.onTileEntityChange();
} }
@Override @Override
public int getFuelLimit() public int getFuelLimit()
{ {
if( this.m_owner.getFamily() == ComputerFamily.ADVANCED ) if( this.owner.getFamily() == ComputerFamily.ADVANCED )
{ {
return ComputerCraft.advancedTurtleFuelLimit; return ComputerCraft.advancedTurtleFuelLimit;
} }
@@ -471,8 +471,8 @@ public class TurtleBrain implements ITurtleAccess
private int issueCommand( ITurtleCommand command ) private int issueCommand( ITurtleCommand command )
{ {
this.m_commandQueue.offer( new TurtleCommandQueueEntry( ++this.m_commandsIssued, command ) ); this.commandQueue.offer( new TurtleCommandQueueEntry( ++this.commandsIssued, command ) );
return this.m_commandsIssued; return this.commandsIssued;
} }
@Override @Override
@@ -483,37 +483,37 @@ public class TurtleBrain implements ITurtleAccess
throw new UnsupportedOperationException( "Cannot play animations on the client" ); throw new UnsupportedOperationException( "Cannot play animations on the client" );
} }
this.m_animation = animation; this.animation = animation;
if( this.m_animation == TurtleAnimation.SHORT_WAIT ) if( this.animation == TurtleAnimation.SHORT_WAIT )
{ {
this.m_animationProgress = ANIM_DURATION / 2; this.animationProgress = ANIM_DURATION / 2;
this.m_lastAnimationProgress = ANIM_DURATION / 2; this.lastAnimationProgress = ANIM_DURATION / 2;
} }
else else
{ {
this.m_animationProgress = 0; this.animationProgress = 0;
this.m_lastAnimationProgress = 0; this.lastAnimationProgress = 0;
} }
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
@Override @Override
public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side ) public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side )
{ {
return this.m_upgrades.get( side ); return this.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( this.m_upgrades.containsKey( side ) ) if( this.upgrades.containsKey( side ) )
{ {
if( this.m_upgrades.get( side ) == upgrade ) if( this.upgrades.get( side ) == upgrade )
{ {
return; return;
} }
this.m_upgrades.remove( side ); this.upgrades.remove( side );
} }
else else
{ {
@@ -523,19 +523,19 @@ public class TurtleBrain implements ITurtleAccess
} }
} }
this.m_upgradeNBTData.remove( side ); this.upgradeNBTData.remove( side );
// Set new upgrade // Set new upgrade
if( upgrade != null ) if( upgrade != null )
{ {
this.m_upgrades.put( side, upgrade ); this.upgrades.put( side, upgrade );
} }
// Notify clients and create peripherals // Notify clients and create peripherals
if( this.m_owner.getWorld() != null ) if( this.owner.getWorld() != null )
{ {
this.updatePeripherals( this.m_owner.createServerComputer() ); this.updatePeripherals( this.owner.createServerComputer() );
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
} }
@@ -549,10 +549,10 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public CompoundTag getUpgradeNBTData( TurtleSide side ) public CompoundTag getUpgradeNBTData( TurtleSide side )
{ {
CompoundTag nbt = this.m_upgradeNBTData.get( side ); CompoundTag nbt = this.upgradeNBTData.get( side );
if( nbt == null ) if( nbt == null )
{ {
this.m_upgradeNBTData.put( side, nbt = new CompoundTag() ); this.upgradeNBTData.put( side, nbt = new CompoundTag() );
} }
return nbt; return nbt;
} }
@@ -560,30 +560,30 @@ public class TurtleBrain implements ITurtleAccess
@Override @Override
public void updateUpgradeNBTData( @Nonnull TurtleSide side ) public void updateUpgradeNBTData( @Nonnull TurtleSide side )
{ {
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
@Nonnull @Nonnull
@Override @Override
public Inventory getInventory() public Inventory getInventory()
{ {
return this.m_inventory; return this.inventory;
} }
public void setOwningPlayer( GameProfile profile ) public void setOwningPlayer( GameProfile profile )
{ {
this.m_owningPlayer = profile; this.owningPlayer = profile;
} }
private void updateCommands() private void updateCommands()
{ {
if( this.m_animation != TurtleAnimation.NONE || this.m_commandQueue.isEmpty() ) if( this.animation != TurtleAnimation.NONE || this.commandQueue.isEmpty() )
{ {
return; 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 = this.m_owner.getServerComputer(); ServerComputer computer = this.owner.getServerComputer();
if( computer != null && !computer.getComputer() if( computer != null && !computer.getComputer()
.getMainThreadMonitor() .getMainThreadMonitor()
.canWork() ) .canWork() )
@@ -592,7 +592,7 @@ public class TurtleBrain implements ITurtleAccess
} }
// Pull a new command // Pull a new command
TurtleCommandQueueEntry nextCommand = this.m_commandQueue.poll(); TurtleCommandQueueEntry nextCommand = this.commandQueue.poll();
if( nextCommand == null ) if( nextCommand == null )
{ {
return; return;
@@ -648,18 +648,18 @@ public class TurtleBrain implements ITurtleAccess
private void updateAnimation() private void updateAnimation()
{ {
if( this.m_animation != TurtleAnimation.NONE ) if( this.animation != TurtleAnimation.NONE )
{ {
World world = this.getWorld(); World world = this.getWorld();
if( ComputerCraft.turtlesCanPush ) if( ComputerCraft.turtlesCanPush )
{ {
// Advance entity pushing // Advance entity pushing
if( this.m_animation == TurtleAnimation.MOVE_FORWARD || this.m_animation == TurtleAnimation.MOVE_BACK || this.m_animation == TurtleAnimation.MOVE_UP || this.m_animation == TurtleAnimation.MOVE_DOWN ) if( this.animation == TurtleAnimation.MOVE_FORWARD || this.animation == TurtleAnimation.MOVE_BACK || this.animation == TurtleAnimation.MOVE_UP || this.animation == TurtleAnimation.MOVE_DOWN )
{ {
BlockPos pos = this.getPosition(); BlockPos pos = this.getPosition();
Direction moveDir; Direction moveDir;
switch( this.m_animation ) switch( this.animation )
{ {
case MOVE_FORWARD: case MOVE_FORWARD:
default: default:
@@ -683,7 +683,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) (this.m_animationProgress + 1) / ANIM_DURATION; float pushFrac = 1.0f - (float) (this.animationProgress + 1) / ANIM_DURATION;
float push = Math.max( pushFrac + 0.0125f, 0.0f ); float push = Math.max( pushFrac + 0.0125f, 0.0f );
if( moveDir.getOffsetX() < 0 ) if( moveDir.getOffsetX() < 0 )
{ {
@@ -729,7 +729,7 @@ public class TurtleBrain implements ITurtleAccess
} }
// Advance valentines day easter egg // Advance valentines day easter egg
if( world.isClient && this.m_animation == TurtleAnimation.MOVE_FORWARD && this.m_animationProgress == 4 ) if( world.isClient && this.animation == TurtleAnimation.MOVE_FORWARD && this.animationProgress == 4 )
{ {
// Spawn love pfx if valentines day // Spawn love pfx if valentines day
Holiday currentHoliday = HolidayUtil.getCurrentHoliday(); Holiday currentHoliday = HolidayUtil.getCurrentHoliday();
@@ -753,19 +753,19 @@ public class TurtleBrain implements ITurtleAccess
} }
// Wait for anim completion // Wait for anim completion
this.m_lastAnimationProgress = this.m_animationProgress; this.lastAnimationProgress = this.animationProgress;
if( ++this.m_animationProgress >= ANIM_DURATION ) if( ++this.animationProgress >= ANIM_DURATION )
{ {
this.m_animation = TurtleAnimation.NONE; this.animation = TurtleAnimation.NONE;
this.m_animationProgress = 0; this.animationProgress = 0;
this.m_lastAnimationProgress = 0; this.lastAnimationProgress = 0;
} }
} }
} }
public Vec3d getRenderOffset( float f ) public Vec3d getRenderOffset( float f )
{ {
switch( this.m_animation ) switch( this.animation )
{ {
case MOVE_FORWARD: case MOVE_FORWARD:
case MOVE_BACK: case MOVE_BACK:
@@ -774,7 +774,7 @@ public class TurtleBrain implements ITurtleAccess
{ {
// Get direction // Get direction
Direction dir; Direction dir;
switch( this.m_animation ) switch( this.animation )
{ {
case MOVE_FORWARD: case MOVE_FORWARD:
default: default:
@@ -803,8 +803,8 @@ public class TurtleBrain implements ITurtleAccess
private float getAnimationFraction( float f ) private float getAnimationFraction( float f )
{ {
float next = (float) this.m_animationProgress / ANIM_DURATION; float next = (float) this.animationProgress / ANIM_DURATION;
float previous = (float) this.m_lastAnimationProgress / ANIM_DURATION; float previous = (float) this.lastAnimationProgress / ANIM_DURATION;
return previous + (next - previous) * f; return previous + (next - previous) * f;
} }
@@ -813,17 +813,17 @@ public class TurtleBrain implements ITurtleAccess
this.readCommon( nbt ); this.readCommon( nbt );
// Read state // Read state
this.m_selectedSlot = nbt.getInt( NBT_SLOT ); this.selectedSlot = nbt.getInt( NBT_SLOT );
// Read owner // Read owner
if( nbt.contains( "Owner", NBTUtil.TAG_COMPOUND ) ) if( nbt.contains( "Owner", NBTUtil.TAG_COMPOUND ) )
{ {
CompoundTag owner = nbt.getCompound( "Owner" ); CompoundTag owner = nbt.getCompound( "Owner" );
this.m_owningPlayer = new GameProfile( new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ), owner.getString( "Name" ) ); this.owningPlayer = new GameProfile( new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ), owner.getString( "Name" ) );
} }
else else
{ {
this.m_owningPlayer = null; this.owningPlayer = null;
} }
} }
@@ -835,25 +835,25 @@ public class TurtleBrain implements ITurtleAccess
private void readCommon( CompoundTag nbt ) private void readCommon( CompoundTag nbt )
{ {
// Read fields // Read fields
this.m_colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1; this.colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1;
this.m_fuelLevel = nbt.contains( NBT_FUEL ) ? nbt.getInt( NBT_FUEL ) : 0; this.fuelLevel = nbt.contains( NBT_FUEL ) ? nbt.getInt( NBT_FUEL ) : 0;
this.m_overlay = nbt.contains( NBT_OVERLAY ) ? new Identifier( nbt.getString( NBT_OVERLAY ) ) : null; this.overlay = nbt.contains( NBT_OVERLAY ) ? new Identifier( nbt.getString( NBT_OVERLAY ) ) : null;
// Read upgrades // Read upgrades
this.setUpgrade( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null ); this.setUpgrade( TurtleSide.LEFT, nbt.contains( NBT_LEFT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_LEFT_UPGRADE ) ) : null );
this.setUpgrade( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null ); this.setUpgrade( TurtleSide.RIGHT, nbt.contains( NBT_RIGHT_UPGRADE ) ? TurtleUpgrades.get( nbt.getString( NBT_RIGHT_UPGRADE ) ) : null );
// NBT // NBT
this.m_upgradeNBTData.clear(); this.upgradeNBTData.clear();
if( nbt.contains( NBT_LEFT_UPGRADE_DATA ) ) if( nbt.contains( NBT_LEFT_UPGRADE_DATA ) )
{ {
this.m_upgradeNBTData.put( TurtleSide.LEFT, this.upgradeNBTData.put( TurtleSide.LEFT,
nbt.getCompound( NBT_LEFT_UPGRADE_DATA ) nbt.getCompound( NBT_LEFT_UPGRADE_DATA )
.copy() ); .copy() );
} }
if( nbt.contains( NBT_RIGHT_UPGRADE_DATA ) ) if( nbt.contains( NBT_RIGHT_UPGRADE_DATA ) )
{ {
this.m_upgradeNBTData.put( TurtleSide.RIGHT, this.upgradeNBTData.put( TurtleSide.RIGHT,
nbt.getCompound( NBT_RIGHT_UPGRADE_DATA ) nbt.getCompound( NBT_RIGHT_UPGRADE_DATA )
.copy() ); .copy() );
} }
@@ -864,19 +864,19 @@ public class TurtleBrain implements ITurtleAccess
this.writeCommon( nbt ); this.writeCommon( nbt );
// Write state // Write state
nbt.putInt( NBT_SLOT, this.m_selectedSlot ); nbt.putInt( NBT_SLOT, this.selectedSlot );
// Write owner // Write owner
if( this.m_owningPlayer != null ) if( this.owningPlayer != null )
{ {
CompoundTag owner = new CompoundTag(); CompoundTag owner = new CompoundTag();
nbt.put( "Owner", owner ); nbt.put( "Owner", owner );
owner.putLong( "UpperId", this.m_owningPlayer.getId() owner.putLong( "UpperId", this.owningPlayer.getId()
.getMostSignificantBits() ); .getMostSignificantBits() );
owner.putLong( "LowerId", this.m_owningPlayer.getId() owner.putLong( "LowerId", this.owningPlayer.getId()
.getLeastSignificantBits() ); .getLeastSignificantBits() );
owner.putString( "Name", this.m_owningPlayer.getName() ); owner.putString( "Name", this.owningPlayer.getName() );
} }
return nbt; return nbt;
@@ -884,14 +884,14 @@ public class TurtleBrain implements ITurtleAccess
private void writeCommon( CompoundTag nbt ) private void writeCommon( CompoundTag nbt )
{ {
nbt.putInt( NBT_FUEL, this.m_fuelLevel ); nbt.putInt( NBT_FUEL, this.fuelLevel );
if( this.m_colourHex != -1 ) if( this.colourHex != -1 )
{ {
nbt.putInt( NBT_COLOUR, this.m_colourHex ); nbt.putInt( NBT_COLOUR, this.colourHex );
} }
if( this.m_overlay != null ) if( this.overlay != null )
{ {
nbt.putString( NBT_OVERLAY, this.m_overlay.toString() ); nbt.putString( NBT_OVERLAY, this.overlay.toString() );
} }
// Write upgrades // Write upgrades
@@ -907,12 +907,12 @@ public class TurtleBrain implements ITurtleAccess
} }
// Write upgrade NBT // Write upgrade NBT
if( this.m_upgradeNBTData.containsKey( TurtleSide.LEFT ) ) if( this.upgradeNBTData.containsKey( TurtleSide.LEFT ) )
{ {
nbt.put( NBT_LEFT_UPGRADE_DATA, nbt.put( NBT_LEFT_UPGRADE_DATA,
this.getUpgradeNBTData( TurtleSide.LEFT ).copy() ); this.getUpgradeNBTData( TurtleSide.LEFT ).copy() );
} }
if( this.m_upgradeNBTData.containsKey( TurtleSide.RIGHT ) ) if( this.upgradeNBTData.containsKey( TurtleSide.RIGHT ) )
{ {
nbt.put( NBT_RIGHT_UPGRADE_DATA, nbt.put( NBT_RIGHT_UPGRADE_DATA,
this.getUpgradeNBTData( TurtleSide.RIGHT ).copy() ); this.getUpgradeNBTData( TurtleSide.RIGHT ).copy() );
@@ -931,41 +931,41 @@ public class TurtleBrain implements ITurtleAccess
// Animation // Animation
TurtleAnimation anim = TurtleAnimation.values()[nbt.getInt( "Animation" )]; TurtleAnimation anim = TurtleAnimation.values()[nbt.getInt( "Animation" )];
if( anim != this.m_animation && anim != TurtleAnimation.WAIT && anim != TurtleAnimation.SHORT_WAIT && anim != TurtleAnimation.NONE ) if( anim != this.animation && anim != TurtleAnimation.WAIT && anim != TurtleAnimation.SHORT_WAIT && anim != TurtleAnimation.NONE )
{ {
this.m_animation = anim; this.animation = anim;
this.m_animationProgress = 0; this.animationProgress = 0;
this.m_lastAnimationProgress = 0; this.lastAnimationProgress = 0;
} }
} }
public void writeDescription( CompoundTag nbt ) public void writeDescription( CompoundTag nbt )
{ {
this.writeCommon( nbt ); this.writeCommon( nbt );
nbt.putInt( "Animation", this.m_animation.ordinal() ); nbt.putInt( "Animation", this.animation.ordinal() );
} }
public Identifier getOverlay() public Identifier getOverlay()
{ {
return this.m_overlay; return this.overlay;
} }
public void setOverlay( Identifier overlay ) public void setOverlay( Identifier overlay )
{ {
if( !Objects.equal( this.m_overlay, overlay ) ) if( !Objects.equal( this.overlay, overlay ) )
{ {
this.m_overlay = overlay; this.overlay = overlay;
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
} }
public DyeColor getDyeColour() public DyeColor getDyeColour()
{ {
if( this.m_colourHex == -1 ) if( this.colourHex == -1 )
{ {
return null; return null;
} }
Colour colour = Colour.fromHex( this.m_colourHex ); Colour colour = Colour.fromHex( this.colourHex );
return colour == null ? null : DyeColor.byId( 15 - colour.ordinal() ); return colour == null ? null : DyeColor.byId( 15 - colour.ordinal() );
} }
@@ -976,16 +976,16 @@ public class TurtleBrain implements ITurtleAccess
{ {
newColour = Colour.values()[15 - dyeColour.getId()].getHex(); newColour = Colour.values()[15 - dyeColour.getId()].getHex();
} }
if( this.m_colourHex != newColour ) if( this.colourHex != newColour )
{ {
this.m_colourHex = newColour; this.colourHex = newColour;
this.m_owner.updateBlock(); this.owner.updateBlock();
} }
} }
public float getToolRenderAngle( TurtleSide side, float f ) public float getToolRenderAngle( TurtleSide side, float f )
{ {
return (side == TurtleSide.LEFT && this.m_animation == TurtleAnimation.SWING_LEFT_TOOL) || (side == TurtleSide.RIGHT && this.m_animation == TurtleAnimation.SWING_RIGHT_TOOL) ? 45.0f * (float) Math.sin( return (side == TurtleSide.LEFT && this.animation == TurtleAnimation.SWING_LEFT_TOOL) || (side == TurtleSide.RIGHT && this.animation == TurtleAnimation.SWING_RIGHT_TOOL) ? 45.0f * (float) Math.sin(
this.getAnimationFraction( f ) * Math.PI ) : 0.0f; this.getAnimationFraction( f ) * Math.PI ) : 0.0f;
} }

View File

@@ -22,11 +22,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 )
{ {
this.m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@@ -34,7 +34,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 = this.m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Get currently selected stack // Get currently selected stack
ItemStack selectedStack = turtle.getInventory() ItemStack selectedStack = turtle.getInventory()

View File

@@ -16,11 +16,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 )
{ {
this.m_slot = slot; this.slot = slot;
} }
@Nonnull @Nonnull
@@ -30,7 +30,7 @@ public class TurtleCompareToCommand implements ITurtleCommand
ItemStack selectedStack = turtle.getInventory() ItemStack selectedStack = turtle.getInventory()
.getStack( turtle.getSelectedSlot() ); .getStack( turtle.getSelectedSlot() );
ItemStack stack = turtle.getInventory() ItemStack stack = turtle.getInventory()
.getStack( this.m_slot ); .getStack( this.slot );
if( InventoryUtil.areItemsStackable( selectedStack, stack ) ) if( InventoryUtil.areItemsStackable( selectedStack, stack ) )
{ {
return TurtleCommandResult.success(); return TurtleCommandResult.success();

View File

@@ -18,11 +18,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 )
{ {
this.m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@@ -30,7 +30,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 = this.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

@@ -25,13 +25,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 )
{ {
this.m_direction = direction; this.direction = direction;
this.m_quantity = quantity; this.quantity = quantity;
} }
@Nonnull @Nonnull
@@ -39,17 +39,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( this.m_quantity == 0 ) if( this.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 = this.m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
// Get things to drop // Get things to drop
ItemStack stack = InventoryUtil.takeItems( this.m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() ); ItemStack stack = InventoryUtil.takeItems( this.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

@@ -22,11 +22,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 )
{ {
this.m_side = side; this.side = side;
} }
@Nonnull @Nonnull
@@ -55,7 +55,7 @@ public class TurtleEquipCommand implements ITurtleCommand
// Determine the upgrade to replace // Determine the upgrade to replace
ItemStack oldUpgradeStack; ItemStack oldUpgradeStack;
ITurtleUpgrade oldUpgrade = turtle.getUpgrade( this.m_side ); ITurtleUpgrade oldUpgrade = turtle.getUpgrade( this.side );
if( oldUpgrade != null ) if( oldUpgrade != null )
{ {
ItemStack craftingItem = oldUpgrade.getCraftingItem(); ItemStack craftingItem = oldUpgrade.getCraftingItem();
@@ -89,7 +89,7 @@ public class TurtleEquipCommand implements ITurtleCommand
WorldUtil.dropItemStack( remainder, turtle.getWorld(), position, turtle.getDirection() ); WorldUtil.dropItemStack( remainder, turtle.getWorld(), position, turtle.getDirection() );
} }
} }
turtle.setUpgrade( this.m_side, newUpgrade ); turtle.setUpgrade( this.side, newUpgrade );
// Animate // Animate
if( newUpgrade != null || oldUpgrade != null ) if( newUpgrade != null || oldUpgrade != null )

View File

@@ -30,11 +30,11 @@ import java.util.List;
public class TurtleMoveCommand implements ITurtleCommand public class TurtleMoveCommand implements ITurtleCommand
{ {
private static final Box EMPTY_BOX = new Box( 0, 0, 0, 0, 0, 0 ); private static final Box EMPTY_BOX = new Box( 0, 0, 0, 0, 0, 0 );
private final MoveDirection m_direction; private final MoveDirection direction;
public TurtleMoveCommand( MoveDirection direction ) public TurtleMoveCommand( MoveDirection direction )
{ {
this.m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@@ -42,7 +42,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 = this.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();
@@ -70,7 +70,7 @@ public class TurtleMoveCommand implements ITurtleCommand
if( !oldWorld.intersectsEntities( null, collision ) ) if( !oldWorld.intersectsEntities( null, collision ) )
{ {
if( !ComputerCraft.turtlesCanPush || this.m_direction == MoveDirection.UP || this.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" );
} }
@@ -110,7 +110,7 @@ public class TurtleMoveCommand implements ITurtleCommand
turtle.consumeFuel( 1 ); turtle.consumeFuel( 1 );
// Animate // Animate
switch( this.m_direction ) switch( this.direction )
{ {
case FORWARD: case FORWARD:
default: default:

View File

@@ -40,13 +40,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 )
{ {
this.m_direction = direction; this.direction = direction;
this.m_extraArguments = arguments; this.extraArguments = arguments;
} }
public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, Direction direction, Object[] extraArguments, String[] outErrorMessage ) public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, Direction direction, Object[] extraArguments, String[] outErrorMessage )
@@ -72,7 +72,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
} }
// Remember old block // Remember old block
Direction direction = this.m_direction.toWorldDir( turtle ); Direction direction = this.direction.toWorldDir( turtle );
BlockPos coordinates = turtle.getPosition() BlockPos coordinates = turtle.getPosition()
.offset( direction ); .offset( direction );
@@ -89,7 +89,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, this.m_extraArguments, errorMessage ); ItemStack remainder = deploy( stack, turtle, turtlePlayer, direction, this.extraArguments, errorMessage );
if( remainder != stack ) if( remainder != stack )
{ {
// Put the remaining items back // Put the remaining items back

View File

@@ -96,10 +96,10 @@ 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() ) || player.getEntityWorld() != access.getWorld() ) if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() ) || player.getEntityWorld() != access.getWorld() )
{ {
player = brain.m_cachedPlayer = create( brain ); player = brain.cachedPlayer = create( brain );
} }
else else
{ {

View File

@@ -28,13 +28,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 )
{ {
this.m_direction = direction; this.direction = direction;
this.m_quantity = quantity; this.quantity = quantity;
} }
@Nonnull @Nonnull
@@ -42,14 +42,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( this.m_quantity == 0 ) if( this.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 = this.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();
@@ -70,7 +70,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( this.m_quantity, ItemStorage.wrap( inventory ) ); ItemStack stack = InventoryUtil.takeItems( this.quantity, ItemStorage.wrap( inventory ) );
if( stack.isEmpty() ) if( stack.isEmpty() )
{ {
return TurtleCommandResult.failure( "No items to take" ); return TurtleCommandResult.failure( "No items to take" );
@@ -118,9 +118,9 @@ public class TurtleSuckCommand implements ITurtleCommand
ItemStack storeStack; ItemStack storeStack;
ItemStack leaveStack; ItemStack leaveStack;
if( stack.getCount() > this.m_quantity ) if( stack.getCount() > this.quantity )
{ {
storeStack = stack.split( this.m_quantity ); storeStack = stack.split( this.quantity );
leaveStack = stack; leaveStack = stack;
} }
else else

View File

@@ -17,13 +17,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 )
{ {
this.m_slot = slot; this.slot = slot;
this.m_quantity = limit; this.quantity = limit;
} }
@Nonnull @Nonnull
@@ -31,7 +31,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( this.m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() ); ItemStack stack = InventoryUtil.takeItems( this.quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() );
if( stack.isEmpty() ) if( stack.isEmpty() )
{ {
turtle.playAnimation( TurtleAnimation.WAIT ); turtle.playAnimation( TurtleAnimation.WAIT );
@@ -39,7 +39,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
} }
// Store stack // Store stack
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), this.m_slot, 1, this.m_slot ); ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), this.slot, 1, this.slot );
if( !remainder.isEmpty() ) if( !remainder.isEmpty() )
{ {
// Put the remainder back // Put the remainder back

View File

@@ -18,11 +18,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 )
{ {
this.m_direction = direction; this.direction = direction;
} }
@Nonnull @Nonnull
@@ -35,7 +35,7 @@ public class TurtleTurnCommand implements ITurtleCommand
return TurtleCommandResult.failure( event.getFailureMessage() ); return TurtleCommandResult.failure( event.getFailureMessage() );
} }
switch( this.m_direction ) switch( this.direction )
{ {
case LEFT: case LEFT:
{ {

View File

@@ -23,10 +23,10 @@ import javax.annotation.Nonnull;
public class TurtleCraftingTable extends AbstractTurtleUpgrade public class TurtleCraftingTable extends AbstractTurtleUpgrade
{ {
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_leftModel; private ModelIdentifier leftModel;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_rightModel; private ModelIdentifier rightModel;
public TurtleCraftingTable( Identifier id ) public TurtleCraftingTable( Identifier id )
{ {
@@ -45,16 +45,16 @@ public class TurtleCraftingTable extends AbstractTurtleUpgrade
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{ {
this.loadModelLocations(); this.loadModelLocations();
return TransformedModel.of( side == TurtleSide.LEFT ? this.m_leftModel : this.m_rightModel ); return TransformedModel.of( side == TurtleSide.LEFT ? this.leftModel : this.rightModel );
} }
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private void loadModelLocations() private void loadModelLocations()
{ {
if( this.m_leftModel == null ) if( this.leftModel == null )
{ {
this.m_leftModel = new ModelIdentifier( "computercraft:turtle_crafting_table_left", "inventory" ); this.leftModel = new ModelIdentifier( "computercraft:turtle_crafting_table_left", "inventory" );
this.m_rightModel = new ModelIdentifier( "computercraft:turtle_crafting_table_right", "inventory" ); this.rightModel = new ModelIdentifier( "computercraft:turtle_crafting_table_right", "inventory" );
} }
} }
} }

View File

@@ -26,9 +26,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;
private int m_yStart; private int yStart;
@SuppressWarnings( "ConstantConditions" ) @SuppressWarnings( "ConstantConditions" )
public TurtleInventoryCrafting( ITurtleAccess turtle ) public TurtleInventoryCrafting( ITurtleAccess turtle )
@@ -36,25 +36,25 @@ 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 );
this.m_turtle = turtle; this.turtle = turtle;
this.m_xStart = 0; this.xStart = 0;
this.m_yStart = 0; this.yStart = 0;
} }
@Nullable @Nullable
private Recipe<CraftingInventory> tryCrafting( int xStart, int yStart ) private Recipe<CraftingInventory> tryCrafting( int xStart, int yStart )
{ {
this.m_xStart = xStart; this.xStart = xStart;
this.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 < this.m_xStart || x >= this.m_xStart + 3 || y < this.m_yStart || y >= this.m_yStart + 3 ) if( x < this.xStart || x >= this.xStart + 3 || y < this.yStart || y >= this.yStart + 3 )
{ {
if( !this.m_turtle.getInventory() if( !this.turtle.getInventory()
.getStack( x + y * TileTurtle.INVENTORY_WIDTH ) .getStack( x + y * TileTurtle.INVENTORY_WIDTH )
.isEmpty() ) .isEmpty() )
{ {
@@ -65,9 +65,9 @@ public class TurtleInventoryCrafting extends CraftingInventory
} }
// Check the actual crafting // Check the actual crafting
return this.m_turtle.getWorld() return this.turtle.getWorld()
.getRecipeManager() .getRecipeManager()
.getFirstMatch( RecipeType.CRAFTING, this, this.m_turtle.getWorld() ) .getFirstMatch( RecipeType.CRAFTING, this, this.turtle.getWorld() )
.orElse( null ); .orElse( null );
} }
@@ -104,7 +104,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
return Collections.emptyList(); return Collections.emptyList();
} }
TurtlePlayer player = TurtlePlayer.get( this.m_turtle ); TurtlePlayer player = TurtlePlayer.get( this.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++ )
@@ -159,7 +159,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
@Override @Override
public int getMaxCountPerStack() public int getMaxCountPerStack()
{ {
return this.m_turtle.getInventory() return this.turtle.getInventory()
.getMaxCountPerStack(); .getMaxCountPerStack();
} }
@@ -173,7 +173,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public boolean isValid( int i, @Nonnull ItemStack stack ) public boolean isValid( int i, @Nonnull ItemStack stack )
{ {
i = this.modifyIndex( i ); i = this.modifyIndex( i );
return this.m_turtle.getInventory() return this.turtle.getInventory()
.isValid( i, stack ); .isValid( i, stack );
} }
@@ -185,8 +185,8 @@ public class TurtleInventoryCrafting extends CraftingInventory
private int modifyIndex( int index ) private int modifyIndex( int index )
{ {
int x = this.m_xStart + index % this.getWidth(); int x = this.xStart + index % this.getWidth();
int y = this.m_yStart + index / this.getHeight(); int y = this.yStart + index / this.getHeight();
return x >= 0 && x < TileTurtle.INVENTORY_WIDTH && y >= 0 && y < TileTurtle.INVENTORY_HEIGHT ? x + y * TileTurtle.INVENTORY_WIDTH : -1; return x >= 0 && x < TileTurtle.INVENTORY_WIDTH && y >= 0 && y < TileTurtle.INVENTORY_HEIGHT ? x + y * TileTurtle.INVENTORY_WIDTH : -1;
} }
@@ -203,7 +203,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public ItemStack getStack( int i ) public ItemStack getStack( int i )
{ {
i = this.modifyIndex( i ); i = this.modifyIndex( i );
return this.m_turtle.getInventory() return this.turtle.getInventory()
.getStack( i ); .getStack( i );
} }
@@ -212,7 +212,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public ItemStack removeStack( int i ) public ItemStack removeStack( int i )
{ {
i = this.modifyIndex( i ); i = this.modifyIndex( i );
return this.m_turtle.getInventory() return this.turtle.getInventory()
.removeStack( i ); .removeStack( i );
} }
@@ -221,7 +221,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public ItemStack removeStack( int i, int size ) public ItemStack removeStack( int i, int size )
{ {
i = this.modifyIndex( i ); i = this.modifyIndex( i );
return this.m_turtle.getInventory() return this.turtle.getInventory()
.removeStack( i, size ); .removeStack( i, size );
} }
@@ -229,7 +229,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
public void setStack( int i, @Nonnull ItemStack stack ) public void setStack( int i, @Nonnull ItemStack stack )
{ {
i = this.modifyIndex( i ); i = this.modifyIndex( i );
this.m_turtle.getInventory() this.turtle.getInventory()
.setStack( i, stack ); .setStack( i, stack );
} }
@@ -237,7 +237,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
@Override @Override
public void markDirty() public void markDirty()
{ {
this.m_turtle.getInventory() this.turtle.getInventory()
.markDirty(); .markDirty();
} }
@@ -254,7 +254,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
for( int i = 0; i < this.size(); i++ ) for( int i = 0; i < this.size(); i++ )
{ {
int j = this.modifyIndex( i ); int j = this.modifyIndex( i );
this.m_turtle.getInventory() this.turtle.getInventory()
.setStack( j, ItemStack.EMPTY ); .setStack( j, ItemStack.EMPTY );
} }
} }

View File

@@ -28,13 +28,13 @@ public class TurtleModem extends AbstractTurtleUpgrade
{ {
private final boolean advanced; private final boolean advanced;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_leftOffModel; private ModelIdentifier leftOffModel;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_rightOffModel; private ModelIdentifier rightOffModel;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_leftOnModel; private ModelIdentifier leftOnModel;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_rightOnModel; private ModelIdentifier rightOnModel;
public TurtleModem( boolean advanced, Identifier id ) public TurtleModem( boolean advanced, Identifier id )
{ {
@@ -71,27 +71,27 @@ public class TurtleModem extends AbstractTurtleUpgrade
active = turtleNBT.contains( "active" ) && turtleNBT.getBoolean( "active" ); active = turtleNBT.contains( "active" ) && turtleNBT.getBoolean( "active" );
} }
return side == TurtleSide.LEFT ? TransformedModel.of( active ? this.m_leftOnModel : this.m_leftOffModel ) : TransformedModel.of( active ? this.m_rightOnModel : this.m_rightOffModel ); return side == TurtleSide.LEFT ? TransformedModel.of( active ? this.leftOnModel : this.leftOffModel ) : TransformedModel.of( active ? this.rightOnModel : this.rightOffModel );
} }
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private void loadModelLocations() private void loadModelLocations()
{ {
if( this.m_leftOffModel == null ) if( this.leftOffModel == null )
{ {
if( this.advanced ) if( this.advanced )
{ {
this.m_leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_left", "inventory" ); this.leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_left", "inventory" );
this.m_rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_right", "inventory" ); this.rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_right", "inventory" );
this.m_leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_left", "inventory" ); this.leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_left", "inventory" );
this.m_rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_right", "inventory" ); this.rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_right", "inventory" );
} }
else else
{ {
this.m_leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_left", "inventory" ); this.leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_left", "inventory" );
this.m_rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_right", "inventory" ); this.rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_right", "inventory" );
this.m_leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_left", "inventory" ); this.leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_left", "inventory" );
this.m_rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_right", "inventory" ); this.rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_right", "inventory" );
} }
} }
} }

View File

@@ -26,9 +26,9 @@ import javax.annotation.Nonnull;
public class TurtleSpeaker extends AbstractTurtleUpgrade public class TurtleSpeaker extends AbstractTurtleUpgrade
{ {
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_leftModel; private ModelIdentifier leftModel;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private ModelIdentifier m_rightModel; private ModelIdentifier rightModel;
public TurtleSpeaker( Identifier id ) public TurtleSpeaker( Identifier id )
{ {
@@ -47,16 +47,16 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{ {
this.loadModelLocations(); this.loadModelLocations();
return TransformedModel.of( side == TurtleSide.LEFT ? this.m_leftModel : this.m_rightModel ); return TransformedModel.of( side == TurtleSide.LEFT ? this.leftModel : this.rightModel );
} }
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
private void loadModelLocations() private void loadModelLocations()
{ {
if( this.m_leftModel == null ) if( this.leftModel == null )
{ {
this.m_leftModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_left", "inventory" ); this.leftModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_left", "inventory" );
this.m_rightModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_right", "inventory" ); this.rightModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_right", "inventory" );
} }
} }

View File

@@ -5,7 +5,10 @@
*/ */
package dan200.computercraft.shared.util; package dan200.computercraft.shared.util;
import com.electronwill.nightconfig.core.*; import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.ConfigSpec;
import com.electronwill.nightconfig.core.EnumGetMethod;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.file.CommentedFileConfig; import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.file.FileNotFoundAction; import com.electronwill.nightconfig.core.file.FileNotFoundAction;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
@@ -27,7 +30,8 @@ import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Config { public class Config
{
private static final int MODEM_MAX_RANGE = 100000; private static final int MODEM_MAX_RANGE = 100000;
public static final String TRANSLATION_PREFIX = "gui.computercraft.config."; public static final String TRANSLATION_PREFIX = "gui.computercraft.config.";
@@ -38,327 +42,346 @@ public class Config {
public static CommentedConfig serverConfig; public static CommentedConfig serverConfig;
public static CommentedConfig clientConfig; public static CommentedConfig clientConfig;
private static final WorldSavePath serverDir = WorldSavePathAccess.createWorldSavePath("serverconfig"); private static final WorldSavePath serverDir = WorldSavePathAccess.createWorldSavePath( "serverconfig" );
private static final String serverFileName = "computercraft-server.toml"; private static final String serverFileName = "computercraft-server.toml";
private static final Path clientPath = FabricLoader.INSTANCE.getConfigDir().resolve("computercraft-client.toml"); private static final Path clientPath = FabricLoader.INSTANCE.getConfigDir().resolve( "computercraft-client.toml" );
private Config() { private Config()
{
} }
static { static
System.setProperty("nightconfig.preserveInsertionOrder", "true"); {
System.setProperty( "nightconfig.preserveInsertionOrder", "true" );
serverSpec = new CommentedConfigSpec(); serverSpec = new CommentedConfigSpec();
{ // General computers { // General computers
serverSpec.comment("computer_space_limit", serverSpec.comment( "computer_space_limit",
"The disk space limit for computers and turtles, in bytes"); "The disk space limit for computers and turtles, in bytes" );
serverSpec.define("computer_space_limit", ComputerCraft.computerSpaceLimit); serverSpec.define( "computer_space_limit", ComputerCraft.computerSpaceLimit );
serverSpec.comment("floppy_space_limit", serverSpec.comment( "floppy_space_limit",
"The disk space limit for floppy disks, in bytes"); "The disk space limit for floppy disks, in bytes" );
serverSpec.define("floppy_space_limit", ComputerCraft.floppySpaceLimit); serverSpec.define( "floppy_space_limit", ComputerCraft.floppySpaceLimit );
serverSpec.comment("maximum_open_files", serverSpec.comment( "maximum_open_files",
"Set how many files a computer can have open at the same time. Set to 0 for unlimited."); "Set how many files a computer can have open at the same time. Set to 0 for unlimited." );
serverSpec.defineInRange("maximum_open_files", ComputerCraft.maximumFilesOpen, 0, Integer.MAX_VALUE); serverSpec.defineInRange( "maximum_open_files", ComputerCraft.maximumFilesOpen, 0, Integer.MAX_VALUE );
serverSpec.comment("disable_lua51_features", serverSpec.comment( "disable_lua51_features",
"Set this to true to disable Lua 5.1 functions that will be removed in a future update. " + "Set this to true to disable Lua 5.1 functions that will be removed in a future update. " +
"Useful for ensuring forward compatibility of your programs now."); "Useful for ensuring forward compatibility of your programs now." );
serverSpec.define("disable_lua51_features", ComputerCraft.disableLua51Features); serverSpec.define( "disable_lua51_features", ComputerCraft.disableLua51Features );
serverSpec.comment("default_computer_settings", serverSpec.comment( "default_computer_settings",
"A comma separated list of default system settings to set on new computers. Example: " + "A comma separated list of default system settings to set on new computers. Example: " +
"\"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all " + "\"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all " +
"autocompletion"); "autocompletion" );
serverSpec.define("default_computer_settings", ComputerCraft.defaultComputerSettings); serverSpec.define( "default_computer_settings", ComputerCraft.defaultComputerSettings );
serverSpec.comment("debug_enabled", serverSpec.comment( "debug_enabled",
"Enable Lua's debug library. This is sandboxed to each computer, so is generally safe to be used by players."); "Enable Lua's debug library. This is sandboxed to each computer, so is generally safe to be used by players." );
serverSpec.define("debug_enabled", ComputerCraft.debugEnable); serverSpec.define( "debug_enabled", ComputerCraft.debugEnable );
serverSpec.comment("log_computer_errors", serverSpec.comment( "log_computer_errors",
"Log exceptions thrown by peripherals and other Lua objects.\n" + "Log exceptions thrown by peripherals and other Lua objects.\n" +
"This makes it easier for mod authors to debug problems, but may result in log spam should people use buggy methods."); "This makes it easier for mod authors to debug problems, but may result in log spam should people use buggy methods." );
serverSpec.define("log_computer_errors", ComputerCraft.logComputerErrors); serverSpec.define( "log_computer_errors", ComputerCraft.logComputerErrors );
serverSpec.comment("command_require_creative", serverSpec.comment( "command_require_creative",
"Require players to be in creative mode and be opped in order to interact with command computers." + "Require players to be in creative mode and be opped in order to interact with command computers." +
"This is the default behaviour for vanilla's Command blocks."); "This is the default behaviour for vanilla's Command blocks." );
serverSpec.define("command_require_creative", ComputerCraft.commandRequireCreative); serverSpec.define( "command_require_creative", ComputerCraft.commandRequireCreative );
} }
{ // Execution { // Execution
serverSpec.comment("execution", serverSpec.comment( "execution",
"Controls execution behaviour of computers. This is largely intended for fine-tuning " + "Controls execution behaviour of computers. This is largely intended for fine-tuning " +
"servers, and generally shouldn't need to be touched"); "servers, and generally shouldn't need to be touched" );
serverSpec.comment("execution.computer_threads", serverSpec.comment( "execution.computer_threads",
"Set the number of threads computers can run on. A higher number means more computers can run " + "Set the number of threads computers can run on. A higher number means more computers can run " +
"at once, but may induce lag.\n" + "at once, but may induce lag.\n" +
"Please note that some mods may not work with a thread count higher than 1. Use with caution."); "Please note that some mods may not work with a thread count higher than 1. Use with caution." );
serverSpec.defineInRange("execution.computer_threads", ComputerCraft.computerThreads, 1, Integer.MAX_VALUE); serverSpec.defineInRange( "execution.computer_threads", ComputerCraft.computerThreads, 1, Integer.MAX_VALUE );
serverSpec.comment("execution.max_main_global_time", serverSpec.comment( "execution.max_main_global_time",
"The maximum time that can be spent executing tasks in a single tick, in milliseconds.\n" + "The maximum time that can be spent executing tasks in a single tick, in milliseconds.\n" +
"Note, we will quite possibly go over this limit, as there's no way to tell how long a will take " + "Note, we will quite possibly go over this limit, as there's no way to tell how long a will take " +
"- this aims to be the upper bound of the average time."); "- this aims to be the upper bound of the average time." );
serverSpec.defineInRange("execution.max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ), 1, Integer.MAX_VALUE); serverSpec.defineInRange( "execution.max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ), 1, Integer.MAX_VALUE );
serverSpec.comment("execution.max_main_computer_time", serverSpec.comment( "execution.max_main_computer_time",
"The ideal maximum time a computer can execute for in a tick, in milliseconds.\n" + "The ideal maximum time a computer can execute for in a tick, in milliseconds.\n" +
"Note, we will quite possibly go over this limit, as there's no way to tell how long a will take " + "Note, we will quite possibly go over this limit, as there's no way to tell how long a will take " +
"- this aims to be the upper bound of the average time."); "- this aims to be the upper bound of the average time." );
serverSpec.defineInRange("execution.max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ), 1, Integer.MAX_VALUE); serverSpec.defineInRange( "execution.max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ), 1, Integer.MAX_VALUE );
} }
{ // HTTP { // HTTP
serverSpec.comment("http", "Controls the HTTP API"); serverSpec.comment( "http", "Controls the HTTP API" );
serverSpec.comment("http.enabled", serverSpec.comment( "http.enabled",
"Enable the \"http\" API on Computers (see \"rules\" for more fine grained control than this)."); "Enable the \"http\" API on Computers (see \"rules\" for more fine grained control than this)." );
serverSpec.define("http.enabled", ComputerCraft.httpEnabled); serverSpec.define( "http.enabled", ComputerCraft.httpEnabled );
serverSpec.comment("http.websocket_enabled", serverSpec.comment( "http.websocket_enabled",
"Enable use of http websockets. This requires the \"http_enable\" option to also be true."); "Enable use of http websockets. This requires the \"http_enable\" option to also be true." );
serverSpec.define("http.websocket_enabled", ComputerCraft.httpWebsocketEnabled); serverSpec.define( "http.websocket_enabled", ComputerCraft.httpWebsocketEnabled );
serverSpec.comment("http.rules", serverSpec.comment( "http.rules",
"A list of rules which control behaviour of the \"http\" API for specific domains or IPs.\n" + "A list of rules which control behaviour of the \"http\" API for specific domains or IPs.\n" +
"Each rule is an item with a 'host' to match against, and a series of properties. " + "Each rule is an item with a 'host' to match against, and a series of properties. " +
"The host may be a domain name (\"pastebin.com\"),\n" + "The host may be a domain name (\"pastebin.com\"),\n" +
"wildcard (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\"). If no rules, the domain is blocked."); "wildcard (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\"). If no rules, the domain is blocked." );
serverSpec.defineList("http.rules", Arrays.asList( serverSpec.defineList( "http.rules", Arrays.asList(
AddressRuleConfig.makeRule("$private", Action.DENY), AddressRuleConfig.makeRule( "$private", Action.DENY ),
AddressRuleConfig.makeRule("*", Action.ALLOW) AddressRuleConfig.makeRule( "*", Action.ALLOW )
), x -> x instanceof UnmodifiableConfig && AddressRuleConfig.checkRule((UnmodifiableConfig) x)); ), x -> x instanceof UnmodifiableConfig && AddressRuleConfig.checkRule( (UnmodifiableConfig) x ) );
serverSpec.comment("http.max_requests", serverSpec.comment( "http.max_requests",
"The number of http requests a computer can make at one time. Additional requests will be queued, and sent when the running requests have finished. Set to 0 for unlimited."); "The number of http requests a computer can make at one time. Additional requests will be queued, and sent when the running requests have finished. Set to 0 for unlimited." );
serverSpec.defineInRange("http.max_requests", ComputerCraft.httpMaxRequests, 0, Integer.MAX_VALUE); serverSpec.defineInRange( "http.max_requests", ComputerCraft.httpMaxRequests, 0, Integer.MAX_VALUE );
serverSpec.comment("http.max_websockets", serverSpec.comment( "http.max_websockets",
"The number of websockets a computer can have open at one time. Set to 0 for unlimited."); "The number of websockets a computer can have open at one time. Set to 0 for unlimited." );
serverSpec.defineInRange("http.max_websockets", ComputerCraft.httpMaxWebsockets, 1, Integer.MAX_VALUE); serverSpec.defineInRange( "http.max_websockets", ComputerCraft.httpMaxWebsockets, 1, Integer.MAX_VALUE );
} }
{ // Peripherals { // Peripherals
serverSpec.comment("peripheral", "Various options relating to peripherals."); serverSpec.comment( "peripheral", "Various options relating to peripherals." );
serverSpec.comment("peripheral.command_block_enabled", serverSpec.comment( "peripheral.command_block_enabled",
"Enable Command Block peripheral support"); "Enable Command Block peripheral support" );
serverSpec.define("peripheral.command_block_enabled", ComputerCraft.enableCommandBlock); serverSpec.define( "peripheral.command_block_enabled", ComputerCraft.enableCommandBlock );
serverSpec.comment("peripheral.modem_range", serverSpec.comment( "peripheral.modem_range",
"The range of Wireless Modems at low altitude in clear weather, in meters"); "The range of Wireless Modems at low altitude in clear weather, in meters" );
serverSpec.defineInRange("peripheral.modem_range", ComputerCraft.modemRange, 0, MODEM_MAX_RANGE); serverSpec.defineInRange( "peripheral.modem_range", ComputerCraft.modemRange, 0, MODEM_MAX_RANGE );
serverSpec.comment("peripheral.modem_high_altitude_range", serverSpec.comment( "peripheral.modem_high_altitude_range",
"The range of Wireless Modems at maximum altitude in clear weather, in meters"); "The range of Wireless Modems at maximum altitude in clear weather, in meters" );
serverSpec.defineInRange("peripheral.modem_high_altitude_range", ComputerCraft.modemHighAltitudeRange, 0, MODEM_MAX_RANGE); serverSpec.defineInRange( "peripheral.modem_high_altitude_range", ComputerCraft.modemHighAltitudeRange, 0, MODEM_MAX_RANGE );
serverSpec.comment("peripheral.modem_range_during_storm", serverSpec.comment( "peripheral.modem_range_during_storm",
"The range of Wireless Modems at low altitude in stormy weather, in meters"); "The range of Wireless Modems at low altitude in stormy weather, in meters" );
serverSpec.defineInRange("peripheral.modem_range_during_storm", ComputerCraft.modemRangeDuringStorm, 0, MODEM_MAX_RANGE); serverSpec.defineInRange( "peripheral.modem_range_during_storm", ComputerCraft.modemRangeDuringStorm, 0, MODEM_MAX_RANGE );
serverSpec.comment("peripheral.modem_high_altitude_range_during_storm", serverSpec.comment( "peripheral.modem_high_altitude_range_during_storm",
"The range of Wireless Modems at maximum altitude in stormy weather, in meters"); "The range of Wireless Modems at maximum altitude in stormy weather, in meters" );
serverSpec.defineInRange("peripheral.modem_high_altitude_range_during_storm", ComputerCraft.modemHighAltitudeRangeDuringStorm, 0, MODEM_MAX_RANGE); serverSpec.defineInRange( "peripheral.modem_high_altitude_range_during_storm", ComputerCraft.modemHighAltitudeRangeDuringStorm, 0, MODEM_MAX_RANGE );
serverSpec.comment("peripheral.max_notes_per_tick", serverSpec.comment( "peripheral.max_notes_per_tick",
"Maximum amount of notes a speaker can play at once"); "Maximum amount of notes a speaker can play at once" );
serverSpec.defineInRange("peripheral.max_notes_per_tick", ComputerCraft.maxNotesPerTick, 1, Integer.MAX_VALUE); serverSpec.defineInRange( "peripheral.max_notes_per_tick", ComputerCraft.maxNotesPerTick, 1, Integer.MAX_VALUE );
serverSpec.comment("peripheral.monitor_bandwidth", serverSpec.comment( "peripheral.monitor_bandwidth",
"The limit to how much monitor data can be sent *per tick*. Note:\n" + "The limit to how much monitor data can be sent *per tick*. Note:\n" +
" - Bandwidth is measured before compression, so the data sent to the client is smaller.\n" + " - Bandwidth is measured before compression, so the data sent to the client is smaller.\n" +
" - This ignores the number of players a packet is sent to. Updating a monitor for one player consumes " + " - This ignores the number of players a packet is sent to. Updating a monitor for one player consumes " +
"the same bandwidth limit as sending to 20.\n" + "the same bandwidth limit as sending to 20.\n" +
" - A full sized monitor sends ~25kb of data. So the default (1MB) allows for ~40 monitors to be updated " + " - A full sized monitor sends ~25kb of data. So the default (1MB) allows for ~40 monitors to be updated " +
"in a single tick. \n" + "in a single tick. \n" +
"Set to 0 to disable."); "Set to 0 to disable." );
serverSpec.defineInRange("peripheral.monitor_bandwidth", (int) ComputerCraft.monitorBandwidth, 0, Integer.MAX_VALUE); serverSpec.defineInRange( "peripheral.monitor_bandwidth", (int) ComputerCraft.monitorBandwidth, 0, Integer.MAX_VALUE );
} }
{ // Turtles { // Turtles
serverSpec.comment("turtle", "Various options relating to turtles."); serverSpec.comment( "turtle", "Various options relating to turtles." );
serverSpec.comment("turtle.need_fuel", serverSpec.comment( "turtle.need_fuel",
"Set whether Turtles require fuel to move"); "Set whether Turtles require fuel to move" );
serverSpec.define("turtle.need_fuel", ComputerCraft.turtlesNeedFuel); serverSpec.define( "turtle.need_fuel", ComputerCraft.turtlesNeedFuel );
serverSpec.comment("turtle.normal_fuel_limit", "The fuel limit for Turtles"); serverSpec.comment( "turtle.normal_fuel_limit", "The fuel limit for Turtles" );
serverSpec.defineInRange("turtle.normal_fuel_limit", ComputerCraft.turtleFuelLimit, 0, Integer.MAX_VALUE); serverSpec.defineInRange( "turtle.normal_fuel_limit", ComputerCraft.turtleFuelLimit, 0, Integer.MAX_VALUE );
serverSpec.comment("turtle.advanced_fuel_limit", serverSpec.comment( "turtle.advanced_fuel_limit",
"The fuel limit for Advanced Turtles"); "The fuel limit for Advanced Turtles" );
serverSpec.defineInRange("turtle.advanced_fuel_limit", ComputerCraft.advancedTurtleFuelLimit, 0, Integer.MAX_VALUE); serverSpec.defineInRange( "turtle.advanced_fuel_limit", ComputerCraft.advancedTurtleFuelLimit, 0, Integer.MAX_VALUE );
serverSpec.comment("turtle.obey_block_protection", serverSpec.comment( "turtle.obey_block_protection",
"If set to true, Turtles will be unable to build, dig, or enter protected areas (such as near the server spawn point)"); "If set to true, Turtles will be unable to build, dig, or enter protected areas (such as near the server spawn point)" );
serverSpec.define("turtle.obey_block_protection", ComputerCraft.turtlesObeyBlockProtection); serverSpec.define( "turtle.obey_block_protection", ComputerCraft.turtlesObeyBlockProtection );
serverSpec.comment("turtle.can_push", serverSpec.comment( "turtle.can_push",
"If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so"); "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
serverSpec.define("turtle.can_push", ComputerCraft.turtlesCanPush); serverSpec.define( "turtle.can_push", ComputerCraft.turtlesCanPush );
serverSpec.comment("turtle.disabled_actions", serverSpec.comment( "turtle.disabled_actions",
"A list of turtle actions which are disabled."); "A list of turtle actions which are disabled." );
serverSpec.defineList("turtle.disabled_actions", Collections.emptyList(), x -> x instanceof String && getAction((String) x) != null); serverSpec.defineList( "turtle.disabled_actions", Collections.emptyList(), x -> x instanceof String && getAction( (String) x ) != null );
} }
{ {
serverSpec.comment("term_sizes", "Configure the size of various computer's terminals.\n" + serverSpec.comment( "term_sizes", "Configure the size of various computer's terminals.\n" +
"Larger terminals require more bandwidth, so use with care."); "Larger terminals require more bandwidth, so use with care." );
serverSpec.comment("term_sizes.computer", "Terminal size of computers"); serverSpec.comment( "term_sizes.computer", "Terminal size of computers" );
serverSpec.defineInRange("term_sizes.computer.width", ComputerCraft.computerTermWidth, 1, 255); serverSpec.defineInRange( "term_sizes.computer.width", ComputerCraft.computerTermWidth, 1, 255 );
serverSpec.defineInRange("term_sizes.computer.height", ComputerCraft.computerTermHeight, 1, 255); serverSpec.defineInRange( "term_sizes.computer.height", ComputerCraft.computerTermHeight, 1, 255 );
serverSpec.comment("term_sizes.pocket_computer", "Terminal size of pocket computers"); serverSpec.comment( "term_sizes.pocket_computer", "Terminal size of pocket computers" );
serverSpec.defineInRange("term_sizes.pocket_computer.width", ComputerCraft.pocketTermWidth, 1, 255); serverSpec.defineInRange( "term_sizes.pocket_computer.width", ComputerCraft.pocketTermWidth, 1, 255 );
serverSpec.defineInRange("term_sizes.pocket_computer.height", ComputerCraft.pocketTermHeight, 1, 255); serverSpec.defineInRange( "term_sizes.pocket_computer.height", ComputerCraft.pocketTermHeight, 1, 255 );
serverSpec.comment("term_sizes.monitor", "Maximum size of monitors (in blocks)"); serverSpec.comment( "term_sizes.monitor", "Maximum size of monitors (in blocks)" );
serverSpec.defineInRange("term_sizes.monitor.width", ComputerCraft.monitorWidth, 1, 32); serverSpec.defineInRange( "term_sizes.monitor.width", ComputerCraft.monitorWidth, 1, 32 );
serverSpec.defineInRange("term_sizes.monitor.height", ComputerCraft.monitorHeight, 1, 32); serverSpec.defineInRange( "term_sizes.monitor.height", ComputerCraft.monitorHeight, 1, 32 );
} }
clientSpec = new CommentedConfigSpec(); clientSpec = new CommentedConfigSpec();
clientSpec.comment("monitor_renderer", clientSpec.comment( "monitor_renderer",
"The renderer to use for monitors. Generally this should be kept at \"best\" - if " + "The renderer to use for monitors. Generally this should be kept at \"best\" - if " +
"monitors have performance issues, you may wish to experiment with alternative renderers."); "monitors have performance issues, you may wish to experiment with alternative renderers." );
clientSpec.defineRestrictedEnum("monitor_renderer", MonitorRenderer.BEST, EnumSet.allOf(MonitorRenderer.class), EnumGetMethod.NAME_IGNORECASE); clientSpec.defineRestrictedEnum( "monitor_renderer", MonitorRenderer.BEST, EnumSet.allOf( MonitorRenderer.class ), EnumGetMethod.NAME_IGNORECASE );
clientSpec.comment("monitor_distance", clientSpec.comment( "monitor_distance",
"The maximum distance monitors will render at. This defaults to the standard tile entity limit, " + "The maximum distance monitors will render at. This defaults to the standard tile entity limit, " +
"but may be extended if you wish to build larger monitors." ); "but may be extended if you wish to build larger monitors." );
clientSpec.defineInRange("monitor_distance", 64, 16, 1024); clientSpec.defineInRange( "monitor_distance", 64, 16, 1024 );
} }
private static final FileNotFoundAction MAKE_DIRECTORIES = (file, configFormat) -> { private static final FileNotFoundAction MAKE_DIRECTORIES = ( file, configFormat ) -> {
Files.createDirectories(file.getParent()); Files.createDirectories( file.getParent() );
Files.createFile(file); Files.createFile( file );
configFormat.initEmptyFile(file); configFormat.initEmptyFile( file );
return false; return false;
}; };
private static CommentedFileConfig buildFileConfig(Path path) { private static CommentedFileConfig buildFileConfig( Path path )
return CommentedFileConfig.builder(path) {
.onFileNotFound(MAKE_DIRECTORIES) return CommentedFileConfig.builder( path )
.preserveInsertionOrder() .onFileNotFound( MAKE_DIRECTORIES )
.build(); .preserveInsertionOrder()
.build();
} }
public static void serverStarting(MinecraftServer server) { public static void serverStarting( MinecraftServer server )
Path serverPath = server.getSavePath(serverDir).resolve(serverFileName); {
Path serverPath = server.getSavePath( serverDir ).resolve( serverFileName );
try(CommentedFileConfig config = buildFileConfig(serverPath)) { try( CommentedFileConfig config = buildFileConfig( serverPath ) )
{
config.load(); config.load();
serverSpec.correct(config, Config::correctionListener); serverSpec.correct( config, Config::correctionListener );
config.save(); config.save();
serverConfig = config; serverConfig = config;
sync(); sync();
} }
} }
public static void serverStopping(MinecraftServer server) { public static void serverStopping( MinecraftServer server )
{
serverConfig = null; serverConfig = null;
} }
public static void clientStarted(MinecraftClient client) { public static void clientStarted( MinecraftClient client )
try (CommentedFileConfig config = buildFileConfig(clientPath)) { {
try( CommentedFileConfig config = buildFileConfig( clientPath ) )
{
config.load(); config.load();
clientSpec.correct(config, Config::correctionListener); clientSpec.correct( config, Config::correctionListener );
config.save(); config.save();
clientConfig = config; clientConfig = config;
sync(); sync();
} }
} }
private static void correctionListener(ConfigSpec.CorrectionAction action, List<String> path, Object incorrectValue, Object correctedValue) { private static void correctionListener( ConfigSpec.CorrectionAction action, List<String> path, Object incorrectValue, Object correctedValue )
String key = String.join(".", path); {
switch(action) { String key = String.join( ".", path );
switch( action )
{
case ADD: case ADD:
ComputerCraft.log.warn("Config key {} missing -> added default value.", key); break; ComputerCraft.log.warn( "Config key {} missing -> added default value.", key );
break;
case REMOVE: case REMOVE:
ComputerCraft.log.warn("Config key {} not defined -> removed from config.", key); break; ComputerCraft.log.warn( "Config key {} not defined -> removed from config.", key );
break;
case REPLACE: case REPLACE:
ComputerCraft.log.warn("Config key {} not valid -> replaced with default value.", key); ComputerCraft.log.warn( "Config key {} not valid -> replaced with default value.", key );
} }
} }
public static void sync() { public static void sync()
if(serverConfig != null) { {
if( serverConfig != null )
{
// General // General
ComputerCraft.computerSpaceLimit = serverConfig.<Integer>get("computer_space_limit"); ComputerCraft.computerSpaceLimit = serverConfig.<Integer>get( "computer_space_limit" );
ComputerCraft.floppySpaceLimit = serverConfig.<Integer>get("floppy_space_limit"); ComputerCraft.floppySpaceLimit = serverConfig.<Integer>get( "floppy_space_limit" );
ComputerCraft.maximumFilesOpen = serverConfig.<Integer>get("maximum_open_files"); ComputerCraft.maximumFilesOpen = serverConfig.<Integer>get( "maximum_open_files" );
ComputerCraft.disableLua51Features = serverConfig.<Boolean>get("disable_lua51_features"); ComputerCraft.disableLua51Features = serverConfig.<Boolean>get( "disable_lua51_features" );
ComputerCraft.defaultComputerSettings = serverConfig.<String>get("default_computer_settings"); ComputerCraft.defaultComputerSettings = serverConfig.<String>get( "default_computer_settings" );
ComputerCraft.debugEnable = serverConfig.<Boolean>get("debug_enabled"); ComputerCraft.debugEnable = serverConfig.<Boolean>get( "debug_enabled" );
ComputerCraft.logComputerErrors = serverConfig.<Boolean>get("log_computer_errors"); ComputerCraft.logComputerErrors = serverConfig.<Boolean>get( "log_computer_errors" );
ComputerCraft.commandRequireCreative = serverConfig.<Boolean>get("command_require_creative"); ComputerCraft.commandRequireCreative = serverConfig.<Boolean>get( "command_require_creative" );
// Execution // Execution
ComputerCraft.computerThreads = serverConfig.<Integer>get("execution.computer_threads"); ComputerCraft.computerThreads = serverConfig.<Integer>get( "execution.computer_threads" );
ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos(serverConfig.<Integer>get("execution.max_main_global_time")); ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( serverConfig.<Integer>get( "execution.max_main_global_time" ) );
ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos(serverConfig.<Integer>get("execution.max_main_computer_time")); ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( serverConfig.<Integer>get( "execution.max_main_computer_time" ) );
// HTTP // HTTP
ComputerCraft.httpEnabled = serverConfig.<Boolean>get("http.enabled"); ComputerCraft.httpEnabled = serverConfig.<Boolean>get( "http.enabled" );
ComputerCraft.httpWebsocketEnabled = serverConfig.<Boolean>get("http.websocket_enabled"); ComputerCraft.httpWebsocketEnabled = serverConfig.<Boolean>get( "http.websocket_enabled" );
ComputerCraft.httpRules = serverConfig.<List<UnmodifiableConfig>>get("http.rules").stream().map(AddressRuleConfig::parseRule) ComputerCraft.httpRules = serverConfig.<List<UnmodifiableConfig>>get( "http.rules" ).stream().map( AddressRuleConfig::parseRule )
.filter(Objects::nonNull).collect(Collectors.toList()); .filter( Objects::nonNull ).collect( Collectors.toList() );
ComputerCraft.httpMaxRequests = serverConfig.<Integer>get("http.max_requests"); ComputerCraft.httpMaxRequests = serverConfig.<Integer>get( "http.max_requests" );
ComputerCraft.httpMaxWebsockets = serverConfig.<Integer>get("http.max_websockets"); ComputerCraft.httpMaxWebsockets = serverConfig.<Integer>get( "http.max_websockets" );
// Peripherals // Peripherals
ComputerCraft.enableCommandBlock = serverConfig.<Boolean>get("peripheral.command_block_enabled"); ComputerCraft.enableCommandBlock = serverConfig.<Boolean>get( "peripheral.command_block_enabled" );
ComputerCraft.modemRange = serverConfig.<Integer>get("peripheral.modem_range"); ComputerCraft.modemRange = serverConfig.<Integer>get( "peripheral.modem_range" );
ComputerCraft.modemHighAltitudeRange = serverConfig.<Integer>get("peripheral.modem_high_altitude_range"); ComputerCraft.modemHighAltitudeRange = serverConfig.<Integer>get( "peripheral.modem_high_altitude_range" );
ComputerCraft.modemRangeDuringStorm = serverConfig.<Integer>get("peripheral.modem_range_during_storm"); ComputerCraft.modemRangeDuringStorm = serverConfig.<Integer>get( "peripheral.modem_range_during_storm" );
ComputerCraft.modemHighAltitudeRangeDuringStorm = serverConfig.<Integer>get("peripheral.modem_high_altitude_range_during_storm"); ComputerCraft.modemHighAltitudeRangeDuringStorm = serverConfig.<Integer>get( "peripheral.modem_high_altitude_range_during_storm" );
ComputerCraft.maxNotesPerTick = serverConfig.<Integer>get("peripheral.max_notes_per_tick"); ComputerCraft.maxNotesPerTick = serverConfig.<Integer>get( "peripheral.max_notes_per_tick" );
ComputerCraft.monitorBandwidth = serverConfig.<Integer>get("peripheral.monitor_bandwidth"); ComputerCraft.monitorBandwidth = serverConfig.<Integer>get( "peripheral.monitor_bandwidth" );
// Turtles // Turtles
ComputerCraft.turtlesNeedFuel = serverConfig.<Boolean>get("turtle.need_fuel"); ComputerCraft.turtlesNeedFuel = serverConfig.<Boolean>get( "turtle.need_fuel" );
ComputerCraft.turtleFuelLimit = serverConfig.<Integer>get("turtle.normal_fuel_limit"); ComputerCraft.turtleFuelLimit = serverConfig.<Integer>get( "turtle.normal_fuel_limit" );
ComputerCraft.advancedTurtleFuelLimit = serverConfig.<Integer>get("turtle.advanced_fuel_limit"); ComputerCraft.advancedTurtleFuelLimit = serverConfig.<Integer>get( "turtle.advanced_fuel_limit" );
ComputerCraft.turtlesObeyBlockProtection = serverConfig.<Boolean>get("turtle.obey_block_protection"); ComputerCraft.turtlesObeyBlockProtection = serverConfig.<Boolean>get( "turtle.obey_block_protection" );
ComputerCraft.turtlesCanPush = serverConfig.<Boolean>get("turtle.can_push"); ComputerCraft.turtlesCanPush = serverConfig.<Boolean>get( "turtle.can_push" );
ComputerCraft.turtleDisabledActions.clear(); ComputerCraft.turtleDisabledActions.clear();
for(String value : serverConfig.<List<String>>get("turtle.disabled_actions")) { for( String value : serverConfig.<List<String>>get( "turtle.disabled_actions" ) )
ComputerCraft.turtleDisabledActions.add(getAction(value)); {
ComputerCraft.turtleDisabledActions.add( getAction( value ) );
} }
// Terminal Size // Terminal Size
ComputerCraft.computerTermWidth = serverConfig.<Integer>get("term_sizes.computer.width"); ComputerCraft.computerTermWidth = serverConfig.<Integer>get( "term_sizes.computer.width" );
ComputerCraft.computerTermHeight = serverConfig.<Integer>get("term_sizes.computer.height"); ComputerCraft.computerTermHeight = serverConfig.<Integer>get( "term_sizes.computer.height" );
ComputerCraft.pocketTermWidth = serverConfig.<Integer>get("term_sizes.pocket_computer.width"); ComputerCraft.pocketTermWidth = serverConfig.<Integer>get( "term_sizes.pocket_computer.width" );
ComputerCraft.pocketTermHeight = serverConfig.<Integer>get("term_sizes.pocket_computer.height"); ComputerCraft.pocketTermHeight = serverConfig.<Integer>get( "term_sizes.pocket_computer.height" );
ComputerCraft.monitorWidth = serverConfig.<Integer>get("term_sizes.monitor.width"); ComputerCraft.monitorWidth = serverConfig.<Integer>get( "term_sizes.monitor.width" );
ComputerCraft.monitorHeight = serverConfig.<Integer>get("term_sizes.monitor.height"); ComputerCraft.monitorHeight = serverConfig.<Integer>get( "term_sizes.monitor.height" );
} }
// Client // Client
if(clientConfig != null) { if( clientConfig != null )
ComputerCraft.monitorRenderer = clientConfig.getEnum("monitor_renderer", MonitorRenderer.class); {
int distance = clientConfig.get("monitor_distance"); ComputerCraft.monitorRenderer = clientConfig.getEnum( "monitor_renderer", MonitorRenderer.class );
int distance = clientConfig.get( "monitor_distance" );
ComputerCraft.monitorDistanceSq = distance * distance; ComputerCraft.monitorDistanceSq = distance * distance;
} }
} }
private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.UPPER_UNDERSCORE); private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE );
private static TurtleAction getAction(String value) { private static TurtleAction getAction( String value )
try { {
return TurtleAction.valueOf(converter.convert(value)); try
{
return TurtleAction.valueOf( converter.convert( value ) );
} }
catch(IllegalArgumentException e) { catch( IllegalArgumentException e )
{
return null; return null;
} }
} }