From 0a4ae7e7149ea57f314096257f2ff3f16e4e2e2c Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Sun, 22 Dec 2024 08:48:46 +0100 Subject: [PATCH] fix: stream codec for machine references (Hopefully) Closes #1254 --- .../api/common/data/MachineReference.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/klikli_dev/occultism/api/common/data/MachineReference.java b/src/main/java/com/klikli_dev/occultism/api/common/data/MachineReference.java index 0983fa8e5..0addf6543 100644 --- a/src/main/java/com/klikli_dev/occultism/api/common/data/MachineReference.java +++ b/src/main/java/com/klikli_dev/occultism/api/common/data/MachineReference.java @@ -59,18 +59,18 @@ public class MachineReference implements INBTSerializable { ).apply(instance, MachineReference::new)); public static final StreamCodec STREAM_CODEC = OccultismExtraStreamCodecs.composite( - GlobalBlockPos.STREAM_CODEC, - (m) -> m.extractGlobalPos, - ResourceLocation.STREAM_CODEC, - (m) -> m.extractRegistryName, + ByteBufCodecs.optional(GlobalBlockPos.STREAM_CODEC), + (m) -> Optional.ofNullable(m.extractGlobalPos), + ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC), + (m) -> Optional.ofNullable(m.extractRegistryName), ByteBufCodecs.BOOL, (m) -> m.extractChunkLoaded, Direction.STREAM_CODEC, (m) -> m.extractFacing, - GlobalBlockPos.STREAM_CODEC, - (m) -> m.insertGlobalPos, - ResourceLocation.STREAM_CODEC, - (m) -> m.insertRegistryName, + ByteBufCodecs.optional(GlobalBlockPos.STREAM_CODEC), + (m) -> Optional.ofNullable(m.insertGlobalPos), + ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC), + (m) -> Optional.ofNullable(m.insertRegistryName), ByteBufCodecs.BOOL, (m) -> m.insertChunkLoaded, Direction.STREAM_CODEC, @@ -214,11 +214,10 @@ public boolean isValidFor(Level level) { @Override public boolean equals(Object obj) { - if(obj == this) + if (obj == this) return true; - if (obj instanceof MachineReference) { - MachineReference other = (MachineReference) obj; + if (obj instanceof MachineReference other) { return this.extractGlobalPos.equals(other.extractGlobalPos) && this.extractRegistryName.equals(other.extractRegistryName) && this.extractChunkLoaded == other.extractChunkLoaded &&