Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * An override mouse click method to add control when using the creative inv. hack
- *
- * @author oxguy3
- */
- protected void mouseClicked(int i, int j, int k)
- {
- if (mc.playerController.isInCreativeMode()||!mc.thePlayer.shouldShowCreativeInventory) { //if not using the hack to get creative inv, or legitimately in creative gamemode
- super.mouseClicked(i, j, k); //use the vanilla code instead of my shit
- } else { //if using the hack to get creative inv
- if (mc.thePlayer instanceof EntityPlayerSP) { //if in SSP
- //super.super.mouseClicked(i, j, k);
- if (k == 0 || k == 1) { //if left or right click
- int stackSize = 64;
- if (k == 1) { //if right click
- stackSize = 1;
- }
- Slot cslot = super.getSlotAtCoords(i, j);
- if (cslot!=null) { //if they actually clicked a slot
- ItemStack slotstack = cslot.getStack();
- ItemStack pstack = mc.thePlayer.inventory.getItemStack();
- if (slotstack!=null) { //if there is an item in that slot
- if(pstack==null) { //if the player is not holding an item with the cursor
- if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //if hotbar slots, use the stack's size instead of 64
- stackSize = slotstack.stackSize;
- }
- if (k == 1 && stackSize > 1) { //if right click and there's more than 1 item, only use half of the stack
- stackSize = stackSize/2;
- }
- mc.thePlayer.inventory.setItemStack(new ItemStack(slotstack.itemID, stackSize, slotstack.getItemDamage()));
- if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //hotbar slots
- if (k == 1 && stackSize > 1) { //if right click and there's more than 1 item
- int newslotsize = slotstack.stackSize-stackSize; //take what was left after halving the stack
- cslot.putStack(new ItemStack(slotstack.itemID, newslotsize, slotstack.getItemDamage())); //put that remainder back in the slot
- } else { //if left click
- cslot.putStack(null); //remove the stack from the slot
- }
- }
- } else { //if the player is holding an item with the cursor
- if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //if clicked in the hotbar slots
- //if they're the same item type and they're stackable and the slot stack isn't already full
- if (pstack.isItemEqual(cslot.getStack())&&pstack.isStackable()&&cslot.getStack().stackSize<64) {
- ItemStack cstack = cslot.getStack();
- if (k == 0) { //if left click
- while (cslot.getStack().stackSize<64&&pstack.stackSize>=1) { //while the slot isnt full and the hand isnt empty
- pstack.stackSize-=1;
- //N.B. the 2nd param for the ItemStack constructor should NOT be changed to cstack!!!
- cslot.putStack(new ItemStack(cstack.itemID, cslot.getStack().stackSize+1, cstack.getItemDamage()));
- }
- } else { //if right click
- pstack.stackSize-=1;
- cslot.putStack(new ItemStack(cstack.itemID, cstack.stackSize+1, cstack.getItemDamage()));
- }
- if (pstack.stackSize==0) { //destroy the held stack if its empty, or else it'll generate dupes
- mc.thePlayer.inventory.setItemStack(null);
- }
- } else { //if the items aren't the same, and should simply be swapped
- ItemStack swappy = pstack.copy();
- mc.thePlayer.inventory.setItemStack(slotstack); //switch the held item with the slot item
- cslot.putStack(pstack);
- }
- } else { //if not in the hotbar slots
- if (k == 0) { //if left click
- mc.thePlayer.inventory.setItemStack(null);
- } else { //if right click
- mc.thePlayer.inventory.setItemStack(new ItemStack(pstack.itemID, pstack.stackSize-1, pstack.getItemDamage()));
- }
- }
- }
- } else { //if there is not an item in that slot
- if (pstack!=null) { //if the player is holding an item with the cursor
- if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //if clicked in hotbar slots
- if (k == 0) { //if left click
- cslot.putStack(pstack);
- mc.thePlayer.inventory.setItemStack(null);
- } else { //if right click
- cslot.putStack(new ItemStack(pstack.itemID, 1, pstack.getItemDamage()));
- mc.thePlayer.inventory.setItemStack(new ItemStack(pstack.itemID, pstack.stackSize-1, pstack.getItemDamage()));
- //this code has been moved to the end of the hotbar slots IF statement
- /*if (pstack.stackSize==0) { //destroy the held stack if its empty, or else it'll generate dupes
- mc.thePlayer.inventory.setItemStack(null);
- }*/
- }
- } else { //if not in the hotbar slots
- if (k == 0) { //if left click
- mc.thePlayer.inventory.setItemStack(null);
- } else { //if right click
- mc.thePlayer.inventory.setItemStack(new ItemStack(pstack.itemID, pstack.stackSize-1, pstack.getItemDamage()));
- }
- }
- if (pstack.stackSize==0) { //destroy the held stack if its empty, or else it'll generate dupes
- mc.thePlayer.inventory.setItemStack(null);
- }
- }
- }
- }
- }
- } else { //if in SMP
- super.mouseClicked(i, j, k);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment