Skip to content

Commit

Permalink
fix forester and worker inv
Browse files Browse the repository at this point in the history
  • Loading branch information
Raycoms committed Aug 20, 2024
1 parent 7f3bce0 commit 31f2d65
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 63 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
89 changes: 29 additions & 60 deletions src/main/java/com/minecolonies/api/inventory/InventoryCitizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 31f2d65

Please sign in to comment.