From 6214f7569910b9bd8fec10c1c3a7a9ef0bf53ad6 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Wed, 24 Apr 2024 03:53:42 -0400 Subject: [PATCH] Use nullable helper methods --- .../mc/protocol/codec/MinecraftCodecHelper.java | 2 +- .../inventory/ClientboundMerchantOffersPacket.java | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java index 9a244015..53fa69c4 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java +++ b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java @@ -359,7 +359,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper { this.writeVarInt(buf, item.getAmount()); DataComponents dataComponents = item.getDataComponents(); - if (item.getDataComponents() == null) { + if (dataComponents == null) { this.writeVarInt(buf, 0); return; } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/inventory/ClientboundMerchantOffersPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/inventory/ClientboundMerchantOffersPacket.java index 3fe2853a..74d1e001 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/inventory/ClientboundMerchantOffersPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/inventory/ClientboundMerchantOffersPacket.java @@ -31,10 +31,7 @@ public class ClientboundMerchantOffersPacket implements MinecraftPacket { for (int i = 0; i < trades.length; i++) { ItemStack firstInput = helper.readTradeItemStack(in); ItemStack output = helper.readOptionalItemStack(in); - ItemStack secondInput = null; - if (in.readBoolean()) { - secondInput = helper.readTradeItemStack(in); - } + ItemStack secondInput = helper.readNullable(in, helper::readTradeItemStack); boolean tradeDisabled = in.readBoolean(); int numUses = in.readInt(); @@ -61,10 +58,7 @@ public class ClientboundMerchantOffersPacket implements MinecraftPacket { for (VillagerTrade trade : this.trades) { helper.writeTradeItemStack(out, trade.getFirstInput()); helper.writeOptionalItemStack(out, trade.getOutput()); - out.writeBoolean(trade.getSecondInput() != null); - if (trade.getSecondInput() != null) { - helper.writeTradeItemStack(out, trade.getSecondInput()); - } + helper.writeNullable(out, trade.getSecondInput(), helper::writeTradeItemStack); out.writeBoolean(trade.isTradeDisabled()); out.writeInt(trade.getNumUses());