Skip to content

Commit

Permalink
broader inventory syncing fixes #1515
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed Oct 11, 2023
1 parent 9039bba commit 52489ba
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/main/java/carpet/script/api/Inventories.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@
import java.util.Set;

import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -258,7 +255,7 @@ else if (recipe instanceof CustomRecipe)
{
// clear slot
ItemStack removedStack = inventoryLocator.inventory().removeItemNoUpdate(slot);
syncPlayerInventory(inventoryLocator, slot);
syncPlayerInventory(inventoryLocator);
return ValueConversions.of(removedStack, regs);
}
if (lv.size() < inventoryLocator.offset() + 3)
Expand All @@ -267,7 +264,7 @@ else if (recipe instanceof CustomRecipe)
ItemStack newStack = previousStack.copy();
newStack.setCount(count);
inventoryLocator.inventory().setItem(slot, newStack);
syncPlayerInventory(inventoryLocator, slot);
syncPlayerInventory(inventoryLocator);
return ValueConversions.of(previousStack, regs);
}
CompoundTag nbt = null; // skipping one argument
Expand All @@ -288,7 +285,7 @@ else if (!nbtValue.isNull())
try
{
inventoryLocator.inventory().setItem(slot, newitem.createItemStack(count, false));
syncPlayerInventory(inventoryLocator, slot);
syncPlayerInventory(inventoryLocator);
}
catch (CommandSyntaxException e)
{
Expand Down Expand Up @@ -369,11 +366,11 @@ else if (!nbtValue.isNull())
{
stack.setCount(left);
inventoryLocator.inventory().setItem(i, stack);
syncPlayerInventory(inventoryLocator, i);
syncPlayerInventory(inventoryLocator);
return Value.TRUE;
}
inventoryLocator.inventory().removeItemNoUpdate(i);
syncPlayerInventory(inventoryLocator, i);
syncPlayerInventory(inventoryLocator);
amount -= stack.getCount();
}
if (amount > 0)
Expand Down Expand Up @@ -510,15 +507,11 @@ else if (owner instanceof LivingEntity livingEntity)
});
}

private static void syncPlayerInventory(NBTSerializableValue.InventoryLocator inventory, int slot)
private static void syncPlayerInventory(NBTSerializableValue.InventoryLocator inventory)
{
if (inventory.owner() instanceof final ServerPlayer player && !inventory.isEnder() && !(inventory.inventory() instanceof ScreenValue.ScreenHandlerInventory))
if (inventory.owner() instanceof ServerPlayer player && !inventory.isEnder() && !(inventory.inventory() instanceof ScreenValue.ScreenHandlerInventory))
{
player.connection.send(new ClientboundContainerSetSlotPacket(
-2, 0, // resolve mystery argument
slot,
inventory.inventory().getItem(slot)
));
player.containerMenu.broadcastChanges();
}
}
}

0 comments on commit 52489ba

Please sign in to comment.