Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

And, I have an container, that duplicates items when moving items out of it using shift click, but only when player hasn't got itemstack to merge with.

I think error is in this function. Please, help me. Only small reply. Every reply will help. I have solving this for 5 months but without result.

 

Function where is the bug.

@Override
        public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
                ItemStack stack = null;
                Slot slotObject = (Slot)inventorySlots.get(slot);
                
                if (slotObject != null && slotObject.getHasStack())
                {
                        ItemStack stackInSlot = slotObject.getStack();
                        stack = stackInSlot.copy();
                        if(slot < 9)
                        {
                        	if (!this.mergeItemStack(stackInSlot, 0, 35, true))
                        	{
                        		System.out.println("There are " + stackInSlot.stackSize + " of " + stackInSlot.getItem().getUnlocalizedName());
                        		return null;
                        	}
                        }
                        else
                        {
                        	if(!this.mergeItemStack(stackInSlot, 0, 9, false))
                        	{
                        		System.out.println("There are " + stackInSlot.stackSize + " of " + stackInSlot.getItem().getUnlocalizedName());
                        		return null;
                        	}
                		}

                        if (stackInSlot.stackSize == 0)
                        {
                                slotObject.putStack(null);
                        }
                        else
                        {
                                slotObject.onSlotChanged();
                        }

                        if (stackInSlot.stackSize == stack.stackSize)
                        {
                                return null;
                        }
                        slotObject.onPickupFromSlot(player, stackInSlot);
                }
                return stack;
        }

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

I assume that you are modifying the container of player.

Then, What is this? Why 0~35?

this.mergeItemStack(stackInSlot, 0, 35, true);

It seems that it should be 9~44.

 

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • Author

Sorry, I did't understood the code, just followed tutorial. I didn't know why is it 0, 35.

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

  • Author

And, thank you very much for answering me. :) :) :) :) :)

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

  • Author

It worked fine. And, can you explain me this method, if you can? Please...

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Sure, I'll explain the code to you, line by line.

@Override
        public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
                ItemStack stack = null;
                Slot slotObject = (Slot)inventorySlots.get(slot); //get the shift-clicked slot.
                
                if (slotObject != null && slotObject.getHasStack()) //If the slot is valid and has ItemStack
                {
                        ItemStack stackInSlot = slotObject.getStack(); //Get the Stack on the slot.
                        stack = stackInSlot.copy(); //Copy stack.
                        if(slot < 9) //If the slot is on hotbar
                        {
                        	if (!this.mergeItemStack(stackInSlot, 9, 44, true)) //Try merging the stack to the rest of the slot.
                        	{
                        		System.out.println("There are " + stackInSlot.stackSize + " of " + stackInSlot.getItem().getUnlocalizedName()); //The print statement when it is not able to merge the stack.
                        		return null; // Drop nothing.
                        	}
                        }
                        else
                        {
                        	if(!this.mergeItemStack(stackInSlot, 0, 9, false))
                        	{
                        		System.out.println("There are " + stackInSlot.stackSize + " of " + stackInSlot.getItem().getUnlocalizedName()); //The print statement when it is not able to merge the stack.
                        		return null; // Drop nothing.
                        	}
                	}

                        //When it is successfully merged,
                        if (stackInSlot.stackSize == 0) //If the slot stack size is 0
                        {
                                slotObject.putStack(null); //Set the stack to null.
                        }
                        else //Yes, da else
                        {
                                slotObject.onSlotChanged(); // Mark the slot as changed.
                        }

                        if (stackInSlot.stackSize == stack.stackSize) //When Slot stacksize is same, (So every stack has merged)
                        { 
                                return null; // Drop Nothing.
                        }
                        slotObject.onPickupFromSlot(player, stackInSlot); // Let the slot to pick up rest of the stack
                                                                                                       //    (which is not merged).
                }

                return stack; //IDK, it just returns null; So it drops nothing when no slot is found.
        }

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • Author

Well, I understood the code. Thank you very much. :)

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.