Handle optional item cost nullability

This commit is contained in:
Nassim Jahnke 2024-06-07 13:51:28 +02:00
parent 842cb8dac5
commit 1e244a126d
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 12 additions and 3 deletions

View File

@ -307,7 +307,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final Item output = handleNonEmptyItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2));
wrapper.write(Types1_20_5.ITEM, output);
final Item secondInput = handleItemToClient(wrapper.user(), wrapper.read(Types.ITEM1_20_2));
Item secondInput = wrapper.read(Types.ITEM1_20_2);
if (secondInput != null) {
secondInput = handleItemToClient(wrapper.user(), secondInput);
if (secondInput.isEmpty()) {
secondInput = null;
}
}
wrapper.write(Types1_20_5.OPTIONAL_ITEM_COST, secondInput);
wrapper.passthrough(Types.BOOLEAN); // Out of stock

View File

@ -296,8 +296,11 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
handleClientboundItem(wrapper); // Result
final Item secondInput = wrapper.read(optionalCostType);
wrapper.write(mappedOptionalCostType, handleItemToClient(wrapper.user(), secondInput));
Item secondInput = wrapper.read(optionalCostType);
if (secondInput != null) {
handleItemToClient(wrapper.user(), secondInput);
}
wrapper.write(mappedOptionalCostType, secondInput);
wrapper.passthrough(Types.BOOLEAN); // Out of stock
wrapper.passthrough(Types.INT); // Number of trade uses