mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 01:10:30 +00:00
Some cleanup to network messages
- Use enums for key and mouse actions, rather than integer ids. - Change TerminalState to always contain a terminal. We now make TerminalState nullable when we want to skip sending anything.
This commit is contained in:
parent
929debd382
commit
7c1f40031b
@ -49,31 +49,31 @@ public final class ClientInputHandler implements InputHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyDown(int key, boolean repeat) {
|
public void keyDown(int key, boolean repeat) {
|
||||||
ClientNetworking.sendToServer(new KeyEventServerMessage(menu, repeat ? KeyEventServerMessage.TYPE_REPEAT : KeyEventServerMessage.TYPE_DOWN, key));
|
ClientNetworking.sendToServer(new KeyEventServerMessage(menu, repeat ? KeyEventServerMessage.Action.REPEAT : KeyEventServerMessage.Action.DOWN, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyUp(int key) {
|
public void keyUp(int key) {
|
||||||
ClientNetworking.sendToServer(new KeyEventServerMessage(menu, KeyEventServerMessage.TYPE_UP, key));
|
ClientNetworking.sendToServer(new KeyEventServerMessage(menu, KeyEventServerMessage.Action.UP, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClick(int button, int x, int y) {
|
public void mouseClick(int button, int x, int y) {
|
||||||
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_CLICK, button, x, y));
|
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.CLICK, button, x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseUp(int button, int x, int y) {
|
public void mouseUp(int button, int x, int y) {
|
||||||
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_UP, button, x, y));
|
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.UP, button, x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDrag(int button, int x, int y) {
|
public void mouseDrag(int button, int x, int y) {
|
||||||
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_DRAG, button, x, y));
|
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.DRAG, button, x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseScroll(int direction, int x, int y) {
|
public void mouseScroll(int direction, int x, int y) {
|
||||||
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_SCROLL, direction, x, y));
|
ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.SCROLL, direction, x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public final class ClientNetworkContextImpl implements ClientNetworkContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMonitorData(BlockPos pos, TerminalState terminal) {
|
public void handleMonitorData(BlockPos pos, @Nullable TerminalState terminal) {
|
||||||
var player = Minecraft.getInstance().player;
|
var player = Minecraft.getInstance().player;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public final class ClientNetworkContextImpl implements ClientNetworkContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, TerminalState terminal) {
|
public void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, @Nullable TerminalState terminal) {
|
||||||
ClientPocketComputers.setState(instanceId, state, lightState, terminal);
|
ClientPocketComputers.setState(instanceId, state, lightState, terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public final class ClientPocketComputers {
|
|||||||
* @param lightColour The current colour of the modem light.
|
* @param lightColour The current colour of the modem light.
|
||||||
* @param terminalData The current terminal contents.
|
* @param terminalData The current terminal contents.
|
||||||
*/
|
*/
|
||||||
public static void setState(UUID instanceId, ComputerState state, int lightColour, TerminalState terminalData) {
|
public static void setState(UUID instanceId, ComputerState state, int lightColour, @Nullable TerminalState terminalData) {
|
||||||
var computer = instances.get(instanceId);
|
var computer = instances.get(instanceId);
|
||||||
if (computer == null) {
|
if (computer == null) {
|
||||||
instances.put(instanceId, new PocketComputerData(state, lightColour, terminalData));
|
instances.put(instanceId, new PocketComputerData(state, lightColour, terminalData));
|
||||||
|
@ -26,10 +26,10 @@ public final class PocketComputerData {
|
|||||||
private ComputerState state;
|
private ComputerState state;
|
||||||
private int lightColour;
|
private int lightColour;
|
||||||
|
|
||||||
PocketComputerData(ComputerState state, int lightColour, TerminalState terminalData) {
|
PocketComputerData(ComputerState state, int lightColour, @Nullable TerminalState terminalData) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.lightColour = lightColour;
|
this.lightColour = lightColour;
|
||||||
if (terminalData.hasTerminal()) terminal = terminalData.create();
|
if (terminalData != null) terminal = terminalData.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLightState() {
|
public int getLightState() {
|
||||||
@ -44,11 +44,11 @@ public final class PocketComputerData {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setState(ComputerState state, int lightColour, TerminalState terminalData) {
|
void setState(ComputerState state, int lightColour, @Nullable TerminalState terminalData) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.lightColour = lightColour;
|
this.lightColour = lightColour;
|
||||||
|
|
||||||
if (terminalData.hasTerminal()) {
|
if (terminalData != null) {
|
||||||
if (terminal == null) {
|
if (terminal == null) {
|
||||||
terminal = terminalData.create();
|
terminal = terminalData.create();
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,6 +7,7 @@ package dan200.computercraft.shared.computer.terminal;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@ -21,68 +22,49 @@ public class TerminalState {
|
|||||||
private final boolean colour;
|
private final boolean colour;
|
||||||
private final int width;
|
private final int width;
|
||||||
private final int height;
|
private final int height;
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final ByteBuf buffer;
|
private final ByteBuf buffer;
|
||||||
|
|
||||||
public TerminalState(@Nullable NetworkedTerminal terminal) {
|
public TerminalState(NetworkedTerminal terminal) {
|
||||||
if (terminal == null) {
|
colour = terminal.isColour();
|
||||||
colour = false;
|
width = terminal.getWidth();
|
||||||
width = height = 0;
|
height = terminal.getHeight();
|
||||||
buffer = null;
|
|
||||||
} else {
|
|
||||||
colour = terminal.isColour();
|
|
||||||
width = terminal.getWidth();
|
|
||||||
height = terminal.getHeight();
|
|
||||||
|
|
||||||
var buf = buffer = Unpooled.buffer();
|
var buf = buffer = Unpooled.buffer();
|
||||||
terminal.write(new FriendlyByteBuf(buf));
|
terminal.write(new FriendlyByteBuf(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Contract("null -> null; !null -> !null")
|
||||||
|
public static @Nullable TerminalState create(@Nullable NetworkedTerminal terminal) {
|
||||||
|
return terminal == null ? null : new TerminalState(terminal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TerminalState(FriendlyByteBuf buf) {
|
public TerminalState(FriendlyByteBuf buf) {
|
||||||
colour = buf.readBoolean();
|
colour = buf.readBoolean();
|
||||||
|
width = buf.readVarInt();
|
||||||
|
height = buf.readVarInt();
|
||||||
|
|
||||||
if (buf.readBoolean()) {
|
var length = buf.readVarInt();
|
||||||
width = buf.readVarInt();
|
buffer = buf.readBytes(length);
|
||||||
height = buf.readVarInt();
|
|
||||||
|
|
||||||
var length = buf.readVarInt();
|
|
||||||
buffer = buf.readBytes(length);
|
|
||||||
} else {
|
|
||||||
width = height = 0;
|
|
||||||
buffer = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(FriendlyByteBuf buf) {
|
public void write(FriendlyByteBuf buf) {
|
||||||
buf.writeBoolean(colour);
|
buf.writeBoolean(colour);
|
||||||
|
buf.writeVarInt(width);
|
||||||
buf.writeBoolean(buffer != null);
|
buf.writeVarInt(height);
|
||||||
if (buffer != null) {
|
buf.writeVarInt(buffer.readableBytes());
|
||||||
buf.writeVarInt(width);
|
buf.writeBytes(buffer, buffer.readerIndex(), buffer.readableBytes());
|
||||||
buf.writeVarInt(height);
|
|
||||||
buf.writeVarInt(buffer.readableBytes());
|
|
||||||
buf.writeBytes(buffer, buffer.readerIndex(), buffer.readableBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasTerminal() {
|
|
||||||
return buffer != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return buffer == null ? 0 : buffer.readableBytes();
|
return buffer.readableBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(NetworkedTerminal terminal) {
|
public void apply(NetworkedTerminal terminal) {
|
||||||
if (buffer == null) throw new NullPointerException("buffer");
|
|
||||||
terminal.resize(width, height);
|
terminal.resize(width, height);
|
||||||
terminal.read(new FriendlyByteBuf(buffer));
|
terminal.read(new FriendlyByteBuf(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkedTerminal create() {
|
public NetworkedTerminal create() {
|
||||||
if (buffer == null) throw new NullPointerException("Terminal does not exist");
|
|
||||||
var terminal = new NetworkedTerminal(width, height, colour);
|
var terminal = new NetworkedTerminal(width, height, colour);
|
||||||
terminal.read(new FriendlyByteBuf(buffer));
|
terminal.read(new FriendlyByteBuf(buffer));
|
||||||
return terminal;
|
return terminal;
|
||||||
|
@ -26,11 +26,11 @@ public interface ClientNetworkContext {
|
|||||||
|
|
||||||
void handleComputerTerminal(int containerId, TerminalState terminal);
|
void handleComputerTerminal(int containerId, TerminalState terminal);
|
||||||
|
|
||||||
void handleMonitorData(BlockPos pos, TerminalState terminal);
|
void handleMonitorData(BlockPos pos, @Nullable TerminalState terminal);
|
||||||
|
|
||||||
void handlePlayRecord(BlockPos pos, @Nullable SoundEvent sound, @Nullable String name);
|
void handlePlayRecord(BlockPos pos, @Nullable SoundEvent sound, @Nullable String name);
|
||||||
|
|
||||||
void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, TerminalState terminal);
|
void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, @Nullable TerminalState terminal);
|
||||||
|
|
||||||
void handlePocketComputerDeleted(UUID instanceId);
|
void handlePocketComputerDeleted(UUID instanceId);
|
||||||
|
|
||||||
|
@ -11,25 +11,26 @@ import dan200.computercraft.shared.network.NetworkMessages;
|
|||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class MonitorClientMessage implements NetworkMessage<ClientNetworkContext> {
|
public class MonitorClientMessage implements NetworkMessage<ClientNetworkContext> {
|
||||||
private final BlockPos pos;
|
private final BlockPos pos;
|
||||||
private final TerminalState state;
|
private final @Nullable TerminalState state;
|
||||||
|
|
||||||
public MonitorClientMessage(BlockPos pos, TerminalState state) {
|
public MonitorClientMessage(BlockPos pos, @Nullable TerminalState state) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MonitorClientMessage(FriendlyByteBuf buf) {
|
public MonitorClientMessage(FriendlyByteBuf buf) {
|
||||||
pos = buf.readBlockPos();
|
pos = buf.readBlockPos();
|
||||||
state = new TerminalState(buf);
|
state = buf.readNullable(TerminalState::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(FriendlyByteBuf buf) {
|
public void write(FriendlyByteBuf buf) {
|
||||||
buf.writeBlockPos(pos);
|
buf.writeBlockPos(pos);
|
||||||
state.write(buf);
|
buf.writeNullable(state, (b, t) -> t.write(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package dan200.computercraft.shared.network.client;
|
package dan200.computercraft.shared.network.client;
|
||||||
|
|
||||||
import dan200.computercraft.shared.computer.core.ComputerState;
|
import dan200.computercraft.shared.computer.core.ComputerState;
|
||||||
import dan200.computercraft.shared.computer.terminal.NetworkedTerminal;
|
|
||||||
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
import dan200.computercraft.shared.computer.terminal.TerminalState;
|
||||||
import dan200.computercraft.shared.network.MessageType;
|
import dan200.computercraft.shared.network.MessageType;
|
||||||
import dan200.computercraft.shared.network.NetworkMessage;
|
import dan200.computercraft.shared.network.NetworkMessage;
|
||||||
@ -13,6 +12,7 @@ import dan200.computercraft.shared.network.NetworkMessages;
|
|||||||
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
import dan200.computercraft.shared.pocket.core.PocketServerComputer;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,20 +22,20 @@ public class PocketComputerDataMessage implements NetworkMessage<ClientNetworkCo
|
|||||||
private final UUID clientId;
|
private final UUID clientId;
|
||||||
private final ComputerState state;
|
private final ComputerState state;
|
||||||
private final int lightState;
|
private final int lightState;
|
||||||
private final TerminalState terminal;
|
private final @Nullable TerminalState terminal;
|
||||||
|
|
||||||
public PocketComputerDataMessage(PocketServerComputer computer, boolean sendTerminal) {
|
public PocketComputerDataMessage(PocketServerComputer computer, boolean sendTerminal) {
|
||||||
clientId = computer.getInstanceUUID();
|
clientId = computer.getInstanceUUID();
|
||||||
state = computer.getState();
|
state = computer.getState();
|
||||||
lightState = computer.getLight();
|
lightState = computer.getLight();
|
||||||
terminal = sendTerminal ? computer.getTerminalState() : new TerminalState((NetworkedTerminal) null);
|
terminal = sendTerminal ? computer.getTerminalState() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PocketComputerDataMessage(FriendlyByteBuf buf) {
|
public PocketComputerDataMessage(FriendlyByteBuf buf) {
|
||||||
clientId = buf.readUUID();
|
clientId = buf.readUUID();
|
||||||
state = buf.readEnum(ComputerState.class);
|
state = buf.readEnum(ComputerState.class);
|
||||||
lightState = buf.readVarInt();
|
lightState = buf.readVarInt();
|
||||||
terminal = new TerminalState(buf);
|
terminal = buf.readNullable(TerminalState::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,7 +43,7 @@ public class PocketComputerDataMessage implements NetworkMessage<ClientNetworkCo
|
|||||||
buf.writeUUID(clientId);
|
buf.writeUUID(clientId);
|
||||||
buf.writeEnum(state);
|
buf.writeEnum(state);
|
||||||
buf.writeVarInt(lightState);
|
buf.writeVarInt(lightState);
|
||||||
terminal.write(buf);
|
buf.writeNullable(terminal, (b, t) -> t.write(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,14 +12,10 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||||||
|
|
||||||
|
|
||||||
public class KeyEventServerMessage extends ComputerServerMessage {
|
public class KeyEventServerMessage extends ComputerServerMessage {
|
||||||
public static final int TYPE_DOWN = 0;
|
private final Action type;
|
||||||
public static final int TYPE_REPEAT = 1;
|
|
||||||
public static final int TYPE_UP = 2;
|
|
||||||
|
|
||||||
private final int type;
|
|
||||||
private final int key;
|
private final int key;
|
||||||
|
|
||||||
public KeyEventServerMessage(AbstractContainerMenu menu, int type, int key) {
|
public KeyEventServerMessage(AbstractContainerMenu menu, Action type, int key) {
|
||||||
super(menu);
|
super(menu);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
@ -27,24 +23,24 @@ public class KeyEventServerMessage extends ComputerServerMessage {
|
|||||||
|
|
||||||
public KeyEventServerMessage(FriendlyByteBuf buf) {
|
public KeyEventServerMessage(FriendlyByteBuf buf) {
|
||||||
super(buf);
|
super(buf);
|
||||||
type = buf.readByte();
|
type = buf.readEnum(Action.class);
|
||||||
key = buf.readVarInt();
|
key = buf.readVarInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(FriendlyByteBuf buf) {
|
public void write(FriendlyByteBuf buf) {
|
||||||
super.write(buf);
|
super.write(buf);
|
||||||
buf.writeByte(type);
|
buf.writeEnum(type);
|
||||||
buf.writeVarInt(key);
|
buf.writeVarInt(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handle(ServerNetworkContext context, ComputerMenu container) {
|
protected void handle(ServerNetworkContext context, ComputerMenu container) {
|
||||||
var input = container.getInput();
|
var input = container.getInput();
|
||||||
if (type == TYPE_UP) {
|
if (type == Action.UP) {
|
||||||
input.keyUp(key);
|
input.keyUp(key);
|
||||||
} else {
|
} else {
|
||||||
input.keyDown(key, type == TYPE_REPEAT);
|
input.keyDown(key, type == Action.REPEAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,4 +48,8 @@ public class KeyEventServerMessage extends ComputerServerMessage {
|
|||||||
public MessageType<KeyEventServerMessage> type() {
|
public MessageType<KeyEventServerMessage> type() {
|
||||||
return NetworkMessages.KEY_EVENT;
|
return NetworkMessages.KEY_EVENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Action {
|
||||||
|
DOWN, REPEAT, UP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,12 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||||||
|
|
||||||
|
|
||||||
public class MouseEventServerMessage extends ComputerServerMessage {
|
public class MouseEventServerMessage extends ComputerServerMessage {
|
||||||
public static final int TYPE_CLICK = 0;
|
private final Action type;
|
||||||
public static final int TYPE_DRAG = 1;
|
|
||||||
public static final int TYPE_UP = 2;
|
|
||||||
public static final int TYPE_SCROLL = 3;
|
|
||||||
|
|
||||||
private final int type;
|
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
private final int arg;
|
private final int arg;
|
||||||
|
|
||||||
public MouseEventServerMessage(AbstractContainerMenu menu, int type, int arg, int x, int y) {
|
public MouseEventServerMessage(AbstractContainerMenu menu, Action type, int arg, int x, int y) {
|
||||||
super(menu);
|
super(menu);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.arg = arg;
|
this.arg = arg;
|
||||||
@ -32,7 +27,7 @@ public class MouseEventServerMessage extends ComputerServerMessage {
|
|||||||
|
|
||||||
public MouseEventServerMessage(FriendlyByteBuf buf) {
|
public MouseEventServerMessage(FriendlyByteBuf buf) {
|
||||||
super(buf);
|
super(buf);
|
||||||
type = buf.readByte();
|
type = buf.readEnum(Action.class);
|
||||||
arg = buf.readVarInt();
|
arg = buf.readVarInt();
|
||||||
x = buf.readVarInt();
|
x = buf.readVarInt();
|
||||||
y = buf.readVarInt();
|
y = buf.readVarInt();
|
||||||
@ -41,7 +36,7 @@ public class MouseEventServerMessage extends ComputerServerMessage {
|
|||||||
@Override
|
@Override
|
||||||
public void write(FriendlyByteBuf buf) {
|
public void write(FriendlyByteBuf buf) {
|
||||||
super.write(buf);
|
super.write(buf);
|
||||||
buf.writeByte(type);
|
buf.writeEnum(type);
|
||||||
buf.writeVarInt(arg);
|
buf.writeVarInt(arg);
|
||||||
buf.writeVarInt(x);
|
buf.writeVarInt(x);
|
||||||
buf.writeVarInt(y);
|
buf.writeVarInt(y);
|
||||||
@ -51,10 +46,10 @@ public class MouseEventServerMessage extends ComputerServerMessage {
|
|||||||
protected void handle(ServerNetworkContext context, ComputerMenu container) {
|
protected void handle(ServerNetworkContext context, ComputerMenu container) {
|
||||||
var input = container.getInput();
|
var input = container.getInput();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TYPE_CLICK -> input.mouseClick(arg, x, y);
|
case CLICK -> input.mouseClick(arg, x, y);
|
||||||
case TYPE_DRAG -> input.mouseDrag(arg, x, y);
|
case DRAG -> input.mouseDrag(arg, x, y);
|
||||||
case TYPE_UP -> input.mouseUp(arg, x, y);
|
case UP -> input.mouseUp(arg, x, y);
|
||||||
case TYPE_SCROLL -> input.mouseScroll(arg, x, y);
|
case SCROLL -> input.mouseScroll(arg, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,4 +57,8 @@ public class MouseEventServerMessage extends ComputerServerMessage {
|
|||||||
public MessageType<MouseEventServerMessage> type() {
|
public MessageType<MouseEventServerMessage> type() {
|
||||||
return NetworkMessages.MOUSE_EVENT;
|
return NetworkMessages.MOUSE_EVENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Action {
|
||||||
|
CLICK, DRAG, UP, SCROLL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ public final class ClientMonitor {
|
|||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(TerminalState state) {
|
void read(@Nullable TerminalState state) {
|
||||||
if (state.hasTerminal()) {
|
if (state != null) {
|
||||||
if (terminal == null) {
|
if (terminal == null) {
|
||||||
terminal = state.create();
|
terminal = state.create();
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,7 +223,7 @@ public class MonitorBlockEntity extends BlockEntity {
|
|||||||
if (xIndex == 0 && yIndex == 0 && clientMonitor == null) clientMonitor = new ClientMonitor(this);
|
if (xIndex == 0 && yIndex == 0 && clientMonitor == null) clientMonitor = new ClientMonitor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void read(TerminalState state) {
|
public final void read(@Nullable TerminalState state) {
|
||||||
if (xIndex != 0 || yIndex != 0) {
|
if (xIndex != 0 || yIndex != 0) {
|
||||||
LOG.warn("Receiving monitor state for non-origin terminal at {}", getBlockPos());
|
LOG.warn("Receiving monitor state for non-origin terminal at {}", getBlockPos());
|
||||||
return;
|
return;
|
||||||
|
@ -68,7 +68,7 @@ public final class MonitorWatcher {
|
|||||||
var state = getState(tile, monitor);
|
var state = getState(tile, monitor);
|
||||||
ServerNetworking.sendToAllTracking(new MonitorClientMessage(pos, state), chunk);
|
ServerNetworking.sendToAllTracking(new MonitorClientMessage(pos, state), chunk);
|
||||||
|
|
||||||
limit -= state.size();
|
limit -= state == null ? 0 : state.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +76,9 @@ public final class MonitorWatcher {
|
|||||||
return !monitor.isRemoved() && monitor.getXIndex() == 0 && monitor.getYIndex() == 0 ? monitor.getCachedServerMonitor() : null;
|
return !monitor.isRemoved() && monitor.getXIndex() == 0 && monitor.getYIndex() == 0 ? monitor.getCachedServerMonitor() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TerminalState getState(MonitorBlockEntity tile, ServerMonitor monitor) {
|
private static @Nullable TerminalState getState(MonitorBlockEntity tile, ServerMonitor monitor) {
|
||||||
var state = tile.cached;
|
var state = tile.cached;
|
||||||
if (state == null) state = tile.cached = new TerminalState(monitor.getTerminal());
|
if (state == null) state = tile.cached = TerminalState.create(monitor.getTerminal());
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ public record EncodedAudio(int charge, int strength, boolean previousBit, ByteBu
|
|||||||
buf.writeVarInt(charge());
|
buf.writeVarInt(charge());
|
||||||
buf.writeVarInt(strength());
|
buf.writeVarInt(strength());
|
||||||
buf.writeBoolean(previousBit());
|
buf.writeBoolean(previousBit());
|
||||||
|
buf.writeVarInt(audio.remaining());
|
||||||
buf.writeBytes(audio().duplicate());
|
buf.writeBytes(audio().duplicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +30,8 @@ public record EncodedAudio(int charge, int strength, boolean previousBit, ByteBu
|
|||||||
var strength = buf.readVarInt();
|
var strength = buf.readVarInt();
|
||||||
var previousBit = buf.readBoolean();
|
var previousBit = buf.readBoolean();
|
||||||
|
|
||||||
var bytes = new byte[buf.readableBytes()];
|
var length = buf.readVarInt();
|
||||||
|
var bytes = new byte[length];
|
||||||
buf.readBytes(bytes);
|
buf.readBytes(bytes);
|
||||||
|
|
||||||
return new EncodedAudio(charge, strength, previousBit, ByteBuffer.wrap(bytes));
|
return new EncodedAudio(charge, strength, previousBit, ByteBuffer.wrap(bytes));
|
||||||
|
Loading…
Reference in New Issue
Block a user