Jump to content

Shift-Clicking not working (transferStackInSlot() not being called)!


Recommended Posts

Posted

Help!

 

I've got this large chest tile-entity. Right now I'm trying to make it work with shift-clicking, however it doesn't...

 

It is a 12x9 inv, same as IronChest's diamond chest. Anyway, here's the problem: only items in certain slots can be shift-clicked *out* of the chest, while only certain other slots can be shift-clicked into the chest from the player...

 

 

After debugging, I realised that for the problem slots, transferStackInSlot() isn't even being called... Strange.

 

<script type="text/javascript" src="http://ideone.com/api/embed.js/link/OQhEPW"></script>

 

Here are the images:

Slots with blocks/items in them are the problem slots.

 

 

fail1.png

fail2.png

 

 

 

 

And here is the code:

 

 

package requimrar.Minecraft.RChem.Machines;

import requimrar.Minecraft.RChem.RChem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerLabBench extends Container
{
        protected TileLabBench  ThisLabBench;

        public ContainerLabBench(TileLabBench te, InventoryPlayer playerinv)
        {
                this.ThisLabBench = te;


                int i = 0;
                for (int y = 0; y < 9; y++)
                {
                        for (int x = 0; x < 12; x++)
                        {
                                addSlotToContainer(new Slot(te, i, x * 18 - 18, y * 18 - 37));
                                i++;
                        }
                }

                for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)
                {
                        addSlotToContainer(new Slot(playerinv, hotbarSlot, 9 + hotbarSlot * 18, 256 - 69));
                }
                
                int leftCol = (238 - 162) / 2 + 1;
                for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
                {
                        for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
                        {
                                addSlotToContainer(new Slot(playerinv, playerInvCol + playerInvRow * 9 + 9, 9 + playerInvCol * 18, 256 - (4 - playerInvRow) * 18
                                                                                                - 55));
                        }
                }


        }

        @Override
        public boolean canInteractWith(EntityPlayer player)
        {
                return ThisLabBench.isUseableByPlayer(player);
        }
        
        @Override
        public ItemStack transferStackInSlot(EntityPlayer p, int i)
        {
                ItemStack itemstack = null;
                Slot slot = (Slot)inventorySlots.get(i);
                if (slot != null && slot.getHasStack())
                {
                        ItemStack itemstack1 = slot.getStack();
                        itemstack = itemstack1.copy();
                        if (i < 108)
                        {
                                if (!mergeItemStack(itemstack1, 108, this.inventorySlots.size(), true))
                                {
                                        return null;
                                }
                        }
//                      else if (!mergeItemStack(itemstack1, 0, 108, false))
//                      {
//                              return null;
//                      }
                        
                        
                        if (itemstack1.stackSize == 0)
                        {
                                slot.putStack(null);
                        }
                        else
                        {
                                slot.onSlotChanged();
                        }
                        
                        if(itemstack1.stackSize == itemstack.stackSize)
                        {
                                return null;
                        }
                        
                        slot.onPickupFromSlot(p, itemstack1);
                }
                return itemstack;
        }



}

 

Thanks for your help!

Posted

The problem is most likely not in your container definition, but in your Gui definition. You most likely didn't set GuiContainer.guiLeft, GuiContainer.guiTop, GuiContainer.xSize and GuiContainer.ySize. These variables are used in the gui (GuiContainer line 385) to check if you clicked outside of the gui and if that is the case, set the slot to -999 which means that the item is dropped.

 

You don't need to set guiLeft and guiRight if the window is centered like every normal gui. initGui() will set them for you using xSize and ySize.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.