Инвентарь предмета не обновляется

Версия Minecraft
1.7.10
1,007
36
206
Если коротко, то я создал предмет с инвентарём из одного слота, в гуи есть кнопка при нажатии на которую отправляется пакет.
Код:
public class SendContractPacket implements IMessage {

   public SendContractPacket() {
        
       }

   public void fromBytes(ByteBuf buf) {
      
   }

   public void toBytes(ByteBuf buf) {
    
   }
   public static class Handler implements IMessageHandler<SendContractPacket, IMessage> {
       private ItemStack is;
       private ItemStack buyslot;
       private ItemStack money;
      
      
      
       @Override
       public IMessage onMessage(SendContractPacket packet, MessageContext message) {
           if (message.side.isClient())
               act(packet);
           else
               act(message.getServerHandler().playerEntity, packet);
           return null;
       }
      
       @SideOnly(Side.CLIENT)
       private void act(SendContractPacket message) {

       }

   private void act(EntityPlayerMP player, SendContractPacket message) {
       InventoryTerminal inventory = new InventoryTerminal(player);
       Random rand = new Random();
       if(inventory.getStackInSlot(0) != null) {
           inventory.decrStackSize(0, 1);
       ItemStack contract = new ItemStack(ContractsMod.contract);
       EntityItem drop = new EntityItem(player.worldObj, player.posX, player.posY + 1.0D, player.posZ, contract);
       player.worldObj.spawnEntityInWorld(drop);
       }
   }        
   }
Этот пакет должен забрать один предмет из слота, а затем выдать другой предмет игроку, но проблема в том, что предмет не забирается(точнее забирается, но изменения видно только если я заново открою инвентарь(короче не синхронизируется)).
Код:
public class InventoryTerminal extends InventoryBasic{

    public static final int INV_SIZE = 1;
    private final EntityPlayer owner;

    public InventoryTerminal(EntityPlayer player){
        super("container.Terminal", false, INV_SIZE);
        owner = player;
        if(!owner.getCurrentEquippedItem().hasTagCompound()){
            owner.getCurrentEquippedItem().setTagCompound(new NBTTagCompound());
        }

        readFromNBT(owner.getCurrentEquippedItem().getTagCompound());
    }

    @Override
    public void markDirty(){
        super.markDirty();
        writeToNBT(owner.getCurrentEquippedItem().getTagCompound());
    }

    @Override
    public boolean isItemValidForSlot(int index, ItemStack stack){
        return stack.getItem() == Items.paper;
    }
    
    public void takeEmeraldFromSlot() {
        NBTTagCompound nbt = owner.getCurrentEquippedItem().getTagCompound();
        readFromNBT(nbt);
          if(this.getStackInSlot(0) != null) {
             ItemStack paper = this.getStackInSlot(0);
             setInventorySlotContents(0, paper.stackSize > 1 ? new ItemStack(paper.getItem(), paper.stackSize--) : null);
          }
          writeToNBT(nbt);
          this.markDirty();
        
       }

    public void readFromNBT(NBTTagCompound compound){
        final NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);

        for(int i = 0; i < items.tagCount(); ++i){
            final NBTTagCompound item = items.getCompoundTagAt(i);
            final int slot = item.getInteger("Slot");

            if(slot >= 0 && slot < getSizeInventory()){
                setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
            }
        }
    }

    public void writeToNBT(NBTTagCompound compound){
        final NBTTagList items = new NBTTagList();

        for(int i = 0; i < getSizeInventory(); ++i){
            if(getStackInSlot(i) != null){
                final NBTTagCompound item = new NBTTagCompound();
                item.setInteger("Slot", i);
                getStackInSlot(i).writeToNBT(item);
                items.appendTag(item);
            }
        }

        compound.setTag("ItemInventory", items);
        
    }   
}
Код:
public class ContainerTerminal extends Container{

    private static final int INV_START = InventoryTerminal.INV_SIZE;
    private static final int INV_END = INV_START + 26;
    private static final int HOTBAR_START = INV_END + 1;
    private static final int HOTBAR_END = HOTBAR_START + 8;

    private final InventoryPlayer inventoryPlayer;
    private final InventoryTerminal inventoryMoneyPouch;

    public ContainerTerminal(IInventory inventoryPlayer, IInventory inventoryMoneyPouch, EntityPlayer player){
        this.inventoryPlayer = (InventoryPlayer)inventoryPlayer;
        this.inventoryMoneyPouch = (InventoryTerminal)inventoryMoneyPouch;
        
        for(int i = 0; i < INV_START; i++){
            final int x = 33;
            final int y = 65;
            addSlotToContainer(new SlotMoneyPouch(inventoryMoneyPouch, i, x, y));
        }

        for(int y = 0; y < 3; y++)
            for(int x = 0; x < 9; x++)
                addSlotToContainer(new Slot(inventoryPlayer, x + y * 9 + 9, 8 + x * 18, 89 + y * 18));

        for(int i = 0; i < 9; i++)
            addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 147));
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer playerIn){
        return inventoryMoneyPouch.isUseableByPlayer(playerIn);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index){
        ItemStack itemStack = null;
        final Slot slot = (Slot)inventorySlots.get(index);

        if(slot != null && slot.getHasStack()){
            final ItemStack itemStack1 = slot.getStack();
            itemStack = itemStack1.copy();

            // If item is in the moneypouch
            if(index < INV_START){
                // Try to place in player inventory
                if(!mergeItemStack(itemStack1, INV_START, HOTBAR_END + 1, true))
                    return null;

                slot.onSlotChange(itemStack1, itemStack);
            }else{
                // If item is a CashCraft coin or note, try to place in money pouch
                boolean result = false;
                if(itemStack1.getItem() == Items.paper)
                    result = mergeItemStack(itemStack1, 0, inventoryMoneyPouch.getSizeInventory(), false);

                // Otherwise swap between player inventory and hotbar
                if(!result)
                    if(index >= INV_START && index <= INV_END){
                        if(!mergeItemStack(itemStack1, HOTBAR_START, HOTBAR_END + 1, false))
                            return null;
                    }else if(index >= HOTBAR_START && index <= HOTBAR_END)
                        if(!mergeItemStack(itemStack1, INV_START, INV_END + 1, false))
                            return null;
            }

            if(itemStack1.stackSize == 0)
                slot.putStack((ItemStack)null);
            else
                slot.onSlotChanged();

            if(itemStack1.stackSize == itemStack.stackSize)
                return null;

            slot.onPickupFromSlot(playerIn, itemStack1);
        }
        return itemStack;
    }

    @Override
    public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player){
        // This will prevent the player interacting with the moneypouch that opened this inventory
        if(slotId >= 0 && getSlot(slotId) != null && getSlot(slotId).getStack() == player.getHeldItem())
            return null;
        return super.slotClick(slotId, dragType, clickTypeIn, player);
    }

    public class SlotMoneyPouch extends Slot{

        public SlotMoneyPouch(IInventory inventoryIn, int index, int xPosition, int yPosition){
            super(inventoryIn, index, xPosition, yPosition);
        }

        @Override
        public boolean isItemValid(ItemStack stack){
            return stack.getItem() == Items.paper;
        }
    }
}
 
7,099
324
1,509
ContainerTerminal#enchantItem чекни- это как actionPerformed, но на стороне сервера
 
Сверху