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 lines, int rows, int columns ) implements CustomPacketPayload { public static final StreamCodec 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 TYPE = new Type<>(Ajar.identifier("screen")); @Override public @NotNull Type type() { return TYPE; } public void handle(IPayloadContext iPayloadContext) { var menu = iPayloadContext.player().containerMenu; if (menu instanceof ComputerMenu computerMenu && computerMenu.containerId == windowId) { computerMenu.updateScreen(this); } } }