Enginecrafter Posted April 5, 2015 Posted April 5, 2015 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; } Quote 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.
Abastro Posted April 5, 2015 Posted April 5, 2015 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. Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
Enginecrafter Posted April 5, 2015 Author Posted April 5, 2015 Sorry, I did't understood the code, just followed tutorial. I didn't know why is it 0, 35. Quote 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.
Enginecrafter Posted April 5, 2015 Author Posted April 5, 2015 And, thank you very much for answering me. :) :) Quote 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.
Enginecrafter Posted April 5, 2015 Author Posted April 5, 2015 It worked fine. And, can you explain me this method, if you can? Please... Quote 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.
Abastro Posted April 6, 2015 Posted April 6, 2015 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. } Quote I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
Enginecrafter Posted April 6, 2015 Author Posted April 6, 2015 Well, I understood the code. Thank you very much. Quote 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.
Recommended Posts
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.