Skip to content

Commit

Permalink
use optional item stream codec
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Apr 24, 2024
1 parent 9feaa91 commit 89f0aac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class ProgressDataImpl extends ProgressData {

buf.writeVarInt(d.input.size());
for (var stack : d.input) {
ItemStack.STREAM_CODEC.encode(buf, stack);
ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, stack);
}

buf.writeVarInt(d.output.size());
for (var stack : d.output) {
ItemStack.STREAM_CODEC.encode(buf, stack);
ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, stack);
}
}, buf -> {
var ratio = buf.readFloat();
Expand All @@ -29,13 +29,13 @@ public class ProgressDataImpl extends ProgressData {
var inputSize = buf.readVarInt();
d.input.ensureCapacity(inputSize);
for (var i = 0; i < inputSize; i++) {
d.input.add(ItemStack.STREAM_CODEC.decode(buf));
d.input.add(ItemStack.OPTIONAL_STREAM_CODEC.decode(buf));
}

var outputSize = buf.readVarInt();
d.output.ensureCapacity(outputSize);
for (var i = 0; i < outputSize; i++) {
d.output.add(ItemStack.STREAM_CODEC.decode(buf));
d.output.add(ItemStack.OPTIONAL_STREAM_CODEC.decode(buf));
}

return d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum ChiseledBookShelfProvider implements IBlockComponentProvider, IDataP

public static final IData.Type<Data> DATA = IData.createType(new ResourceLocation("chiseled_bookshelf"));
public static final StreamCodec<RegistryFriendlyByteBuf, Data> DATA_CODEC = StreamCodec.composite(
ByteBufCodecs.collection(ArrayList::new, ItemStack.STREAM_CODEC), Data::items,
ByteBufCodecs.collection(ArrayList::new, ItemStack.OPTIONAL_STREAM_CODEC), Data::items,
Data::new);

private int lastUpdateId = 0;
Expand Down

0 comments on commit 89f0aac

Please sign in to comment.