From 81e3fbd5fe82ffbce27710628527a754340ceeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Wed, 21 Aug 2024 15:25:57 +0200 Subject: [PATCH] Bugfix --- gradle.properties | 2 +- .../brn/servershop/lib/records/ItemPriceRecord.java | 11 +++++++---- .../brn/servershop/lib/storages/PriceStorage.java | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index f6dc480..0ff3705 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.21.1 yarn_mappings=1.21.1+build.3 loader_version=0.16.2 # Mod Properties -mod_version=1.4.2 +mod_version=1.4.3 maven_group=systems.brn archives_base_name=servershop # Dependencies diff --git a/src/main/java/systems/brn/servershop/lib/records/ItemPriceRecord.java b/src/main/java/systems/brn/servershop/lib/records/ItemPriceRecord.java index 356e77b..43a0598 100644 --- a/src/main/java/systems/brn/servershop/lib/records/ItemPriceRecord.java +++ b/src/main/java/systems/brn/servershop/lib/records/ItemPriceRecord.java @@ -16,17 +16,20 @@ public record ItemPriceRecord(int buyPrice, int sellPrice, ItemStack stack) { nbt.putInt("SellPrice", this.sellPrice); // Serialize the ItemStack to NBT and add it to the compound - NbtElement stackNbt = stack.encode(wrapperLookup); - nbt.put("ItemStack", stackNbt); // Adds the ItemStack's NBT data to the main NBT compound + if (stack != null && !stack.isEmpty()) { + NbtElement stackNbt = stack.encode(wrapperLookup); + nbt.put("ItemStack", stackNbt); // Adds the ItemStack's NBT data to the main NBT compound + return nbt; + } + return null; - return nbt; } public static ItemPriceRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { int buyPrice = nbt.getInt("BuyPrice"); int sellPrice = nbt.getInt("SellPrice"); - if(sellPrice > buyPrice && buyPrice != 0) { + if (sellPrice > buyPrice && buyPrice != 0) { buyPrice = sellPrice; } // Deserialize the ItemStack from the NBT diff --git a/src/main/java/systems/brn/servershop/lib/storages/PriceStorage.java b/src/main/java/systems/brn/servershop/lib/storages/PriceStorage.java index 0b15efe..8fa25e2 100644 --- a/src/main/java/systems/brn/servershop/lib/storages/PriceStorage.java +++ b/src/main/java/systems/brn/servershop/lib/storages/PriceStorage.java @@ -116,7 +116,10 @@ public class PriceStorage { for (ItemStack stack : prices.keySet()) { ItemPriceRecord itemPriceRecord = prices.get(stack); if (!stack.isEmpty()) { - nbtList.add(itemPriceRecord.toNbt(wrapperLookup)); + NbtCompound compound = itemPriceRecord.toNbt(wrapperLookup); + if (compound != null) { + nbtList.add(compound); + } } }