Add screen
This commit is contained in:
parent
d7ade1a759
commit
a86c1086b7
14 changed files with 514 additions and 114 deletions
|
|
@ -0,0 +1,48 @@
|
|||
package dev.exhq.ajarc.network;
|
||||
|
||||
import dev.exhq.ajarc.Ajar;
|
||||
import dev.exhq.ajarc.computer.ComputerMenu;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record ComputerScreenUpdate(
|
||||
int windowId,
|
||||
List<String> lines,
|
||||
int rows,
|
||||
int columns
|
||||
) implements CustomPacketPayload {
|
||||
public static final StreamCodec<ByteBuf, ComputerScreenUpdate> STREAM_CODEC =
|
||||
StreamCodec.composite(
|
||||
ByteBufCodecs.VAR_INT,
|
||||
ComputerScreenUpdate::windowId,
|
||||
ByteBufCodecs.collection(ArrayList::new, ByteBufCodecs.STRING_UTF8),
|
||||
ComputerScreenUpdate::lines,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
ComputerScreenUpdate::rows,
|
||||
ByteBufCodecs.VAR_INT,
|
||||
ComputerScreenUpdate::columns,
|
||||
ComputerScreenUpdate::new
|
||||
);
|
||||
|
||||
public static final Type<ComputerScreenUpdate> TYPE = new Type<>(Ajar.identifier("screen"));
|
||||
|
||||
@Override
|
||||
public @NotNull Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public void handle(IPayloadContext iPayloadContext) {
|
||||
var menu = iPayloadContext.player().containerMenu;
|
||||
if (menu instanceof ComputerMenu computerMenu && computerMenu.containerId == windowId) {
|
||||
computerMenu.updateScreen(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue