Replace `Option<ItemStack>` with `ItemStack`
rj00a opened this issue · 2 comments
rj00a commented
Describe the problem related to your feature request.
In Valence we are using Option
to indicate the emptyness of an itemstack. However, vanilla does something semantically different.
public boolean isEmpty() {
return this == EMPTY || this.item == Items.AIR || this.count <= 0;
}
This has an impact in the protocol
public PacketByteBuf writeItemStack(ItemStack stack) {
if (stack.isEmpty()) {
this.writeBoolean(false);
} else {
this.writeBoolean(true);
Item item = stack.getItem();
this.writeRegistryValue(Registries.ITEM, item);
this.writeByte(stack.getCount());
NbtCompound nbtCompound = null;
if (item.isDamageable() || item.isNbtSynced()) {
nbtCompound = stack.getNbt();
}
this.writeNbt(nbtCompound);
}
return this;
}
What solution would you like?
- Replace all occurrences of
Option<ItemStack>
withItemStack
. - Add
is_empty
method toItemStack
with same semantics as vanillaisEmpty
. - Make the item count in
ItemStack
public and ani8
. impl {Encode, Decode} for ItemStack
.
dyc3 commented
Makes sense. This could make inventories easier to work with.
IoaNNUwU commented
I'll give it a try.