From 31f2d65dd48c9a69d1807157b6564069cfd12424 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Tue, 20 Aug 2024 16:19:22 +0200 Subject: [PATCH] fix forester and worker inv --- gradle.properties | 2 +- .../api/inventory/InventoryCitizen.java | 89 ++++++------------- .../api/util/constant/NbtTagConstants.java | 1 + .../colony/crafting/RecipeStorageFactory.java | 2 +- .../production/EntityAIWorkLumberjack.java | 2 +- 5 files changed, 33 insertions(+), 63 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8fa73bd10a8..be36983659f 100755 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ minecraft_range=[1.21, 1.22) dataGeneratorsVersion=1.20.4-0.1.57-ALPHA blockUI_version=1.21.1-1.0.182-beta -structurize_version=1.0.747-1.21.1-beta +structurize_version=1.0.750-1.21.1-beta domumOrnamentumVersion=1.21.1-1.0.200-BETA multiPistonVersion=1.21-1.2.47-BETA diff --git a/src/main/java/com/minecolonies/api/inventory/InventoryCitizen.java b/src/main/java/com/minecolonies/api/inventory/InventoryCitizen.java index d95b2a45e5b..086b279783f 100755 --- a/src/main/java/com/minecolonies/api/inventory/InventoryCitizen.java +++ b/src/main/java/com/minecolonies/api/inventory/InventoryCitizen.java @@ -550,8 +550,9 @@ public void write(@NotNull final HolderLookup.Provider provider, final CompoundT if (!(this.mainInventory.get(i)).isEmpty()) { final CompoundTag compoundNBT = new CompoundTag(); - compoundNBT.putByte("Slot", (byte) i); - invTagList.add(this.mainInventory.get(i).saveOptional(provider)); + compoundNBT.putByte(NbtTagConstants.SLOT, (byte) i); + compoundNBT.put(NbtTagConstants.STACK, this.mainInventory.get(i).saveOptional(provider)); + invTagList.add(compoundNBT); freeSlots--; } } @@ -563,7 +564,7 @@ public void write(@NotNull final HolderLookup.Provider provider, final CompoundT if (!(this.armorInventory.get(i)).isEmpty()) { final CompoundTag compoundNBT = new CompoundTag(); - compoundNBT.putByte("Slot", (byte) i); + compoundNBT.putByte(NbtTagConstants.SLOT, (byte) i); compoundNBT.put(NbtTagConstants.STACK, this.armorInventory.get(i).saveOptional(provider)); armorTagList.add(compoundNBT); } @@ -578,76 +579,44 @@ public void write(@NotNull final HolderLookup.Provider provider, final CompoundT */ public void read(@NotNull final HolderLookup.Provider provider, final CompoundTag nbtTagCompound) { - if (nbtTagCompound.contains(TAG_ARMOR_INVENTORY)) + int size = nbtTagCompound.getInt(TAG_INV_SIZE); + if (this.mainInventory.size() < size) { - int size = nbtTagCompound.getInt(TAG_INV_SIZE); - if (this.mainInventory.size() < size) - { - size -= size % ROW_SIZE; - this.mainInventory = NonNullList.withSize(size, ItemStackUtils.EMPTY); - } - - freeSlots = mainInventory.size(); + size -= size % ROW_SIZE; + this.mainInventory = NonNullList.withSize(size, ItemStackUtils.EMPTY); + } - final ListTag nbtTagList = nbtTagCompound.getList(TAG_INVENTORY, 10); - for (int i = 0; i < nbtTagList.size(); i++) - { - final CompoundTag compoundNBT = nbtTagList.getCompound(i); - final int j = compoundNBT.getByte("Slot") & 255; - final ItemStack itemstack = ItemStack.parseOptional(provider, compoundNBT); + freeSlots = mainInventory.size(); - if (!itemstack.isEmpty()) - { - if (j < this.mainInventory.size()) - { - this.mainInventory.set(j, itemstack); - freeSlots--; - } - } - } + final ListTag nbtTagList = nbtTagCompound.getList(TAG_INVENTORY, 10); + for (int i = 0; i < nbtTagList.size(); i++) + { + final CompoundTag compoundNBT = nbtTagList.getCompound(i); + final int j = compoundNBT.getByte(NbtTagConstants.SLOT) & 255; + final ItemStack itemstack = ItemStack.parseOptional(provider, compoundNBT.getCompound(NbtTagConstants.STACK)); - final ListTag armorTagList = nbtTagCompound.getList(TAG_ARMOR_INVENTORY, 10); - for (int i = 0; i < armorTagList.size(); ++i) + if (!itemstack.isEmpty()) { - final CompoundTag compoundNBT = armorTagList.getCompound(i); - final int j = compoundNBT.getByte("Slot") & 255; - final ItemStack itemstack = ItemStack.parseOptional(provider, compoundNBT.getCompound(NbtTagConstants.STACK)); - - if (!itemstack.isEmpty()) + if (j < this.mainInventory.size()) { - if (j < this.armorInventory.size()) - { - this.armorInventory.set(j, itemstack); - } + this.mainInventory.set(j, itemstack); + freeSlots--; } } } - else - { - final ListTag nbtTagList = nbtTagCompound.getList(TAG_INVENTORY, 10); - if (this.mainInventory.size() < nbtTagList.getCompound(0).getInt(TAG_SIZE)) - { - int size = nbtTagList.getCompound(0).getInt(TAG_SIZE); - size -= size % ROW_SIZE; - this.mainInventory = NonNullList.withSize(size, ItemStackUtils.EMPTY); - } - freeSlots = mainInventory.size(); + final ListTag armorTagList = nbtTagCompound.getList(TAG_ARMOR_INVENTORY, 10); + for (int i = 0; i < armorTagList.size(); ++i) + { + final CompoundTag compoundNBT = armorTagList.getCompound(i); + final int j = compoundNBT.getByte(SLOT) & 255; + final ItemStack itemstack = ItemStack.parseOptional(provider, compoundNBT.getCompound(NbtTagConstants.STACK)); - for (int i = 1; i < nbtTagList.size(); i++) + if (!itemstack.isEmpty()) { - final CompoundTag compoundNBT = nbtTagList.getCompound(i); - - final int j = compoundNBT.getByte("Slot") & 255; - final ItemStack itemstack = ItemStack.parseOptional(provider, compoundNBT); - - if (!itemstack.isEmpty()) + if (j < this.armorInventory.size()) { - if (j < this.mainInventory.size()) - { - this.mainInventory.set(j, itemstack); - freeSlots--; - } + this.armorInventory.set(j, itemstack); } } } diff --git a/src/main/java/com/minecolonies/api/util/constant/NbtTagConstants.java b/src/main/java/com/minecolonies/api/util/constant/NbtTagConstants.java index ef7573fd861..ef680983210 100755 --- a/src/main/java/com/minecolonies/api/util/constant/NbtTagConstants.java +++ b/src/main/java/com/minecolonies/api/util/constant/NbtTagConstants.java @@ -34,6 +34,7 @@ public final class NbtTagConstants public static final String TAG_CHUNK_CLAIM = "chunkclaimdata"; public static final String TAG_CHUNK_POS = "chunkpos"; public static final String STACK = "stack"; + public static final String SLOT = "slot"; /** * @deprecated Superseeded by request-based pickup system. diff --git a/src/main/java/com/minecolonies/core/colony/crafting/RecipeStorageFactory.java b/src/main/java/com/minecolonies/core/colony/crafting/RecipeStorageFactory.java index 1f2feb6aec7..3cab968d1d4 100755 --- a/src/main/java/com/minecolonies/core/colony/crafting/RecipeStorageFactory.java +++ b/src/main/java/com/minecolonies/core/colony/crafting/RecipeStorageFactory.java @@ -185,7 +185,7 @@ public RecipeStorage deserialize(@NotNull final HolderLookup.Provider provider, } } - final ItemStack primaryOutput = ItemStack.parseOptional(provider, nbt); + final ItemStack primaryOutput = ItemStack.parseOptional(provider, nbt.getCompound(NbtTagConstants.STACK)); final Block intermediate = NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), nbt.getCompound(BLOCK_TAG)).getBlock(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java index dff78f32343..d6d66db2f7f 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java @@ -926,7 +926,7 @@ else if (sapling.is(fungi)) } } - if (!(block instanceof SpecialPlantable && block.canSustainPlant(world.getBlockState(pos.below()), world, pos.below(), Direction.UP, block.defaultBlockState()).isTrue()) + if (!(block instanceof SaplingBlock) || block.canSustainPlant(world.getBlockState(pos.below()), world, pos.below(), Direction.UP, block.defaultBlockState()).isFalse() || Objects.equals(world.getBlockState(pos), block.defaultBlockState())) { job.getTree().removeStump(pos);