1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Sync computer state through TE data

Previously we would send computer state (labels, id, on/off) through the
ClientComputer rather than as part of the TE description. While this
mostly worked fine, it did end up making things more complex than they
needed to be.

We sync most data to the tile each tick, so there's little risk of
things getting out of date.
This commit is contained in:
SquidDev 2018-12-29 12:38:19 +00:00
parent 42d3901ee3
commit 54acf1d087
26 changed files with 145 additions and 294 deletions

View File

@ -9,8 +9,8 @@ package dan200.computercraft.client.gui;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
@ -28,12 +28,12 @@ public class GuiComputer extends GuiContainer
private static final ResourceLocation backgroundCommand = new ResourceLocation( "computercraft", "textures/gui/corners_command.png" );
private final ComputerFamily m_family;
private final IComputer m_computer;
private final ClientComputer m_computer;
private final int m_termWidth;
private final int m_termHeight;
private WidgetTerminal m_terminal;
public GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
{
super( container );
m_family = family;
@ -48,7 +48,7 @@ public class GuiComputer extends GuiContainer
this(
new ContainerComputer( computer ),
computer.getFamily(),
computer.createComputer(),
computer.createClientComputer(),
ComputerCraft.terminalWidth_computer,
ComputerCraft.terminalHeight_computer
);

View File

@ -9,8 +9,8 @@ package dan200.computercraft.client.gui;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import net.minecraft.client.Minecraft;
@ -34,7 +34,7 @@ public class GuiTurtle extends GuiContainer
protected final ComputerFamily m_family;
protected final ITurtleAccess m_turtle;
protected final IComputer m_computer;
protected final ClientComputer m_computer;
protected WidgetTerminal m_terminalGui;
public GuiTurtle( World world, InventoryPlayer inventoryplayer, TileTurtle turtle )
@ -50,7 +50,7 @@ public class GuiTurtle extends GuiContainer
m_container = container;
m_family = turtle.getFamily();
m_turtle = turtle.getAccess();
m_computer = turtle.createComputer();
m_computer = turtle.getClientComputer();
xSize = 254;
ySize = 217;

View File

@ -15,8 +15,8 @@ import dan200.computercraft.shared.command.CommandCopy;
import dan200.computercraft.shared.command.ContainerViewComputer;
import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
import dan200.computercraft.shared.media.items.ItemPrintout;
@ -216,7 +216,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
}
@Override
public Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family )
public Object getComputerGUI( ClientComputer computer, int width, int height, ComputerFamily family )
{
ContainerViewComputer container = new ContainerViewComputer( computer );
return new GuiComputer( container, family, computer, width, height );

View File

@ -8,8 +8,8 @@ package dan200.computercraft.server.proxy;
import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
@ -63,7 +63,7 @@ public class ComputerCraftProxyServer extends ComputerCraftProxyCommon
}
@Override
public Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family )
public Object getComputerGUI( ClientComputer computer, int width, int height, ComputerFamily family )
{
return null;
}

View File

@ -1,12 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.common;
public interface ITerminalTile
{
ITerminal getTerminal();
}

View File

@ -9,7 +9,6 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
@ -83,12 +82,7 @@ public class BlockCommandComputer extends BlockComputerBase
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof IComputerTile )
{
IComputer computer = ((IComputerTile) tile).getComputer();
if( computer != null ) return state.withProperty( Properties.STATE, computer.getState() );
}
return state.withProperty( Properties.STATE, ComputerState.OFF );
return state.withProperty( Properties.STATE, tile instanceof TileComputer ? ((TileComputer) tile).getState() : ComputerState.OFF );
}
@Override

View File

@ -9,7 +9,6 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import dan200.computercraft.shared.computer.items.ItemComputer;
import dan200.computercraft.shared.util.DirectionUtil;
@ -127,12 +126,7 @@ public class BlockComputer extends BlockComputerBase
public IBlockState getActualState( @Nonnull IBlockState state, IBlockAccess world, BlockPos pos )
{
TileEntity tile = world.getTileEntity( pos );
if( tile instanceof IComputerTile )
{
IComputer computer = ((IComputerTile) tile).getComputer();
if( computer != null ) return state.withProperty( Properties.STATE, computer.getState() );
}
return state.withProperty( Properties.STATE, ComputerState.OFF );
return state.withProperty( Properties.STATE, tile instanceof TileComputer ? ((TileComputer) tile).getState() : ComputerState.OFF );
}
@Override

View File

@ -1,6 +1,7 @@
package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
/**
* A proxy object for computer objects, delegating to {@link IComputer} or {@link TileComputer} where appropriate.
@ -12,7 +13,7 @@ public abstract class ComputerProxy
public void turnOn()
{
TileComputerBase tile = getTile();
IComputer computer = tile.getComputer();
ServerComputer computer = tile.getServerComputer();
if( computer == null )
{
tile.m_startOn = true;
@ -26,7 +27,7 @@ public abstract class ComputerProxy
public void shutdown()
{
TileComputerBase tile = getTile();
IComputer computer = tile.getComputer();
ServerComputer computer = tile.getServerComputer();
if( computer == null )
{
tile.m_startOn = false;
@ -40,7 +41,7 @@ public abstract class ComputerProxy
public void reboot()
{
TileComputerBase tile = getTile();
IComputer computer = tile.getComputer();
ServerComputer computer = tile.getServerComputer();
if( computer == null )
{
tile.m_startOn = true;
@ -54,7 +55,7 @@ public abstract class ComputerProxy
public int assignID()
{
TileComputerBase tile = getTile();
IComputer computer = tile.getComputer();
ServerComputer computer = tile.getServerComputer();
if( computer == null )
{
return tile.m_computerID;
@ -67,21 +68,14 @@ public abstract class ComputerProxy
public boolean isOn()
{
IComputer computer = getTile().getComputer();
ServerComputer computer = getTile().getServerComputer();
return computer != null && computer.isOn();
}
public String getLabel()
{
TileComputerBase tile = getTile();
IComputer computer = tile.getComputer();
if( computer == null )
{
return tile.m_label;
}
else
{
return computer.getLabel();
}
ServerComputer computer = tile.getServerComputer();
return computer == null ? tile.m_label : computer.getLabel();
}
}

View File

@ -6,19 +6,17 @@
package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.shared.common.ITerminalTile;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
public interface IComputerTile extends ITerminalTile
public interface IComputerTile
{
int getComputerID();
void setComputerID( int id );
String getLabel();
void setLabel( String label );
IComputer getComputer();
IComputer createComputer();
ComputerFamily getFamily();
}

View File

@ -8,7 +8,6 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.apis.CommandAPI;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.state.IBlockState;
@ -60,16 +59,8 @@ public class TileCommandComputer extends TileComputer
@Override
public ITextComponent getDisplayName()
{
IComputer computer = TileCommandComputer.this.getComputer();
if( computer != null )
{
String label = computer.getLabel();
if( label != null )
{
return new TextComponentString( computer.getLabel() );
}
}
return new TextComponentString( "@" );
String label = getLabel();
return new TextComponentString( label != null ? label : "@" );
}
@Override

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import net.minecraft.block.state.IBlockState;
@ -22,14 +22,10 @@ import javax.annotation.Nonnull;
public class TileComputer extends TileComputerBase
{
// Statics
private static final String TAG_STATE = "state";
// Members
private ComputerProxy m_proxy;
public TileComputer()
{
}
private ComputerState state = ComputerState.OFF;
@Override
protected ServerComputer createComputer( int instanceID, int id )
@ -68,11 +64,7 @@ public class TileComputer extends TileComputerBase
@Override
public void getDroppedItems( @Nonnull NonNullList<ItemStack> drops, boolean creative )
{
IComputer computer = getComputer();
if( !creative || (computer != null && computer.getLabel() != null) )
{
drops.add( ComputerItemFactory.create( this ) );
}
if( !creative || getLabel() != null ) drops.add( ComputerItemFactory.create( this ) );
}
@Override
@ -82,9 +74,17 @@ public class TileComputer extends TileComputerBase
}
@Override
public final void readDescription( @Nonnull NBTTagCompound nbttagcompound )
public void writeDescription( @Nonnull NBTTagCompound tag )
{
super.readDescription( nbttagcompound );
super.writeDescription( tag );
tag.setInteger( TAG_STATE, state.ordinal() );
}
@Override
public final void readDescription( @Nonnull NBTTagCompound tag )
{
super.readDescription( tag );
state = ComputerState.valueOf( tag.getInteger( TAG_STATE ) );
updateBlock();
}
@ -93,6 +93,17 @@ public class TileComputer extends TileComputerBase
return isUsable( player, false );
}
@Override
public void update()
{
super.update();
if( !world.isRemote )
{
ServerComputer computer = getServerComputer();
state = computer == null ? ComputerState.OFF : computer.getState();
}
}
// IDirectionalTile
@Override
@ -105,10 +116,7 @@ public class TileComputer extends TileComputerBase
@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( BlockComputer.Properties.FACING, dir ) );
updateInput();
}
@ -121,4 +129,9 @@ public class TileComputer extends TileComputerBase
{
return s_remapSide[localSide];
}
public ComputerState getState()
{
return state;
}
}

View File

@ -10,11 +10,9 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.BundledRedstone;
import dan200.computercraft.shared.Peripherals;
import dan200.computercraft.shared.common.IDirectionalTile;
import dan200.computercraft.shared.common.ITerminal;
import dan200.computercraft.shared.common.TileGeneric;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.RedstoneUtil;
@ -29,26 +27,16 @@ import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nonnull;
import java.util.Objects;
public abstract class TileComputerBase extends TileGeneric
implements IComputerTile, IDirectionalTile, ITickable
public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IDirectionalTile, ITickable
{
protected int m_instanceID;
protected int m_computerID;
protected String m_label;
protected boolean m_on;
protected boolean m_startOn;
protected boolean m_fresh;
protected TileComputerBase()
{
m_instanceID = -1;
m_computerID = -1;
m_label = null;
m_on = false;
m_startOn = false;
m_fresh = false;
}
private int m_instanceID = -1;
protected int m_computerID = -1;
protected String m_label = null;
private boolean m_on = false;
protected boolean m_startOn = false;
private boolean m_fresh = false;
@Override
public BlockComputerBase getBlock()
@ -385,15 +373,19 @@ public abstract class TileComputerBase extends TileGeneric
public abstract ComputerProxy createProxy();
// ITerminalTile
// IComputerTile
@Override
public ITerminal getTerminal()
public int getComputerID()
{
return getComputer();
return m_computerID;
}
// IComputerTile
@Override
public String getLabel()
{
return m_label;
}
@Override
public void setComputerID( int id )
@ -413,35 +405,12 @@ public abstract class TileComputerBase extends TileGeneric
@Override
public void setLabel( String label )
{
if( !getWorld().isRemote )
if( !getWorld().isRemote && !Objects.equals( m_label, label ) )
{
createServerComputer().setLabel( label );
}
}
@Override
public IComputer createComputer()
{
if( getWorld().isRemote )
{
return createClientComputer();
}
else
{
return createServerComputer();
}
}
@Override
public IComputer getComputer()
{
if( getWorld().isRemote )
{
return getClientComputer();
}
else
{
return getServerComputer();
m_label = label;
ServerComputer computer = getServerComputer();
if( computer != null ) computer.setLabel( label );
markDirty();
}
}
@ -520,17 +489,21 @@ public abstract class TileComputerBase extends TileGeneric
// Networking stuff
@Override
public void writeDescription( @Nonnull NBTTagCompound nbttagcompound )
public void writeDescription( @Nonnull NBTTagCompound tag )
{
super.writeDescription( nbttagcompound );
nbttagcompound.setInteger( "instanceID", createServerComputer().getInstanceID() );
super.writeDescription( tag );
tag.setInteger( "instanceID", createServerComputer().getInstanceID() );
if( m_label != null ) tag.setString( "label", m_label );
if( m_computerID >= 0 ) tag.setInteger( "computerID", m_computerID );
}
@Override
public void readDescription( @Nonnull NBTTagCompound nbttagcompound )
public void readDescription( @Nonnull NBTTagCompound tag )
{
super.readDescription( nbttagcompound );
m_instanceID = nbttagcompound.getInteger( "instanceID" );
super.readDescription( tag );
m_instanceID = tag.getInteger( "instanceID" );
m_label = tag.hasKey( "label" ) ? tag.getString( "label" ) : null;
m_computerID = tag.hasKey( "computerID" ) ? tag.getInteger( "computerID" ) : -1;
}
protected void transferStateFrom( TileComputerBase copy )

View File

@ -18,27 +18,17 @@ public class ClientComputer extends ClientTerminal implements IComputer
{
private final int m_instanceID;
private int m_computerID;
private String m_label;
private boolean m_on;
private boolean m_blinking;
private boolean m_changed;
private NBTTagCompound m_userData;
private boolean m_on = false;
private boolean m_blinking = false;
private boolean m_changed = true;
private NBTTagCompound m_userData = null;
private boolean m_changedLastFrame;
private boolean m_changedLastFrame = false;
public ClientComputer( int instanceID )
{
super( false );
m_instanceID = instanceID;
m_computerID = -1;
m_label = null;
m_on = false;
m_blinking = false;
m_changed = true;
m_userData = null;
m_changedLastFrame = false;
}
@Override
@ -73,18 +63,6 @@ public class ClientComputer extends ClientTerminal implements IComputer
return m_instanceID;
}
@Override
public int getID()
{
return m_computerID;
}
@Override
public String getLabel()
{
return m_label;
}
@Override
public boolean isOn()
{
@ -125,21 +103,16 @@ public class ClientComputer extends ClientTerminal implements IComputer
ComputerCraft.sendToServer( new QueueEventServerMessage( m_instanceID, event, arguments ) );
}
public void setState( int id, String label, ComputerState state, NBTTagCompound userData )
public void setState( ComputerState state, NBTTagCompound userData )
{
int oldID = m_computerID;
String oldLabel = m_label;
boolean oldOn = m_on;
boolean oldBlinking = m_blinking;
NBTTagCompound oldUserData = m_userData;
m_computerID = id;
m_label = label;
m_on = state != ComputerState.OFF;
m_blinking = state == ComputerState.BLINKING;
m_userData = userData;
m_changed |= m_computerID != oldID || m_on != oldOn || m_blinking != oldBlinking
|| !Objects.equal( m_label, oldLabel ) || !Objects.equal( m_userData, oldUserData );
m_changed |= m_on != oldOn || m_blinking != oldBlinking || !Objects.equal( m_userData, oldUserData );
}
}

View File

@ -50,21 +50,6 @@ public class ComputerRegistry<TComputer extends IComputer>
return null;
}
public TComputer lookup( int computerID )
{
if( computerID >= 0 )
{
for( TComputer computer : getComputers() )
{
if( computer.getID() == computerID )
{
return computer;
}
}
}
return null;
}
public boolean contains( int instanceID )
{
return m_computers.containsKey( instanceID );
@ -82,10 +67,7 @@ public class ComputerRegistry<TComputer extends IComputer>
public void remove( int instanceID )
{
if( m_computers.containsKey( instanceID ) )
{
m_computers.remove( instanceID );
}
m_computers.remove( instanceID );
}
public void reset()

View File

@ -16,6 +16,8 @@ public enum ComputerState implements IStringSerializable
ON( "on" ),
BLINKING( "blinking" );
private static final ComputerState[] VALUES = ComputerState.values();
private String m_name;
ComputerState( String name )
@ -35,5 +37,10 @@ public enum ComputerState implements IStringSerializable
{
return getName();
}
public static ComputerState valueOf( int ordinal )
{
return ordinal < 0 || ordinal >= VALUES.length ? ComputerState.OFF : VALUES[ordinal];
}
}

View File

@ -12,10 +12,6 @@ public interface IComputer extends ITerminal
{
int getInstanceID();
int getID();
String getLabel();
boolean isOn();
boolean isCursorDisplayed();

View File

@ -226,13 +226,11 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
return m_instanceID;
}
@Override
public int getID()
{
return m_computer.getID();
}
@Override
public String getLabel()
{
return m_computer.getLabel();

View File

@ -10,10 +10,6 @@ import java.util.Iterator;
public class ServerComputerRegistry extends ComputerRegistry<ServerComputer>
{
public ServerComputerRegistry()
{
}
public void update()
{
Iterator<ServerComputer> it = getComputers().iterator();
@ -73,4 +69,15 @@ public class ServerComputerRegistry extends ComputerRegistry<ServerComputer>
super.reset();
//System.out.println( getComputers().size() + " SERVER COMPUTERS" );
}
public ServerComputer lookup( int computerID )
{
if( computerID < 0 ) return null;
for( ServerComputer computer : getComputers() )
{
if( computer.getID() == computerID ) return computer;
}
return null;
}
}

View File

@ -7,9 +7,8 @@
package dan200.computercraft.shared.computer.items;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.blocks.IComputerTile;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -18,38 +17,31 @@ import javax.annotation.Nonnull;
public class ComputerItemFactory
{
@Nonnull
public static ItemStack create( IComputerTile computerTile )
public static ItemStack create( TileComputer tile )
{
IComputer computer = computerTile.getComputer();
if( computer != null )
{
String label = computer.getLabel();
int id = (label != null) ? computer.getID() : -1;
return create( id, label, computerTile.getFamily() );
}
else
{
return create( -1, null, computerTile.getFamily() );
}
String label = tile.getLabel();
int id = label != null ? tile.getComputerID() : -1;
return create( id, label, tile.getFamily() );
}
@Nonnull
public static ItemStack create( int id, String label, ComputerFamily family )
{
ItemComputer computer = ((ItemComputer) Item.getItemFromBlock( ComputerCraft.Blocks.computer ));
ItemCommandComputer commandComputer = ((ItemCommandComputer) Item.getItemFromBlock( ComputerCraft.Blocks.commandComputer ));
switch( family )
{
case Normal:
case Advanced:
{
ItemComputer computer = ((ItemComputer) Item.getItemFromBlock( ComputerCraft.Blocks.computer ));
return computer.create( id, label, family );
}
case Command:
{
ItemCommandComputer commandComputer = ((ItemCommandComputer) Item.getItemFromBlock( ComputerCraft.Blocks.commandComputer ));
return commandComputer.create( id, label, family );
}
default:
return ItemStack.EMPTY;
}
return ItemStack.EMPTY;
}
}

View File

@ -21,17 +21,13 @@ import java.io.UncheckedIOException;
*/
public class ComputerDataClientMessage extends ComputerClientMessage
{
private int computerId;
private ComputerState state;
private String label;
private NBTTagCompound userData;
public ComputerDataClientMessage( ServerComputer computer )
{
super( computer.getInstanceID() );
this.computerId = computer.getID();
this.state = computer.getState();
this.label = computer.getLabel();
this.userData = computer.getUserData();
}
@ -45,21 +41,11 @@ public class ComputerDataClientMessage extends ComputerClientMessage
return NetworkMessages.COMPUTER_DATA_CLIENT_MESSAGE;
}
public int getComputerId()
{
return computerId;
}
public ComputerState getState()
{
return state;
}
public String getLabel()
{
return label;
}
public NBTTagCompound getUserData()
{
return userData;
@ -69,10 +55,7 @@ public class ComputerDataClientMessage extends ComputerClientMessage
public void toBytes( @Nonnull PacketBuffer buf )
{
super.toBytes( buf );
buf.writeVarInt( computerId );
buf.writeEnumValue( state );
buf.writeBoolean( label != null );
if( label != null ) buf.writeString( label );
buf.writeCompoundTag( userData );
}
@ -80,9 +63,7 @@ public class ComputerDataClientMessage extends ComputerClientMessage
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
computerId = buf.readVarInt();
state = buf.readEnumValue( ComputerState.class );
if( buf.readBoolean() ) label = buf.readString( Short.MAX_VALUE );
try
{
userData = buf.readCompoundTag();

View File

@ -562,7 +562,6 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
private static final IItemPropertyGetter COMPUTER_STATE = ( stack, world, player ) -> {
ItemPocketComputer itemPocketComputer = (ItemPocketComputer) stack.getItem();
ComputerState state = itemPocketComputer.getState( stack );
return state.ordinal();
};

View File

@ -407,7 +407,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
} );
ComputerClientMessage.register( ComputerDataClientMessage::new, ( computer, packet ) ->
computer.setState( packet.getComputerId(), packet.getLabel(), packet.getState(), packet.getUserData() ) );
computer.setState( packet.getState(), packet.getUserData() ) );
ComputerClientMessage.register( ComputerTerminalClientMessage::new, ( computer, packet ) ->
computer.readDescription( packet.getTag() ) );

View File

@ -8,8 +8,8 @@ package dan200.computercraft.shared.proxy;
import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
@ -43,7 +43,7 @@ public interface IComputerCraftProxy
Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family );
Object getComputerGUI( ClientComputer computer, int width, int height, ComputerFamily family );
File getWorldDir( World world );

View File

@ -14,7 +14,6 @@ import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.turtle.apis.TurtleAPI;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
@ -170,11 +169,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override
public void getDroppedItems( @Nonnull NonNullList<ItemStack> drops, boolean creative )
{
IComputer computer = getComputer();
if( !creative || (computer != null && computer.getLabel() != null) )
{
drops.add( TurtleItemFactory.create( this ) );
}
if( !creative || getLabel() != null ) drops.add( TurtleItemFactory.create( this ) );
}
@Override
@ -254,11 +249,8 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
{
if( !getWorld().isRemote && m_inventoryChanged )
{
IComputer computer = getComputer();
if( computer != null )
{
computer.queueEvent( "turtle_inventory" );
}
ServerComputer computer = getServerComputer();
if( computer != null ) computer.queueEvent( "turtle_inventory" );
m_inventoryChanged = false;
for( int n = 0; n < getSizeInventory(); n++ )
@ -551,31 +543,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Override
public String getName()
{
IComputer computer = getComputer();
if( computer != null )
{
String label = computer.getLabel();
if( label != null && label.length() > 0 )
{
return label;
}
}
return "tile.computercraft:turtle.name";
String label = getLabel();
return label == null || label.isEmpty() ? "tile.computercraft:turtle.name" : label;
}
@Override
public boolean hasCustomName()
{
IComputer computer = getComputer();
if( computer != null )
{
String label = computer.getLabel();
if( label != null && label.length() > 0 )
{
return true;
}
}
return false;
String label = getLabel();
return label != null && !label.isEmpty();
}
@Nonnull

View File

@ -17,7 +17,6 @@ import dan200.computercraft.shared.TurtleUpgrades;
import dan200.computercraft.shared.computer.blocks.ComputerProxy;
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.util.Colour;
@ -990,7 +989,7 @@ public class TurtleBrain implements ITurtleAccess
{
if( result != null && result.isSuccess() )
{
IComputer computer = m_owner.getComputer();
ServerComputer computer = m_owner.getServerComputer();
if( computer != null )
{
Object[] results = result.getResults();
@ -1012,11 +1011,11 @@ public class TurtleBrain implements ITurtleAccess
}
else
{
IComputer computer = m_owner.getComputer();
ServerComputer computer = m_owner.getServerComputer();
if( computer != null )
{
computer.queueEvent( "turtle_response", new Object[] {
callbackID, false, (result != null) ? result.getErrorMessage() : null
callbackID, false, result != null ? result.getErrorMessage() : null
} );
}
}

View File

@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.turtle.blocks.ITurtleTile;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -26,18 +25,15 @@ public class TurtleItemFactory
ITurtleUpgrade leftUpgrade = turtle.getAccess().getUpgrade( TurtleSide.Left );
ITurtleUpgrade rightUpgrade = turtle.getAccess().getUpgrade( TurtleSide.Right );
IComputer computer = turtle.getComputer();
if( computer != null )
String label = turtle.getLabel();
if( label == null )
{
String label = computer.getLabel();
if( label != null )
{
int id = computer.getID();
int fuelLevel = turtle.getAccess().getFuelLevel();
return create( id, label, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, fuelLevel, turtle.getOverlay() );
}
return create( -1, null, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, 0, turtle.getOverlay() );
}
return create( -1, null, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, 0, turtle.getOverlay() );
int id = turtle.getComputerID();
int fuelLevel = turtle.getAccess().getFuelLevel();
return create( id, label, turtle.getColour(), turtle.getFamily(), leftUpgrade, rightUpgrade, fuelLevel, turtle.getOverlay() );
}
@Nonnull