small fixes

This commit is contained in:
Ell 2024-09-15 20:24:34 +02:00
parent a8d1a99e28
commit 9f55e87972
9 changed files with 14 additions and 16 deletions

View file

@ -42,7 +42,7 @@ public final class Utility {
public static final Codec<ItemStackHandler> 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++)

View file

@ -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;

View file

@ -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() {

View file

@ -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));
}

View file

@ -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));
}

View file

@ -64,8 +64,7 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
public PipeNetwork(CompoundTag nbt, HolderLookup.Provider provider) {
this();
var nodes = nbt.getList("nodes", Tag.TAG_COMPOUND);
for (var node : nodes)
for (var node : nbt.getList("nodes", Tag.TAG_INT_ARRAY))
this.graph.addVertex(Utility.readBlockPos(node));
var edges = nbt.getList("edges", Tag.TAG_COMPOUND);
for (var i = 0; i < edges.size(); i++)

View file

@ -19,8 +19,8 @@ public record PacketCraftingModuleTransfer(List<ItemStack> inputs, List<ItemStac
public static final Type<PacketCraftingModuleTransfer> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "crafting_module_transfer"));
public static final StreamCodec<RegistryFriendlyByteBuf, PacketCraftingModuleTransfer> 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

View file

@ -46,7 +46,7 @@ public record PacketGhostSlot(BlockPos pos, List<Entry> stacks) implements Custo
public record Entry(List<ItemStack> stacks, TagKey<Item> tag) {
public static final StreamCodec<RegistryFriendlyByteBuf, Entry> 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);

View file

@ -18,9 +18,9 @@ public record PacketNetworkItems(List<ItemStack> items, List<ItemStack> craftabl
public static final Type<PacketNetworkItems> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(PrettyPipes.ID, "network_items"));
public static final StreamCodec<RegistryFriendlyByteBuf, PacketNetworkItems> 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