1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-09-29 23:40:46 +00:00

Merge branch 'mc-1.15.x' into mc-1.16.x

This commit is contained in:
Jonathan Coates 2021-06-19 15:18:12 +01:00
commit df7a40354e
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
18 changed files with 204 additions and 307 deletions

View File

@ -0,0 +1,98 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.gui;
import com.mojang.blaze3d.matrix.MatrixStack;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
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.inventory.ContainerComputerBase;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull;
public abstract class ComputerScreenBase<T extends ContainerComputerBase> extends ContainerScreen<T>
{
protected WidgetTerminal terminal;
protected final ClientComputer computer;
protected final ComputerFamily family;
protected final int sidebarYOffset;
public ComputerScreenBase( T container, PlayerInventory player, ITextComponent title, int sidebarYOffset )
{
super( container, player, title );
computer = (ClientComputer) container.getComputer();
family = container.getFamily();
this.sidebarYOffset = sidebarYOffset;
}
protected abstract WidgetTerminal createTerminal();
@Override
protected final void init()
{
super.init();
minecraft.keyboardHandler.setSendRepeatsToGui( true );
terminal = addButton( createTerminal() );
ComputerSidebar.addButtons( this, computer, this::addButton, leftPos, topPos + sidebarYOffset );
setFocused( terminal );
}
@Override
public final void removed()
{
super.removed();
minecraft.keyboardHandler.setSendRepeatsToGui( false );
}
@Override
public final void tick()
{
super.tick();
terminal.update();
}
@Override
public final boolean keyPressed( int key, int scancode, int modifiers )
{
// Forward the tab key to the terminal, rather than moving between controls.
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminal )
{
return getFocused().keyPressed( key, scancode, modifiers );
}
return super.keyPressed( key, scancode, modifiers );
}
@Override
public final void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
{
renderBackground( stack );
super.render( stack, mouseX, mouseY, partialTicks );
renderTooltip( stack, mouseX, mouseY );
}
@Override
public final boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
{
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|| super.mouseDragged( x, y, button, deltaX, deltaY );
}
@Override
protected void renderLabels( @Nonnull MatrixStack transform, int mouseX, int mouseY )
{
// Skip rendering labels.
}
}

View File

@ -11,37 +11,27 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull;
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
public final class GuiComputer<T extends ContainerComputerBase> extends ContainerScreen<T>
public final class GuiComputer<T extends ContainerComputerBase> extends ComputerScreenBase<T>
{
private final ComputerFamily family;
private final ClientComputer computer;
private final int termWidth;
private final int termHeight;
private WidgetTerminal terminal = null;
private GuiComputer(
T container, PlayerInventory player, ITextComponent title, int termWidth, int termHeight
)
{
super( container, player, title );
family = container.getFamily();
computer = (ClientComputer) container.getComputer();
super( container, player, title, BORDER );
this.termWidth = termWidth;
this.termHeight = termHeight;
@ -73,45 +63,12 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Containe
);
}
@Override
protected void init()
protected WidgetTerminal createTerminal()
{
super.init();
minecraft.keyboardHandler.setSendRepeatsToGui( true );
terminal = addButton( new WidgetTerminal( computer,
return new WidgetTerminal( computer,
leftPos + ComputerSidebar.WIDTH + BORDER, topPos + BORDER, termWidth, termHeight
) );
ComputerSidebar.addButtons( this, computer, this::addButton, leftPos, topPos + BORDER );
setFocused( terminal );
}
@Override
public void removed()
{
super.removed();
minecraft.keyboardHandler.setSendRepeatsToGui( false );
}
@Override
public void tick()
{
super.tick();
terminal.update();
}
@Override
public boolean keyPressed( int key, int scancode, int modifiers )
{
// Forward the tab key to the terminal, rather than moving between controls.
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminal )
{
return getFocused().keyPressed( key, scancode, modifiers );
}
return super.keyPressed( key, scancode, modifiers );
);
}
@Override
@ -121,27 +78,6 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Containe
RenderSystem.color4f( 1, 1, 1, 1 );
minecraft.getTextureManager().bind( ComputerBorderRenderer.getTexture( family ) );
ComputerBorderRenderer.render( terminal.x, terminal.y, getBlitOffset(), terminal.getWidth(), terminal.getHeight() );
ComputerSidebar.renderBackground( stack, leftPos, topPos + BORDER );
}
@Override
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
{
renderBackground( stack );
super.render( stack, mouseX, mouseY, partialTicks );
renderTooltip( stack, mouseX, mouseY );
}
@Override
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
{
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|| super.mouseDragged( x, y, button, deltaX, deltaY );
}
@Override
protected void renderLabels( @Nonnull MatrixStack transform, int mouseX, int mouseY )
{
// Skip rendering labels.
ComputerSidebar.renderBackground( stack, leftPos, topPos + sidebarYOffset );
}
}

View File

@ -11,81 +11,42 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.render.ComputerBorderRenderer;
import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nonnull;
import static dan200.computercraft.shared.turtle.inventory.ContainerTurtle.*;
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
{
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_normal.png" );
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_advanced.png" );
private final ContainerTurtle container;
private static final int TEX_WIDTH = 254;
private static final int TEX_HEIGHT = 217;
private final ComputerFamily family;
private final ClientComputer computer;
private WidgetTerminal terminal;
public GuiTurtle( ContainerTurtle container, PlayerInventory player, ITextComponent title )
{
super( container, player, title );
this.container = container;
super( container, player, title, BORDER );
family = container.getFamily();
computer = (ClientComputer) container.getComputer();
imageWidth = 254;
imageHeight = 217;
imageWidth = TEX_WIDTH + ComputerSidebar.WIDTH;
imageHeight = TEX_HEIGHT;
}
@Override
protected void init()
protected WidgetTerminal createTerminal()
{
super.init();
minecraft.keyboardHandler.setSendRepeatsToGui( true );
terminal = addButton( new WidgetTerminal(
return new WidgetTerminal(
computer, leftPos + BORDER + ComputerSidebar.WIDTH, topPos + BORDER,
ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight
) );
ComputerSidebar.addButtons( this, computer, this::addButton, leftPos, topPos + BORDER );
setFocused( terminal );
}
@Override
public void removed()
{
super.removed();
minecraft.keyboardHandler.setSendRepeatsToGui( false );
}
@Override
public void tick()
{
super.tick();
terminal.update();
}
@Override
public boolean keyPressed( int key, int scancode, int modifiers )
{
// Forward the tab key to the terminal, rather than moving between controls.
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminal )
{
return getFocused().keyPressed( key, scancode, modifiers );
}
return super.keyPressed( key, scancode, modifiers );
);
}
@Override
@ -93,12 +54,12 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
{
boolean advanced = family == ComputerFamily.ADVANCED;
minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
blit( transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, imageWidth, imageHeight );
blit( transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT );
minecraft.getTextureManager().bind( advanced ? ComputerBorderRenderer.BACKGROUND_ADVANCED : ComputerBorderRenderer.BACKGROUND_NORMAL );
ComputerSidebar.renderBackground( transform, leftPos, topPos + BORDER );
ComputerSidebar.renderBackground( transform, leftPos, topPos + sidebarYOffset );
int slot = container.getSelectedSlot();
int slot = getMenu().getSelectedSlot();
if( slot >= 0 )
{
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
@ -110,25 +71,4 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
);
}
}
@Override
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
{
renderBackground( stack );
super.render( stack, mouseX, mouseY, partialTicks );
renderTooltip( stack, mouseX, mouseY );
}
@Override
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
{
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|| super.mouseDragged( x, y, button, deltaX, deltaY );
}
@Override
protected void renderLabels( @Nonnull MatrixStack transform, int mouseX, int mouseY )
{
// Skip rendering labels.
}
}

View File

@ -172,8 +172,8 @@ public class WidgetTerminal extends Widget
Terminal term = computer.getTerminal();
if( term != null )
{
int charX = (int) ((mouseX - x) / FONT_WIDTH);
int charY = (int) ((mouseY - x) / FONT_HEIGHT);
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
@ -196,8 +196,8 @@ public class WidgetTerminal extends Widget
Terminal term = computer.getTerminal();
if( term != null )
{
int charX = (int) ((mouseX - x) / FONT_WIDTH);
int charY = (int) ((mouseY - x) / FONT_HEIGHT);
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
@ -223,8 +223,8 @@ public class WidgetTerminal extends Widget
Terminal term = computer.getTerminal();
if( term != null )
{
int charX = (int) ((mouseX - x) / FONT_WIDTH);
int charY = (int) ((mouseY - x) / FONT_HEIGHT);
int charX = (int) ((mouseX - innerX) / FONT_WIDTH);
int charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );

View File

@ -43,17 +43,17 @@ public final class NetworkHandler
.simpleChannel();
// Server messages
registerMainThread( 0, NetworkDirection.PLAY_TO_SERVER, ComputerActionServerMessage::new );
registerMainThread( 1, NetworkDirection.PLAY_TO_SERVER, QueueEventServerMessage::new );
registerMainThread( 2, NetworkDirection.PLAY_TO_SERVER, RequestComputerMessage::new );
registerMainThread( 3, NetworkDirection.PLAY_TO_SERVER, KeyEventServerMessage::new );
registerMainThread( 4, NetworkDirection.PLAY_TO_SERVER, MouseEventServerMessage::new );
registerMainThread( 0, NetworkDirection.PLAY_TO_SERVER, ComputerActionServerMessage.class, ComputerActionServerMessage::new );
registerMainThread( 1, NetworkDirection.PLAY_TO_SERVER, QueueEventServerMessage.class, QueueEventServerMessage::new );
registerMainThread( 2, NetworkDirection.PLAY_TO_SERVER, RequestComputerMessage.class, RequestComputerMessage::new );
registerMainThread( 3, NetworkDirection.PLAY_TO_SERVER, KeyEventServerMessage.class, KeyEventServerMessage::new );
registerMainThread( 4, NetworkDirection.PLAY_TO_SERVER, MouseEventServerMessage.class, MouseEventServerMessage::new );
// Client messages
registerMainThread( 10, NetworkDirection.PLAY_TO_CLIENT, ChatTableClientMessage::new );
registerMainThread( 11, NetworkDirection.PLAY_TO_CLIENT, ComputerDataClientMessage::new );
registerMainThread( 12, NetworkDirection.PLAY_TO_CLIENT, ComputerDeletedClientMessage::new );
registerMainThread( 13, NetworkDirection.PLAY_TO_CLIENT, ComputerTerminalClientMessage::new );
registerMainThread( 10, NetworkDirection.PLAY_TO_CLIENT, ChatTableClientMessage.class, ChatTableClientMessage::new );
registerMainThread( 11, NetworkDirection.PLAY_TO_CLIENT, ComputerDataClientMessage.class, ComputerDataClientMessage::new );
registerMainThread( 12, NetworkDirection.PLAY_TO_CLIENT, ComputerDeletedClientMessage.class, ComputerDeletedClientMessage::new );
registerMainThread( 13, NetworkDirection.PLAY_TO_CLIENT, ComputerTerminalClientMessage.class, ComputerTerminalClientMessage::new );
registerMainThread( 14, NetworkDirection.PLAY_TO_CLIENT, PlayRecordClientMessage.class, PlayRecordClientMessage::new );
registerMainThread( 15, NetworkDirection.PLAY_TO_CLIENT, MonitorClientMessage.class, MonitorClientMessage::new );
registerMainThread( 16, NetworkDirection.PLAY_TO_CLIENT, SpeakerPlayClientMessage.class, SpeakerPlayClientMessage::new );
@ -90,24 +90,6 @@ public final class NetworkHandler
network.send( PacketDistributor.TRACKING_CHUNK.with( () -> chunk ), packet );
}
/**
* /**
* Register packet, and a thread-unsafe handler for it.
*
* @param <T> The type of the packet to send.
* @param id The identifier for this packet type.
* @param direction A network direction which will be asserted before any processing of this message occurs.
* @param factory The factory for this type of packet.
*/
private static <T extends NetworkMessage> void registerMainThread( int id, NetworkDirection direction, Supplier<T> factory )
{
registerMainThread( id, direction, getType( factory ), buf -> {
T instance = factory.get();
instance.fromBytes( buf );
return instance;
} );
}
/**
* /**
* Register packet, and a thread-unsafe handler for it.

View File

@ -27,18 +27,6 @@ public interface NetworkMessage
*/
void toBytes( @Nonnull PacketBuffer buf );
/**
* Read this packet from a buffer.
*
* This may be called on any thread, so this should be a pure operation.
*
* @param buf The buffer to read data from.
*/
default void fromBytes( @Nonnull PacketBuffer buf )
{
throw new IllegalStateException( "Should have been registered using a \"from bytes\" method" );
}
/**
* Handle this {@link NetworkMessage}.
*

View File

@ -16,7 +16,7 @@ import javax.annotation.Nonnull;
public class ChatTableClientMessage implements NetworkMessage
{
private TableBuilder table;
private final TableBuilder table;
public ChatTableClientMessage( TableBuilder table )
{
@ -24,32 +24,7 @@ public class ChatTableClientMessage implements NetworkMessage
this.table = table;
}
public ChatTableClientMessage()
{
}
@Override
public void toBytes( @Nonnull PacketBuffer buf )
{
buf.writeVarInt( table.getId() );
buf.writeVarInt( table.getColumns() );
buf.writeBoolean( table.getHeaders() != null );
if( table.getHeaders() != null )
{
for( ITextComponent header : table.getHeaders() ) buf.writeComponent( header );
}
buf.writeVarInt( table.getRows().size() );
for( ITextComponent[] row : table.getRows() )
{
for( ITextComponent column : row ) buf.writeComponent( column );
}
buf.writeVarInt( table.getAdditional() );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
public ChatTableClientMessage( @Nonnull PacketBuffer buf )
{
int id = buf.readVarInt();
int columns = buf.readVarInt();
@ -77,6 +52,26 @@ public class ChatTableClientMessage implements NetworkMessage
this.table = table;
}
@Override
public void toBytes( @Nonnull PacketBuffer buf )
{
buf.writeVarInt( table.getId() );
buf.writeVarInt( table.getColumns() );
buf.writeBoolean( table.getHeaders() != null );
if( table.getHeaders() != null )
{
for( ITextComponent header : table.getHeaders() ) buf.writeComponent( header );
}
buf.writeVarInt( table.getRows().size() );
for( ITextComponent[] row : table.getRows() )
{
for( ITextComponent column : row ) buf.writeComponent( column );
}
buf.writeVarInt( table.getAdditional() );
}
@Override
public void handle( NetworkEvent.Context context )
{

View File

@ -17,15 +17,16 @@ import javax.annotation.Nonnull;
*/
public abstract class ComputerClientMessage implements NetworkMessage
{
private int instanceId;
private final int instanceId;
public ComputerClientMessage( int instanceId )
{
this.instanceId = instanceId;
}
public ComputerClientMessage()
public ComputerClientMessage( @Nonnull PacketBuffer buf )
{
instanceId = buf.readVarInt();
}
public int getInstanceId()
@ -39,12 +40,6 @@ public abstract class ComputerClientMessage implements NetworkMessage
buf.writeVarInt( instanceId );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
instanceId = buf.readVarInt();
}
public ClientComputer getComputer()
{
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( instanceId );

View File

@ -18,8 +18,8 @@ import javax.annotation.Nonnull;
*/
public class ComputerDataClientMessage extends ComputerClientMessage
{
private ComputerState state;
private CompoundNBT userData;
private final ComputerState state;
private final CompoundNBT userData;
public ComputerDataClientMessage( ServerComputer computer )
{
@ -28,8 +28,11 @@ public class ComputerDataClientMessage extends ComputerClientMessage
userData = computer.getUserData();
}
public ComputerDataClientMessage()
public ComputerDataClientMessage( @Nonnull PacketBuffer buf )
{
super( buf );
state = buf.readEnum( ComputerState.class );
userData = buf.readNbt();
}
@Override
@ -40,14 +43,6 @@ public class ComputerDataClientMessage extends ComputerClientMessage
buf.writeNbt( userData );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
state = buf.readEnum( ComputerState.class );
userData = buf.readNbt();
}
@Override
public void handle( NetworkEvent.Context context )
{

View File

@ -6,6 +6,7 @@
package dan200.computercraft.shared.network.client;
import dan200.computercraft.ComputerCraft;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;
public class ComputerDeletedClientMessage extends ComputerClientMessage
@ -15,8 +16,9 @@ public class ComputerDeletedClientMessage extends ComputerClientMessage
super( instanceId );
}
public ComputerDeletedClientMessage()
public ComputerDeletedClientMessage( PacketBuffer buffer )
{
super( buffer );
}
@Override

View File

@ -12,7 +12,7 @@ import javax.annotation.Nonnull;
public class ComputerTerminalClientMessage extends ComputerClientMessage
{
private TerminalState state;
private final TerminalState state;
public ComputerTerminalClientMessage( int instanceId, TerminalState state )
{
@ -20,8 +20,10 @@ public class ComputerTerminalClientMessage extends ComputerClientMessage
this.state = state;
}
public ComputerTerminalClientMessage()
public ComputerTerminalClientMessage( @Nonnull PacketBuffer buf )
{
super( buf );
state = new TerminalState( buf );
}
@Override
@ -31,13 +33,6 @@ public class ComputerTerminalClientMessage extends ComputerClientMessage
state.write( buf );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
state = new TerminalState( buf );
}
@Override
public void handle( NetworkEvent.Context context )
{

View File

@ -13,7 +13,7 @@ import javax.annotation.Nonnull;
public class ComputerActionServerMessage extends ComputerServerMessage
{
private Action action;
private final Action action;
public ComputerActionServerMessage( int instanceId, Action action )
{
@ -21,8 +21,10 @@ public class ComputerActionServerMessage extends ComputerServerMessage
this.action = action;
}
public ComputerActionServerMessage()
public ComputerActionServerMessage( @Nonnull PacketBuffer buf )
{
super( buf );
action = buf.readEnum( Action.class );
}
@Override
@ -32,13 +34,6 @@ public class ComputerActionServerMessage extends ComputerServerMessage
buf.writeEnum( action );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
action = buf.readEnum( Action.class );
}
@Override
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
{

View File

@ -22,15 +22,16 @@ import javax.annotation.Nonnull;
*/
public abstract class ComputerServerMessage implements NetworkMessage
{
private int instanceId;
private final int instanceId;
public ComputerServerMessage( int instanceId )
{
this.instanceId = instanceId;
}
public ComputerServerMessage()
public ComputerServerMessage( @Nonnull PacketBuffer buf )
{
instanceId = buf.readVarInt();
}
@Override
@ -39,12 +40,6 @@ public abstract class ComputerServerMessage implements NetworkMessage
buf.writeVarInt( instanceId );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
instanceId = buf.readVarInt();
}
@Override
public void handle( NetworkEvent.Context context )
{

View File

@ -18,8 +18,8 @@ public class KeyEventServerMessage extends ComputerServerMessage
public static final int TYPE_REPEAT = 1;
public static final int TYPE_UP = 2;
private int type;
private int key;
private final int type;
private final int key;
public KeyEventServerMessage( int instanceId, int type, int key )
{
@ -28,8 +28,11 @@ public class KeyEventServerMessage extends ComputerServerMessage
this.key = key;
}
public KeyEventServerMessage()
public KeyEventServerMessage( @Nonnull PacketBuffer buf )
{
super( buf );
type = buf.readByte();
key = buf.readVarInt();
}
@Override
@ -40,14 +43,6 @@ public class KeyEventServerMessage extends ComputerServerMessage
buf.writeVarInt( key );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
type = buf.readByte();
key = buf.readVarInt();
}
@Override
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
{

View File

@ -19,10 +19,10 @@ public class MouseEventServerMessage extends ComputerServerMessage
public static final int TYPE_UP = 2;
public static final int TYPE_SCROLL = 3;
private int type;
private int x;
private int y;
private int arg;
private final int type;
private final int x;
private final int y;
private final int arg;
public MouseEventServerMessage( int instanceId, int type, int arg, int x, int y )
{
@ -33,8 +33,13 @@ public class MouseEventServerMessage extends ComputerServerMessage
this.y = y;
}
public MouseEventServerMessage()
public MouseEventServerMessage( @Nonnull PacketBuffer buf )
{
super( buf );
type = buf.readByte();
arg = buf.readVarInt();
x = buf.readVarInt();
y = buf.readVarInt();
}
@Override
@ -47,16 +52,6 @@ public class MouseEventServerMessage extends ComputerServerMessage
buf.writeVarInt( y );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
type = buf.readByte();
arg = buf.readVarInt();
x = buf.readVarInt();
y = buf.readVarInt();
}
@Override
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
{

View File

@ -22,8 +22,8 @@ import javax.annotation.Nullable;
*/
public class QueueEventServerMessage extends ComputerServerMessage
{
private String event;
private Object[] args;
private final String event;
private final Object[] args;
public QueueEventServerMessage( int instanceId, @Nonnull String event, @Nullable Object[] args )
{
@ -32,8 +32,13 @@ public class QueueEventServerMessage extends ComputerServerMessage
this.args = args;
}
public QueueEventServerMessage()
public QueueEventServerMessage( @Nonnull PacketBuffer buf )
{
super( buf );
event = buf.readUtf( Short.MAX_VALUE );
CompoundNBT args = buf.readNbt();
this.args = args == null ? null : NBTUtil.decodeObjects( args );
}
@Override
@ -44,16 +49,6 @@ public class QueueEventServerMessage extends ComputerServerMessage
buf.writeNbt( args == null ? null : NBTUtil.encodeObjects( args ) );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
super.fromBytes( buf );
event = buf.readUtf( Short.MAX_VALUE );
CompoundNBT args = buf.readNbt();
this.args = args == null ? null : NBTUtil.decodeObjects( args );
}
@Override
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
{

View File

@ -15,15 +15,16 @@ import javax.annotation.Nonnull;
public class RequestComputerMessage implements NetworkMessage
{
private int instance;
private final int instance;
public RequestComputerMessage( int instance )
{
this.instance = instance;
}
public RequestComputerMessage()
public RequestComputerMessage( @Nonnull PacketBuffer buf )
{
instance = buf.readVarInt();
}
@Override
@ -32,12 +33,6 @@ public class RequestComputerMessage implements NetworkMessage
buf.writeVarInt( instance );
}
@Override
public void fromBytes( @Nonnull PacketBuffer buf )
{
instance = buf.readVarInt();
}
@Override
public void handle( NetworkEvent.Context context )
{

View File

@ -290,6 +290,7 @@ local menu_choices = {
return false
end,
Exit = function()
sleep(0) -- Super janky, but consumes stray "char" events from pressing Ctrl then E separately.
return true
end,
}