mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-29 16:47:56 +00:00
No more m_ nice guy
This commit is contained in:
@@ -25,11 +25,11 @@ import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||
|
||||
public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
{
|
||||
private final boolean m_book;
|
||||
private final int m_pages;
|
||||
private final TextBuffer[] m_text;
|
||||
private final TextBuffer[] m_colours;
|
||||
private int m_page;
|
||||
private final boolean book;
|
||||
private final int pages;
|
||||
private final TextBuffer[] text;
|
||||
private final TextBuffer[] colours;
|
||||
private int page;
|
||||
|
||||
public GuiPrintout( ContainerHeldItem container, PlayerInventory player, Text title )
|
||||
{
|
||||
@@ -38,22 +38,22 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
this.backgroundHeight = Y_SIZE;
|
||||
|
||||
String[] text = ItemPrintout.getText( container.getStack() );
|
||||
this.m_text = new TextBuffer[text.length];
|
||||
for( int i = 0; i < this.m_text.length; i++ )
|
||||
this.text = new TextBuffer[text.length];
|
||||
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() );
|
||||
this.m_colours = new TextBuffer[colours.length];
|
||||
for( int i = 0; i < this.m_colours.length; i++ )
|
||||
this.colours = new TextBuffer[colours.length];
|
||||
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.m_pages = Math.max( this.m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||
this.m_book = ((ItemPrintout) container.getStack()
|
||||
this.page = 0;
|
||||
this.pages = Math.max( this.text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||
this.book = ((ItemPrintout) container.getStack()
|
||||
.getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
if( delta < 0 )
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
@@ -77,9 +77,9 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
if( delta > 0 )
|
||||
{
|
||||
// Scroll down goes to the previous page
|
||||
if( this.m_page > 0 )
|
||||
if( this.page > 0 )
|
||||
{
|
||||
this.m_page--;
|
||||
this.page--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -116,8 +116,8 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
.getEntityVertexConsumers();
|
||||
Matrix4f matrix = transform.peek()
|
||||
.getModel();
|
||||
drawBorder( matrix, renderer, this.x, this.y, this.getZOffset(), this.m_page, this.m_pages, this.m_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 );
|
||||
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.page, this.text, this.colours );
|
||||
renderer.draw();
|
||||
}
|
||||
|
||||
@@ -131,18 +131,18 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if( key == GLFW.GLFW_KEY_LEFT )
|
||||
{
|
||||
if( this.m_page > 0 )
|
||||
if( this.page > 0 )
|
||||
{
|
||||
this.m_page--;
|
||||
this.page--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -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_ADVANCED = new Identifier( "computercraft", "textures/gui/turtle_advanced.png" );
|
||||
private final ComputerFamily m_family;
|
||||
private final ClientComputer m_computer;
|
||||
private ContainerTurtle m_container;
|
||||
private final ComputerFamily family;
|
||||
private final ClientComputer computer;
|
||||
private final ContainerTurtle container;
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
|
||||
@@ -36,9 +36,9 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
|
||||
{
|
||||
super( container, player, title );
|
||||
|
||||
this.m_container = container;
|
||||
this.m_family = container.getFamily();
|
||||
this.m_computer = (ClientComputer) container.getComputer();
|
||||
this.container = container;
|
||||
this.family = container.getFamily();
|
||||
this.computer = (ClientComputer) container.getComputer();
|
||||
|
||||
this.backgroundWidth = 254;
|
||||
this.backgroundHeight = 217;
|
||||
@@ -53,7 +53,7 @@ public class GuiTurtle extends HandledScreen<ContainerTurtle>
|
||||
int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
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.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 )
|
||||
{
|
||||
// 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() );
|
||||
|
||||
// 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 );
|
||||
|
||||
// Draw selection slot
|
||||
int slot = this.m_container.getSelectedSlot();
|
||||
int slot = this.container.getSelectedSlot();
|
||||
if( slot >= 0 )
|
||||
{
|
||||
int slotX = slot % 4;
|
||||
|
@@ -23,23 +23,23 @@ import java.util.*;
|
||||
@Environment( EnvType.CLIENT )
|
||||
public class TurtleMultiModel implements BakedModel
|
||||
{
|
||||
private final BakedModel m_baseModel;
|
||||
private final BakedModel m_overlayModel;
|
||||
private final AffineTransformation m_generalTransform;
|
||||
private final TransformedModel m_leftUpgradeModel;
|
||||
private final TransformedModel m_rightUpgradeModel;
|
||||
private List<BakedQuad> m_generalQuads = null;
|
||||
private Map<Direction, List<BakedQuad>> m_faceQuads = new EnumMap<>( Direction.class );
|
||||
private final BakedModel baseModel;
|
||||
private final BakedModel overlayModel;
|
||||
private final AffineTransformation generalTransform;
|
||||
private final TransformedModel leftUpgradeModel;
|
||||
private final TransformedModel rightUpgradeModel;
|
||||
private List<BakedQuad> generalQuads = null;
|
||||
private Map<Direction, List<BakedQuad>> faceQuads = new EnumMap<>( Direction.class );
|
||||
|
||||
public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, AffineTransformation generalTransform, TransformedModel leftUpgradeModel,
|
||||
TransformedModel rightUpgradeModel )
|
||||
{
|
||||
// Get the models
|
||||
this.m_baseModel = baseModel;
|
||||
this.m_overlayModel = overlayModel;
|
||||
this.m_leftUpgradeModel = leftUpgradeModel;
|
||||
this.m_rightUpgradeModel = rightUpgradeModel;
|
||||
this.m_generalTransform = generalTransform;
|
||||
this.baseModel = baseModel;
|
||||
this.overlayModel = overlayModel;
|
||||
this.leftUpgradeModel = leftUpgradeModel;
|
||||
this.rightUpgradeModel = rightUpgradeModel;
|
||||
this.generalTransform = generalTransform;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -48,19 +48,19 @@ public class TurtleMultiModel implements BakedModel
|
||||
{
|
||||
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
|
||||
{
|
||||
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<>();
|
||||
|
||||
|
||||
ModelTransformer.transformQuadsTo( quads, this.m_baseModel.getQuads( state, side, rand ), this.m_generalTransform.getMatrix() );
|
||||
if( this.m_overlayModel != null )
|
||||
ModelTransformer.transformQuadsTo( quads, this.baseModel.getQuads( state, side, rand ), this.generalTransform.getMatrix() );
|
||||
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() );
|
||||
ModelTransformer.transformQuadsTo( quads, this.m_leftUpgradeModel.getModel()
|
||||
AffineTransformation upgradeTransform = this.generalTransform.multiply( this.leftUpgradeModel.getMatrix() );
|
||||
ModelTransformer.transformQuadsTo( quads, this.leftUpgradeModel.getModel()
|
||||
.getQuads( state, side, rand ),
|
||||
upgradeTransform.getMatrix() );
|
||||
}
|
||||
if( this.m_rightUpgradeModel != null )
|
||||
if( this.rightUpgradeModel != null )
|
||||
{
|
||||
AffineTransformation upgradeTransform = this.m_generalTransform.multiply( this.m_rightUpgradeModel.getMatrix() );
|
||||
ModelTransformer.transformQuadsTo( quads, this.m_rightUpgradeModel.getModel()
|
||||
AffineTransformation upgradeTransform = this.generalTransform.multiply( this.rightUpgradeModel.getMatrix() );
|
||||
ModelTransformer.transformQuadsTo( quads, this.rightUpgradeModel.getModel()
|
||||
.getQuads( state, side, rand ),
|
||||
upgradeTransform.getMatrix() );
|
||||
}
|
||||
@@ -95,25 +95,25 @@ public class TurtleMultiModel implements BakedModel
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
return this.m_baseModel.useAmbientOcclusion();
|
||||
return this.baseModel.useAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth()
|
||||
{
|
||||
return this.m_baseModel.hasDepth();
|
||||
return this.baseModel.hasDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit()
|
||||
{
|
||||
return this.m_baseModel.isSideLit();
|
||||
return this.baseModel.isSideLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin()
|
||||
{
|
||||
return this.m_baseModel.isBuiltin();
|
||||
return this.baseModel.isBuiltin();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -121,7 +121,7 @@ public class TurtleMultiModel implements BakedModel
|
||||
@Deprecated
|
||||
public Sprite getSprite()
|
||||
{
|
||||
return this.m_baseModel.getSprite();
|
||||
return this.baseModel.getSprite();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -129,7 +129,7 @@ public class TurtleMultiModel implements BakedModel
|
||||
@Deprecated
|
||||
public net.minecraft.client.render.model.json.ModelTransformation getTransformation()
|
||||
{
|
||||
return this.m_baseModel.getTransformation();
|
||||
return this.baseModel.getTransformation();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@@ -57,8 +57,8 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
|
||||
private final BakedModel familyModel;
|
||||
private final BakedModel colourModel;
|
||||
private final HashMap<TurtleModelCombination, BakedModel> m_cachedModels = new HashMap<>();
|
||||
private final ModelOverrideList m_overrides;
|
||||
private final HashMap<TurtleModelCombination, BakedModel> cachedModels = new HashMap<>();
|
||||
private final ModelOverrideList overrides;
|
||||
|
||||
public TurtleSmartItemModel( BakedModel familyModel, BakedModel colourModel )
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
this.colourModel = colourModel;
|
||||
|
||||
// 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
|
||||
@Override
|
||||
@@ -85,10 +85,10 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
boolean flip = false;
|
||||
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 )
|
||||
{
|
||||
TurtleSmartItemModel.this.m_cachedModels.put( combo, model = TurtleSmartItemModel.this.buildModel( combo ) );
|
||||
TurtleSmartItemModel.this.cachedModels.put( combo, model = TurtleSmartItemModel.this.buildModel( combo ) );
|
||||
}
|
||||
return model;
|
||||
}
|
||||
@@ -101,13 +101,13 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
BakedModelManager modelManager = mc.getItemRenderer()
|
||||
.getModels()
|
||||
.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;
|
||||
AffineTransformation transform = combo.m_flip ? flip : identity;
|
||||
TransformedModel leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.LEFT ) : null;
|
||||
TransformedModel rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null;
|
||||
AffineTransformation transform = combo.flip ? flip : identity;
|
||||
TransformedModel leftModel = combo.leftUpgrade != null ? combo.leftUpgrade.getModel( null, TurtleSide.LEFT ) : null;
|
||||
TransformedModel rightModel = combo.rightUpgrade != null ? combo.rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null;
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel );
|
||||
}
|
||||
|
||||
@@ -163,27 +163,27 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
@Override
|
||||
public ModelOverrideList getOverrides()
|
||||
{
|
||||
return this.m_overrides;
|
||||
return this.overrides;
|
||||
}
|
||||
|
||||
private static class TurtleModelCombination
|
||||
{
|
||||
final boolean m_colour;
|
||||
final ITurtleUpgrade m_leftUpgrade;
|
||||
final ITurtleUpgrade m_rightUpgrade;
|
||||
final Identifier m_overlay;
|
||||
final boolean m_christmas;
|
||||
final boolean m_flip;
|
||||
final boolean colour;
|
||||
final ITurtleUpgrade leftUpgrade;
|
||||
final ITurtleUpgrade rightUpgrade;
|
||||
final Identifier overlay;
|
||||
final boolean christmas;
|
||||
final boolean flip;
|
||||
|
||||
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, Identifier overlay, boolean christmas,
|
||||
boolean flip )
|
||||
{
|
||||
this.m_colour = colour;
|
||||
this.m_leftUpgrade = leftUpgrade;
|
||||
this.m_rightUpgrade = rightUpgrade;
|
||||
this.m_overlay = overlay;
|
||||
this.m_christmas = christmas;
|
||||
this.m_flip = flip;
|
||||
this.colour = colour;
|
||||
this.leftUpgrade = leftUpgrade;
|
||||
this.rightUpgrade = rightUpgrade;
|
||||
this.overlay = overlay;
|
||||
this.christmas = christmas;
|
||||
this.flip = flip;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,12 +191,12 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 0;
|
||||
result = prime * result + (this.m_colour ? 1 : 0);
|
||||
result = prime * result + (this.m_leftUpgrade != null ? this.m_leftUpgrade.hashCode() : 0);
|
||||
result = prime * result + (this.m_rightUpgrade != null ? this.m_rightUpgrade.hashCode() : 0);
|
||||
result = prime * result + (this.m_overlay != null ? this.m_overlay.hashCode() : 0);
|
||||
result = prime * result + (this.m_christmas ? 1 : 0);
|
||||
result = prime * result + (this.m_flip ? 1 : 0);
|
||||
result = prime * result + (this.colour ? 1 : 0);
|
||||
result = prime * result + (this.leftUpgrade != null ? this.leftUpgrade.hashCode() : 0);
|
||||
result = prime * result + (this.rightUpgrade != null ? this.rightUpgrade.hashCode() : 0);
|
||||
result = prime * result + (this.overlay != null ? this.overlay.hashCode() : 0);
|
||||
result = prime * result + (this.christmas ? 1 : 0);
|
||||
result = prime * result + (this.flip ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -213,8 +213,8 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
}
|
||||
|
||||
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(
|
||||
otherCombo.m_overlay, this.m_overlay ) && otherCombo.m_christmas == this.m_christmas && otherCombo.m_flip == this.m_flip;
|
||||
return otherCombo.colour == this.colour && otherCombo.leftUpgrade == this.leftUpgrade && otherCombo.rightUpgrade == this.rightUpgrade && Objects.equal(
|
||||
otherCombo.overlay, this.overlay ) && otherCombo.christmas == this.christmas && otherCombo.flip == this.flip;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,21 +12,21 @@ import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ClientTerminal implements ITerminal
|
||||
{
|
||||
private boolean m_colour;
|
||||
private Terminal m_terminal;
|
||||
private boolean m_terminalChanged;
|
||||
private boolean colour;
|
||||
private Terminal terminal;
|
||||
private boolean terminalChanged;
|
||||
|
||||
public ClientTerminal( boolean colour )
|
||||
{
|
||||
this.m_colour = colour;
|
||||
this.m_terminal = null;
|
||||
this.m_terminalChanged = false;
|
||||
this.colour = colour;
|
||||
this.terminal = null;
|
||||
this.terminalChanged = false;
|
||||
}
|
||||
|
||||
public boolean pollTerminalChanged()
|
||||
{
|
||||
boolean changed = this.m_terminalChanged;
|
||||
this.m_terminalChanged = false;
|
||||
boolean changed = this.terminalChanged;
|
||||
this.terminalChanged = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -35,22 +35,22 @@ public class ClientTerminal implements ITerminal
|
||||
@Override
|
||||
public Terminal getTerminal()
|
||||
{
|
||||
return this.m_terminal;
|
||||
return this.terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColour()
|
||||
{
|
||||
return this.m_colour;
|
||||
return this.colour;
|
||||
}
|
||||
|
||||
public void read( TerminalState state )
|
||||
{
|
||||
this.m_colour = state.colour;
|
||||
this.colour = state.colour;
|
||||
if( state.hasTerminal() )
|
||||
{
|
||||
this.resizeTerminal( state.width, state.height );
|
||||
state.apply( this.m_terminal );
|
||||
state.apply( this.terminal );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -60,34 +60,34 @@ public class ClientTerminal implements ITerminal
|
||||
|
||||
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.m_terminalChanged = true;
|
||||
this.terminal = new Terminal( width, height, () -> this.terminalChanged = true );
|
||||
this.terminalChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_terminal.resize( width, height );
|
||||
this.terminal.resize( width, height );
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteTerminal()
|
||||
{
|
||||
if( this.m_terminal != null )
|
||||
if( this.terminal != null )
|
||||
{
|
||||
this.m_terminal = null;
|
||||
this.m_terminalChanged = true;
|
||||
this.terminal = null;
|
||||
this.terminalChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void readDescription( CompoundTag nbt )
|
||||
{
|
||||
this.m_colour = nbt.getBoolean( "colour" );
|
||||
this.colour = nbt.getBoolean( "colour" );
|
||||
if( nbt.contains( "terminal" ) )
|
||||
{
|
||||
CompoundTag terminal = nbt.getCompound( "terminal" );
|
||||
this.resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
|
||||
this.m_terminal.readFromNBT( terminal );
|
||||
this.terminal.readFromNBT( terminal );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -14,86 +14,86 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class ServerTerminal implements ITerminal
|
||||
{
|
||||
private final boolean m_colour;
|
||||
private final AtomicBoolean m_terminalChanged = new AtomicBoolean( false );
|
||||
private Terminal m_terminal;
|
||||
private boolean m_terminalChangedLastFrame = false;
|
||||
private final boolean colour;
|
||||
private final AtomicBoolean terminalChanged = new AtomicBoolean( false );
|
||||
private Terminal terminal;
|
||||
private boolean terminalChangedLastFrame = false;
|
||||
|
||||
public ServerTerminal( boolean colour )
|
||||
{
|
||||
this.m_colour = colour;
|
||||
this.m_terminal = null;
|
||||
this.colour = colour;
|
||||
this.terminal = null;
|
||||
}
|
||||
|
||||
public ServerTerminal( boolean colour, int terminalWidth, int terminalHeight )
|
||||
{
|
||||
this.m_colour = colour;
|
||||
this.m_terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
|
||||
this.colour = colour;
|
||||
this.terminal = new Terminal( terminalWidth, terminalHeight, this::markTerminalChanged );
|
||||
}
|
||||
|
||||
protected void markTerminalChanged()
|
||||
{
|
||||
this.m_terminalChanged.set( true );
|
||||
this.terminalChanged.set( true );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_terminal.resize( width, height );
|
||||
this.terminal.resize( width, height );
|
||||
}
|
||||
}
|
||||
|
||||
public void delete()
|
||||
{
|
||||
if( this.m_terminal != null )
|
||||
if( this.terminal != null )
|
||||
{
|
||||
this.m_terminal = null;
|
||||
this.terminal = null;
|
||||
this.markTerminalChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
this.m_terminalChangedLastFrame = this.m_terminalChanged.getAndSet( false );
|
||||
this.terminalChangedLastFrame = this.terminalChanged.getAndSet( false );
|
||||
}
|
||||
|
||||
public boolean hasTerminalChanged()
|
||||
{
|
||||
return this.m_terminalChangedLastFrame;
|
||||
return this.terminalChangedLastFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal getTerminal()
|
||||
{
|
||||
return this.m_terminal;
|
||||
return this.terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColour()
|
||||
{
|
||||
return this.m_colour;
|
||||
return this.colour;
|
||||
}
|
||||
|
||||
public TerminalState write()
|
||||
{
|
||||
return new TerminalState( this.m_colour, this.m_terminal );
|
||||
return new TerminalState( this.colour, this.terminal );
|
||||
}
|
||||
|
||||
public void writeDescription( CompoundTag nbt )
|
||||
{
|
||||
nbt.putBoolean( "colour", this.m_colour );
|
||||
if( this.m_terminal != null )
|
||||
nbt.putBoolean( "colour", this.colour );
|
||||
if( this.terminal != null )
|
||||
{
|
||||
CompoundTag terminal = new CompoundTag();
|
||||
terminal.putInt( "term_width", this.m_terminal.getWidth() );
|
||||
terminal.putInt( "term_height", this.m_terminal.getHeight() );
|
||||
this.m_terminal.writeToNBT( terminal );
|
||||
terminal.putInt( "term_width", this.terminal.getWidth() );
|
||||
terminal.putInt( "term_height", this.terminal.getHeight() );
|
||||
this.terminal.writeToNBT( terminal );
|
||||
nbt.put( "terminal", terminal );
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ public class ComputerProxy
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
tile.m_startOn = true;
|
||||
tile.startOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,7 +48,7 @@ public class ComputerProxy
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
tile.m_startOn = false;
|
||||
tile.startOn = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -62,7 +62,7 @@ public class ComputerProxy
|
||||
ServerComputer computer = tile.getServerComputer();
|
||||
if( computer == null )
|
||||
{
|
||||
tile.m_startOn = true;
|
||||
tile.startOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -56,11 +56,11 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
private static final String NBT_ON = "On";
|
||||
private final ComputerFamily family;
|
||||
protected String label = null;
|
||||
boolean m_startOn = false;
|
||||
private int m_instanceID = -1;
|
||||
private int m_computerID = -1;
|
||||
private boolean m_on = false;
|
||||
private boolean m_fresh = false;
|
||||
boolean startOn = false;
|
||||
private int instanceID = -1;
|
||||
private int computerID = -1;
|
||||
private boolean on = false;
|
||||
private boolean fresh = false;
|
||||
|
||||
public TileComputerBase( BlockEntityType<? extends TileGeneric> type, ComputerFamily family )
|
||||
{
|
||||
@@ -86,13 +86,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
|
||||
protected void unload()
|
||||
{
|
||||
if( this.m_instanceID >= 0 )
|
||||
if( this.instanceID >= 0 )
|
||||
{
|
||||
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;
|
||||
if( this.m_instanceID < 0 )
|
||||
if( this.instanceID < 0 )
|
||||
{
|
||||
this.m_instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID();
|
||||
this.instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID();
|
||||
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 );
|
||||
ComputerCraft.serverComputerRegistry.add( this.m_instanceID, computer );
|
||||
this.m_fresh = true;
|
||||
ServerComputer computer = this.createComputer( this.instanceID, this.computerID );
|
||||
ComputerCraft.serverComputerRegistry.add( this.instanceID, computer );
|
||||
this.fresh = true;
|
||||
changed = true;
|
||||
}
|
||||
if( changed )
|
||||
@@ -156,12 +156,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
this.updateBlock();
|
||||
this.updateInput();
|
||||
}
|
||||
return ComputerCraft.serverComputerRegistry.get( this.m_instanceID );
|
||||
return ComputerCraft.serverComputerRegistry.get( this.instanceID );
|
||||
}
|
||||
|
||||
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 );
|
||||
@@ -255,7 +255,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
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
|
||||
@@ -266,9 +266,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
{
|
||||
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( this.m_startOn || (this.m_fresh && this.m_on) )
|
||||
if( this.startOn || (this.fresh && this.on) )
|
||||
{
|
||||
computer.turnOn();
|
||||
this.m_startOn = false;
|
||||
this.startOn = false;
|
||||
}
|
||||
|
||||
computer.keepAlive();
|
||||
|
||||
this.m_fresh = false;
|
||||
this.m_computerID = computer.getID();
|
||||
this.fresh = false;
|
||||
this.computerID = computer.getID();
|
||||
this.label = computer.getLabel();
|
||||
this.m_on = computer.isOn();
|
||||
this.on = computer.isOn();
|
||||
|
||||
if( computer.hasOutputChanged() )
|
||||
{
|
||||
@@ -331,9 +331,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
super.fromTag( state, nbt );
|
||||
|
||||
// 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.m_on = this.m_startOn = nbt.getBoolean( NBT_ON );
|
||||
this.on = this.startOn = nbt.getBoolean( NBT_ON );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -341,15 +341,15 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
public CompoundTag toTag( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
// 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 )
|
||||
{
|
||||
nbt.putString( NBT_LABEL, this.label );
|
||||
}
|
||||
nbt.putBoolean( NBT_ON, this.m_on );
|
||||
nbt.putBoolean( NBT_ON, this.on );
|
||||
|
||||
return super.toTag( nbt );
|
||||
}
|
||||
@@ -407,22 +407,22 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
@Override
|
||||
public final int getComputerID()
|
||||
{
|
||||
return this.m_computerID;
|
||||
return this.computerID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setComputerID( int id )
|
||||
{
|
||||
if( this.getWorld().isClient || this.m_computerID == id )
|
||||
if( this.getWorld().isClient || this.computerID == id )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.m_computerID = id;
|
||||
this.computerID = id;
|
||||
ServerComputer computer = this.getServerComputer();
|
||||
if( computer != null )
|
||||
{
|
||||
computer.setID( this.m_computerID );
|
||||
computer.setID( this.computerID );
|
||||
}
|
||||
this.markDirty();
|
||||
}
|
||||
@@ -460,17 +460,17 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
|
||||
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.m_instanceID = copy.m_instanceID;
|
||||
this.m_computerID = copy.m_computerID;
|
||||
this.instanceID = copy.instanceID;
|
||||
this.computerID = copy.computerID;
|
||||
this.label = copy.label;
|
||||
this.m_on = copy.m_on;
|
||||
this.m_startOn = copy.m_startOn;
|
||||
this.on = copy.on;
|
||||
this.startOn = copy.startOn;
|
||||
this.updateBlock();
|
||||
}
|
||||
copy.m_instanceID = -1;
|
||||
copy.instanceID = -1;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@@ -13,22 +13,22 @@ import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ClientComputer extends ClientTerminal implements IComputer
|
||||
{
|
||||
private final int m_instanceID;
|
||||
private final int instanceID;
|
||||
|
||||
private boolean m_on = false;
|
||||
private boolean m_blinking = false;
|
||||
private CompoundTag m_userData = null;
|
||||
private boolean on = false;
|
||||
private boolean blinking = false;
|
||||
private CompoundTag userData = null;
|
||||
|
||||
|
||||
public ClientComputer( int instanceID )
|
||||
{
|
||||
super( false );
|
||||
this.m_instanceID = instanceID;
|
||||
this.instanceID = instanceID;
|
||||
}
|
||||
|
||||
public CompoundTag getUserData()
|
||||
{
|
||||
return this.m_userData;
|
||||
return this.userData;
|
||||
}
|
||||
|
||||
public void requestState()
|
||||
@@ -42,53 +42,53 @@ public class ClientComputer extends ClientTerminal implements IComputer
|
||||
@Override
|
||||
public int getInstanceID()
|
||||
{
|
||||
return this.m_instanceID;
|
||||
return this.instanceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOn()
|
||||
{
|
||||
// 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
|
||||
public void shutdown()
|
||||
{
|
||||
// Send shutdown to server
|
||||
NetworkHandler.sendToServer( new ComputerActionServerMessage( this.m_instanceID, ComputerActionServerMessage.Action.SHUTDOWN ) );
|
||||
NetworkHandler.sendToServer( new ComputerActionServerMessage( this.instanceID, ComputerActionServerMessage.Action.SHUTDOWN ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reboot()
|
||||
{
|
||||
// Send reboot to server
|
||||
NetworkHandler.sendToServer( new ComputerActionServerMessage( this.m_instanceID, ComputerActionServerMessage.Action.REBOOT ) );
|
||||
NetworkHandler.sendToServer( new ComputerActionServerMessage( this.instanceID, ComputerActionServerMessage.Action.REBOOT ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueEvent( String event, Object[] arguments )
|
||||
{
|
||||
// Send event to server
|
||||
NetworkHandler.sendToServer( new QueueEventServerMessage( this.m_instanceID, event, arguments ) );
|
||||
NetworkHandler.sendToServer( new QueueEventServerMessage( this.instanceID, event, arguments ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOn()
|
||||
{
|
||||
return this.m_on;
|
||||
return this.on;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCursorDisplayed()
|
||||
{
|
||||
return this.m_on && this.m_blinking;
|
||||
return this.on && this.blinking;
|
||||
}
|
||||
|
||||
@Override
|
||||
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,
|
||||
key ) );
|
||||
}
|
||||
@@ -96,37 +96,37 @@ public class ClientComputer extends ClientTerminal implements IComputer
|
||||
@Override
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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 )
|
||||
{
|
||||
this.m_on = state != ComputerState.OFF;
|
||||
this.m_blinking = state == ComputerState.BLINKING;
|
||||
this.m_userData = userData;
|
||||
this.on = state != ComputerState.OFF;
|
||||
this.blinking = state == ComputerState.BLINKING;
|
||||
this.userData = userData;
|
||||
}
|
||||
}
|
||||
|
@@ -13,45 +13,45 @@ import java.util.Random;
|
||||
|
||||
public class ComputerRegistry<T extends IComputer>
|
||||
{
|
||||
private Map<Integer, T> m_computers;
|
||||
private int m_nextUnusedInstanceID;
|
||||
private int m_sessionID;
|
||||
private final Map<Integer, T> computers;
|
||||
private int nextUnusedInstanceID;
|
||||
private int sessionID;
|
||||
|
||||
protected ComputerRegistry()
|
||||
{
|
||||
this.m_computers = new HashMap<>();
|
||||
this.computers = new HashMap<>();
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
this.m_computers.clear();
|
||||
this.m_nextUnusedInstanceID = 0;
|
||||
this.m_sessionID = new Random().nextInt();
|
||||
this.computers.clear();
|
||||
this.nextUnusedInstanceID = 0;
|
||||
this.sessionID = new Random().nextInt();
|
||||
}
|
||||
|
||||
public int getSessionID()
|
||||
{
|
||||
return this.m_sessionID;
|
||||
return this.sessionID;
|
||||
}
|
||||
|
||||
public int getUnusedInstanceID()
|
||||
{
|
||||
return this.m_nextUnusedInstanceID++;
|
||||
return this.nextUnusedInstanceID++;
|
||||
}
|
||||
|
||||
public Collection<T> getComputers()
|
||||
{
|
||||
return this.m_computers.values();
|
||||
return this.computers.values();
|
||||
}
|
||||
|
||||
public T get( int instanceID )
|
||||
{
|
||||
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;
|
||||
@@ -59,21 +59,21 @@ public class ComputerRegistry<T extends IComputer>
|
||||
|
||||
public boolean contains( int instanceID )
|
||||
{
|
||||
return this.m_computers.containsKey( instanceID );
|
||||
return this.computers.containsKey( instanceID );
|
||||
}
|
||||
|
||||
public void add( int instanceID, T computer )
|
||||
{
|
||||
if( this.m_computers.containsKey( instanceID ) )
|
||||
if( this.computers.containsKey( instanceID ) )
|
||||
{
|
||||
this.remove( instanceID );
|
||||
}
|
||||
this.m_computers.put( instanceID, computer );
|
||||
this.m_nextUnusedInstanceID = Math.max( this.m_nextUnusedInstanceID, instanceID + 1 );
|
||||
this.computers.put( instanceID, computer );
|
||||
this.nextUnusedInstanceID = Math.max( this.nextUnusedInstanceID, instanceID + 1 );
|
||||
}
|
||||
|
||||
public void remove( int instanceID )
|
||||
{
|
||||
this.m_computers.remove( instanceID );
|
||||
this.computers.remove( instanceID );
|
||||
}
|
||||
}
|
||||
|
@@ -37,109 +37,109 @@ import java.io.InputStream;
|
||||
|
||||
public class ServerComputer extends ServerTerminal implements IComputer, IComputerEnvironment
|
||||
{
|
||||
private final int m_instanceID;
|
||||
private final ComputerFamily m_family;
|
||||
private final Computer m_computer;
|
||||
private World m_world;
|
||||
private BlockPos m_position;
|
||||
private CompoundTag m_userData;
|
||||
private boolean m_changed;
|
||||
private final int instanceID;
|
||||
private final ComputerFamily family;
|
||||
private final Computer computer;
|
||||
private World world;
|
||||
private BlockPos position;
|
||||
private CompoundTag userData;
|
||||
private boolean changed;
|
||||
|
||||
private boolean m_changedLastFrame;
|
||||
private int m_ticksSincePing;
|
||||
private boolean changedLastFrame;
|
||||
private int ticksSincePing;
|
||||
|
||||
public ServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family, int terminalWidth, int terminalHeight )
|
||||
{
|
||||
super( family != ComputerFamily.NORMAL, terminalWidth, terminalHeight );
|
||||
this.m_instanceID = instanceID;
|
||||
this.instanceID = instanceID;
|
||||
|
||||
this.m_world = world;
|
||||
this.m_position = null;
|
||||
this.world = world;
|
||||
this.position = null;
|
||||
|
||||
this.m_family = family;
|
||||
this.m_computer = new Computer( this, this.getTerminal(), computerID );
|
||||
this.m_computer.setLabel( label );
|
||||
this.m_userData = null;
|
||||
this.m_changed = false;
|
||||
this.family = family;
|
||||
this.computer = new Computer( this, this.getTerminal(), computerID );
|
||||
this.computer.setLabel( label );
|
||||
this.userData = null;
|
||||
this.changed = false;
|
||||
|
||||
this.m_changedLastFrame = false;
|
||||
this.m_ticksSincePing = 0;
|
||||
this.changedLastFrame = false;
|
||||
this.ticksSincePing = 0;
|
||||
}
|
||||
|
||||
public ComputerFamily getFamily()
|
||||
{
|
||||
return this.m_family;
|
||||
return this.family;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
return this.m_world;
|
||||
return this.world;
|
||||
}
|
||||
|
||||
public void setWorld( World world )
|
||||
{
|
||||
this.m_world = world;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public BlockPos getPosition()
|
||||
{
|
||||
return this.m_position;
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public void setPosition( BlockPos pos )
|
||||
{
|
||||
this.m_position = new BlockPos( pos );
|
||||
this.position = new BlockPos( pos );
|
||||
}
|
||||
|
||||
public IAPIEnvironment getAPIEnvironment()
|
||||
{
|
||||
return this.m_computer.getAPIEnvironment();
|
||||
return this.computer.getAPIEnvironment();
|
||||
}
|
||||
|
||||
public Computer getComputer()
|
||||
{
|
||||
return this.m_computer;
|
||||
return this.computer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
super.update();
|
||||
this.m_computer.tick();
|
||||
this.computer.tick();
|
||||
|
||||
this.m_changedLastFrame = this.m_computer.pollAndResetChanged() || this.m_changed;
|
||||
this.m_changed = false;
|
||||
this.changedLastFrame = this.computer.pollAndResetChanged() || this.changed;
|
||||
this.changed = false;
|
||||
|
||||
this.m_ticksSincePing++;
|
||||
this.ticksSincePing++;
|
||||
}
|
||||
|
||||
public void keepAlive()
|
||||
{
|
||||
this.m_ticksSincePing = 0;
|
||||
this.ticksSincePing = 0;
|
||||
}
|
||||
|
||||
public boolean hasTimedOut()
|
||||
{
|
||||
return this.m_ticksSincePing > 100;
|
||||
return this.ticksSincePing > 100;
|
||||
}
|
||||
|
||||
public void unload()
|
||||
{
|
||||
this.m_computer.unload();
|
||||
this.computer.unload();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
this.m_changed = true;
|
||||
this.changed = true;
|
||||
}
|
||||
|
||||
public void broadcastState( boolean force )
|
||||
@@ -180,7 +180,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
|
||||
public boolean hasOutputChanged()
|
||||
{
|
||||
return this.m_changedLastFrame;
|
||||
return this.changedLastFrame;
|
||||
}
|
||||
|
||||
private NetworkMessage createComputerPacket()
|
||||
@@ -219,14 +219,14 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
@Override
|
||||
public int getInstanceID()
|
||||
{
|
||||
return this.m_instanceID;
|
||||
return this.instanceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOn()
|
||||
{
|
||||
// Turn on
|
||||
this.m_computer.turnOn();
|
||||
this.computer.turnOn();
|
||||
}
|
||||
|
||||
// IComputer
|
||||
@@ -235,33 +235,33 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
public void shutdown()
|
||||
{
|
||||
// Shutdown
|
||||
this.m_computer.shutdown();
|
||||
this.computer.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reboot()
|
||||
{
|
||||
// Reboot
|
||||
this.m_computer.reboot();
|
||||
this.computer.reboot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueEvent( String event, Object[] arguments )
|
||||
{
|
||||
// Queue event
|
||||
this.m_computer.queueEvent( event, arguments );
|
||||
this.computer.queueEvent( event, arguments );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOn()
|
||||
{
|
||||
return this.m_computer.isOn();
|
||||
return this.computer.isOn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCursorDisplayed()
|
||||
{
|
||||
return this.m_computer.isOn() && this.m_computer.isBlinking();
|
||||
return this.computer.isOn() && this.computer.isBlinking();
|
||||
}
|
||||
|
||||
public void sendComputerState( PlayerEntity player )
|
||||
@@ -288,77 +288,77 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
|
||||
public int getID()
|
||||
{
|
||||
return this.m_computer.getID();
|
||||
return this.computer.getID();
|
||||
}
|
||||
|
||||
public void setID( int id )
|
||||
{
|
||||
this.m_computer.setID( id );
|
||||
this.computer.setID( id );
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return this.m_computer.getLabel();
|
||||
return this.computer.getLabel();
|
||||
}
|
||||
|
||||
public void setLabel( String label )
|
||||
{
|
||||
this.m_computer.setLabel( label );
|
||||
this.computer.setLabel( label );
|
||||
}
|
||||
|
||||
public int getRedstoneOutput( ComputerSide side )
|
||||
{
|
||||
return this.m_computer.getEnvironment()
|
||||
return this.computer.getEnvironment()
|
||||
.getExternalRedstoneOutput( side );
|
||||
}
|
||||
|
||||
public void setRedstoneInput( ComputerSide side, int level )
|
||||
{
|
||||
this.m_computer.getEnvironment()
|
||||
this.computer.getEnvironment()
|
||||
.setRedstoneInput( side, level );
|
||||
}
|
||||
|
||||
public int getBundledRedstoneOutput( ComputerSide side )
|
||||
{
|
||||
return this.m_computer.getEnvironment()
|
||||
return this.computer.getEnvironment()
|
||||
.getExternalBundledRedstoneOutput( side );
|
||||
}
|
||||
|
||||
public void setBundledRedstoneInput( ComputerSide side, int combination )
|
||||
{
|
||||
this.m_computer.getEnvironment()
|
||||
this.computer.getEnvironment()
|
||||
.setBundledRedstoneInput( side, combination );
|
||||
}
|
||||
|
||||
public void addAPI( ILuaAPI api )
|
||||
{
|
||||
this.m_computer.addApi( api );
|
||||
this.computer.addApi( api );
|
||||
}
|
||||
|
||||
// IComputerEnvironment implementation
|
||||
|
||||
public void setPeripheral( ComputerSide side, IPeripheral peripheral )
|
||||
{
|
||||
this.m_computer.getEnvironment()
|
||||
this.computer.getEnvironment()
|
||||
.setPeripheral( side, peripheral );
|
||||
}
|
||||
|
||||
public IPeripheral getPeripheral( ComputerSide side )
|
||||
{
|
||||
return this.m_computer.getEnvironment()
|
||||
return this.computer.getEnvironment()
|
||||
.getPeripheral( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDay()
|
||||
{
|
||||
return (int) ((this.m_world.getTimeOfDay() + 6000) / 24000) + 1;
|
||||
return (int) ((this.world.getTimeOfDay() + 6000) / 24000) + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTimeOfDay()
|
||||
{
|
||||
return (this.m_world.getTimeOfDay() + 6000) % 24000 / 1000.0;
|
||||
return (this.world.getTimeOfDay() + 6000) % 24000 / 1000.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -384,13 +384,13 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
|
||||
@Override
|
||||
public int assignNewID()
|
||||
{
|
||||
return ComputerCraftAPI.createUniqueNumberedSaveDir( this.m_world, "computer" );
|
||||
return ComputerCraftAPI.createUniqueNumberedSaveDir( this.world, "computer" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWritableMount createSaveDirMount( String subPath, long capacity )
|
||||
{
|
||||
return ComputerCraftAPI.createSaveDirMount( this.m_world, subPath, capacity );
|
||||
return ComputerCraftAPI.createSaveDirMount( this.world, subPath, capacity );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -47,15 +47,15 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
{
|
||||
private static final String NBT_NAME = "CustomName";
|
||||
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;
|
||||
@Nonnull
|
||||
private ItemStack m_diskStack = ItemStack.EMPTY;
|
||||
private IMount m_diskMount = null;
|
||||
private boolean m_recordQueued = false;
|
||||
private boolean m_recordPlaying = false;
|
||||
private boolean m_restartRecord = false;
|
||||
private boolean m_ejectQueued;
|
||||
private ItemStack diskStack = ItemStack.EMPTY;
|
||||
private IMount diskMount = null;
|
||||
private boolean recordQueued = false;
|
||||
private boolean recordPlaying = false;
|
||||
private boolean restartRecord = false;
|
||||
private boolean ejectQueued;
|
||||
|
||||
public TileDiskDrive( BlockEntityType<TileDiskDrive> type )
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
public void destroy()
|
||||
{
|
||||
this.ejectContents( true );
|
||||
if( this.m_recordPlaying )
|
||||
if( this.recordPlaying )
|
||||
{
|
||||
this.stopRecord();
|
||||
}
|
||||
@@ -115,8 +115,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
if( nbt.contains( NBT_ITEM ) )
|
||||
{
|
||||
CompoundTag item = nbt.getCompound( NBT_ITEM );
|
||||
this.m_diskStack = ItemStack.fromTag( item );
|
||||
this.m_diskMount = null;
|
||||
this.diskStack = ItemStack.fromTag( item );
|
||||
this.diskMount = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
nbt.putString( NBT_NAME, Text.Serializer.toJson( this.customName ) );
|
||||
}
|
||||
|
||||
if( !this.m_diskStack.isEmpty() )
|
||||
if( !this.diskStack.isEmpty() )
|
||||
{
|
||||
CompoundTag item = new CompoundTag();
|
||||
this.m_diskStack.toTag( item );
|
||||
this.diskStack.toTag( item );
|
||||
nbt.put( NBT_ITEM, item );
|
||||
}
|
||||
return super.toTag( nbt );
|
||||
@@ -152,36 +152,36 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
public void tick()
|
||||
{
|
||||
// Ejection
|
||||
if( this.m_ejectQueued )
|
||||
if( this.ejectQueued )
|
||||
{
|
||||
this.ejectContents( false );
|
||||
this.m_ejectQueued = false;
|
||||
this.ejectQueued = false;
|
||||
}
|
||||
|
||||
// Music
|
||||
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;
|
||||
if( this.m_recordQueued )
|
||||
this.restartRecord = false;
|
||||
if( this.recordQueued )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
this.m_recordPlaying = true;
|
||||
this.recordPlaying = true;
|
||||
this.playRecord();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_recordQueued = false;
|
||||
this.recordQueued = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.stopRecord();
|
||||
this.m_recordPlaying = false;
|
||||
this.recordPlaying = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,34 +198,34 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.m_diskStack.isEmpty();
|
||||
return this.diskStack.isEmpty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStack( int slot )
|
||||
{
|
||||
return this.m_diskStack;
|
||||
return this.diskStack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack removeStack( int slot, int count )
|
||||
{
|
||||
if( this.m_diskStack.isEmpty() )
|
||||
if( this.diskStack.isEmpty() )
|
||||
{
|
||||
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 );
|
||||
return disk;
|
||||
}
|
||||
|
||||
ItemStack part = this.m_diskStack.split( count );
|
||||
this.setStack( slot, this.m_diskStack.isEmpty() ? ItemStack.EMPTY : this.m_diskStack );
|
||||
ItemStack part = this.diskStack.split( count );
|
||||
this.setStack( slot, this.diskStack.isEmpty() ? ItemStack.EMPTY : this.diskStack );
|
||||
return part;
|
||||
}
|
||||
|
||||
@@ -233,9 +233,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
@Override
|
||||
public ItemStack removeStack( int slot )
|
||||
{
|
||||
ItemStack result = this.m_diskStack;
|
||||
this.m_diskStack = ItemStack.EMPTY;
|
||||
this.m_diskMount = null;
|
||||
ItemStack result = this.diskStack;
|
||||
this.diskStack = ItemStack.EMPTY;
|
||||
this.diskMount = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -245,25 +245,25 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
{
|
||||
if( this.getWorld().isClient )
|
||||
{
|
||||
this.m_diskStack = stack;
|
||||
this.m_diskMount = null;
|
||||
this.diskStack = stack;
|
||||
this.diskMount = null;
|
||||
this.markDirty();
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized( this )
|
||||
{
|
||||
if( InventoryUtil.areItemsStackable( stack, this.m_diskStack ) )
|
||||
if( InventoryUtil.areItemsStackable( stack, this.diskStack ) )
|
||||
{
|
||||
this.m_diskStack = stack;
|
||||
this.diskStack = stack;
|
||||
return;
|
||||
}
|
||||
|
||||
// Unmount old disk
|
||||
if( !this.m_diskStack.isEmpty() )
|
||||
if( !this.diskStack.isEmpty() )
|
||||
{
|
||||
// TODO: Is this iteration thread safe?
|
||||
Set<IComputerAccess> computers = this.m_computers.keySet();
|
||||
Set<IComputerAccess> computers = this.computers.keySet();
|
||||
for( IComputerAccess computer : computers )
|
||||
{
|
||||
this.unmountDisk( computer );
|
||||
@@ -271,22 +271,22 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
}
|
||||
|
||||
// Stop music
|
||||
if( this.m_recordPlaying )
|
||||
if( this.recordPlaying )
|
||||
{
|
||||
this.stopRecord();
|
||||
this.m_recordPlaying = false;
|
||||
this.m_recordQueued = false;
|
||||
this.recordPlaying = false;
|
||||
this.recordQueued = false;
|
||||
}
|
||||
|
||||
// Swap disk over
|
||||
this.m_diskStack = stack;
|
||||
this.m_diskMount = null;
|
||||
this.diskStack = stack;
|
||||
this.diskMount = null;
|
||||
this.markDirty();
|
||||
|
||||
// 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 )
|
||||
{
|
||||
this.mountDisk( computer );
|
||||
@@ -318,7 +318,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
MountInfo info = this.m_computers.get( computer );
|
||||
MountInfo info = this.computers.get( computer );
|
||||
return info != null ? info.mountPath : null;
|
||||
}
|
||||
}
|
||||
@@ -327,32 +327,32 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
this.m_computers.put( computer, new MountInfo() );
|
||||
this.computers.put( computer, new MountInfo() );
|
||||
this.mountDisk( 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();
|
||||
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
|
||||
int n = 1;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@@ -362,7 +362,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
int n = 1;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@@ -397,15 +397,15 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
synchronized( this )
|
||||
{
|
||||
this.unmountDisk( computer );
|
||||
this.m_computers.remove( computer );
|
||||
this.computers.remove( 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;
|
||||
if( info.mountPath != null )
|
||||
{
|
||||
@@ -421,10 +421,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
synchronized( this )
|
||||
{
|
||||
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.m_restartRecord = this.m_recordPlaying;
|
||||
this.recordQueued = true;
|
||||
this.restartRecord = this.recordPlaying;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -433,8 +433,8 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
this.m_recordQueued = false;
|
||||
this.m_restartRecord = false;
|
||||
this.recordQueued = false;
|
||||
this.restartRecord = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
this.m_ejectQueued = true;
|
||||
this.ejectQueued = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
return;
|
||||
}
|
||||
|
||||
if( !this.m_diskStack.isEmpty() )
|
||||
if( !this.diskStack.isEmpty() )
|
||||
{
|
||||
IMedia contents = this.getDiskMedia();
|
||||
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 )
|
||||
{
|
||||
if( this.getWorld().isClient || this.m_diskStack.isEmpty() )
|
||||
if( this.getWorld().isClient || this.diskStack.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the disks from the inventory
|
||||
ItemStack disks = this.m_diskStack;
|
||||
ItemStack disks = this.diskStack;
|
||||
this.setDiskStack( ItemStack.EMPTY );
|
||||
|
||||
// Spawn the item in the world
|
||||
@@ -515,10 +515,10 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
private void playRecord()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
RecordUtil.playRecord( record, contents.getAudioTitle( this.m_diskStack ), this.getWorld(), this.getPos() );
|
||||
RecordUtil.playRecord( record, contents.getAudioTitle( this.diskStack ), this.getWorld(), this.getPos() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -28,18 +28,18 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPacketReceiver
|
||||
{
|
||||
private final Set<IComputerAccess> m_computers = new HashSet<>( 1 );
|
||||
private final ModemState m_state;
|
||||
private IPacketNetwork m_network;
|
||||
private final Set<IComputerAccess> computers = new HashSet<>( 1 );
|
||||
private final ModemState state;
|
||||
private IPacketNetwork network;
|
||||
|
||||
protected ModemPeripheral( ModemState state )
|
||||
{
|
||||
this.m_state = state;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public ModemState getModemState()
|
||||
{
|
||||
return this.m_state;
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
@@ -50,14 +50,14 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
synchronized( this.m_computers )
|
||||
synchronized( this.computers )
|
||||
{
|
||||
for( IComputerAccess computer : this.m_computers )
|
||||
for( IComputerAccess computer : this.computers )
|
||||
{
|
||||
computer.queueEvent( "modem_message",
|
||||
computer.getAttachmentName(),
|
||||
@@ -72,14 +72,14 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
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() );
|
||||
}
|
||||
@@ -96,9 +96,9 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@Override
|
||||
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() );
|
||||
@@ -108,24 +108,24 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
|
||||
private synchronized void setNetwork( IPacketNetwork network )
|
||||
{
|
||||
if( this.m_network == network )
|
||||
if( this.network == network )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Leave old network
|
||||
if( this.m_network != null )
|
||||
if( this.network != null )
|
||||
{
|
||||
this.m_network.removeReceiver( this );
|
||||
this.network.removeReceiver( this );
|
||||
}
|
||||
|
||||
// Set new network
|
||||
this.m_network = network;
|
||||
this.network = 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 )
|
||||
{
|
||||
boolean empty;
|
||||
synchronized( this.m_computers )
|
||||
synchronized( this.computers )
|
||||
{
|
||||
this.m_computers.remove( computer );
|
||||
empty = this.m_computers.isEmpty();
|
||||
this.computers.remove( computer );
|
||||
empty = this.computers.isEmpty();
|
||||
}
|
||||
|
||||
if( empty )
|
||||
@@ -155,7 +155,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@LuaFunction
|
||||
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
|
||||
@@ -177,7 +177,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@LuaFunction
|
||||
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
|
||||
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
|
||||
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();
|
||||
Vec3d position = this.getPosition();
|
||||
IPacketNetwork network = this.m_network;
|
||||
IPacketNetwork network = this.network;
|
||||
|
||||
if( world == null || position == null || network == null )
|
||||
{
|
||||
@@ -247,7 +247,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@LuaFunction
|
||||
public final boolean isWireless()
|
||||
{
|
||||
IPacketNetwork network = this.m_network;
|
||||
IPacketNetwork network = this.network;
|
||||
return network != null && network.isWireless();
|
||||
}
|
||||
|
||||
@@ -255,15 +255,15 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
@Override
|
||||
public String getSenderID()
|
||||
{
|
||||
synchronized( this.m_computers )
|
||||
synchronized( this.computers )
|
||||
{
|
||||
if( this.m_computers.size() != 1 )
|
||||
if( this.computers.size() != 1 )
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
IComputerAccess computer = this.m_computers.iterator()
|
||||
IComputerAccess computer = this.computers.iterator()
|
||||
.next();
|
||||
return computer.getID() + "_" + computer.getAttachmentName();
|
||||
}
|
||||
|
@@ -41,19 +41,19 @@ import java.util.Map;
|
||||
public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
private static final String NBT_PERIPHERAL_ENABLED = "PeirpheralAccess";
|
||||
private final WiredModemLocalPeripheral m_peripheral = new WiredModemLocalPeripheral();
|
||||
private final WiredModemElement m_cable = new CableElement();
|
||||
private final IWiredNode m_node = this.m_cable.getNode();
|
||||
private boolean m_peripheralAccessAllowed;
|
||||
private boolean m_destroyed = false;
|
||||
private final WiredModemLocalPeripheral peripheral = new WiredModemLocalPeripheral();
|
||||
private final WiredModemElement cable = new CableElement();
|
||||
private final IWiredNode node = this.cable.getNode();
|
||||
private boolean peripheralAccessAllowed;
|
||||
private boolean destroyed = false;
|
||||
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
|
||||
@Override
|
||||
protected WiredModemLocalPeripheral getLocalPeripheral()
|
||||
{
|
||||
return TileCable.this.m_peripheral;
|
||||
return TileCable.this.peripheral;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -72,7 +72,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
}
|
||||
};
|
||||
private boolean hasModemDirection = false;
|
||||
private boolean m_connectionsFormed = false;
|
||||
private boolean connectionsFormed = false;
|
||||
|
||||
public TileCable( BlockEntityType<? extends TileCable> type )
|
||||
{
|
||||
@@ -82,10 +82,10 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
if( !this.m_destroyed )
|
||||
if( !this.destroyed )
|
||||
{
|
||||
this.m_destroyed = true;
|
||||
this.m_modem.destroy();
|
||||
this.destroyed = true;
|
||||
this.modem.destroy();
|
||||
this.onRemove();
|
||||
}
|
||||
}
|
||||
@@ -101,8 +101,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
if( this.world == null || !this.world.isClient )
|
||||
{
|
||||
this.m_node.remove();
|
||||
this.m_connectionsFormed = false;
|
||||
this.node.remove();
|
||||
this.connectionsFormed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,9 +124,9 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
String oldName = this.m_peripheral.getConnectedName();
|
||||
String oldName = this.peripheral.getConnectedName();
|
||||
this.togglePeripheralAccess();
|
||||
String newName = this.m_peripheral.getConnectedName();
|
||||
String newName = this.peripheral.getConnectedName();
|
||||
if( !Objects.equal( newName, oldName ) )
|
||||
{
|
||||
if( oldName != null )
|
||||
@@ -200,11 +200,11 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
|
||||
// If we can no longer attach peripherals, then detach any
|
||||
// which may have existed
|
||||
if( !this.canAttachPeripheral() && this.m_peripheralAccessAllowed )
|
||||
if( !this.canAttachPeripheral() && this.peripheralAccessAllowed )
|
||||
{
|
||||
this.m_peripheralAccessAllowed = false;
|
||||
this.m_peripheral.detach();
|
||||
this.m_node.updatePeripherals( Collections.emptyMap() );
|
||||
this.peripheralAccessAllowed = false;
|
||||
this.peripheral.detach();
|
||||
this.node.updatePeripherals( Collections.emptyMap() );
|
||||
this.markDirty();
|
||||
this.updateBlockState();
|
||||
}
|
||||
@@ -233,17 +233,17 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
// TODO Figure out why this crashes.
|
||||
IWiredNode node = element.getNode();
|
||||
if( node != null && this.m_node != null )
|
||||
if( node != null && this.node != null )
|
||||
{
|
||||
if( BlockCable.canConnectIn( state, facing ) )
|
||||
{
|
||||
// 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.
|
||||
this.m_node.disconnectFrom( node );
|
||||
this.node.disconnectFrom( node );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,8 +259,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
BlockState state = this.getCachedState();
|
||||
CableModemVariant oldVariant = state.get( BlockCable.MODEM );
|
||||
CableModemVariant newVariant = CableModemVariant.from( oldVariant.getFacing(), this.m_modem.getModemState()
|
||||
.isOpen(), this.m_peripheralAccessAllowed );
|
||||
CableModemVariant newVariant = CableModemVariant.from( oldVariant.getFacing(), this.modem.getModemState()
|
||||
.isOpen(), this.peripheralAccessAllowed );
|
||||
|
||||
if( oldVariant != newVariant )
|
||||
{
|
||||
@@ -270,7 +270,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -278,22 +278,22 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private void updateConnectedPeripherals()
|
||||
{
|
||||
Map<String, IPeripheral> peripherals = this.m_peripheral.toMap();
|
||||
Map<String, IPeripheral> peripherals = this.peripheral.toMap();
|
||||
if( peripherals.isEmpty() )
|
||||
{
|
||||
// If there are no peripherals then disable access and update the display state.
|
||||
this.m_peripheralAccessAllowed = false;
|
||||
this.peripheralAccessAllowed = false;
|
||||
this.updateBlockState();
|
||||
}
|
||||
|
||||
this.m_node.updatePeripherals( peripherals );
|
||||
this.node.updatePeripherals( peripherals );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
super.onNeighbourTileEntityChange( neighbour );
|
||||
if( !this.world.isClient && this.m_peripheralAccessAllowed )
|
||||
if( !this.world.isClient && this.peripheralAccessAllowed )
|
||||
{
|
||||
Direction facing = this.getDirection();
|
||||
if( this.getPos().offset( facing )
|
||||
@@ -314,20 +314,20 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
|
||||
this.refreshDirection();
|
||||
|
||||
if( this.m_modem.getModemState()
|
||||
if( this.modem.getModemState()
|
||||
.pollChanged() )
|
||||
{
|
||||
this.updateBlockState();
|
||||
}
|
||||
|
||||
if( !this.m_connectionsFormed )
|
||||
if( !this.connectionsFormed )
|
||||
{
|
||||
this.m_connectionsFormed = true;
|
||||
this.connectionsFormed = true;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -335,23 +335,23 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private void togglePeripheralAccess()
|
||||
{
|
||||
if( !this.m_peripheralAccessAllowed )
|
||||
if( !this.peripheralAccessAllowed )
|
||||
{
|
||||
this.m_peripheral.attach( this.world, this.getPos(), this.getDirection() );
|
||||
if( !this.m_peripheral.hasPeripheral() )
|
||||
this.peripheral.attach( this.world, this.getPos(), this.getDirection() );
|
||||
if( !this.peripheral.hasPeripheral() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.m_peripheralAccessAllowed = true;
|
||||
this.m_node.updatePeripherals( this.m_peripheral.toMap() );
|
||||
this.peripheralAccessAllowed = true;
|
||||
this.node.updatePeripherals( this.peripheral.toMap() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_peripheral.detach();
|
||||
this.peripheral.detach();
|
||||
|
||||
this.m_peripheralAccessAllowed = false;
|
||||
this.m_node.updatePeripherals( Collections.emptyMap() );
|
||||
this.peripheralAccessAllowed = false;
|
||||
this.node.updatePeripherals( Collections.emptyMap() );
|
||||
}
|
||||
|
||||
this.updateBlockState();
|
||||
@@ -380,16 +380,16 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt )
|
||||
{
|
||||
super.fromTag( state, nbt );
|
||||
this.m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
|
||||
this.m_peripheral.read( nbt, "" );
|
||||
this.peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
|
||||
this.peripheral.read( nbt, "" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompoundTag toTag( CompoundTag nbt )
|
||||
{
|
||||
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.m_peripheralAccessAllowed );
|
||||
this.m_peripheral.write( nbt, "" );
|
||||
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.peripheralAccessAllowed );
|
||||
this.peripheral.write( nbt, "" );
|
||||
return super.toTag( nbt );
|
||||
}
|
||||
|
||||
@@ -422,14 +422,14 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
|
||||
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
|
||||
@Override
|
||||
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
|
||||
@@ -452,13 +452,13 @@ public class TileCable extends TileGeneric implements IPeripheralTile
|
||||
@Override
|
||||
protected void attachPeripheral( String name, IPeripheral peripheral )
|
||||
{
|
||||
TileCable.this.m_modem.attachPeripheral( name, peripheral );
|
||||
TileCable.this.modem.attachPeripheral( name, peripheral );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void detachPeripheral( String name )
|
||||
{
|
||||
TileCable.this.m_modem.detachPeripheral( name );
|
||||
TileCable.this.modem.detachPeripheral( name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,30 +41,30 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
private static final String NBT_PERIPHERAL_ENABLED = "PeripheralAccess";
|
||||
private final WiredModemPeripheral[] modems = new WiredModemPeripheral[6];
|
||||
private final WiredModemLocalPeripheral[] m_peripherals = new WiredModemLocalPeripheral[6];
|
||||
private final ModemState m_modemState = new ModemState( () -> TickScheduler.schedule( this ) );
|
||||
private final WiredModemElement m_element = new FullElement( this );
|
||||
private final IWiredNode m_node = this.m_element.getNode();
|
||||
private boolean m_peripheralAccessAllowed = false;
|
||||
private boolean m_destroyed = false;
|
||||
private boolean m_connectionsFormed = false;
|
||||
private final WiredModemLocalPeripheral[] peripherals = new WiredModemLocalPeripheral[6];
|
||||
private final ModemState modemState = new ModemState( () -> TickScheduler.schedule( this ) );
|
||||
private final WiredModemElement element = new FullElement( this );
|
||||
private final IWiredNode node = this.element.getNode();
|
||||
private boolean peripheralAccessAllowed = false;
|
||||
private boolean destroyed = false;
|
||||
private boolean connectionsFormed = false;
|
||||
|
||||
public TileWiredModemFull( BlockEntityType<TileWiredModemFull> 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 );
|
||||
this.m_peripherals[i] = new WiredModemLocalPeripheral();
|
||||
this.peripherals[i] = new WiredModemLocalPeripheral();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
if( !this.m_destroyed )
|
||||
if( !this.destroyed )
|
||||
{
|
||||
this.m_destroyed = true;
|
||||
this.destroyed = true;
|
||||
this.doRemove();
|
||||
}
|
||||
super.destroy();
|
||||
@@ -81,8 +81,8 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
if( this.world == null || !this.world.isClient )
|
||||
{
|
||||
this.m_node.remove();
|
||||
this.m_connectionsFormed = false;
|
||||
this.node.remove();
|
||||
this.connectionsFormed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
@Override
|
||||
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
if( !this.world.isClient && this.m_peripheralAccessAllowed )
|
||||
if( !this.world.isClient && this.peripheralAccessAllowed )
|
||||
{
|
||||
for( Direction facing : DirectionUtil.FACINGS )
|
||||
{
|
||||
@@ -139,21 +139,21 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.m_modemState.pollChanged() )
|
||||
if( this.modemState.pollChanged() )
|
||||
{
|
||||
this.updateBlockState();
|
||||
}
|
||||
|
||||
if( !this.m_connectionsFormed )
|
||||
if( !this.connectionsFormed )
|
||||
{
|
||||
this.m_connectionsFormed = true;
|
||||
this.connectionsFormed = true;
|
||||
|
||||
this.connectionsChanged();
|
||||
if( this.m_peripheralAccessAllowed )
|
||||
if( this.peripheralAccessAllowed )
|
||||
{
|
||||
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();
|
||||
}
|
||||
@@ -183,13 +183,13 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
continue;
|
||||
}
|
||||
|
||||
this.m_node.connectTo( element.getNode() );
|
||||
this.node.connectTo( element.getNode() );
|
||||
}
|
||||
}
|
||||
|
||||
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 ) )
|
||||
{
|
||||
this.updateConnectedPeripherals();
|
||||
@@ -202,22 +202,22 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
if( peripherals.isEmpty() )
|
||||
{
|
||||
// If there are no peripherals then disable access and update the display state.
|
||||
this.m_peripheralAccessAllowed = false;
|
||||
this.peripheralAccessAllowed = false;
|
||||
this.updateBlockState();
|
||||
}
|
||||
|
||||
this.m_node.updatePeripherals( peripherals );
|
||||
this.node.updatePeripherals( peripherals );
|
||||
}
|
||||
|
||||
private Map<String, IPeripheral> getConnectedPeripherals()
|
||||
{
|
||||
if( !this.m_peripheralAccessAllowed )
|
||||
if( !this.peripheralAccessAllowed )
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, IPeripheral> peripherals = new HashMap<>( 6 );
|
||||
for( WiredModemLocalPeripheral peripheral : this.m_peripherals )
|
||||
for( WiredModemLocalPeripheral peripheral : this.peripherals )
|
||||
{
|
||||
peripheral.extendMap( peripherals );
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
private void updateBlockState()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
return;
|
||||
@@ -240,13 +240,13 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private Set<String> getConnectedPeripheralNames()
|
||||
{
|
||||
if( !this.m_peripheralAccessAllowed )
|
||||
if( !this.peripheralAccessAllowed )
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<String> peripherals = new HashSet<>( 6 );
|
||||
for( WiredModemLocalPeripheral peripheral : this.m_peripherals )
|
||||
for( WiredModemLocalPeripheral peripheral : this.peripherals )
|
||||
{
|
||||
String name = peripheral.getConnectedName();
|
||||
if( name != null )
|
||||
@@ -259,12 +259,12 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private void togglePeripheralAccess()
|
||||
{
|
||||
if( !this.m_peripheralAccessAllowed )
|
||||
if( !this.peripheralAccessAllowed )
|
||||
{
|
||||
boolean hasAny = false;
|
||||
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 );
|
||||
hasAny |= peripheral.hasPeripheral();
|
||||
}
|
||||
@@ -274,18 +274,18 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
return;
|
||||
}
|
||||
|
||||
this.m_peripheralAccessAllowed = true;
|
||||
this.m_node.updatePeripherals( this.getConnectedPeripherals() );
|
||||
this.peripheralAccessAllowed = true;
|
||||
this.node.updatePeripherals( this.getConnectedPeripherals() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_peripheralAccessAllowed = false;
|
||||
this.peripheralAccessAllowed = false;
|
||||
|
||||
for( WiredModemLocalPeripheral peripheral : this.m_peripherals )
|
||||
for( WiredModemLocalPeripheral peripheral : this.peripherals )
|
||||
{
|
||||
peripheral.detach();
|
||||
}
|
||||
this.m_node.updatePeripherals( Collections.emptyMap() );
|
||||
this.node.updatePeripherals( Collections.emptyMap() );
|
||||
}
|
||||
|
||||
this.updateBlockState();
|
||||
@@ -318,10 +318,10 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt )
|
||||
{
|
||||
super.fromTag( state, nbt );
|
||||
this.m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
|
||||
for( int i = 0; i < this.m_peripherals.length; i++ )
|
||||
this.peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
|
||||
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
|
||||
public CompoundTag toTag( CompoundTag nbt )
|
||||
{
|
||||
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.m_peripheralAccessAllowed );
|
||||
for( int i = 0; i < this.m_peripherals.length; i++ )
|
||||
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, this.peripheralAccessAllowed );
|
||||
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 );
|
||||
}
|
||||
@@ -353,7 +353,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
|
||||
public IWiredElement getElement()
|
||||
{
|
||||
return this.m_element;
|
||||
return this.element;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -366,8 +366,8 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
return peripheral;
|
||||
}
|
||||
|
||||
WiredModemLocalPeripheral localPeripheral = this.m_peripherals[side.ordinal()];
|
||||
return this.modems[side.ordinal()] = new WiredModemPeripheral( this.m_modemState, this.m_element )
|
||||
WiredModemLocalPeripheral localPeripheral = this.peripherals[side.ordinal()];
|
||||
return this.modems[side.ordinal()] = new WiredModemPeripheral( this.modemState, this.element )
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
@@ -395,11 +395,11 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private static final class FullElement extends WiredModemElement
|
||||
{
|
||||
private final TileWiredModemFull m_entity;
|
||||
private final TileWiredModemFull entity;
|
||||
|
||||
private FullElement( TileWiredModemFull entity )
|
||||
{
|
||||
this.m_entity = entity;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -407,7 +407,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
WiredModemPeripheral modem = this.m_entity.modems[i];
|
||||
WiredModemPeripheral modem = this.entity.modems[i];
|
||||
if( modem != null )
|
||||
{
|
||||
modem.detachPeripheral( name );
|
||||
@@ -420,7 +420,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
WiredModemPeripheral modem = this.m_entity.modems[i];
|
||||
WiredModemPeripheral modem = this.entity.modems[i];
|
||||
if( modem != null )
|
||||
{
|
||||
modem.attachPeripheral( name, peripheral );
|
||||
@@ -432,14 +432,14 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return this.m_entity.getWorld();
|
||||
return this.entity.getWorld();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@@ -15,18 +15,18 @@ import net.minecraft.world.World;
|
||||
|
||||
public abstract class WirelessModemPeripheral extends ModemPeripheral
|
||||
{
|
||||
private final boolean m_advanced;
|
||||
private final boolean advanced;
|
||||
|
||||
public WirelessModemPeripheral( ModemState state, boolean advanced )
|
||||
{
|
||||
super( state );
|
||||
this.m_advanced = advanced;
|
||||
this.advanced = advanced;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRange()
|
||||
{
|
||||
if( this.m_advanced )
|
||||
if( this.advanced )
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral
|
||||
@Override
|
||||
public boolean isInterdimensional()
|
||||
{
|
||||
return this.m_advanced;
|
||||
return this.advanced;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,35 +19,35 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class WirelessNetwork implements IPacketNetwork
|
||||
{
|
||||
private static WirelessNetwork s_universalNetwork = null;
|
||||
private final Set<IPacketReceiver> m_receivers = Collections.newSetFromMap( new ConcurrentHashMap<>() );
|
||||
private static WirelessNetwork universalNetwork = null;
|
||||
private final Set<IPacketReceiver> receivers = Collections.newSetFromMap( new ConcurrentHashMap<>() );
|
||||
|
||||
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()
|
||||
{
|
||||
s_universalNetwork = null;
|
||||
universalNetwork = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReceiver( @Nonnull IPacketReceiver receiver )
|
||||
{
|
||||
Objects.requireNonNull( receiver, "device cannot be null" );
|
||||
this.m_receivers.add( receiver );
|
||||
this.receivers.add( receiver );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeReceiver( @Nonnull IPacketReceiver receiver )
|
||||
{
|
||||
Objects.requireNonNull( receiver, "device cannot be null" );
|
||||
this.m_receivers.remove( receiver );
|
||||
this.receivers.remove( receiver );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +60,7 @@ public class WirelessNetwork implements IPacketNetwork
|
||||
public void transmitSameDimension( @Nonnull Packet packet, double range )
|
||||
{
|
||||
Objects.requireNonNull( packet, "packet cannot be null" );
|
||||
for( IPacketReceiver device : this.m_receivers )
|
||||
for( IPacketReceiver device : this.receivers )
|
||||
{
|
||||
tryTransmit( device, packet, range, false );
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class WirelessNetwork implements IPacketNetwork
|
||||
public void transmitInterdimensional( @Nonnull Packet packet )
|
||||
{
|
||||
Objects.requireNonNull( packet, "packet cannot be null" );
|
||||
for( IPacketReceiver device : this.m_receivers )
|
||||
for( IPacketReceiver device : this.receivers )
|
||||
{
|
||||
tryTransmit( device, packet, 0, true );
|
||||
}
|
||||
|
@@ -43,20 +43,20 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
private static final String NBT_HEIGHT = "Height";
|
||||
|
||||
private final boolean advanced;
|
||||
private final Set<IComputerAccess> m_computers = new HashSet<>();
|
||||
private final Set<IComputerAccess> computers = new HashSet<>();
|
||||
// MonitorWatcher state.
|
||||
boolean enqueued;
|
||||
TerminalState cached;
|
||||
private ServerMonitor m_serverMonitor;
|
||||
private ClientMonitor m_clientMonitor;
|
||||
private ServerMonitor serverMonitor;
|
||||
private ClientMonitor clientMonitor;
|
||||
private MonitorPeripheral peripheral;
|
||||
private boolean needsUpdate = false;
|
||||
private boolean m_destroyed = false;
|
||||
private boolean destroyed = false;
|
||||
private boolean visiting = false;
|
||||
private int m_width = 1;
|
||||
private int m_height = 1;
|
||||
private int m_xIndex = 0;
|
||||
private int m_yIndex = 0;
|
||||
private int width = 1;
|
||||
private int height = 1;
|
||||
private int xIndex = 0;
|
||||
private int yIndex = 0;
|
||||
|
||||
public TileMonitor( BlockEntityType<? extends TileMonitor> type, boolean advanced )
|
||||
{
|
||||
@@ -68,11 +68,11 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
public void destroy()
|
||||
{
|
||||
// TODO: Call this before using the block
|
||||
if( this.m_destroyed )
|
||||
if( this.destroyed )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.m_destroyed = true;
|
||||
this.destroyed = true;
|
||||
if( !this.getWorld().isClient )
|
||||
{
|
||||
this.contractNeighbours();
|
||||
@@ -83,9 +83,9 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
public void 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()
|
||||
{
|
||||
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
|
||||
@@ -130,18 +130,18 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
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;
|
||||
}
|
||||
|
||||
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 );
|
||||
if( monitor == null )
|
||||
@@ -149,7 +149,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
continue;
|
||||
}
|
||||
|
||||
for( IComputerAccess computer : monitor.m_computers )
|
||||
for( IComputerAccess computer : monitor.computers )
|
||||
{
|
||||
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();
|
||||
}
|
||||
@@ -168,38 +168,38 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
|
||||
int oldXIndex = this.m_xIndex;
|
||||
int oldYIndex = this.m_yIndex;
|
||||
int oldWidth = this.m_width;
|
||||
int oldHeight = this.m_height;
|
||||
int oldXIndex = this.xIndex;
|
||||
int oldYIndex = this.yIndex;
|
||||
int oldWidth = this.width;
|
||||
int oldHeight = this.height;
|
||||
|
||||
this.m_xIndex = nbt.getInt( NBT_X );
|
||||
this.m_yIndex = nbt.getInt( NBT_Y );
|
||||
this.m_width = nbt.getInt( NBT_WIDTH );
|
||||
this.m_height = nbt.getInt( NBT_HEIGHT );
|
||||
this.xIndex = nbt.getInt( NBT_X );
|
||||
this.yIndex = nbt.getInt( NBT_Y );
|
||||
this.width = nbt.getInt( NBT_WIDTH );
|
||||
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
|
||||
// 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( 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
|
||||
this.updateBlock();
|
||||
@@ -210,14 +210,14 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
protected void writeDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
super.writeDescription( nbt );
|
||||
nbt.putInt( NBT_X, this.m_xIndex );
|
||||
nbt.putInt( NBT_Y, this.m_yIndex );
|
||||
nbt.putInt( NBT_WIDTH, this.m_width );
|
||||
nbt.putInt( NBT_HEIGHT, this.m_height );
|
||||
nbt.putInt( NBT_X, this.xIndex );
|
||||
nbt.putInt( NBT_Y, this.yIndex );
|
||||
nbt.putInt( NBT_WIDTH, this.width );
|
||||
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();
|
||||
Direction right = this.getRight();
|
||||
Direction down = this.getDown();
|
||||
int xOffset = -this.m_xIndex + x;
|
||||
int yOffset = -this.m_yIndex + y;
|
||||
int xOffset = -this.xIndex + x;
|
||||
int yOffset = -this.yIndex + y;
|
||||
return this.getSimilarMonitorAt( pos.offset( right, xOffset )
|
||||
.offset( down, yOffset ) );
|
||||
}
|
||||
@@ -268,7 +268,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
}
|
||||
|
||||
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
|
||||
@@ -290,10 +290,10 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
{
|
||||
super.fromTag( state, nbt );
|
||||
|
||||
this.m_xIndex = nbt.getInt( NBT_X );
|
||||
this.m_yIndex = nbt.getInt( NBT_Y );
|
||||
this.m_width = nbt.getInt( NBT_WIDTH );
|
||||
this.m_height = nbt.getInt( NBT_HEIGHT );
|
||||
this.xIndex = nbt.getInt( NBT_X );
|
||||
this.yIndex = nbt.getInt( NBT_Y );
|
||||
this.width = nbt.getInt( NBT_WIDTH );
|
||||
this.height = nbt.getInt( NBT_HEIGHT );
|
||||
}
|
||||
|
||||
// Networking stuff
|
||||
@@ -302,10 +302,10 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
@Override
|
||||
public CompoundTag toTag( CompoundTag tag )
|
||||
{
|
||||
tag.putInt( NBT_X, this.m_xIndex );
|
||||
tag.putInt( NBT_Y, this.m_yIndex );
|
||||
tag.putInt( NBT_WIDTH, this.m_width );
|
||||
tag.putInt( NBT_HEIGHT, this.m_height );
|
||||
tag.putInt( NBT_X, this.xIndex );
|
||||
tag.putInt( NBT_Y, this.yIndex );
|
||||
tag.putInt( NBT_WIDTH, this.width );
|
||||
tag.putInt( NBT_HEIGHT, this.height );
|
||||
return super.toTag( tag );
|
||||
}
|
||||
|
||||
@@ -338,14 +338,14 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
public ServerMonitor getCachedServerMonitor()
|
||||
{
|
||||
return this.m_serverMonitor;
|
||||
return this.serverMonitor;
|
||||
}
|
||||
|
||||
private ServerMonitor getServerMonitor()
|
||||
{
|
||||
if( this.m_serverMonitor != null )
|
||||
if( this.serverMonitor != null )
|
||||
{
|
||||
return this.m_serverMonitor;
|
||||
return this.serverMonitor;
|
||||
}
|
||||
|
||||
TileMonitor origin = this.getOrigin();
|
||||
@@ -354,92 +354,92 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.m_serverMonitor = origin.m_serverMonitor;
|
||||
return this.serverMonitor = origin.serverMonitor;
|
||||
}
|
||||
|
||||
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
|
||||
this.m_serverMonitor = new ServerMonitor( this.advanced, this );
|
||||
this.m_serverMonitor.rebuild();
|
||||
this.serverMonitor = new ServerMonitor( this.advanced, this );
|
||||
this.serverMonitor.rebuild();
|
||||
|
||||
// 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 );
|
||||
if( monitor != null )
|
||||
{
|
||||
monitor.m_serverMonitor = this.m_serverMonitor;
|
||||
monitor.serverMonitor = this.serverMonitor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.m_serverMonitor;
|
||||
return this.serverMonitor;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise fetch the origin and attempt to get its monitor
|
||||
// Note this may load chunks, but we don't really have a choice here.
|
||||
BlockPos pos = this.getPos();
|
||||
BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.m_xIndex )
|
||||
.offset( this.getDown(), -this.m_yIndex ) );
|
||||
BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.xIndex )
|
||||
.offset( this.getDown(), -this.yIndex ) );
|
||||
if( !(te instanceof TileMonitor) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.m_serverMonitor = ((TileMonitor) te).createServerMonitor();
|
||||
return this.serverMonitor = ((TileMonitor) te).createServerMonitor();
|
||||
}
|
||||
}
|
||||
|
||||
public ClientMonitor getClientMonitor()
|
||||
{
|
||||
if( this.m_clientMonitor != null )
|
||||
if( this.clientMonitor != null )
|
||||
{
|
||||
return this.m_clientMonitor;
|
||||
return this.clientMonitor;
|
||||
}
|
||||
|
||||
BlockPos pos = this.getPos();
|
||||
BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.m_xIndex )
|
||||
.offset( this.getDown(), -this.m_yIndex ) );
|
||||
BlockEntity te = this.world.getBlockEntity( pos.offset( this.getRight(), -this.xIndex )
|
||||
.offset( this.getDown(), -this.yIndex ) );
|
||||
if( !(te instanceof TileMonitor) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.m_clientMonitor = ((TileMonitor) te).m_clientMonitor;
|
||||
return this.clientMonitor = ((TileMonitor) te).clientMonitor;
|
||||
}
|
||||
|
||||
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() );
|
||||
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()
|
||||
{
|
||||
this.getWorld().setBlockState( this.getPos(),
|
||||
this.getCachedState().with( BlockMonitor.STATE,
|
||||
MonitorEdgeState.fromConnections( this.m_yIndex < this.m_height - 1,
|
||||
this.m_yIndex > 0, this.m_xIndex > 0, this.m_xIndex < this.m_width - 1 ) ),
|
||||
MonitorEdgeState.fromConnections( this.yIndex < this.height - 1,
|
||||
this.yIndex > 0, this.xIndex > 0, this.xIndex < this.width - 1 ) ),
|
||||
2 );
|
||||
}
|
||||
|
||||
@@ -451,22 +451,22 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return this.m_width;
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return this.m_height;
|
||||
return this.height;
|
||||
}
|
||||
|
||||
public int getXIndex()
|
||||
{
|
||||
return this.m_xIndex;
|
||||
return this.xIndex;
|
||||
}
|
||||
|
||||
public int getYIndex()
|
||||
{
|
||||
return this.m_yIndex;
|
||||
return this.yIndex;
|
||||
}
|
||||
|
||||
private TileMonitor getOrigin()
|
||||
@@ -477,15 +477,15 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
private void resize( int width, int height )
|
||||
{
|
||||
// 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.m_yIndex = 0;
|
||||
this.m_width = width;
|
||||
this.m_height = height;
|
||||
this.xIndex = 0;
|
||||
this.yIndex = 0;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
// 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
|
||||
@@ -508,21 +508,21 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
// Either delete the current monitor or sync a new one.
|
||||
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
|
||||
{
|
||||
this.m_serverMonitor = null;
|
||||
this.serverMonitor = null;
|
||||
}
|
||||
|
||||
// Update the terminal's width and height and rebuild it. This ensures the monitor
|
||||
// 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
|
||||
@@ -536,11 +536,11 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
continue;
|
||||
}
|
||||
|
||||
monitor.m_xIndex = x;
|
||||
monitor.m_yIndex = y;
|
||||
monitor.m_width = width;
|
||||
monitor.m_height = height;
|
||||
monitor.m_serverMonitor = this.m_serverMonitor;
|
||||
monitor.xIndex = x;
|
||||
monitor.yIndex = y;
|
||||
monitor.width = width;
|
||||
monitor.height = height;
|
||||
monitor.serverMonitor = this.serverMonitor;
|
||||
monitor.updateBlockState();
|
||||
monitor.updateBlock();
|
||||
}
|
||||
@@ -550,12 +550,12 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
private boolean mergeLeft()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int width = left.m_width + this.m_width;
|
||||
int width = left.width + this.width;
|
||||
if( width > ComputerCraft.monitorWidth )
|
||||
{
|
||||
return false;
|
||||
@@ -564,7 +564,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
TileMonitor origin = left.getOrigin();
|
||||
if( origin != null )
|
||||
{
|
||||
origin.resize( width, this.m_height );
|
||||
origin.resize( width, this.height );
|
||||
}
|
||||
left.expand();
|
||||
return true;
|
||||
@@ -572,13 +572,13 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private boolean mergeRight()
|
||||
{
|
||||
TileMonitor right = this.getNeighbour( this.m_width, 0 );
|
||||
if( right == null || right.m_yIndex != 0 || right.m_height != this.m_height )
|
||||
TileMonitor right = this.getNeighbour( this.width, 0 );
|
||||
if( right == null || right.yIndex != 0 || right.height != this.height )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int width = this.m_width + right.m_width;
|
||||
int width = this.width + right.width;
|
||||
if( width > ComputerCraft.monitorWidth )
|
||||
{
|
||||
return false;
|
||||
@@ -587,7 +587,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
TileMonitor origin = this.getOrigin();
|
||||
if( origin != null )
|
||||
{
|
||||
origin.resize( width, this.m_height );
|
||||
origin.resize( width, this.height );
|
||||
}
|
||||
this.expand();
|
||||
return true;
|
||||
@@ -595,13 +595,13 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
private boolean mergeUp()
|
||||
{
|
||||
TileMonitor above = this.getNeighbour( 0, this.m_height );
|
||||
if( above == null || above.m_xIndex != 0 || above.m_width != this.m_width )
|
||||
TileMonitor above = this.getNeighbour( 0, this.height );
|
||||
if( above == null || above.xIndex != 0 || above.width != this.width )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int height = above.m_height + this.m_height;
|
||||
int height = above.height + this.height;
|
||||
if( height > ComputerCraft.monitorHeight )
|
||||
{
|
||||
return false;
|
||||
@@ -610,7 +610,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
TileMonitor origin = this.getOrigin();
|
||||
if( origin != null )
|
||||
{
|
||||
origin.resize( this.m_width, height );
|
||||
origin.resize( this.width, height );
|
||||
}
|
||||
this.expand();
|
||||
return true;
|
||||
@@ -619,12 +619,12 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
private boolean mergeDown()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int height = this.m_height + below.m_height;
|
||||
int height = this.height + below.height;
|
||||
if( height > ComputerCraft.monitorHeight )
|
||||
{
|
||||
return false;
|
||||
@@ -633,7 +633,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
TileMonitor origin = below.getOrigin();
|
||||
if( origin != null )
|
||||
{
|
||||
origin.resize( this.m_width, height );
|
||||
origin.resize( this.width, height );
|
||||
}
|
||||
below.expand();
|
||||
return true;
|
||||
@@ -662,33 +662,33 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
void contractNeighbours()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
above.contract();
|
||||
@@ -699,8 +699,8 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
void contract()
|
||||
{
|
||||
int height = this.m_height;
|
||||
int width = this.m_width;
|
||||
int height = this.height;
|
||||
int width = this.width;
|
||||
|
||||
TileMonitor origin = this.getOrigin();
|
||||
if( origin == null )
|
||||
@@ -791,9 +791,9 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
private void monitorTouched( float xPos, float yPos, float zPos )
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -810,15 +810,15 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
return;
|
||||
}
|
||||
|
||||
double xCharWidth = (this.m_width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth();
|
||||
double yCharHeight = (this.m_height - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getHeight();
|
||||
double xCharWidth = (this.width - (RENDER_BORDER + RENDER_MARGIN) * 2.0) / originTerminal.getWidth();
|
||||
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 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 );
|
||||
if( monitor == null )
|
||||
@@ -826,7 +826,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
continue;
|
||||
}
|
||||
|
||||
for( IComputerAccess computer : monitor.m_computers )
|
||||
for( IComputerAccess computer : monitor.computers )
|
||||
{
|
||||
computer.queueEvent( "monitor_touch", computer.getAttachmentName(), xCharPos, yCharPos );
|
||||
}
|
||||
@@ -836,7 +836,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
void addComputer( IComputerAccess computer )
|
||||
{
|
||||
this.m_computers.add( computer );
|
||||
this.computers.add( computer );
|
||||
}
|
||||
|
||||
// @Nonnull
|
||||
@@ -866,6 +866,6 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
|
||||
|
||||
void removeComputer( IComputerAccess computer )
|
||||
{
|
||||
this.m_computers.remove( computer );
|
||||
this.computers.remove( computer );
|
||||
}
|
||||
}
|
||||
|
@@ -63,12 +63,12 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
6
|
||||
};
|
||||
private static final int[] SIDE_SLOTS = new int[] { 0 };
|
||||
private final DefaultedList<ItemStack> m_inventory = DefaultedList.ofSize( SLOTS, ItemStack.EMPTY );
|
||||
private final ItemStorage m_itemHandlerAll = ItemStorage.wrap( this );
|
||||
private final Terminal m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
|
||||
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize( SLOTS, ItemStack.EMPTY );
|
||||
private final ItemStorage itemHandlerAll = ItemStorage.wrap( this );
|
||||
private final Terminal page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE );
|
||||
Text customName;
|
||||
private String m_pageTitle = "";
|
||||
private boolean m_printing = false;
|
||||
private String pageTitle = "";
|
||||
private boolean printing = false;
|
||||
|
||||
public TilePrinter( BlockEntityType<TilePrinter> type )
|
||||
{
|
||||
@@ -101,7 +101,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
{
|
||||
for( int i = 0; i < 13; i++ )
|
||||
{
|
||||
ItemStack stack = this.m_inventory.get( i );
|
||||
ItemStack stack = this.inventory.get( i );
|
||||
if( !stack.isEmpty() )
|
||||
{
|
||||
// Remove the stack from the inventory
|
||||
@@ -120,7 +120,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
boolean top = false, bottom = false;
|
||||
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 ) )
|
||||
{
|
||||
top = true;
|
||||
@@ -129,7 +129,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
}
|
||||
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 ) )
|
||||
{
|
||||
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;
|
||||
|
||||
// Read page
|
||||
synchronized( this.m_page )
|
||||
synchronized( this.page )
|
||||
{
|
||||
this.m_printing = nbt.getBoolean( NBT_PRINTING );
|
||||
this.m_pageTitle = nbt.getString( NBT_PAGE_TITLE );
|
||||
this.m_page.readFromNBT( nbt );
|
||||
this.printing = nbt.getBoolean( NBT_PRINTING );
|
||||
this.pageTitle = nbt.getString( NBT_PAGE_TITLE );
|
||||
this.page.readFromNBT( nbt );
|
||||
}
|
||||
|
||||
// Read inventory
|
||||
Inventories.fromTag( nbt, this.m_inventory );
|
||||
Inventories.fromTag( nbt, this.inventory );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -193,35 +193,35 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
}
|
||||
|
||||
// Write page
|
||||
synchronized( this.m_page )
|
||||
synchronized( this.page )
|
||||
{
|
||||
nbt.putBoolean( NBT_PRINTING, this.m_printing );
|
||||
nbt.putString( NBT_PAGE_TITLE, this.m_pageTitle );
|
||||
this.m_page.writeToNBT( nbt );
|
||||
nbt.putBoolean( NBT_PRINTING, this.printing );
|
||||
nbt.putString( NBT_PAGE_TITLE, this.pageTitle );
|
||||
this.page.writeToNBT( nbt );
|
||||
}
|
||||
|
||||
// Write inventory
|
||||
Inventories.toTag( nbt, this.m_inventory );
|
||||
Inventories.toTag( nbt, this.inventory );
|
||||
|
||||
return super.toTag( nbt );
|
||||
}
|
||||
|
||||
boolean isPrinting()
|
||||
{
|
||||
return this.m_printing;
|
||||
return this.printing;
|
||||
}
|
||||
|
||||
// IInventory implementation
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.m_inventory.size();
|
||||
return this.inventory.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
for( ItemStack stack : this.m_inventory )
|
||||
for( ItemStack stack : this.inventory )
|
||||
{
|
||||
if( !stack.isEmpty() )
|
||||
{
|
||||
@@ -235,14 +235,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
@Override
|
||||
public ItemStack getStack( int slot )
|
||||
{
|
||||
return this.m_inventory.get( slot );
|
||||
return this.inventory.get( slot );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack removeStack( int slot, int count )
|
||||
{
|
||||
ItemStack stack = this.m_inventory.get( slot );
|
||||
ItemStack stack = this.inventory.get( slot );
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
@@ -255,10 +255,10 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
}
|
||||
|
||||
ItemStack part = stack.split( count );
|
||||
if( this.m_inventory.get( slot )
|
||||
if( this.inventory.get( slot )
|
||||
.isEmpty() )
|
||||
{
|
||||
this.m_inventory.set( slot, ItemStack.EMPTY );
|
||||
this.inventory.set( slot, ItemStack.EMPTY );
|
||||
this.updateBlockState();
|
||||
}
|
||||
this.markDirty();
|
||||
@@ -269,8 +269,8 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
@Override
|
||||
public ItemStack removeStack( int slot )
|
||||
{
|
||||
ItemStack result = this.m_inventory.get( slot );
|
||||
this.m_inventory.set( slot, ItemStack.EMPTY );
|
||||
ItemStack result = this.inventory.get( slot );
|
||||
this.inventory.set( slot, ItemStack.EMPTY );
|
||||
this.markDirty();
|
||||
this.updateBlockState();
|
||||
return result;
|
||||
@@ -281,7 +281,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
@Override
|
||||
public void setStack( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
this.m_inventory.set( slot, stack );
|
||||
this.inventory.set( slot, stack );
|
||||
this.markDirty();
|
||||
this.updateBlockState();
|
||||
}
|
||||
@@ -295,9 +295,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
@Override
|
||||
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.updateBlockState();
|
||||
@@ -350,21 +350,21 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
@Nullable
|
||||
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()
|
||||
{
|
||||
synchronized( this.m_page )
|
||||
synchronized( this.page )
|
||||
{
|
||||
if( !this.canInputPage() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.m_printing && !this.outputPage() )
|
||||
if( this.printing && !this.outputPage() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -374,33 +374,33 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
|
||||
boolean endCurrentPage()
|
||||
{
|
||||
synchronized( this.m_page )
|
||||
synchronized( this.page )
|
||||
{
|
||||
return this.m_printing && this.outputPage();
|
||||
return this.printing && this.outputPage();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean outputPage()
|
||||
{
|
||||
int height = this.m_page.getHeight();
|
||||
int height = this.page.getHeight();
|
||||
String[] lines = new String[height];
|
||||
String[] colours = new String[height];
|
||||
for( int i = 0; i < height; i++ )
|
||||
{
|
||||
lines[i] = this.m_page.getLine( i )
|
||||
lines[i] = this.page.getLine( i )
|
||||
.toString();
|
||||
colours[i] = this.m_page.getTextColourLine( i )
|
||||
colours[i] = this.page.getTextColourLine( i )
|
||||
.toString();
|
||||
}
|
||||
|
||||
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( this.m_pageTitle, lines, colours );
|
||||
ItemStack stack = ItemPrintout.createSingleFromTitleAndText( this.pageTitle, lines, colours );
|
||||
for( int slot : BOTTOM_SLOTS )
|
||||
{
|
||||
if( this.m_inventory.get( slot )
|
||||
if( this.inventory.get( slot )
|
||||
.isEmpty() )
|
||||
{
|
||||
this.setStack( slot, stack );
|
||||
this.m_printing = false;
|
||||
this.printing = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -409,7 +409,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
|
||||
int getInkLevel()
|
||||
{
|
||||
ItemStack inkStack = this.m_inventory.get( 0 );
|
||||
ItemStack inkStack = this.inventory.get( 0 );
|
||||
return isInk( inkStack ) ? inkStack.getCount() : 0;
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
int count = 0;
|
||||
for( int i = 1; i < 7; i++ )
|
||||
{
|
||||
ItemStack paperStack = this.m_inventory.get( i );
|
||||
ItemStack paperStack = this.inventory.get( i );
|
||||
if( isPaper( paperStack ) )
|
||||
{
|
||||
count += paperStack.getCount();
|
||||
@@ -429,72 +429,72 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
|
||||
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()
|
||||
{
|
||||
ItemStack inkStack = this.m_inventory.get( 0 );
|
||||
ItemStack inkStack = this.inventory.get( 0 );
|
||||
return !inkStack.isEmpty() && isInk( inkStack ) && this.getPaperLevel() > 0;
|
||||
}
|
||||
|
||||
private boolean inputPage()
|
||||
{
|
||||
ItemStack inkStack = this.m_inventory.get( 0 );
|
||||
ItemStack inkStack = this.inventory.get( 0 );
|
||||
DyeColor dye = ColourUtils.getStackColour( inkStack );
|
||||
if( dye == null ) return false;
|
||||
|
||||
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 ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 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 )
|
||||
{
|
||||
this.m_pageTitle = ItemPrintout.getTitle( paperStack );
|
||||
this.pageTitle = ItemPrintout.getTitle( paperStack );
|
||||
String[] text = ItemPrintout.getText( 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
|
||||
{
|
||||
this.m_pageTitle = "";
|
||||
this.pageTitle = "";
|
||||
}
|
||||
this.m_page.setCursorPos( 0, 0 );
|
||||
this.page.setCursorPos( 0, 0 );
|
||||
|
||||
// Decrement ink
|
||||
inkStack.decrement( 1 );
|
||||
if( inkStack.isEmpty() )
|
||||
{
|
||||
this.m_inventory.set( 0, ItemStack.EMPTY );
|
||||
this.inventory.set( 0, ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
// Decrement paper
|
||||
paperStack.decrement( 1 );
|
||||
if( paperStack.isEmpty() )
|
||||
{
|
||||
this.m_inventory.set( i, ItemStack.EMPTY );
|
||||
this.inventory.set( i, ItemStack.EMPTY );
|
||||
this.updateBlockState();
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
this.m_printing = true;
|
||||
this.printing = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -34,19 +34,19 @@ import static dan200.computercraft.api.lua.LuaValues.checkFinite;
|
||||
*/
|
||||
public abstract class SpeakerPeripheral implements IPeripheral
|
||||
{
|
||||
private final AtomicInteger m_notesThisTick = new AtomicInteger();
|
||||
private long m_clock = 0;
|
||||
private long m_lastPlayTime = 0;
|
||||
private final AtomicInteger notesThisTick = new AtomicInteger();
|
||||
private long clock = 0;
|
||||
private long lastPlayTime = 0;
|
||||
|
||||
public void update()
|
||||
{
|
||||
this.m_clock++;
|
||||
this.m_notesThisTick.set( 0 );
|
||||
this.clock++;
|
||||
this.notesThisTick.set( 0 );
|
||||
}
|
||||
|
||||
public boolean madeSound( long ticks )
|
||||
{
|
||||
return this.m_clock - this.m_lastPlayTime <= ticks;
|
||||
return this.clock - this.lastPlayTime <= ticks;
|
||||
}
|
||||
|
||||
@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
|
||||
{
|
||||
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
|
||||
// played more notes than allowable within the current tick.
|
||||
@@ -119,7 +119,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
|
||||
return null;
|
||||
} );
|
||||
|
||||
this.m_lastPlayTime = this.m_clock;
|
||||
this.lastPlayTime = this.clock;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public abstract class SpeakerPeripheral implements IPeripheral
|
||||
true );
|
||||
if( success )
|
||||
{
|
||||
this.m_notesThisTick.incrementAndGet();
|
||||
this.notesThisTick.incrementAndGet();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@@ -36,9 +36,9 @@ import static dan200.computercraft.shared.pocket.items.ItemPocketComputer.NBT_LI
|
||||
|
||||
public class PocketServerComputer extends ServerComputer implements IPocketAccess
|
||||
{
|
||||
private IPocketUpgrade m_upgrade;
|
||||
private Entity m_entity;
|
||||
private ItemStack m_stack;
|
||||
private IPocketUpgrade upgrade;
|
||||
private Entity entity;
|
||||
private ItemStack stack;
|
||||
|
||||
public PocketServerComputer( World world, int computerID, String label, int instanceID, ComputerFamily family )
|
||||
{
|
||||
@@ -49,8 +49,8 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
@Override
|
||||
public Entity getEntity()
|
||||
{
|
||||
Entity entity = this.m_entity;
|
||||
if( entity == null || this.m_stack == null || !entity.isAlive() )
|
||||
Entity entity = this.entity;
|
||||
if( entity == null || this.stack == null || !entity.isAlive() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -58,12 +58,12 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
if( entity instanceof PlayerEntity )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -74,13 +74,13 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
@Override
|
||||
public int getColour()
|
||||
{
|
||||
return IColouredItem.getColourBasic( this.m_stack );
|
||||
return IColouredItem.getColourBasic( this.stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColour( int colour )
|
||||
{
|
||||
IColouredItem.setColourBasic( this.m_stack, colour );
|
||||
IColouredItem.setColourBasic( this.stack, colour );
|
||||
this.updateUpgradeNBTData();
|
||||
}
|
||||
|
||||
@@ -114,22 +114,22 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
@Override
|
||||
public CompoundTag getUpgradeNBTData()
|
||||
{
|
||||
return ItemPocketComputer.getUpgradeInfo( this.m_stack );
|
||||
return ItemPocketComputer.getUpgradeInfo( this.stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -137,12 +137,12 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
@Override
|
||||
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()
|
||||
{
|
||||
return this.m_upgrade;
|
||||
return this.upgrade;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,16 +154,16 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
*/
|
||||
public void setUpgrade( IPocketUpgrade upgrade )
|
||||
{
|
||||
if( this.m_upgrade == upgrade )
|
||||
if( this.upgrade == upgrade )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized( this )
|
||||
{
|
||||
ItemPocketComputer.setUpgrade( this.m_stack, upgrade );
|
||||
ItemPocketComputer.setUpgrade( this.stack, upgrade );
|
||||
this.updateUpgradeNBTData();
|
||||
this.m_upgrade = upgrade;
|
||||
this.upgrade = upgrade;
|
||||
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( entity != this.m_entity && entity instanceof ServerPlayerEntity )
|
||||
if( entity != this.entity && entity instanceof ServerPlayerEntity )
|
||||
{
|
||||
this.markTerminalChanged();
|
||||
}
|
||||
|
||||
this.m_entity = entity;
|
||||
this.m_stack = stack;
|
||||
this.entity = entity;
|
||||
this.stack = stack;
|
||||
|
||||
if( this.m_upgrade != upgrade )
|
||||
if( this.upgrade != upgrade )
|
||||
{
|
||||
this.m_upgrade = upgrade;
|
||||
this.upgrade = upgrade;
|
||||
this.invalidatePeripheral();
|
||||
}
|
||||
}
|
||||
@@ -197,10 +197,10 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
|
||||
{
|
||||
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.
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) this.m_entity;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) this.entity;
|
||||
if( player.networkHandler != null && !this.isInteracting( player ) )
|
||||
{
|
||||
NetworkHandler.sendToPlayer( player, this.createTerminalPacket() );
|
||||
|
@@ -51,11 +51,11 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
public static final int INVENTORY_SIZE = 16;
|
||||
public static final int INVENTORY_WIDTH = 4;
|
||||
public static final int INVENTORY_HEIGHT = 4;
|
||||
private final DefaultedList<ItemStack> m_inventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||
private final DefaultedList<ItemStack> m_previousInventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||
private boolean m_inventoryChanged = false;
|
||||
private TurtleBrain m_brain = new TurtleBrain( this );
|
||||
private MoveState m_moveState = MoveState.NOT_MOVED;
|
||||
private final DefaultedList<ItemStack> inventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||
private final DefaultedList<ItemStack> previousInventory = DefaultedList.ofSize( INVENTORY_SIZE, ItemStack.EMPTY );
|
||||
private boolean inventoryChanged = false;
|
||||
private TurtleBrain brain = new TurtleBrain( this );
|
||||
private MoveState moveState = MoveState.NOT_MOVED;
|
||||
|
||||
public TileTurtle( BlockEntityType<? extends TileGeneric> type, ComputerFamily family )
|
||||
{
|
||||
@@ -105,7 +105,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
|
||||
private boolean hasMoved()
|
||||
{
|
||||
return this.m_moveState == MoveState.MOVED;
|
||||
return this.moveState == MoveState.MOVED;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,7 +117,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
for( ItemStack stack : this.m_inventory )
|
||||
for( ItemStack stack : this.inventory )
|
||||
{
|
||||
if( !stack.isEmpty() )
|
||||
{
|
||||
@@ -131,7 +131,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
@Override
|
||||
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
|
||||
@@ -172,9 +172,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
private void onInventoryDefinitelyChanged()
|
||||
{
|
||||
super.markDirty();
|
||||
this.m_inventoryChanged = true;
|
||||
this.inventoryChanged = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,9 +211,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
if( !this.getWorld().isClient )
|
||||
{
|
||||
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() )
|
||||
{
|
||||
currentItem.decrement( 1 );
|
||||
@@ -222,14 +222,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
}
|
||||
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
|
||||
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() )
|
||||
{
|
||||
player.setStackInHand( hand, new ItemStack( Items.BUCKET ) );
|
||||
@@ -248,7 +248,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
@Override
|
||||
public void onNeighbourChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
if( this.m_moveState == MoveState.NOT_MOVED )
|
||||
if( this.moveState == MoveState.NOT_MOVED )
|
||||
{
|
||||
super.onNeighbourChange( neighbour );
|
||||
}
|
||||
@@ -257,7 +257,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
@Override
|
||||
public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour )
|
||||
{
|
||||
if( this.m_moveState == MoveState.NOT_MOVED )
|
||||
if( this.moveState == MoveState.NOT_MOVED )
|
||||
{
|
||||
super.onNeighbourTileEntityChange( neighbour );
|
||||
}
|
||||
@@ -267,8 +267,8 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
public void tick()
|
||||
{
|
||||
super.tick();
|
||||
this.m_brain.update();
|
||||
if( !this.getWorld().isClient && this.m_inventoryChanged )
|
||||
this.brain.update();
|
||||
if( !this.getWorld().isClient && this.inventoryChanged )
|
||||
{
|
||||
ServerComputer computer = this.getServerComputer();
|
||||
if( computer != null )
|
||||
@@ -276,10 +276,10 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
computer.queueEvent( "turtle_inventory" );
|
||||
}
|
||||
|
||||
this.m_inventoryChanged = false;
|
||||
this.inventoryChanged = false;
|
||||
for( int n = 0; n < this.size(); n++ )
|
||||
{
|
||||
this.m_previousInventory.set( n,
|
||||
this.previousInventory.set( n,
|
||||
this.getStack( n ).copy() );
|
||||
}
|
||||
}
|
||||
@@ -298,12 +298,12 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
ListTag nbttaglist = new ListTag();
|
||||
for( int i = 0; i < INVENTORY_SIZE; i++ )
|
||||
{
|
||||
if( !this.m_inventory.get( i )
|
||||
if( !this.inventory.get( i )
|
||||
.isEmpty() )
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putByte( "Slot", (byte) i );
|
||||
this.m_inventory.get( i )
|
||||
this.inventory.get( i )
|
||||
.toTag( tag );
|
||||
nbttaglist.add( tag );
|
||||
}
|
||||
@@ -311,7 +311,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
nbt.put( "Items", nbttaglist );
|
||||
|
||||
// Write brain
|
||||
nbt = this.m_brain.writeToNBT( nbt );
|
||||
nbt = this.brain.writeToNBT( nbt );
|
||||
|
||||
return super.toTag( nbt );
|
||||
}
|
||||
@@ -325,22 +325,22 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
|
||||
// Read inventory
|
||||
ListTag nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND );
|
||||
this.m_inventory.clear();
|
||||
this.m_previousInventory.clear();
|
||||
this.inventory.clear();
|
||||
this.previousInventory.clear();
|
||||
for( int i = 0; i < nbttaglist.size(); i++ )
|
||||
{
|
||||
CompoundTag tag = nbttaglist.getCompound( i );
|
||||
int slot = tag.getByte( "Slot" ) & 0xff;
|
||||
if( slot < this.size() )
|
||||
{
|
||||
this.m_inventory.set( slot, ItemStack.fromTag( tag ) );
|
||||
this.m_previousInventory.set( slot, this.m_inventory.get( slot )
|
||||
this.inventory.set( slot, ItemStack.fromTag( tag ) );
|
||||
this.previousInventory.set( slot, this.inventory.get( slot )
|
||||
.copy() );
|
||||
}
|
||||
}
|
||||
|
||||
// Read state
|
||||
this.m_brain.readFromNBT( nbt );
|
||||
this.brain.readFromNBT( nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -367,7 +367,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
ComputerCraft.turtleTermHeight );
|
||||
computer.setPosition( this.getPos() );
|
||||
computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), this.getAccess() ) );
|
||||
this.m_brain.setupComputer( computer );
|
||||
this.brain.setupComputer( computer );
|
||||
return computer;
|
||||
}
|
||||
|
||||
@@ -375,20 +375,20 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
protected void writeDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
super.writeDescription( nbt );
|
||||
this.m_brain.writeDescription( nbt );
|
||||
this.brain.writeDescription( nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readDescription( @Nonnull CompoundTag nbt )
|
||||
{
|
||||
super.readDescription( nbt );
|
||||
this.m_brain.readDescription( nbt );
|
||||
this.brain.readDescription( nbt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputerProxy createProxy()
|
||||
{
|
||||
return this.m_brain.getProxy();
|
||||
return this.brain.getProxy();
|
||||
}
|
||||
|
||||
public void setDirection( Direction dir )
|
||||
@@ -437,66 +437,66 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
|
||||
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()
|
||||
{
|
||||
// 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
|
||||
public int getColour()
|
||||
{
|
||||
return this.m_brain.getColour();
|
||||
return this.brain.getColour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getOverlay()
|
||||
{
|
||||
return this.m_brain.getOverlay();
|
||||
return this.brain.getOverlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITurtleUpgrade getUpgrade( TurtleSide side )
|
||||
{
|
||||
return this.m_brain.getUpgrade( side );
|
||||
return this.brain.getUpgrade( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITurtleAccess getAccess()
|
||||
{
|
||||
return this.m_brain;
|
||||
return this.brain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getRenderOffset( float f )
|
||||
{
|
||||
return this.m_brain.getRenderOffset( f );
|
||||
return this.brain.getRenderOffset( f );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRenderYaw( float f )
|
||||
{
|
||||
return this.m_brain.getVisualYaw( f );
|
||||
return this.brain.getVisualYaw( f );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getToolRenderAngle( TurtleSide side, float f )
|
||||
{
|
||||
return this.m_brain.getToolRenderAngle( side, f );
|
||||
return this.brain.getToolRenderAngle( side, f );
|
||||
}
|
||||
|
||||
void setOwningPlayer( GameProfile player )
|
||||
{
|
||||
this.m_brain.setOwningPlayer( player );
|
||||
this.brain.setOwningPlayer( player );
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@@ -506,13 +506,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
public void markDirty()
|
||||
{
|
||||
super.markDirty();
|
||||
if( !this.m_inventoryChanged )
|
||||
if( !this.inventoryChanged )
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -525,10 +525,10 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
boolean changed = false;
|
||||
for( int i = 0; i < INVENTORY_SIZE; i++ )
|
||||
{
|
||||
if( !this.m_inventory.get( i )
|
||||
if( !this.inventory.get( i )
|
||||
.isEmpty() )
|
||||
{
|
||||
this.m_inventory.set( i, ItemStack.EMPTY );
|
||||
this.inventory.set( i, ItemStack.EMPTY );
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@@ -544,21 +544,21 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
|
||||
public void transferStateFrom( TileTurtle copy )
|
||||
{
|
||||
super.transferStateFrom( copy );
|
||||
Collections.copy( this.m_inventory, copy.m_inventory );
|
||||
Collections.copy( this.m_previousInventory, copy.m_previousInventory );
|
||||
this.m_inventoryChanged = copy.m_inventoryChanged;
|
||||
this.m_brain = copy.m_brain;
|
||||
this.m_brain.setOwner( this );
|
||||
Collections.copy( this.inventory, copy.inventory );
|
||||
Collections.copy( this.previousInventory, copy.previousInventory );
|
||||
this.inventoryChanged = copy.inventoryChanged;
|
||||
this.brain = copy.brain;
|
||||
this.brain.setOwner( this );
|
||||
|
||||
// Mark the other turtle as having moved, and so its peripheral is dead.
|
||||
copy.m_moveState = MoveState.MOVED;
|
||||
copy.moveState = MoveState.MOVED;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
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
|
||||
|
@@ -59,51 +59,51 @@ public class TurtleBrain implements ITurtleAccess
|
||||
private static final String NBT_SLOT = "Slot";
|
||||
|
||||
private static final int ANIM_DURATION = 8;
|
||||
private final Queue<TurtleCommandQueueEntry> m_commandQueue = new ArrayDeque<>();
|
||||
private final Map<TurtleSide, ITurtleUpgrade> m_upgrades = new EnumMap<>( TurtleSide.class );
|
||||
private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>();
|
||||
private final Map<TurtleSide, ITurtleUpgrade> upgrades = 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 );
|
||||
TurtlePlayer m_cachedPlayer;
|
||||
private TileTurtle m_owner;
|
||||
private final Inventory m_inventory = (InventoryDelegate) () -> this.m_owner;
|
||||
private ComputerProxy m_proxy;
|
||||
private GameProfile m_owningPlayer;
|
||||
private int m_commandsIssued = 0;
|
||||
private int m_selectedSlot = 0;
|
||||
private int m_fuelLevel = 0;
|
||||
private int m_colourHex = -1;
|
||||
private Identifier m_overlay = null;
|
||||
private TurtleAnimation m_animation = TurtleAnimation.NONE;
|
||||
private int m_animationProgress = 0;
|
||||
private int m_lastAnimationProgress = 0;
|
||||
private final Map<TurtleSide, CompoundTag> upgradeNBTData = new EnumMap<>( TurtleSide.class );
|
||||
TurtlePlayer cachedPlayer;
|
||||
private TileTurtle owner;
|
||||
private final Inventory inventory = (InventoryDelegate) () -> this.owner;
|
||||
private ComputerProxy proxy;
|
||||
private GameProfile owningPlayer;
|
||||
private int commandsIssued = 0;
|
||||
private int selectedSlot = 0;
|
||||
private int fuelLevel = 0;
|
||||
private int colourHex = -1;
|
||||
private Identifier overlay = null;
|
||||
private TurtleAnimation animation = TurtleAnimation.NONE;
|
||||
private int animationProgress = 0;
|
||||
private int lastAnimationProgress = 0;
|
||||
|
||||
public TurtleBrain( TileTurtle turtle )
|
||||
{
|
||||
this.m_owner = turtle;
|
||||
this.owner = turtle;
|
||||
}
|
||||
|
||||
public TileTurtle getOwner()
|
||||
{
|
||||
return this.m_owner;
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setOwner( TileTurtle owner )
|
||||
{
|
||||
this.m_owner = owner;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return this.m_owner.getFamily();
|
||||
return this.owner.getFamily();
|
||||
}
|
||||
|
||||
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
|
||||
// when being mined). If so, abort.
|
||||
if( m_owner.isRemoved() ) return;
|
||||
if( owner.isRemoved() ) return;
|
||||
}
|
||||
|
||||
// Advance animation
|
||||
this.updateAnimation();
|
||||
|
||||
// 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()
|
||||
.update( this, entry.getKey() );
|
||||
@@ -189,14 +189,14 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return this.m_owner.getWorld();
|
||||
return this.owner.getWorld();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockPos getPosition()
|
||||
{
|
||||
return this.m_owner.getPos();
|
||||
return this.owner.getPos();
|
||||
}
|
||||
|
||||
@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)
|
||||
World oldWorld = this.getWorld();
|
||||
TileTurtle oldOwner = this.m_owner;
|
||||
BlockPos oldPos = this.m_owner.getPos();
|
||||
BlockState oldBlock = this.m_owner.getCachedState();
|
||||
TileTurtle oldOwner = this.owner;
|
||||
BlockPos oldPos = this.owner.getPos();
|
||||
BlockState oldBlock = this.owner.getCachedState();
|
||||
|
||||
if( oldWorld == world && oldPos.equals( pos ) )
|
||||
{
|
||||
@@ -292,7 +292,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
public Vec3d getVisualPosition( float 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 );
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
public float getVisualYaw( float f )
|
||||
{
|
||||
float yaw = this.getDirection().asRotation();
|
||||
switch( this.m_animation )
|
||||
switch( this.animation )
|
||||
{
|
||||
case TURN_LEFT:
|
||||
{
|
||||
@@ -328,19 +328,19 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public Direction getDirection()
|
||||
{
|
||||
return this.m_owner.getDirection();
|
||||
return this.owner.getDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection( @Nonnull Direction dir )
|
||||
{
|
||||
this.m_owner.setDirection( dir );
|
||||
this.owner.setDirection( dir );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSelectedSlot()
|
||||
{
|
||||
return this.m_selectedSlot;
|
||||
return this.selectedSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -351,17 +351,17 @@ public class TurtleBrain implements ITurtleAccess
|
||||
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.m_owner.onTileEntityChange();
|
||||
this.selectedSlot = slot;
|
||||
this.owner.onTileEntityChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColour()
|
||||
{
|
||||
return this.m_colourHex;
|
||||
return this.colourHex;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -369,16 +369,16 @@ public class TurtleBrain implements ITurtleAccess
|
||||
{
|
||||
if( colour >= 0 && colour <= 0xFFFFFF )
|
||||
{
|
||||
if( this.m_colourHex != colour )
|
||||
if( this.colourHex != colour )
|
||||
{
|
||||
this.m_colourHex = colour;
|
||||
this.m_owner.updateBlock();
|
||||
this.colourHex = colour;
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
}
|
||||
else if( this.m_colourHex != -1 )
|
||||
else if( this.colourHex != -1 )
|
||||
{
|
||||
this.m_colourHex = -1;
|
||||
this.m_owner.updateBlock();
|
||||
this.colourHex = -1;
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public GameProfile getOwningPlayer()
|
||||
{
|
||||
return this.m_owningPlayer;
|
||||
return this.owningPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -398,20 +398,20 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public int getFuelLevel()
|
||||
{
|
||||
return Math.min( this.m_fuelLevel, this.getFuelLimit() );
|
||||
return Math.min( this.fuelLevel, this.getFuelLimit() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuelLevel( int level )
|
||||
{
|
||||
this.m_fuelLevel = Math.min( level, this.getFuelLimit() );
|
||||
this.m_owner.onTileEntityChange();
|
||||
this.fuelLevel = Math.min( level, this.getFuelLimit() );
|
||||
this.owner.onTileEntityChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFuelLimit()
|
||||
{
|
||||
if( this.m_owner.getFamily() == ComputerFamily.ADVANCED )
|
||||
if( this.owner.getFamily() == ComputerFamily.ADVANCED )
|
||||
{
|
||||
return ComputerCraft.advancedTurtleFuelLimit;
|
||||
}
|
||||
@@ -471,8 +471,8 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
private int issueCommand( ITurtleCommand command )
|
||||
{
|
||||
this.m_commandQueue.offer( new TurtleCommandQueueEntry( ++this.m_commandsIssued, command ) );
|
||||
return this.m_commandsIssued;
|
||||
this.commandQueue.offer( new TurtleCommandQueueEntry( ++this.commandsIssued, command ) );
|
||||
return this.commandsIssued;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -483,37 +483,37 @@ public class TurtleBrain implements ITurtleAccess
|
||||
throw new UnsupportedOperationException( "Cannot play animations on the client" );
|
||||
}
|
||||
|
||||
this.m_animation = animation;
|
||||
if( this.m_animation == TurtleAnimation.SHORT_WAIT )
|
||||
this.animation = animation;
|
||||
if( this.animation == TurtleAnimation.SHORT_WAIT )
|
||||
{
|
||||
this.m_animationProgress = ANIM_DURATION / 2;
|
||||
this.m_lastAnimationProgress = ANIM_DURATION / 2;
|
||||
this.animationProgress = ANIM_DURATION / 2;
|
||||
this.lastAnimationProgress = ANIM_DURATION / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_animationProgress = 0;
|
||||
this.m_lastAnimationProgress = 0;
|
||||
this.animationProgress = 0;
|
||||
this.lastAnimationProgress = 0;
|
||||
}
|
||||
this.m_owner.updateBlock();
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITurtleUpgrade getUpgrade( @Nonnull TurtleSide side )
|
||||
{
|
||||
return this.m_upgrades.get( side );
|
||||
return this.upgrades.get( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUpgrade( @Nonnull TurtleSide side, ITurtleUpgrade 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;
|
||||
}
|
||||
this.m_upgrades.remove( side );
|
||||
this.upgrades.remove( side );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -523,19 +523,19 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
}
|
||||
|
||||
this.m_upgradeNBTData.remove( side );
|
||||
this.upgradeNBTData.remove( side );
|
||||
|
||||
// Set new upgrade
|
||||
if( upgrade != null )
|
||||
{
|
||||
this.m_upgrades.put( side, upgrade );
|
||||
this.upgrades.put( side, upgrade );
|
||||
}
|
||||
|
||||
// Notify clients and create peripherals
|
||||
if( this.m_owner.getWorld() != null )
|
||||
if( this.owner.getWorld() != null )
|
||||
{
|
||||
this.updatePeripherals( this.m_owner.createServerComputer() );
|
||||
this.m_owner.updateBlock();
|
||||
this.updatePeripherals( this.owner.createServerComputer() );
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,10 +549,10 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public CompoundTag getUpgradeNBTData( TurtleSide side )
|
||||
{
|
||||
CompoundTag nbt = this.m_upgradeNBTData.get( side );
|
||||
CompoundTag nbt = this.upgradeNBTData.get( side );
|
||||
if( nbt == null )
|
||||
{
|
||||
this.m_upgradeNBTData.put( side, nbt = new CompoundTag() );
|
||||
this.upgradeNBTData.put( side, nbt = new CompoundTag() );
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
@@ -560,30 +560,30 @@ public class TurtleBrain implements ITurtleAccess
|
||||
@Override
|
||||
public void updateUpgradeNBTData( @Nonnull TurtleSide side )
|
||||
{
|
||||
this.m_owner.updateBlock();
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Inventory getInventory()
|
||||
{
|
||||
return this.m_inventory;
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
public void setOwningPlayer( GameProfile profile )
|
||||
{
|
||||
this.m_owningPlayer = profile;
|
||||
this.owningPlayer = profile;
|
||||
}
|
||||
|
||||
private void updateCommands()
|
||||
{
|
||||
if( this.m_animation != TurtleAnimation.NONE || this.m_commandQueue.isEmpty() )
|
||||
if( this.animation != TurtleAnimation.NONE || this.commandQueue.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 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()
|
||||
.getMainThreadMonitor()
|
||||
.canWork() )
|
||||
@@ -592,7 +592,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
|
||||
// Pull a new command
|
||||
TurtleCommandQueueEntry nextCommand = this.m_commandQueue.poll();
|
||||
TurtleCommandQueueEntry nextCommand = this.commandQueue.poll();
|
||||
if( nextCommand == null )
|
||||
{
|
||||
return;
|
||||
@@ -648,18 +648,18 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
private void updateAnimation()
|
||||
{
|
||||
if( this.m_animation != TurtleAnimation.NONE )
|
||||
if( this.animation != TurtleAnimation.NONE )
|
||||
{
|
||||
World world = this.getWorld();
|
||||
|
||||
if( ComputerCraft.turtlesCanPush )
|
||||
{
|
||||
// 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();
|
||||
Direction moveDir;
|
||||
switch( this.m_animation )
|
||||
switch( this.animation )
|
||||
{
|
||||
case MOVE_FORWARD:
|
||||
default:
|
||||
@@ -683,7 +683,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
double maxY = minY + 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 );
|
||||
if( moveDir.getOffsetX() < 0 )
|
||||
{
|
||||
@@ -729,7 +729,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
|
||||
// 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
|
||||
Holiday currentHoliday = HolidayUtil.getCurrentHoliday();
|
||||
@@ -753,19 +753,19 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
|
||||
// Wait for anim completion
|
||||
this.m_lastAnimationProgress = this.m_animationProgress;
|
||||
if( ++this.m_animationProgress >= ANIM_DURATION )
|
||||
this.lastAnimationProgress = this.animationProgress;
|
||||
if( ++this.animationProgress >= ANIM_DURATION )
|
||||
{
|
||||
this.m_animation = TurtleAnimation.NONE;
|
||||
this.m_animationProgress = 0;
|
||||
this.m_lastAnimationProgress = 0;
|
||||
this.animation = TurtleAnimation.NONE;
|
||||
this.animationProgress = 0;
|
||||
this.lastAnimationProgress = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vec3d getRenderOffset( float f )
|
||||
{
|
||||
switch( this.m_animation )
|
||||
switch( this.animation )
|
||||
{
|
||||
case MOVE_FORWARD:
|
||||
case MOVE_BACK:
|
||||
@@ -774,7 +774,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
{
|
||||
// Get direction
|
||||
Direction dir;
|
||||
switch( this.m_animation )
|
||||
switch( this.animation )
|
||||
{
|
||||
case MOVE_FORWARD:
|
||||
default:
|
||||
@@ -803,8 +803,8 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
private float getAnimationFraction( float f )
|
||||
{
|
||||
float next = (float) this.m_animationProgress / ANIM_DURATION;
|
||||
float previous = (float) this.m_lastAnimationProgress / ANIM_DURATION;
|
||||
float next = (float) this.animationProgress / ANIM_DURATION;
|
||||
float previous = (float) this.lastAnimationProgress / ANIM_DURATION;
|
||||
return previous + (next - previous) * f;
|
||||
}
|
||||
|
||||
@@ -813,17 +813,17 @@ public class TurtleBrain implements ITurtleAccess
|
||||
this.readCommon( nbt );
|
||||
|
||||
// Read state
|
||||
this.m_selectedSlot = nbt.getInt( NBT_SLOT );
|
||||
this.selectedSlot = nbt.getInt( NBT_SLOT );
|
||||
|
||||
// Read owner
|
||||
if( nbt.contains( "Owner", NBTUtil.TAG_COMPOUND ) )
|
||||
{
|
||||
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
|
||||
{
|
||||
this.m_owningPlayer = null;
|
||||
this.owningPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -835,25 +835,25 @@ public class TurtleBrain implements ITurtleAccess
|
||||
private void readCommon( CompoundTag nbt )
|
||||
{
|
||||
// Read fields
|
||||
this.m_colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1;
|
||||
this.m_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.colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1;
|
||||
this.fuelLevel = nbt.contains( NBT_FUEL ) ? nbt.getInt( NBT_FUEL ) : 0;
|
||||
this.overlay = nbt.contains( NBT_OVERLAY ) ? new Identifier( nbt.getString( NBT_OVERLAY ) ) : null;
|
||||
|
||||
// Read upgrades
|
||||
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 );
|
||||
|
||||
// NBT
|
||||
this.m_upgradeNBTData.clear();
|
||||
this.upgradeNBTData.clear();
|
||||
if( nbt.contains( NBT_LEFT_UPGRADE_DATA ) )
|
||||
{
|
||||
this.m_upgradeNBTData.put( TurtleSide.LEFT,
|
||||
this.upgradeNBTData.put( TurtleSide.LEFT,
|
||||
nbt.getCompound( NBT_LEFT_UPGRADE_DATA )
|
||||
.copy() );
|
||||
}
|
||||
if( nbt.contains( NBT_RIGHT_UPGRADE_DATA ) )
|
||||
{
|
||||
this.m_upgradeNBTData.put( TurtleSide.RIGHT,
|
||||
this.upgradeNBTData.put( TurtleSide.RIGHT,
|
||||
nbt.getCompound( NBT_RIGHT_UPGRADE_DATA )
|
||||
.copy() );
|
||||
}
|
||||
@@ -864,19 +864,19 @@ public class TurtleBrain implements ITurtleAccess
|
||||
this.writeCommon( nbt );
|
||||
|
||||
// Write state
|
||||
nbt.putInt( NBT_SLOT, this.m_selectedSlot );
|
||||
nbt.putInt( NBT_SLOT, this.selectedSlot );
|
||||
|
||||
// Write owner
|
||||
if( this.m_owningPlayer != null )
|
||||
if( this.owningPlayer != null )
|
||||
{
|
||||
CompoundTag owner = new CompoundTag();
|
||||
nbt.put( "Owner", owner );
|
||||
|
||||
owner.putLong( "UpperId", this.m_owningPlayer.getId()
|
||||
owner.putLong( "UpperId", this.owningPlayer.getId()
|
||||
.getMostSignificantBits() );
|
||||
owner.putLong( "LowerId", this.m_owningPlayer.getId()
|
||||
owner.putLong( "LowerId", this.owningPlayer.getId()
|
||||
.getLeastSignificantBits() );
|
||||
owner.putString( "Name", this.m_owningPlayer.getName() );
|
||||
owner.putString( "Name", this.owningPlayer.getName() );
|
||||
}
|
||||
|
||||
return nbt;
|
||||
@@ -884,14 +884,14 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
private void writeCommon( CompoundTag nbt )
|
||||
{
|
||||
nbt.putInt( NBT_FUEL, this.m_fuelLevel );
|
||||
if( this.m_colourHex != -1 )
|
||||
nbt.putInt( NBT_FUEL, this.fuelLevel );
|
||||
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
|
||||
@@ -907,12 +907,12 @@ public class TurtleBrain implements ITurtleAccess
|
||||
}
|
||||
|
||||
// Write upgrade NBT
|
||||
if( this.m_upgradeNBTData.containsKey( TurtleSide.LEFT ) )
|
||||
if( this.upgradeNBTData.containsKey( TurtleSide.LEFT ) )
|
||||
{
|
||||
nbt.put( NBT_LEFT_UPGRADE_DATA,
|
||||
this.getUpgradeNBTData( TurtleSide.LEFT ).copy() );
|
||||
}
|
||||
if( this.m_upgradeNBTData.containsKey( TurtleSide.RIGHT ) )
|
||||
if( this.upgradeNBTData.containsKey( TurtleSide.RIGHT ) )
|
||||
{
|
||||
nbt.put( NBT_RIGHT_UPGRADE_DATA,
|
||||
this.getUpgradeNBTData( TurtleSide.RIGHT ).copy() );
|
||||
@@ -931,41 +931,41 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
// 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.m_animationProgress = 0;
|
||||
this.m_lastAnimationProgress = 0;
|
||||
this.animation = anim;
|
||||
this.animationProgress = 0;
|
||||
this.lastAnimationProgress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeDescription( CompoundTag nbt )
|
||||
{
|
||||
this.writeCommon( nbt );
|
||||
nbt.putInt( "Animation", this.m_animation.ordinal() );
|
||||
nbt.putInt( "Animation", this.animation.ordinal() );
|
||||
}
|
||||
|
||||
public Identifier getOverlay()
|
||||
{
|
||||
return this.m_overlay;
|
||||
return this.overlay;
|
||||
}
|
||||
|
||||
public void setOverlay( Identifier overlay )
|
||||
{
|
||||
if( !Objects.equal( this.m_overlay, overlay ) )
|
||||
if( !Objects.equal( this.overlay, overlay ) )
|
||||
{
|
||||
this.m_overlay = overlay;
|
||||
this.m_owner.updateBlock();
|
||||
this.overlay = overlay;
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
public DyeColor getDyeColour()
|
||||
{
|
||||
if( this.m_colourHex == -1 )
|
||||
if( this.colourHex == -1 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Colour colour = Colour.fromHex( this.m_colourHex );
|
||||
Colour colour = Colour.fromHex( this.colourHex );
|
||||
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();
|
||||
}
|
||||
if( this.m_colourHex != newColour )
|
||||
if( this.colourHex != newColour )
|
||||
{
|
||||
this.m_colourHex = newColour;
|
||||
this.m_owner.updateBlock();
|
||||
this.colourHex = newColour;
|
||||
this.owner.updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -22,11 +22,11 @@ import java.util.List;
|
||||
|
||||
public class TurtleCompareCommand implements ITurtleCommand
|
||||
{
|
||||
private final InteractDirection m_direction;
|
||||
private final InteractDirection direction;
|
||||
|
||||
public TurtleCompareCommand( InteractDirection direction )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -34,7 +34,7 @@ public class TurtleCompareCommand implements ITurtleCommand
|
||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
// Get world direction from direction
|
||||
Direction direction = this.m_direction.toWorldDir( turtle );
|
||||
Direction direction = this.direction.toWorldDir( turtle );
|
||||
|
||||
// Get currently selected stack
|
||||
ItemStack selectedStack = turtle.getInventory()
|
||||
|
@@ -16,11 +16,11 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleCompareToCommand implements ITurtleCommand
|
||||
{
|
||||
private final int m_slot;
|
||||
private final int slot;
|
||||
|
||||
public TurtleCompareToCommand( int slot )
|
||||
{
|
||||
this.m_slot = slot;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -30,7 +30,7 @@ public class TurtleCompareToCommand implements ITurtleCommand
|
||||
ItemStack selectedStack = turtle.getInventory()
|
||||
.getStack( turtle.getSelectedSlot() );
|
||||
ItemStack stack = turtle.getInventory()
|
||||
.getStack( this.m_slot );
|
||||
.getStack( this.slot );
|
||||
if( InventoryUtil.areItemsStackable( selectedStack, stack ) )
|
||||
{
|
||||
return TurtleCommandResult.success();
|
||||
|
@@ -18,11 +18,11 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleDetectCommand implements ITurtleCommand
|
||||
{
|
||||
private final InteractDirection m_direction;
|
||||
private final InteractDirection direction;
|
||||
|
||||
public TurtleDetectCommand( InteractDirection direction )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -30,7 +30,7 @@ public class TurtleDetectCommand implements ITurtleCommand
|
||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
// 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
|
||||
World world = turtle.getWorld();
|
||||
|
@@ -25,13 +25,13 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleDropCommand implements ITurtleCommand
|
||||
{
|
||||
private final InteractDirection m_direction;
|
||||
private final int m_quantity;
|
||||
private final InteractDirection direction;
|
||||
private final int quantity;
|
||||
|
||||
public TurtleDropCommand( InteractDirection direction, int quantity )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.m_quantity = quantity;
|
||||
this.direction = direction;
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -39,17 +39,17 @@ public class TurtleDropCommand implements ITurtleCommand
|
||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
// Dropping nothing is easy
|
||||
if( this.m_quantity == 0 )
|
||||
if( this.quantity == 0 )
|
||||
{
|
||||
turtle.playAnimation( TurtleAnimation.WAIT );
|
||||
return TurtleCommandResult.success();
|
||||
}
|
||||
|
||||
// Get world direction from direction
|
||||
Direction direction = this.m_direction.toWorldDir( turtle );
|
||||
Direction direction = this.direction.toWorldDir( turtle );
|
||||
|
||||
// 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() )
|
||||
{
|
||||
return TurtleCommandResult.failure( "No items to drop" );
|
||||
|
@@ -22,11 +22,11 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleEquipCommand implements ITurtleCommand
|
||||
{
|
||||
private final TurtleSide m_side;
|
||||
private final TurtleSide side;
|
||||
|
||||
public TurtleEquipCommand( TurtleSide side )
|
||||
{
|
||||
this.m_side = side;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -55,7 +55,7 @@ public class TurtleEquipCommand implements ITurtleCommand
|
||||
|
||||
// Determine the upgrade to replace
|
||||
ItemStack oldUpgradeStack;
|
||||
ITurtleUpgrade oldUpgrade = turtle.getUpgrade( this.m_side );
|
||||
ITurtleUpgrade oldUpgrade = turtle.getUpgrade( this.side );
|
||||
if( oldUpgrade != null )
|
||||
{
|
||||
ItemStack craftingItem = oldUpgrade.getCraftingItem();
|
||||
@@ -89,7 +89,7 @@ public class TurtleEquipCommand implements ITurtleCommand
|
||||
WorldUtil.dropItemStack( remainder, turtle.getWorld(), position, turtle.getDirection() );
|
||||
}
|
||||
}
|
||||
turtle.setUpgrade( this.m_side, newUpgrade );
|
||||
turtle.setUpgrade( this.side, newUpgrade );
|
||||
|
||||
// Animate
|
||||
if( newUpgrade != null || oldUpgrade != null )
|
||||
|
@@ -30,11 +30,11 @@ import java.util.List;
|
||||
public class TurtleMoveCommand implements ITurtleCommand
|
||||
{
|
||||
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 )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -42,7 +42,7 @@ public class TurtleMoveCommand implements ITurtleCommand
|
||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
// Get world direction from direction
|
||||
Direction direction = this.m_direction.toWorldDir( turtle );
|
||||
Direction direction = this.direction.toWorldDir( turtle );
|
||||
|
||||
// Check if we can move
|
||||
World oldWorld = turtle.getWorld();
|
||||
@@ -70,7 +70,7 @@ public class TurtleMoveCommand implements ITurtleCommand
|
||||
|
||||
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" );
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class TurtleMoveCommand implements ITurtleCommand
|
||||
turtle.consumeFuel( 1 );
|
||||
|
||||
// Animate
|
||||
switch( this.m_direction )
|
||||
switch( this.direction )
|
||||
{
|
||||
case FORWARD:
|
||||
default:
|
||||
|
@@ -40,13 +40,13 @@ import java.util.List;
|
||||
|
||||
public class TurtlePlaceCommand implements ITurtleCommand
|
||||
{
|
||||
private final InteractDirection m_direction;
|
||||
private final Object[] m_extraArguments;
|
||||
private final InteractDirection direction;
|
||||
private final Object[] extraArguments;
|
||||
|
||||
public TurtlePlaceCommand( InteractDirection direction, Object[] arguments )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.m_extraArguments = arguments;
|
||||
this.direction = direction;
|
||||
this.extraArguments = arguments;
|
||||
}
|
||||
|
||||
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
|
||||
Direction direction = this.m_direction.toWorldDir( turtle );
|
||||
Direction direction = this.direction.toWorldDir( turtle );
|
||||
BlockPos coordinates = turtle.getPosition()
|
||||
.offset( direction );
|
||||
|
||||
@@ -89,7 +89,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
|
||||
// Do the deploying
|
||||
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 )
|
||||
{
|
||||
// Put the remaining items back
|
||||
|
@@ -96,10 +96,10 @@ public final class TurtlePlayer extends FakePlayer
|
||||
if( !(access instanceof TurtleBrain) ) return create( 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() )
|
||||
{
|
||||
player = brain.m_cachedPlayer = create( brain );
|
||||
player = brain.cachedPlayer = create( brain );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -28,13 +28,13 @@ import java.util.List;
|
||||
|
||||
public class TurtleSuckCommand implements ITurtleCommand
|
||||
{
|
||||
private final InteractDirection m_direction;
|
||||
private final int m_quantity;
|
||||
private final InteractDirection direction;
|
||||
private final int quantity;
|
||||
|
||||
public TurtleSuckCommand( InteractDirection direction, int quantity )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.m_quantity = quantity;
|
||||
this.direction = direction;
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -42,14 +42,14 @@ public class TurtleSuckCommand implements ITurtleCommand
|
||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
// Sucking nothing is easy
|
||||
if( this.m_quantity == 0 )
|
||||
if( this.quantity == 0 )
|
||||
{
|
||||
turtle.playAnimation( TurtleAnimation.WAIT );
|
||||
return TurtleCommandResult.success();
|
||||
}
|
||||
|
||||
// Get world direction from direction
|
||||
Direction direction = this.m_direction.toWorldDir( turtle );
|
||||
Direction direction = this.direction.toWorldDir( turtle );
|
||||
|
||||
// Get inventory for thing in front
|
||||
World world = turtle.getWorld();
|
||||
@@ -70,7 +70,7 @@ public class TurtleSuckCommand implements ITurtleCommand
|
||||
if( inventory != null )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
return TurtleCommandResult.failure( "No items to take" );
|
||||
@@ -118,9 +118,9 @@ public class TurtleSuckCommand implements ITurtleCommand
|
||||
|
||||
ItemStack storeStack;
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
@@ -17,13 +17,13 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleTransferToCommand implements ITurtleCommand
|
||||
{
|
||||
private final int m_slot;
|
||||
private final int m_quantity;
|
||||
private final int slot;
|
||||
private final int quantity;
|
||||
|
||||
public TurtleTransferToCommand( int slot, int limit )
|
||||
{
|
||||
this.m_slot = slot;
|
||||
this.m_quantity = limit;
|
||||
this.slot = slot;
|
||||
this.quantity = limit;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -31,7 +31,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
|
||||
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
||||
{
|
||||
// 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() )
|
||||
{
|
||||
turtle.playAnimation( TurtleAnimation.WAIT );
|
||||
@@ -39,7 +39,7 @@ public class TurtleTransferToCommand implements ITurtleCommand
|
||||
}
|
||||
|
||||
// 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() )
|
||||
{
|
||||
// Put the remainder back
|
||||
|
@@ -18,11 +18,11 @@ import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleTurnCommand implements ITurtleCommand
|
||||
{
|
||||
private final TurnDirection m_direction;
|
||||
private final TurnDirection direction;
|
||||
|
||||
public TurtleTurnCommand( TurnDirection direction )
|
||||
{
|
||||
this.m_direction = direction;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -35,7 +35,7 @@ public class TurtleTurnCommand implements ITurtleCommand
|
||||
return TurtleCommandResult.failure( event.getFailureMessage() );
|
||||
}
|
||||
|
||||
switch( this.m_direction )
|
||||
switch( this.direction )
|
||||
{
|
||||
case LEFT:
|
||||
{
|
||||
|
@@ -23,10 +23,10 @@ import javax.annotation.Nonnull;
|
||||
public class TurtleCraftingTable extends AbstractTurtleUpgrade
|
||||
{
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_leftModel;
|
||||
private ModelIdentifier leftModel;
|
||||
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_rightModel;
|
||||
private ModelIdentifier rightModel;
|
||||
|
||||
public TurtleCraftingTable( Identifier id )
|
||||
{
|
||||
@@ -45,16 +45,16 @@ public class TurtleCraftingTable extends AbstractTurtleUpgrade
|
||||
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
|
||||
{
|
||||
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 )
|
||||
private void loadModelLocations()
|
||||
{
|
||||
if( this.m_leftModel == null )
|
||||
if( this.leftModel == null )
|
||||
{
|
||||
this.m_leftModel = new ModelIdentifier( "computercraft:turtle_crafting_table_left", "inventory" );
|
||||
this.m_rightModel = new ModelIdentifier( "computercraft:turtle_crafting_table_right", "inventory" );
|
||||
this.leftModel = new ModelIdentifier( "computercraft:turtle_crafting_table_left", "inventory" );
|
||||
this.rightModel = new ModelIdentifier( "computercraft:turtle_crafting_table_right", "inventory" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,9 @@ import java.util.List;
|
||||
|
||||
public class TurtleInventoryCrafting extends CraftingInventory
|
||||
{
|
||||
private ITurtleAccess m_turtle;
|
||||
private int m_xStart;
|
||||
private int m_yStart;
|
||||
private final ITurtleAccess turtle;
|
||||
private int xStart;
|
||||
private int yStart;
|
||||
|
||||
@SuppressWarnings( "ConstantConditions" )
|
||||
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
|
||||
// avoid throwing any NPEs.
|
||||
super( null, 0, 0 );
|
||||
this.m_turtle = turtle;
|
||||
this.m_xStart = 0;
|
||||
this.m_yStart = 0;
|
||||
this.turtle = turtle;
|
||||
this.xStart = 0;
|
||||
this.yStart = 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Recipe<CraftingInventory> tryCrafting( int xStart, int yStart )
|
||||
{
|
||||
this.m_xStart = xStart;
|
||||
this.m_yStart = yStart;
|
||||
this.xStart = xStart;
|
||||
this.yStart = yStart;
|
||||
|
||||
// Check the non-relevant parts of the inventory are empty
|
||||
for( int x = 0; x < TileTurtle.INVENTORY_WIDTH; x++ )
|
||||
{
|
||||
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 )
|
||||
.isEmpty() )
|
||||
{
|
||||
@@ -65,9 +65,9 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
}
|
||||
|
||||
// Check the actual crafting
|
||||
return this.m_turtle.getWorld()
|
||||
return this.turtle.getWorld()
|
||||
.getRecipeManager()
|
||||
.getFirstMatch( RecipeType.CRAFTING, this, this.m_turtle.getWorld() )
|
||||
.getFirstMatch( RecipeType.CRAFTING, this, this.turtle.getWorld() )
|
||||
.orElse( null );
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
TurtlePlayer player = TurtlePlayer.get( this.m_turtle );
|
||||
TurtlePlayer player = TurtlePlayer.get( this.turtle );
|
||||
|
||||
ArrayList<ItemStack> results = new ArrayList<>();
|
||||
for( int i = 0; i < maxCount && recipe.matches( this, world ); i++ )
|
||||
@@ -159,7 +159,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
@Override
|
||||
public int getMaxCountPerStack()
|
||||
{
|
||||
return this.m_turtle.getInventory()
|
||||
return this.turtle.getInventory()
|
||||
.getMaxCountPerStack();
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
public boolean isValid( int i, @Nonnull ItemStack stack )
|
||||
{
|
||||
i = this.modifyIndex( i );
|
||||
return this.m_turtle.getInventory()
|
||||
return this.turtle.getInventory()
|
||||
.isValid( i, stack );
|
||||
}
|
||||
|
||||
@@ -185,8 +185,8 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
|
||||
private int modifyIndex( int index )
|
||||
{
|
||||
int x = this.m_xStart + index % this.getWidth();
|
||||
int y = this.m_yStart + index / this.getHeight();
|
||||
int x = this.xStart + index % this.getWidth();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
public ItemStack getStack( int i )
|
||||
{
|
||||
i = this.modifyIndex( i );
|
||||
return this.m_turtle.getInventory()
|
||||
return this.turtle.getInventory()
|
||||
.getStack( i );
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
public ItemStack removeStack( int i )
|
||||
{
|
||||
i = this.modifyIndex( i );
|
||||
return this.m_turtle.getInventory()
|
||||
return this.turtle.getInventory()
|
||||
.removeStack( i );
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
public ItemStack removeStack( int i, int size )
|
||||
{
|
||||
i = this.modifyIndex( i );
|
||||
return this.m_turtle.getInventory()
|
||||
return this.turtle.getInventory()
|
||||
.removeStack( i, size );
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
public void setStack( int i, @Nonnull ItemStack stack )
|
||||
{
|
||||
i = this.modifyIndex( i );
|
||||
this.m_turtle.getInventory()
|
||||
this.turtle.getInventory()
|
||||
.setStack( i, stack );
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
this.m_turtle.getInventory()
|
||||
this.turtle.getInventory()
|
||||
.markDirty();
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
|
||||
for( int i = 0; i < this.size(); i++ )
|
||||
{
|
||||
int j = this.modifyIndex( i );
|
||||
this.m_turtle.getInventory()
|
||||
this.turtle.getInventory()
|
||||
.setStack( j, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
|
@@ -28,13 +28,13 @@ public class TurtleModem extends AbstractTurtleUpgrade
|
||||
{
|
||||
private final boolean advanced;
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_leftOffModel;
|
||||
private ModelIdentifier leftOffModel;
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_rightOffModel;
|
||||
private ModelIdentifier rightOffModel;
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_leftOnModel;
|
||||
private ModelIdentifier leftOnModel;
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_rightOnModel;
|
||||
private ModelIdentifier rightOnModel;
|
||||
|
||||
public TurtleModem( boolean advanced, Identifier id )
|
||||
{
|
||||
@@ -71,27 +71,27 @@ public class TurtleModem extends AbstractTurtleUpgrade
|
||||
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 )
|
||||
private void loadModelLocations()
|
||||
{
|
||||
if( this.m_leftOffModel == null )
|
||||
if( this.leftOffModel == null )
|
||||
{
|
||||
if( this.advanced )
|
||||
{
|
||||
this.m_leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_left", "inventory" );
|
||||
this.m_rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_right", "inventory" );
|
||||
this.m_leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_left", "inventory" );
|
||||
this.m_rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_right", "inventory" );
|
||||
this.leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_left", "inventory" );
|
||||
this.rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_off_right", "inventory" );
|
||||
this.leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_left", "inventory" );
|
||||
this.rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_advanced_on_right", "inventory" );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_left", "inventory" );
|
||||
this.m_rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_right", "inventory" );
|
||||
this.m_leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_left", "inventory" );
|
||||
this.m_rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_right", "inventory" );
|
||||
this.leftOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_left", "inventory" );
|
||||
this.rightOffModel = new ModelIdentifier( "computercraft:turtle_modem_normal_off_right", "inventory" );
|
||||
this.leftOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_left", "inventory" );
|
||||
this.rightOnModel = new ModelIdentifier( "computercraft:turtle_modem_normal_on_right", "inventory" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,9 @@ import javax.annotation.Nonnull;
|
||||
public class TurtleSpeaker extends AbstractTurtleUpgrade
|
||||
{
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_leftModel;
|
||||
private ModelIdentifier leftModel;
|
||||
@Environment( EnvType.CLIENT )
|
||||
private ModelIdentifier m_rightModel;
|
||||
private ModelIdentifier rightModel;
|
||||
|
||||
public TurtleSpeaker( Identifier id )
|
||||
{
|
||||
@@ -47,16 +47,16 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
|
||||
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
|
||||
{
|
||||
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 )
|
||||
private void loadModelLocations()
|
||||
{
|
||||
if( this.m_leftModel == null )
|
||||
if( this.leftModel == null )
|
||||
{
|
||||
this.m_leftModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_left", "inventory" );
|
||||
this.m_rightModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_right", "inventory" );
|
||||
this.leftModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_left", "inventory" );
|
||||
this.rightModel = new ModelIdentifier( "computercraft:turtle_speaker_upgrade_right", "inventory" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,10 @@
|
||||
*/
|
||||
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.FileNotFoundAction;
|
||||
import com.google.common.base.CaseFormat;
|
||||
@@ -27,7 +30,8 @@ import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Config {
|
||||
public class Config
|
||||
{
|
||||
private static final int MODEM_MAX_RANGE = 100000;
|
||||
|
||||
public static final String TRANSLATION_PREFIX = "gui.computercraft.config.";
|
||||
@@ -42,10 +46,12 @@ public class Config {
|
||||
private static final String serverFileName = "computercraft-server.toml";
|
||||
private static final Path clientPath = FabricLoader.INSTANCE.getConfigDir().resolve( "computercraft-client.toml" );
|
||||
|
||||
private Config() {
|
||||
private Config()
|
||||
{
|
||||
}
|
||||
|
||||
static {
|
||||
static
|
||||
{
|
||||
System.setProperty( "nightconfig.preserveInsertionOrder", "true" );
|
||||
|
||||
serverSpec = new CommentedConfigSpec();
|
||||
@@ -244,17 +250,20 @@ public class Config {
|
||||
return false;
|
||||
};
|
||||
|
||||
private static CommentedFileConfig buildFileConfig(Path path) {
|
||||
private static CommentedFileConfig buildFileConfig( Path path )
|
||||
{
|
||||
return CommentedFileConfig.builder( path )
|
||||
.onFileNotFound( MAKE_DIRECTORIES )
|
||||
.preserveInsertionOrder()
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void serverStarting(MinecraftServer server) {
|
||||
public static void serverStarting( MinecraftServer server )
|
||||
{
|
||||
Path serverPath = server.getSavePath( serverDir ).resolve( serverFileName );
|
||||
|
||||
try(CommentedFileConfig config = buildFileConfig(serverPath)) {
|
||||
try( CommentedFileConfig config = buildFileConfig( serverPath ) )
|
||||
{
|
||||
config.load();
|
||||
serverSpec.correct( config, Config::correctionListener );
|
||||
config.save();
|
||||
@@ -263,12 +272,15 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
public static void serverStopping(MinecraftServer server) {
|
||||
public static void serverStopping( MinecraftServer server )
|
||||
{
|
||||
serverConfig = null;
|
||||
}
|
||||
|
||||
public static void clientStarted(MinecraftClient client) {
|
||||
try (CommentedFileConfig config = buildFileConfig(clientPath)) {
|
||||
public static void clientStarted( MinecraftClient client )
|
||||
{
|
||||
try( CommentedFileConfig config = buildFileConfig( clientPath ) )
|
||||
{
|
||||
config.load();
|
||||
clientSpec.correct( config, Config::correctionListener );
|
||||
config.save();
|
||||
@@ -277,20 +289,26 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
switch( action )
|
||||
{
|
||||
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:
|
||||
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:
|
||||
ComputerCraft.log.warn( "Config key {} not valid -> replaced with default value.", key );
|
||||
}
|
||||
}
|
||||
|
||||
public static void sync() {
|
||||
if(serverConfig != null) {
|
||||
public static void sync()
|
||||
{
|
||||
if( serverConfig != null )
|
||||
{
|
||||
// General
|
||||
ComputerCraft.computerSpaceLimit = serverConfig.<Integer>get( "computer_space_limit" );
|
||||
ComputerCraft.floppySpaceLimit = serverConfig.<Integer>get( "floppy_space_limit" );
|
||||
@@ -331,7 +349,8 @@ public class Config {
|
||||
ComputerCraft.turtlesCanPush = serverConfig.<Boolean>get( "turtle.can_push" );
|
||||
|
||||
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 ) );
|
||||
}
|
||||
|
||||
@@ -345,7 +364,8 @@ public class Config {
|
||||
}
|
||||
|
||||
// Client
|
||||
if(clientConfig != null) {
|
||||
if( clientConfig != null )
|
||||
{
|
||||
ComputerCraft.monitorRenderer = clientConfig.getEnum( "monitor_renderer", MonitorRenderer.class );
|
||||
int distance = clientConfig.get( "monitor_distance" );
|
||||
ComputerCraft.monitorDistanceSq = distance * distance;
|
||||
@@ -354,11 +374,14 @@ public class Config {
|
||||
|
||||
private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE );
|
||||
|
||||
private static TurtleAction getAction(String value) {
|
||||
try {
|
||||
private static TurtleAction getAction( String value )
|
||||
{
|
||||
try
|
||||
{
|
||||
return TurtleAction.valueOf( converter.convert( value ) );
|
||||
}
|
||||
catch(IllegalArgumentException e) {
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user