diff --git a/common/src/main/java/com/mrbysco/armorposer/client/gui/widgets/ArmorGlowWidget.java b/common/src/main/java/com/mrbysco/armorposer/client/gui/widgets/ArmorGlowWidget.java index 29f5582..def7bb1 100644 --- a/common/src/main/java/com/mrbysco/armorposer/client/gui/widgets/ArmorGlowWidget.java +++ b/common/src/main/java/com/mrbysco/armorposer/client/gui/widgets/ArmorGlowWidget.java @@ -92,6 +92,10 @@ public ArmorStand getArmorStand() { return armorStand; } + public boolean isLocked() { + return locked; + } + public void renderPose(GuiGraphics guiGraphics, int xPos, int yPos, float size) { if (armorStand != null) { InventoryScreen.renderEntityInInventory(guiGraphics, xPos, yPos, size, diff --git a/common/src/main/java/com/mrbysco/armorposer/data/RenameData.java b/common/src/main/java/com/mrbysco/armorposer/data/RenameData.java index 36b5068..0a4789e 100644 --- a/common/src/main/java/com/mrbysco/armorposer/data/RenameData.java +++ b/common/src/main/java/com/mrbysco/armorposer/data/RenameData.java @@ -1,21 +1,22 @@ package com.mrbysco.armorposer.data; +import net.minecraft.core.UUIDUtil; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.entity.decoration.ArmorStand; import net.minecraft.world.entity.player.Player; import java.util.UUID; public record RenameData(UUID entityUUID, String name) { - public void encode(FriendlyByteBuf buf) { - buf.writeUUID(entityUUID); - buf.writeUtf(name); - } - - public static RenameData decode(final FriendlyByteBuf packetBuffer) { - return new RenameData(packetBuffer.readUUID(), packetBuffer.readUtf()); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + UUIDUtil.STREAM_CODEC, + RenameData::entityUUID, + ByteBufCodecs.STRING_UTF8, + RenameData::name, + RenameData::new); public void handleData(ArmorStand armorStand, Player player) { if (!name.isEmpty() && (player.experienceLevel >= 1 || player.getAbilities().instabuild)) { diff --git a/common/src/main/java/com/mrbysco/armorposer/data/SwapData.java b/common/src/main/java/com/mrbysco/armorposer/data/SwapData.java index 5d1860b..523c75b 100644 --- a/common/src/main/java/com/mrbysco/armorposer/data/SwapData.java +++ b/common/src/main/java/com/mrbysco/armorposer/data/SwapData.java @@ -1,6 +1,7 @@ package com.mrbysco.armorposer.data; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.decoration.ArmorStand; @@ -9,13 +10,17 @@ import java.util.UUID; public record SwapData(UUID entityUUID, Action action) { - public void write(FriendlyByteBuf buf) { - buf.writeUUID(entityUUID); - buf.writeEnum(action); + public static final StreamCodec STREAM_CODEC = StreamCodec.of( + SwapData::write, + SwapData::new); + + public SwapData(final FriendlyByteBuf packetBuffer) { + this(packetBuffer.readUUID(), packetBuffer.readEnum(Action.class)); } - public static SwapData read(final FriendlyByteBuf packetBuffer) { - return new SwapData(packetBuffer.readUUID(), packetBuffer.readEnum(Action.class)); + private static void write(FriendlyByteBuf friendlyByteBuf, SwapData swapData) { + friendlyByteBuf.writeUUID(swapData.entityUUID); + friendlyByteBuf.writeEnum(swapData.action); } public void handleData(ArmorStand armorStand) { diff --git a/common/src/main/java/com/mrbysco/armorposer/data/SyncData.java b/common/src/main/java/com/mrbysco/armorposer/data/SyncData.java index 4b9d6b9..02563d8 100644 --- a/common/src/main/java/com/mrbysco/armorposer/data/SyncData.java +++ b/common/src/main/java/com/mrbysco/armorposer/data/SyncData.java @@ -1,10 +1,13 @@ package com.mrbysco.armorposer.data; import com.mrbysco.armorposer.Reference; +import net.minecraft.core.UUIDUtil; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.world.entity.ai.attributes.AttributeInstance; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.decoration.ArmorStand; @@ -13,14 +16,12 @@ import java.util.UUID; public record SyncData(UUID entityUUID, CompoundTag tag) { - public void encode(FriendlyByteBuf buf) { - buf.writeUUID(entityUUID); - buf.writeNbt(tag); - } - - public static SyncData decode(final FriendlyByteBuf packetBuffer) { - return new SyncData(packetBuffer.readUUID(), packetBuffer.readNbt()); - } + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + UUIDUtil.STREAM_CODEC, + SyncData::entityUUID, + ByteBufCodecs.COMPOUND_TAG, + SyncData::tag, + SyncData::new); public void handleData(ArmorStand armorStand, Player player) { CompoundTag entityTag = armorStand.saveWithoutId(new CompoundTag()); diff --git a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandRenamePayload.java b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandRenamePayload.java index c042155..427fb8f 100644 --- a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandRenamePayload.java +++ b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandRenamePayload.java @@ -2,7 +2,6 @@ import com.mrbysco.armorposer.Reference; import com.mrbysco.armorposer.data.RenameData; -import com.mrbysco.armorposer.data.SyncData; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; @@ -15,11 +14,11 @@ public record ArmorStandRenamePayload(RenameData data) implements CustomPacketPa public static final Type ID = new Type<>(Reference.RENAME_PACKET_ID); public ArmorStandRenamePayload(final FriendlyByteBuf packetBuffer) { - this(RenameData.decode(packetBuffer)); + this(RenameData.STREAM_CODEC.decode(packetBuffer)); } public void write(FriendlyByteBuf buf) { - data.encode(buf); + RenameData.STREAM_CODEC.encode(buf, data()); } @Override diff --git a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandScreenPayload.java b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandScreenPayload.java index 3dc827c..1721a9d 100644 --- a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandScreenPayload.java +++ b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandScreenPayload.java @@ -2,23 +2,17 @@ import com.mrbysco.armorposer.Reference; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; public record ArmorStandScreenPayload(int entityID) implements CustomPacketPayload { - public static final StreamCodec CODEC = CustomPacketPayload.codec( - ArmorStandScreenPayload::write, + public static final StreamCodec CODEC = StreamCodec.composite( + ByteBufCodecs.INT, + ArmorStandScreenPayload::entityID, ArmorStandScreenPayload::new); public static final Type ID = new Type<>(Reference.SCREEN_PACKET_ID); - public ArmorStandScreenPayload(final FriendlyByteBuf packetBuffer) { - this(packetBuffer.readInt()); - } - - public void write(FriendlyByteBuf buf) { - buf.writeInt(entityID); - } - @Override public Type type() { return ID; diff --git a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSwapPayload.java b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSwapPayload.java index e1ee0a6..d6e70b7 100644 --- a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSwapPayload.java +++ b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSwapPayload.java @@ -14,11 +14,11 @@ public record ArmorStandSwapPayload(SwapData data) implements CustomPacketPayloa public static final Type ID = new Type<>(Reference.SWAP_PACKET_ID); public ArmorStandSwapPayload(final FriendlyByteBuf packetBuffer) { - this(SwapData.read(packetBuffer)); + this(SwapData.STREAM_CODEC.decode(packetBuffer)); } public void write(FriendlyByteBuf buf) { - data.write(buf); + SwapData.STREAM_CODEC.encode(buf, data()); } @Override diff --git a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSyncPayload.java b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSyncPayload.java index 9ef4b44..9152730 100644 --- a/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSyncPayload.java +++ b/common/src/main/java/com/mrbysco/armorposer/packets/ArmorStandSyncPayload.java @@ -14,11 +14,11 @@ public record ArmorStandSyncPayload(SyncData data) implements CustomPacketPayloa public static final Type ID = new Type<>(Reference.SYNC_PACKET_ID); public ArmorStandSyncPayload(final FriendlyByteBuf packetBuffer) { - this(SyncData.decode(packetBuffer)); + this(SyncData.STREAM_CODEC.decode(packetBuffer)); } public void write(FriendlyByteBuf buf) { - data.encode(buf); + SyncData.STREAM_CODEC.encode(buf, data()); } @Override