diff --git a/src/main/java/de/ellpeck/prettypipes/Utility.java b/src/main/java/de/ellpeck/prettypipes/Utility.java index 70c8ba5..de44c34 100644 --- a/src/main/java/de/ellpeck/prettypipes/Utility.java +++ b/src/main/java/de/ellpeck/prettypipes/Utility.java @@ -42,7 +42,7 @@ public final class Utility { public static final Codec ITEM_STACK_HANDLER_CODEC = RecordCodecBuilder.create(builder -> builder.group( Codec.INT.fieldOf("size").forGetter(h -> h.getSlots()), - Codec.list(ItemStack.CODEC).fieldOf("items").forGetter(h -> IntStream.range(0, h.getSlots()).mapToObj(h::getStackInSlot).toList()) + Codec.list(ItemStack.OPTIONAL_CODEC).fieldOf("items").forGetter(h -> IntStream.range(0, h.getSlots()).mapToObj(h::getStackInSlot).toList()) ).apply(builder, (size, items) -> { var ret = new ItemStackHandler(size); for (var i = 0; i < items.size(); i++) diff --git a/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java b/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java index b64f78d..409f5b1 100644 --- a/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java +++ b/src/main/java/de/ellpeck/prettypipes/compat/jei/JEIPrettyPipesPlugin.java @@ -103,7 +103,7 @@ public class JEIPrettyPipesPlugin implements IModPlugin { } @SubscribeEvent - public void onClientTick(ClientTickEvent event) { + public void onClientTick(ClientTickEvent.Pre event) { if (!PlayerPrefs.get().syncJei) return; diff --git a/src/main/java/de/ellpeck/prettypipes/misc/DirectionSelector.java b/src/main/java/de/ellpeck/prettypipes/misc/DirectionSelector.java index e0b94ef..9e2e99c 100644 --- a/src/main/java/de/ellpeck/prettypipes/misc/DirectionSelector.java +++ b/src/main/java/de/ellpeck/prettypipes/misc/DirectionSelector.java @@ -5,6 +5,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.pipe.PipeBlockEntity; +import joptsimple.internal.Strings; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.core.Direction; import net.minecraft.core.component.DataComponentType; @@ -68,13 +69,13 @@ public class DirectionSelector { if (!this.modified) return; this.modified = false; - this.stack.set(Data.TYPE, new Data(this.direction.getName())); + this.stack.set(Data.TYPE, new Data(this.direction != null ? this.direction.getName() : "")); } public void load() { var data = this.stack.get(Data.TYPE); if (data != null) - this.direction = Direction.byName(data.direction); + this.direction = !Strings.isNullOrEmpty(data.direction) ? Direction.byName(data.direction) : null; } public Direction[] directions() { diff --git a/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java b/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java index b8dfcf9..3f9efe5 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java +++ b/src/main/java/de/ellpeck/prettypipes/network/NetworkEdge.java @@ -45,8 +45,7 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable @Override public void deserializeNBT(HolderLookup.Provider provider, CompoundTag nbt) { this.pipes.clear(); - var list = nbt.getList("pipes", Tag.TAG_COMPOUND); - for (var tag : list) + for (var tag : nbt.getList("pipes", Tag.TAG_INT_ARRAY)) this.pipes.add(Utility.readBlockPos(tag)); } diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java index 8098ef5..43bb248 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeItem.java @@ -274,8 +274,7 @@ public class PipeItem implements IPipeItem { this.y = nbt.getFloat("y"); this.z = nbt.getFloat("z"); this.path.clear(); - var list = nbt.getList("path", Tag.TAG_COMPOUND); - for (var tag : list) + for (var tag : nbt.getList("path", Tag.TAG_INT_ARRAY)) this.path.add(Utility.readBlockPos(tag)); } diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index 03e2573..c3af28a 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -64,8 +64,7 @@ public class PipeNetwork extends SavedData implements GraphListener inputs, List TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "crafting_module_transfer")); public static final StreamCodec CODEC = StreamCodec.composite( - ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketCraftingModuleTransfer::inputs, - ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketCraftingModuleTransfer::outputs, + ItemStack.LIST_STREAM_CODEC, PacketCraftingModuleTransfer::inputs, + ItemStack.LIST_STREAM_CODEC, PacketCraftingModuleTransfer::outputs, PacketCraftingModuleTransfer::new); @Override diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java index c06aef7..b1f50fa 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketGhostSlot.java @@ -46,7 +46,7 @@ public record PacketGhostSlot(BlockPos pos, List stacks) implements Custo public record Entry(List stacks, TagKey tag) { public static final StreamCodec CODEC = StreamCodec.composite( - ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), Entry::stacks, + ItemStack.OPTIONAL_LIST_STREAM_CODEC, Entry::stacks, ByteBufCodecs.fromCodec(TagKey.codec(Registries.ITEM)), Entry::tag, Entry::new); diff --git a/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java b/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java index daee1df..a708a8e 100644 --- a/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java +++ b/src/main/java/de/ellpeck/prettypipes/packets/PacketNetworkItems.java @@ -18,9 +18,9 @@ public record PacketNetworkItems(List items, List craftabl public static final Type TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "network_items")); public static final StreamCodec CODEC = StreamCodec.composite( - ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketNetworkItems::items, - ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketNetworkItems::craftables, - ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), PacketNetworkItems::currentlyCrafting, + ItemStack.LIST_STREAM_CODEC, PacketNetworkItems::items, + ItemStack.LIST_STREAM_CODEC, PacketNetworkItems::craftables, + ItemStack.LIST_STREAM_CODEC, PacketNetworkItems::currentlyCrafting, PacketNetworkItems::new); @Override