1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

A whole bunch of refomatting

- Remove redundant constructors and super calls
 - Standardise naming of texture fields
 - Always use postfix notations for loops
 - Cleanup several peripheral classes
This commit is contained in:
SquidDev 2018-12-30 16:14:07 +00:00
parent 27aaec9a82
commit ee3347afbd
49 changed files with 391 additions and 644 deletions

View File

@ -268,10 +268,6 @@ public static class Config
@SidedProxy( clientSide = "dan200.computercraft.client.proxy.CCTurtleProxyClient", serverSide = "dan200.computercraft.server.proxy.CCTurtleProxyServer" )
public static ICCTurtleProxy turtleProxy;
public ComputerCraft()
{
}
@Mod.EventHandler
public void preInit( FMLPreInitializationEvent event )
{

View File

@ -35,7 +35,7 @@ public static FixedWidthFontRenderer instance()
return instance = new FixedWidthFontRenderer();
}
private TextureManager m_textureManager;
private final TextureManager m_textureManager;
private FixedWidthFontRenderer()
{

View File

@ -24,9 +24,9 @@
public class GuiComputer extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/corners.png" );
private static final ResourceLocation backgroundAdvanced = new ResourceLocation( "computercraft", "textures/gui/corners_advanced.png" );
private static final ResourceLocation backgroundCommand = new ResourceLocation( "computercraft", "textures/gui/corners_command.png" );
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/corners.png" );
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/corners_advanced.png" );
private static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( "computercraft", "textures/gui/corners_command.png" );
private final ComputerFamily m_family;
private final ClientComputer m_computer;
@ -165,17 +165,17 @@ public void drawScreen( int mouseX, int mouseY, float f )
case Normal:
default:
{
this.mc.getTextureManager().bindTexture( background );
this.mc.getTextureManager().bindTexture( BACKGROUND );
break;
}
case Advanced:
{
this.mc.getTextureManager().bindTexture( backgroundAdvanced );
this.mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
break;
}
case Command:
{
this.mc.getTextureManager().bindTexture( backgroundCommand );
this.mc.getTextureManager().bindTexture( BACKGROUND_COMMAND );
break;
}
}

View File

@ -14,7 +14,7 @@
public class GuiDiskDrive extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/diskdrive.png" );
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/diskdrive.png" );
private final ContainerDiskDrive m_container;
@ -36,7 +36,7 @@ protected void drawGuiContainerForegroundLayer( int par1, int par2 )
protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
this.mc.getTextureManager().bindTexture( background );
this.mc.getTextureManager().bindTexture( BACKGROUND );
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
drawTexturedModalRect( l, i1, 0, 0, xSize, ySize );

View File

@ -14,7 +14,7 @@
public class GuiPrinter extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
private final ContainerPrinter m_container;
@ -36,7 +36,7 @@ protected void drawGuiContainerForegroundLayer( int par1, int par2 )
protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
{
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
this.mc.getTextureManager().bindTexture( background );
this.mc.getTextureManager().bindTexture( BACKGROUND );
int startX = (width - xSize) / 2;
int startY = (height - ySize) / 2;
drawTexturedModalRect( startX, startY, 0, 0, xSize, ySize );

View File

@ -42,30 +42,12 @@ public GuiPrintout( ContainerHeldItem container )
m_book = ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book;
}
@Override
public void initGui()
{
super.initGui();
}
@Override
public void onGuiClosed()
{
super.onGuiClosed();
}
@Override
public boolean doesGuiPauseGame()
{
return false;
}
@Override
public void updateScreen()
{
super.updateScreen();
}
@Override
protected void keyTyped( char c, int k ) throws IOException
{

View File

@ -23,8 +23,8 @@
public class GuiTurtle extends GuiContainer
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/turtle.png" );
private static final ResourceLocation backgroundAdvanced = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/turtle.png" );
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
private ContainerTurtle m_container;
@ -122,7 +122,7 @@ protected void drawSelectionSlot( boolean advanced )
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
int slotX = (slot % 4);
int slotY = (slot / 4);
this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background );
this.mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND );
drawTexturedModalRect( x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
}
}
@ -136,7 +136,7 @@ protected void drawGuiContainerBackgroundLayer( float f, int mouseX, int mouseY
// Draw border/inventory
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
this.mc.getTextureManager().bindTexture( advanced ? backgroundAdvanced : background );
this.mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND );
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect( x, y, 0, 0, xSize, ySize );

View File

@ -18,15 +18,15 @@
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.util.ArrayList;
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
public class WidgetTerminal extends Widget
{
private static final ResourceLocation background = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
private static final float TERMINATE_TIME = 0.5f;
private final IComputerContainer m_computer;
@ -409,7 +409,7 @@ public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY
}
// Draw lines
for( int line = 0; line < th; ++line )
for( int line = 0; line < th; line++ )
{
TextBuffer text = terminal.getLine( line );
TextBuffer colour = terminal.getTextColourLine( line );
@ -437,7 +437,7 @@ public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY
else
{
// Draw a black background
mc.getTextureManager().bindTexture( background );
mc.getTextureManager().bindTexture( BACKGROUND );
Colour black = Colour.Black;
GlStateManager.color( black.getR(), black.getG(), black.getB(), 1.0f );
try

View File

@ -32,7 +32,7 @@ protected void renderItemFirstPerson( EnumHand hand, float pitch, float equipPro
GlStateManager.pushMatrix();
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
{
renderItemFirstCentre( pitch, equipProgress, swingProgress, stack );
renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack );
}
else
{
@ -95,7 +95,7 @@ private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress,
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPerson(float, float, float)
*/
private void renderItemFirstCentre( float pitch, float equipProgress, float swingProgress, ItemStack stack )
private void renderItemFirstPersonCenter( float pitch, float equipProgress, float swingProgress, ItemStack stack )
{
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();

View File

@ -1,5 +1,10 @@
package dan200.computercraft.client.render;
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.render;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.FrameInfo;
@ -127,7 +132,7 @@ protected void renderItem( ItemStack stack )
Palette palette = terminal.getPalette();
// Render the actual text
for( int line = 0; line < th; ++line )
for( int line = 0; line < th; line++ )
{
TextBuffer text = terminal.getLine( line );
TextBuffer colour = terminal.getTextColourLine( line );

View File

@ -1,3 +1,9 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.render;
import dan200.computercraft.ComputerCraft;

View File

@ -56,7 +56,7 @@ public static void drawText( int x, int y, int start, TextBuffer[] text, TextBuf
{
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
{
fontRenderer.drawString( text[start + line], x, y + line * FONT_HEIGHT, colours[start + line], null, 0, 0, false, Palette.DEFAULT );
}
@ -70,7 +70,7 @@ public static void drawText( int x, int y, int start, String[] text, String[] co
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
{
fontRenderer.drawString( new TextBuffer( text[start + line] ), x, y + line * FONT_HEIGHT, new TextBuffer( colours[start + line] ), null, 0, 0, false, Palette.DEFAULT );
}

View File

@ -1,3 +1,9 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.render;
import dan200.computercraft.ComputerCraft;

View File

@ -28,10 +28,6 @@
public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMonitor>
{
public TileEntityMonitorRenderer()
{
}
@Override
public void render( TileMonitor tileEntity, double posX, double posY, double posZ, float f, int i, float f2 )
{

View File

@ -47,10 +47,6 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
private static final ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_white", "inventory" );
private static final ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
public TileEntityTurtleRenderer()
{
}
@Override
public void render( TileTurtle tileEntity, double posX, double posY, double posZ, float f, int i, float f2 )
{

View File

@ -16,12 +16,6 @@
public class EmptyMount implements IMount
{
public EmptyMount()
{
}
// IMount implementation
@Override
public boolean exists( @Nonnull String path )
{

View File

@ -1,3 +1,9 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.command;
import com.google.common.collect.Lists;

View File

@ -1,5 +1,12 @@
package dan200.computercraft.shared.command.framework;
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.command;
import dan200.computercraft.shared.command.framework.CommandContext;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;

View File

@ -1,5 +1,7 @@
package dan200.computercraft.shared.command.framework;
import dan200.computercraft.shared.command.UserLevel;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;

View File

@ -77,7 +77,7 @@ public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv )
return ItemStack.EMPTY;
}
return ((IColouredItem) colourable.getItem()).setColour( colourable, tracker.getColour() );
return ((IColouredItem) colourable.getItem()).withColour( colourable, tracker.getColour() );
}
@Override

View File

@ -16,10 +16,6 @@
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
{
public DefaultBundledRedstoneProvider()
{
}
@Override
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
{

View File

@ -6,5 +6,5 @@ public interface IColouredItem
{
int getColour( ItemStack stack );
ItemStack setColour( ItemStack stack, int colour );
ItemStack withColour( ItemStack stack, int colour );
}

View File

@ -56,14 +56,7 @@ public int assignID()
{
TileComputerBase tile = getTile();
ServerComputer computer = tile.getServerComputer();
if( computer == null )
{
return tile.m_computerID;
}
else
{
return computer.getID();
}
return computer == null ? tile.getComputerID() : computer.getID();
}
public boolean isOn()
@ -76,6 +69,6 @@ public String getLabel()
{
TileComputerBase tile = getTile();
ServerComputer computer = tile.getServerComputer();
return computer == null ? tile.m_label : computer.getLabel();
return computer == null ? tile.getLabel() : computer.getLabel();
}
}

View File

@ -32,10 +32,10 @@
public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IDirectionalTile, ITickable
{
private int m_instanceID = -1;
protected int m_computerID = -1;
private int m_computerID = -1;
protected String m_label = null;
private boolean m_on = false;
protected boolean m_startOn = false;
boolean m_startOn = false;
private boolean m_fresh = false;
@Override
@ -138,16 +138,10 @@ public boolean getRedstoneConnectivity( EnumFacing side )
public int getRedstoneOutput( EnumFacing side )
{
int localDir = remapLocalSide( DirectionUtil.toLocal( this, side ) );
if( !isRedstoneBlockedOnSide( localDir ) )
if( !isRedstoneBlockedOnSide( localDir ) && getWorld() != null && !getWorld().isRemote )
{
if( getWorld() != null && !getWorld().isRemote )
{
ServerComputer computer = getServerComputer();
if( computer != null )
{
return computer.getRedstoneOutput( localDir );
}
}
ServerComputer computer = getServerComputer();
if( computer != null ) return computer.getRedstoneOutput( localDir );
}
return 0;
}
@ -383,28 +377,23 @@ public String getLabel()
@Override
public void setComputerID( int id )
{
if( !getWorld().isRemote && m_computerID != id )
{
m_computerID = id;
ServerComputer computer = getServerComputer();
if( computer != null )
{
computer.setID( m_computerID );
}
markDirty();
}
if( getWorld().isRemote || m_computerID == id ) return;
m_computerID = id;
ServerComputer computer = getServerComputer();
if( computer != null ) computer.setID( m_computerID );
markDirty();
}
@Override
public void setLabel( String label )
{
if( !getWorld().isRemote && !Objects.equals( m_label, label ) )
{
m_label = label;
ServerComputer computer = getServerComputer();
if( computer != null ) computer.setLabel( label );
markDirty();
}
if( getWorld().isRemote || Objects.equals( m_label, label ) ) return;
m_label = label;
ServerComputer computer = getServerComputer();
if( computer != null ) computer.setLabel( label );
markDirty();
}
@Override
@ -420,63 +409,48 @@ public ComputerFamily getFamily()
public ServerComputer createServerComputer()
{
if( !getWorld().isRemote )
if( getWorld().isRemote ) return null;
boolean changed = false;
if( m_instanceID < 0 )
{
boolean changed = false;
if( m_instanceID < 0 )
{
m_instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID();
changed = true;
}
if( !ComputerCraft.serverComputerRegistry.contains( m_instanceID ) )
{
ServerComputer computer = createComputer( m_instanceID, m_computerID );
ComputerCraft.serverComputerRegistry.add( m_instanceID, computer );
m_fresh = true;
changed = true;
}
if( changed )
{
updateBlock();
updateInput();
}
return ComputerCraft.serverComputerRegistry.get( m_instanceID );
m_instanceID = ComputerCraft.serverComputerRegistry.getUnusedInstanceID();
changed = true;
}
return null;
if( !ComputerCraft.serverComputerRegistry.contains( m_instanceID ) )
{
ServerComputer computer = createComputer( m_instanceID, m_computerID );
ComputerCraft.serverComputerRegistry.add( m_instanceID, computer );
m_fresh = true;
changed = true;
}
if( changed )
{
updateBlock();
updateInput();
}
return ComputerCraft.serverComputerRegistry.get( m_instanceID );
}
public ServerComputer getServerComputer()
{
if( !getWorld().isRemote )
{
return ComputerCraft.serverComputerRegistry.get( m_instanceID );
}
return null;
return getWorld().isRemote ? null : ComputerCraft.serverComputerRegistry.get( m_instanceID );
}
public ClientComputer createClientComputer()
{
if( getWorld().isRemote )
if( !getWorld().isRemote || m_instanceID < 0 ) return null;
if( !ComputerCraft.clientComputerRegistry.contains( m_instanceID ) )
{
if( m_instanceID >= 0 )
{
if( !ComputerCraft.clientComputerRegistry.contains( m_instanceID ) )
{
ComputerCraft.clientComputerRegistry.add( m_instanceID, new ClientComputer( m_instanceID ) );
}
return ComputerCraft.clientComputerRegistry.get( m_instanceID );
}
ComputerCraft.clientComputerRegistry.add( m_instanceID, new ClientComputer( m_instanceID ) );
}
return null;
return ComputerCraft.clientComputerRegistry.get( m_instanceID );
}
public ClientComputer getClientComputer()
{
if( getWorld().isRemote )
{
return ComputerCraft.clientComputerRegistry.get( m_instanceID );
}
return null;
return getWorld().isRemote ? ComputerCraft.clientComputerRegistry.get( m_instanceID ) : null;
}
// Networking stuff

View File

@ -8,10 +8,6 @@
public class ClientComputerRegistry extends ComputerRegistry<ClientComputer>
{
public ClientComputerRegistry()
{
}
public void update()
{
for( ClientComputer computer : getComputers() )
@ -23,25 +19,7 @@ public void update()
@Override
public void add( int instanceID, ClientComputer computer )
{
//System.out.println( "ADD CLIENT COMPUTER " + instanceID );
super.add( instanceID, computer );
computer.requestState();
//System.out.println( getComputers().size() + " CLIENT COMPUTERS" );
}
@Override
public void remove( int instanceID )
{
//System.out.println( "REMOVE CLIENT COMPUTER " + instanceID );
super.remove( instanceID );
//System.out.println( getComputers().size() + " CLIENT COMPUTERS" );
}
@Override
public void reset()
{
//System.out.println( "RESET CLIENT COMPUTERS" );
super.reset();
//System.out.println( getComputers().size() + " CLIENT COMPUTERS" );
}
}

View File

@ -21,7 +21,7 @@ public ComputerConvertRecipe( String group, @Nonnull CraftingHelper.ShapedPrimer
}
@Nonnull
protected abstract ItemStack convert( @Nonnull ItemStack stack );
protected abstract ItemStack convert( IComputerItem item, @Nonnull ItemStack stack );
@Override
public boolean matches( @Nonnull InventoryCrafting inventory, @Nonnull World world )
@ -54,10 +54,13 @@ public ItemStack getCraftingResult( @Nonnull InventoryCrafting inventory )
{
for( int x = 0; x < 3; x++ )
{
ItemStack item = inventory.getStackInRowAndColumn( x, y );
ItemStack stack = inventory.getStackInRowAndColumn( x, y );
// If we're a computer, convert!
if( item.getItem() instanceof IComputerItem ) return convert( item );
if( stack.getItem() instanceof IComputerItem )
{
return convert( ((IComputerItem) stack.getItem()), stack );
}
}
}

View File

@ -25,9 +25,9 @@ public ComputerFamilyRecipe( String group, @Nonnull CraftingHelper.ShapedPrimer
@Nonnull
@Override
protected ItemStack convert( @Nonnull ItemStack stack )
protected ItemStack convert( IComputerItem item, @Nonnull ItemStack stack )
{
return ((IComputerItem) stack.getItem()).withFamily( stack, family );
return item.withFamily( stack, family );
}
public static class Factory implements IRecipeFactory

View File

@ -1,3 +1,9 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.media.common;
import dan200.computercraft.api.media.IMedia;

View File

@ -15,10 +15,6 @@
public class ItemDiskExpanded extends ItemDiskLegacy
{
public ItemDiskExpanded()
{
}
@Nonnull
public static ItemStack createFromIDAndColour( int id, String label, int colour )
{

View File

@ -40,7 +40,7 @@ public ItemDiskLegacy()
public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
{
if( !isInCreativeTab( tabs ) ) return;
for( int colour = 0; colour < 16; ++colour )
for( int colour = 0; colour < 16; colour++ )
{
ItemStack stack = createFromIDAndColour( -1, null, Colour.values()[colour].getHex() );
if( stack.getItem() == this )
@ -142,7 +142,7 @@ public boolean doesSneakBypassUse( @Nonnull ItemStack stack, IBlockAccess world,
}
@Override
public ItemStack setColour( ItemStack stack, int colour )
public ItemStack withColour( ItemStack stack, int colour )
{
return ItemDiskExpanded.createFromIDAndColour( getDiskID( stack ), getLabel( stack ), colour );
}

View File

@ -113,7 +113,7 @@ else if( leather.apply( stack ) && !leatherFound )
String[] colours = new String[numPages * ItemPrintout.LINES_PER_PAGE];
int line = 0;
for( int printout = 0; printout < numPrintouts; ++printout )
for( int printout = 0; printout < numPrintouts; printout++ )
{
ItemStack stack = printouts[printout];
if( stack.getItem() instanceof ItemPrintout )
@ -121,7 +121,7 @@ else if( leather.apply( stack ) && !leatherFound )
// Add a printout
String[] pageText = ItemPrintout.getText( printouts[printout] );
String[] pageColours = ItemPrintout.getColours( printouts[printout] );
for( int pageLine = 0; pageLine < pageText.length; ++pageLine )
for( int pageLine = 0; pageLine < pageText.length; pageLine++ )
{
text[line] = pageText[pageLine];
colours[line] = pageColours[pageLine];
@ -131,7 +131,7 @@ else if( leather.apply( stack ) && !leatherFound )
else
{
// Add a blank page
for( int pageLine = 0; pageLine < ItemPrintout.LINES_PER_PAGE; ++pageLine )
for( int pageLine = 0; pageLine < ItemPrintout.LINES_PER_PAGE; pageLine++ )
{
text[line] = "";
colours[line] = "";

View File

@ -9,12 +9,11 @@
import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.network.NetworkMessage;
import dan200.computercraft.shared.network.NetworkMessages;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.UncheckedIOException;
public class ChatTableClientMessage implements NetworkMessage
{
@ -62,34 +61,27 @@ public void toBytes( @Nonnull PacketBuffer buf )
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
try
int id = buf.readVarInt();
int columns = buf.readVarInt();
TableBuilder table;
if( buf.readBoolean() )
{
int id = buf.readVarInt();
int columns = buf.readVarInt();
TableBuilder table;
if( buf.readBoolean() )
{
ITextComponent[] headers = new ITextComponent[columns];
for( int i = 0; i < columns; i++ ) headers[i] = buf.readTextComponent();
table = new TableBuilder( id, headers );
}
else
{
table = new TableBuilder( id );
}
ITextComponent[] headers = new ITextComponent[columns];
for( int i = 0; i < columns; i++ ) headers[i] = NBTUtil.readTextComponent( buf );
table = new TableBuilder( id, headers );
}
else
{
table = new TableBuilder( id );
}
int rows = buf.readVarInt();
for( int i = 0; i < rows; i++ )
{
ITextComponent[] row = new ITextComponent[columns];
for( int j = 0; j < columns; j++ ) row[j] = buf.readTextComponent();
table.row( row );
}
this.table = table;
}
catch( IOException e )
int rows = buf.readVarInt();
for( int i = 0; i < rows; i++ )
{
throw new UncheckedIOException( e );
ITextComponent[] row = new ITextComponent[columns];
for( int j = 0; j < columns; j++ ) row[j] = NBTUtil.readTextComponent( buf );
table.row( row );
}
this.table = table;
}
}

View File

@ -9,12 +9,11 @@
import dan200.computercraft.shared.computer.blocks.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.network.NetworkMessages;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.UncheckedIOException;
/**
* Provides additional data about a client computer, such as its ID and current state.
@ -64,13 +63,6 @@ public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
state = buf.readEnumValue( ComputerState.class );
try
{
userData = buf.readCompoundTag();
}
catch( IOException e )
{
throw new UncheckedIOException( e );
}
userData = NBTUtil.readCompoundTag( buf );
}
}

View File

@ -7,12 +7,11 @@
package dan200.computercraft.shared.network.client;
import dan200.computercraft.shared.network.NetworkMessages;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.UncheckedIOException;
public class ComputerTerminalClientMessage extends ComputerClientMessage
{
@ -50,13 +49,6 @@ public void toBytes( @Nonnull PacketBuffer buf )
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
try
{
tag = buf.readCompoundTag();
}
catch( IOException e )
{
throw new UncheckedIOException( e );
}
tag = NBTUtil.readCompoundTag( buf );
}
}

View File

@ -13,8 +13,6 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.UncheckedIOException;
/**
* Queue an event on a {@link dan200.computercraft.shared.computer.core.ServerComputer}.
@ -70,14 +68,7 @@ public void fromBytes( @Nonnull PacketBuffer buf )
super.fromBytes( buf );
event = buf.readString( Short.MAX_VALUE );
try
{
NBTTagCompound args = buf.readCompoundTag();
this.args = args == null ? null : NBTUtil.decodeObjects( args );
}
catch( IOException e )
{
throw new UncheckedIOException( e );
}
NBTTagCompound args = NBTUtil.readCompoundTag( buf );
this.args = args == null ? null : NBTUtil.decodeObjects( args );
}
}

View File

@ -20,10 +20,6 @@
public class DefaultPeripheralProvider implements IPeripheralProvider
{
public DefaultPeripheralProvider()
{
}
@Override
public IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
{

View File

@ -23,17 +23,17 @@ public ContainerDiskDrive( IInventory playerInventory, TileDiskDrive diskDrive )
m_diskDrive = diskDrive;
addSlotToContainer( new Slot( m_diskDrive, 0, 8 + 4 * 18, 35 ) );
for( int j = 0; j < 3; j++ )
for( int y = 0; y < 3; y++ )
{
for( int i1 = 0; i1 < 9; i1++ )
for( int x = 0; x < 9; x++ )
{
addSlotToContainer( new Slot( playerInventory, i1 + j * 9 + 9, 8 + i1 * 18, 84 + j * 18 ) );
addSlotToContainer( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18 ) );
}
}
for( int k = 0; k < 9; k++ )
for( int x = 0; x < 9; x++ )
{
addSlotToContainer( new Slot( playerInventory, k, 8 + k * 18, 142 ) );
addSlotToContainer( new Slot( playerInventory, x, 8 + x * 18, 142 ) );
}
}
@ -50,44 +50,38 @@ public boolean canInteractWith( @Nonnull EntityPlayer player )
@Nonnull
@Override
public ItemStack transferStackInSlot( EntityPlayer player, int i )
public ItemStack transferStackInSlot( EntityPlayer player, int slotIndex )
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = inventorySlots.get( i );
if( slot != null && slot.getHasStack() )
ItemStack extract = ItemStack.EMPTY;
Slot slot = inventorySlots.get( slotIndex );
if( slot == null || !slot.getHasStack() ) return extract;
ItemStack existing = slot.getStack().copy();
extract = existing.copy();
if( slotIndex == 0 )
{
ItemStack itemstack1 = slot.getStack().copy();
itemstack = itemstack1.copy();
if( i == 0 )
{
if( !mergeItemStack( itemstack1, 1, 37, true ) )
{
return ItemStack.EMPTY;
}
}
else if( !mergeItemStack( itemstack1, 0, 1, false ) )
{
return ItemStack.EMPTY;
}
if( itemstack1.isEmpty() )
{
slot.putStack( ItemStack.EMPTY );
}
else
{
slot.onSlotChanged();
}
if( itemstack1.getCount() != itemstack.getCount() )
{
slot.onTake( player, itemstack1 );
}
else
if( !mergeItemStack( existing, 1, 37, true ) )
{
return ItemStack.EMPTY;
}
}
return itemstack;
else if( !mergeItemStack( existing, 0, 1, false ) )
{
return ItemStack.EMPTY;
}
if( existing.isEmpty() )
{
slot.putStack( ItemStack.EMPTY );
}
else
{
slot.onSlotChanged();
}
if( existing.getCount() == extract.getCount() ) return ItemStack.EMPTY;
slot.onTake( player, existing );
return extract;
}
}

View File

@ -61,21 +61,13 @@ public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaCont
switch( method )
{
case 0:
{
// isDiskPresent
return new Object[] {
!m_diskDrive.getDiskStack().isEmpty()
};
}
return new Object[] { !m_diskDrive.getDiskStack().isEmpty() };
case 1:
{
// getDiskLabel
IMedia media = m_diskDrive.getDiskMedia();
if( media != null )
{
return new Object[] { media.getLabel( m_diskDrive.getDiskStack() ) };
}
return null;
return media == null ? null : new Object[] { media.getLabel( m_diskDrive.getDiskStack() ) };
}
case 2:
{
@ -83,91 +75,55 @@ public Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaCont
String label = optString( arguments, 0, null );
IMedia media = m_diskDrive.getDiskMedia();
if( media != null )
{
ItemStack disk = m_diskDrive.getDiskStack();
label = StringUtil.normaliseLabel( label );
if( media.setLabel( disk, label ) )
{
m_diskDrive.setDiskStack( disk );
}
else
{
throw new LuaException( "Disk label cannot be changed" );
}
}
if( media == null ) return null;
ItemStack disk = m_diskDrive.getDiskStack();
label = StringUtil.normaliseLabel( label );
if( !media.setLabel( disk, label ) ) throw new LuaException( "Disk label cannot be changed" );
m_diskDrive.setDiskStack( disk );
return null;
}
case 3:
{
// hasData
return new Object[] {
m_diskDrive.getDiskMountPath( computer ) != null
};
}
return new Object[] { m_diskDrive.getDiskMountPath( computer ) != null };
case 4:
{
// getMountPath
return new Object[] {
m_diskDrive.getDiskMountPath( computer )
};
return new Object[] { m_diskDrive.getDiskMountPath( computer ) };
}
case 5:
{
// hasAudio
IMedia media = m_diskDrive.getDiskMedia();
if( media != null )
{
return new Object[] { media.getAudio( m_diskDrive.getDiskStack() ) != null };
}
return new Object[] { false };
return new Object[] { media != null && media.getAudio( m_diskDrive.getDiskStack() ) != null };
}
case 6:
{
// getAudioTitle
IMedia media = m_diskDrive.getDiskMedia();
if( media != null )
{
return new Object[] { media.getAudioTitle( m_diskDrive.getDiskStack() ) };
}
return new Object[] { false };
return new Object[] { media != null ? media.getAudioTitle( m_diskDrive.getDiskStack() ) : false };
}
case 7:
{
// playAudio
m_diskDrive.playDiskAudio();
return null;
}
case 8:
{
// stopAudio
m_diskDrive.stopDiskAudio();
return null;
}
case 9:
{
// eject
m_diskDrive.ejectDisk();
return null;
}
case 10:
{
// getDiskID
ItemStack disk = m_diskDrive.getDiskStack();
if( disk != null )
{
Item item = disk.getItem();
if( item instanceof ItemDiskLegacy )
{
return new Object[] { ((ItemDiskLegacy) item).getDiskID( disk ) };
}
}
return null;
Item item = disk.getItem();
return item instanceof ItemDiskLegacy ? new Object[] { ((ItemDiskLegacy) item).getDiskID( disk ) } : null;
}
default:
{
return null;
}
}
}
@ -186,15 +142,9 @@ public void detach( @Nonnull IComputerAccess computer )
@Override
public boolean equals( IPeripheral other )
{
if( other instanceof DiskDrivePeripheral )
{
DiskDrivePeripheral otherDiskDrive = (DiskDrivePeripheral) other;
if( otherDiskDrive.m_diskDrive == this.m_diskDrive )
{
return true;
}
}
return false;
if( this == other ) return true;
if( !(other instanceof DiskDrivePeripheral) ) return false;
return ((DiskDrivePeripheral) other).m_diskDrive == this.m_diskDrive;
}
@Nonnull

View File

@ -129,10 +129,7 @@ public EnumFacing getDirection()
@Override
public void setDirection( EnumFacing dir )
{
if( dir.getAxis() == EnumFacing.Axis.Y )
{
dir = EnumFacing.NORTH;
}
if( dir.getAxis() == EnumFacing.Axis.Y ) dir = EnumFacing.NORTH;
setBlockState( getBlockState().withProperty( BlockPeripheral.Properties.FACING, dir ) );
}
@ -239,10 +236,7 @@ public ItemStack removeStackFromSlot( int i )
@Override
public ItemStack decrStackSize( int i, int j )
{
if( m_diskStack.isEmpty() )
{
return ItemStack.EMPTY;
}
if( m_diskStack.isEmpty() ) return ItemStack.EMPTY;
if( m_diskStack.getCount() <= j )
{
@ -252,14 +246,7 @@ public ItemStack decrStackSize( int i, int j )
}
ItemStack part = m_diskStack.splitStack( j );
if( m_diskStack.isEmpty() )
{
setInventorySlotContents( 0, ItemStack.EMPTY );
}
else
{
setInventorySlotContents( 0, m_diskStack );
}
setInventorySlotContents( 0, m_diskStack.isEmpty() ? ItemStack.EMPTY : m_diskStack );
return part;
}
@ -331,28 +318,14 @@ public boolean hasCustomName()
public String getName()
{
String label = getLabel();
if( label != null )
{
return label;
}
else
{
return "tile.computercraft:drive.name";
}
return label != null ? label : "tile.computercraft:drive.name";
}
@Nonnull
@Override
public ITextComponent getDisplayName()
{
if( hasCustomName() )
{
return new TextComponentString( getName() );
}
else
{
return new TextComponentTranslation( getName() );
}
return hasCustomName() ? new TextComponentString( getName() ) : new TextComponentTranslation( getName() );
}
@Override
@ -448,10 +421,7 @@ public void ejectDisk()
{
synchronized( this )
{
if( !m_ejectQueued )
{
m_ejectQueued = true;
}
m_ejectQueued = true;
}
}
@ -521,14 +491,7 @@ private void updateAnim()
if( !m_diskStack.isEmpty() )
{
IMedia contents = getDiskMedia();
if( contents != null )
{
setAnim( 2 );
}
else
{
setAnim( 1 );
}
setAnim( contents != null ? 2 : 1 );
}
else
{

View File

@ -424,20 +424,14 @@ private TileMonitor getSimilarMonitorAt( BlockPos pos )
if( pos.equals( getPos() ) ) return this;
World world = getWorld();
if( world != null && world.isBlockLoaded( pos ) )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileMonitor )
{
TileMonitor monitor = (TileMonitor) tile;
if( monitor.getDir() == getDir() && monitor.m_advanced == m_advanced &&
!monitor.m_destroyed && !monitor.m_ignoreMe )
{
return monitor;
}
}
}
return null;
if( world == null || !world.isBlockLoaded( pos ) ) return null;
TileEntity tile = world.getTileEntity( pos );
if( !(tile instanceof TileMonitor) ) return null;
TileMonitor monitor = (TileMonitor) tile;
return monitor.getDir() == getDir() && monitor.m_advanced == m_advanced &&
!monitor.m_destroyed && !monitor.m_ignoreMe ? monitor : null;
}
private TileMonitor getNeighbour( int x, int y )
@ -447,9 +441,7 @@ private TileMonitor getNeighbour( int x, int y )
EnumFacing down = getDown();
int xOffset = -m_xIndex + x;
int yOffset = -m_yIndex + y;
return getSimilarMonitorAt(
pos.offset( right, xOffset ).offset( down, yOffset )
);
return getSimilarMonitorAt( pos.offset( right, xOffset ).offset( down, yOffset ) );
}
public TileMonitor getOrigin()
@ -520,88 +512,62 @@ private void resize( int width, int height )
private boolean mergeLeft()
{
TileMonitor left = getNeighbour( -1, 0 );
if( left != null && left.m_yIndex == 0 && left.m_height == m_height )
{
int width = left.m_width + m_width;
if( width <= MAX_WIDTH )
{
TileMonitor origin = left.getOrigin();
if( origin != null )
{
origin.resize( width, m_height );
}
left.expand();
return true;
}
}
return false;
if( left == null || left.m_yIndex != 0 || left.m_height != m_height ) return false;
int width = left.m_width + m_width;
if( width > MAX_WIDTH ) return false;
TileMonitor origin = left.getOrigin();
if( origin != null ) origin.resize( width, m_height );
left.expand();
return true;
}
private boolean mergeRight()
{
TileMonitor right = getNeighbour( m_width, 0 );
if( right != null && right.m_yIndex == 0 && right.m_height == m_height )
{
int width = m_width + right.m_width;
if( width <= MAX_WIDTH )
{
TileMonitor origin = getOrigin();
if( origin != null )
{
origin.resize( width, m_height );
}
expand();
return true;
}
}
return false;
if( right == null || right.m_yIndex != 0 || right.m_height != m_height ) return false;
int width = m_width + right.m_width;
if( width > MAX_WIDTH ) return false;
TileMonitor origin = getOrigin();
if( origin != null ) origin.resize( width, m_height );
expand();
return true;
}
private boolean mergeUp()
{
TileMonitor above = getNeighbour( 0, m_height );
if( above != null && above.m_xIndex == 0 && above.m_width == m_width )
{
int height = above.m_height + m_height;
if( height <= MAX_HEIGHT )
{
TileMonitor origin = getOrigin();
if( origin != null )
{
origin.resize( m_width, height );
}
expand();
return true;
}
}
return false;
if( above == null || above.m_xIndex != 0 || above.m_width != m_width ) return false;
int height = above.m_height + m_height;
if( height > MAX_HEIGHT ) return false;
TileMonitor origin = getOrigin();
if( origin != null ) origin.resize( m_width, height );
expand();
return true;
}
private boolean mergeDown()
{
TileMonitor below = getNeighbour( 0, -1 );
if( below != null && below.m_xIndex == 0 && below.m_width == m_width )
{
int height = m_height + below.m_height;
if( height <= MAX_HEIGHT )
{
TileMonitor origin = below.getOrigin();
if( origin != null )
{
origin.resize( m_width, height );
}
below.expand();
return true;
}
}
return false;
if( below == null || below.m_xIndex != 0 || below.m_width != m_width ) return false;
int height = m_height + below.m_height;
if( height > MAX_HEIGHT ) return false;
TileMonitor origin = below.getOrigin();
if( origin != null ) origin.resize( m_width, height );
below.expand();
return true;
}
public void expand()
{
while( mergeLeft() || mergeRight() || mergeUp() || mergeDown() )
{
}
while( mergeLeft() || mergeRight() || mergeUp() || mergeDown() ) ;
}
public void contractNeighbours()
@ -610,34 +576,22 @@ public void contractNeighbours()
if( m_xIndex > 0 )
{
TileMonitor left = getNeighbour( m_xIndex - 1, m_yIndex );
if( left != null )
{
left.contract();
}
if( left != null ) left.contract();
}
if( m_xIndex + 1 < m_width )
{
TileMonitor right = getNeighbour( m_xIndex + 1, m_yIndex );
if( right != null )
{
right.contract();
}
if( right != null ) right.contract();
}
if( m_yIndex > 0 )
{
TileMonitor below = getNeighbour( m_xIndex, m_yIndex - 1 );
if( below != null )
{
below.contract();
}
if( below != null ) below.contract();
}
if( m_yIndex + 1 < m_height )
{
TileMonitor above = getNeighbour( m_xIndex, m_yIndex + 1 );
if( above != null )
{
above.contract();
}
if( above != null ) above.contract();
}
m_ignoreMe = false;
}
@ -650,32 +604,13 @@ public void contract()
TileMonitor origin = getOrigin();
if( origin == null )
{
TileMonitor right = null;
TileMonitor below = null;
if( width > 1 )
{
right = getNeighbour( 1, 0 );
}
if( height > 1 )
{
below = getNeighbour( 0, 1 );
}
if( right != null )
{
right.resize( width - 1, 1 );
}
if( below != null )
{
below.resize( width, height - 1 );
}
if( right != null )
{
right.expand();
}
if( below != null )
{
below.expand();
}
TileMonitor right = width > 1 ? getNeighbour( 1, 0 ) : null;
TileMonitor below = height > 1 ? getNeighbour( 0, 1 ) : null;
if( right != null ) right.resize( width - 1, 1 );
if( below != null ) below.resize( width, height - 1 );
if( right != null ) right.expand();
if( below != null ) below.expand();
return;
}
@ -684,54 +619,41 @@ public void contract()
for( int x = 0; x < width; x++ )
{
TileMonitor monitor = origin.getNeighbour( x, y );
if( monitor == null )
if( monitor != null ) continue;
// Decompose
TileMonitor above = null;
TileMonitor left = null;
TileMonitor right = null;
TileMonitor below = null;
if( y > 0 )
{
// Decompose
TileMonitor above = null;
TileMonitor left = null;
TileMonitor right = null;
TileMonitor below = null;
if( y > 0 )
{
above = origin;
above.resize( width, y );
}
if( x > 0 )
{
left = origin.getNeighbour( 0, y );
left.resize( x, 1 );
}
if( x + 1 < width )
{
right = origin.getNeighbour( x + 1, y );
right.resize( width - (x + 1), 1 );
}
if( y + 1 < height )
{
below = origin.getNeighbour( 0, y + 1 );
below.resize( width, height - (y + 1) );
}
// Re-expand
if( above != null )
{
above.expand();
}
if( left != null )
{
left.expand();
}
if( right != null )
{
right.expand();
}
if( below != null )
{
below.expand();
}
return;
above = origin;
above.resize( width, y );
}
if( x > 0 )
{
left = origin.getNeighbour( 0, y );
left.resize( x, 1 );
}
if( x + 1 < width )
{
right = origin.getNeighbour( x + 1, y );
right.resize( width - (x + 1), 1 );
}
if( y + 1 < height )
{
below = origin.getNeighbour( 0, y + 1 );
below.resize( width, height - (y + 1) );
}
// Re-expand
if( above != null ) above.expand();
if( left != null ) left.expand();
if( right != null ) right.expand();
if( below != null ) below.expand();
return;
}
}
}
@ -739,7 +661,7 @@ public void contract()
public void monitorTouched( float xPos, float yPos, float zPos )
{
int side = getDir();
XYPair pair = convertToXY( xPos, yPos, zPos, side );
XYPair pair = XYPair.of( xPos, yPos, zPos, side );
pair = new XYPair( pair.x + m_xIndex, pair.y + m_height - m_yIndex - 1 );
if( pair.x > (m_width - RENDER_BORDER) || pair.y > (m_height - RENDER_BORDER) || pair.x < (RENDER_BORDER) || pair.y < (RENDER_BORDER) )
@ -776,39 +698,6 @@ public void monitorTouched( float xPos, float yPos, float zPos )
}
}
private XYPair convertToXY( float xPos, float yPos, float zPos, int side )
{
switch( side )
{
case 2:
return new XYPair( 1 - xPos, 1 - yPos );
case 3:
return new XYPair( xPos, 1 - yPos );
case 4:
return new XYPair( zPos, 1 - yPos );
case 5:
return new XYPair( 1 - zPos, 1 - yPos );
case 8:
return new XYPair( 1 - xPos, zPos );
case 9:
return new XYPair( xPos, 1 - zPos );
case 10:
return new XYPair( zPos, xPos );
case 11:
return new XYPair( 1 - zPos, 1 - xPos );
case 14:
return new XYPair( 1 - xPos, 1 - zPos );
case 15:
return new XYPair( xPos, zPos );
case 16:
return new XYPair( zPos, 1 - xPos );
case 17:
return new XYPair( 1 - zPos, xPos );
default:
return new XYPair( xPos, zPos );
}
}
public void addComputer( IComputerAccess computer )
{
synchronized( this )
@ -825,18 +714,6 @@ public void removeComputer( IComputerAccess computer )
}
}
public static class XYPair
{
public final float x;
public final float y;
private XYPair( float x, float y )
{
this.x = x;
this.y = y;
}
}
@Nonnull
@Override
public AxisAlignedBB getRenderBoundingBox()

View File

@ -0,0 +1,57 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.peripheral.monitor;
public class XYPair
{
public final float x;
public final float y;
public XYPair( float x, float y )
{
this.x = x;
this.y = y;
}
public XYPair add( float x, float y )
{
return new XYPair( this.x + x, this.y + y );
}
public static XYPair of( float xPos, float yPos, float zPos, int side )
{
switch( side )
{
case 2:
return new XYPair( 1 - xPos, 1 - yPos );
case 3:
return new XYPair( xPos, 1 - yPos );
case 4:
return new XYPair( zPos, 1 - yPos );
case 5:
return new XYPair( 1 - zPos, 1 - yPos );
case 8:
return new XYPair( 1 - xPos, zPos );
case 9:
return new XYPair( xPos, 1 - zPos );
case 10:
return new XYPair( zPos, xPos );
case 11:
return new XYPair( 1 - zPos, 1 - xPos );
case 14:
return new XYPair( 1 - xPos, 1 - zPos );
case 15:
return new XYPair( xPos, zPos );
case 16:
return new XYPair( zPos, 1 - xPos );
case 17:
return new XYPair( 1 - zPos, xPos );
default:
return new XYPair( xPos, zPos );
}
}
}

View File

@ -341,18 +341,9 @@ public boolean startNewPage()
{
synchronized( m_inventory )
{
if( canInputPage() )
{
if( m_printing && !outputPage() )
{
return false;
}
if( inputPage() )
{
return true;
}
}
return false;
if( !canInputPage() ) return false;
if( m_printing && !outputPage() ) return false;
return inputPage();
}
}
@ -373,12 +364,8 @@ public int getInkLevel()
synchronized( m_inventory )
{
ItemStack inkStack = m_inventory.get( 0 );
if( !inkStack.isEmpty() && isInk( inkStack ) )
{
return inkStack.getCount();
}
return isInk( inkStack ) ? inkStack.getCount() : 0;
}
return 0;
}
public int getPaperLevel()
@ -431,10 +418,7 @@ private boolean inputPage()
synchronized( m_inventory )
{
ItemStack inkStack = m_inventory.get( 0 );
if( inkStack.isEmpty() || !isInk( inkStack ) )
{
return false;
}
if( !isInk( inkStack ) ) return false;
for( int i = 1; i < 7; i++ )
{

View File

@ -538,7 +538,7 @@ public int getColour( ItemStack stack )
}
@Override
public ItemStack setColour( ItemStack stack, int colour )
public ItemStack withColour( ItemStack stack, int colour )
{
ItemStack copy = stack.copy();
setColourDirect( copy, colour );

View File

@ -24,10 +24,6 @@
public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
public PocketComputerUpgradeRecipe()
{
}
@Override
public boolean canFit( int x, int y )
{

View File

@ -212,14 +212,14 @@ public void registerRecipes( RegistryEvent.Register<IRecipe> event )
// Impostor Disk recipes (to fool NEI)
ItemStack paper = new ItemStack( Items.PAPER, 1 );
ItemStack redstone = new ItemStack( Items.REDSTONE, 1 );
for( int colour = 0; colour < 16; ++colour )
for( int colour = 0; colour < 16; colour++ )
{
ItemStack disk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[colour].getHex() );
ItemStack dye = new ItemStack( Items.DYE, 1, colour );
int diskIdx = 0;
ItemStack[] disks = new ItemStack[15];
for( int otherColour = 0; otherColour < 16; ++otherColour )
for( int otherColour = 0; otherColour < 16; otherColour++ )
{
if( colour != otherColour )
{

View File

@ -182,7 +182,7 @@ public ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily f
}
@Override
public ItemStack setColour( ItemStack stack, int colour )
public ItemStack withColour( ItemStack stack, int colour )
{
return TurtleItemFactory.create(
getComputerID( stack ), getLabel( stack ), colour, getFamily( stack ),

View File

@ -33,9 +33,8 @@ public TurtleRecipe( String group, @Nonnull CraftingHelper.ShapedPrimer primer,
@Nonnull
@Override
protected ItemStack convert( @Nonnull ItemStack stack )
protected ItemStack convert( IComputerItem item, @Nonnull ItemStack stack )
{
IComputerItem item = (IComputerItem) stack.getItem();
int computerID = item.getComputerID( stack );
String label = item.getLabel( stack );

View File

@ -40,12 +40,6 @@ private static class Peripheral extends SpeakerPeripheral
this.turtle = turtle;
}
@Override
public void update()
{
super.update();
}
@Override
public World getWorld()
{

View File

@ -7,8 +7,12 @@
package dan200.computercraft.shared.util;
import net.minecraft.nbt.*;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.util.Constants;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.Map;
@ -135,4 +139,28 @@ public static Object[] decodeObjects( NBTTagCompound tagCompound )
}
return null;
}
public static NBTTagCompound readCompoundTag( PacketBuffer buf )
{
try
{
return buf.readCompoundTag();
}
catch( IOException e )
{
throw new UncheckedIOException( e );
}
}
public static ITextComponent readTextComponent( PacketBuffer buf )
{
try
{
return buf.readTextComponent();
}
catch( IOException e )
{
throw new UncheckedIOException( e );
}
}
}