This commit is contained in:
Bruno Rybársky 2024-08-21 15:25:57 +02:00
parent a5dfcd4635
commit 81e3fbd5fe
3 changed files with 12 additions and 6 deletions

@ -6,7 +6,7 @@ minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3 yarn_mappings=1.21.1+build.3
loader_version=0.16.2 loader_version=0.16.2
# Mod Properties # Mod Properties
mod_version=1.4.2 mod_version=1.4.3
maven_group=systems.brn maven_group=systems.brn
archives_base_name=servershop archives_base_name=servershop
# Dependencies # Dependencies

@ -16,17 +16,20 @@ public record ItemPriceRecord(int buyPrice, int sellPrice, ItemStack stack) {
nbt.putInt("SellPrice", this.sellPrice); nbt.putInt("SellPrice", this.sellPrice);
// Serialize the ItemStack to NBT and add it to the compound // Serialize the ItemStack to NBT and add it to the compound
if (stack != null && !stack.isEmpty()) {
NbtElement stackNbt = stack.encode(wrapperLookup); NbtElement stackNbt = stack.encode(wrapperLookup);
nbt.put("ItemStack", stackNbt); // Adds the ItemStack's NBT data to the main NBT compound nbt.put("ItemStack", stackNbt); // Adds the ItemStack's NBT data to the main NBT compound
return nbt; return nbt;
} }
return null;
}
public static ItemPriceRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) { public static ItemPriceRecord fromNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapperLookup) {
int buyPrice = nbt.getInt("BuyPrice"); int buyPrice = nbt.getInt("BuyPrice");
int sellPrice = nbt.getInt("SellPrice"); int sellPrice = nbt.getInt("SellPrice");
if(sellPrice > buyPrice && buyPrice != 0) { if (sellPrice > buyPrice && buyPrice != 0) {
buyPrice = sellPrice; buyPrice = sellPrice;
} }
// Deserialize the ItemStack from the NBT // Deserialize the ItemStack from the NBT

@ -116,7 +116,10 @@ public class PriceStorage {
for (ItemStack stack : prices.keySet()) { for (ItemStack stack : prices.keySet()) {
ItemPriceRecord itemPriceRecord = prices.get(stack); ItemPriceRecord itemPriceRecord = prices.get(stack);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
nbtList.add(itemPriceRecord.toNbt(wrapperLookup)); NbtCompound compound = itemPriceRecord.toNbt(wrapperLookup);
if (compound != null) {
nbtList.add(compound);
}
} }
} }