Advertisement
oxguy3

Logic to make MC creative inv function correctly

Dec 30th, 2011
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1.         if (k == 0 || k == 1) { //if left or right click
  2.                    
  3.             int stackSize = 64;
  4.             if (k == 1) { //if right click
  5.                 stackSize = 1;
  6.             }
  7.            
  8.             Slot cslot = super.getSlotAtCoords(i, j);
  9.             if (cslot!=null) { //if they actually clicked a slot
  10.                
  11.                 ItemStack slotstack = cslot.getStack();
  12.                 ItemStack pstack = mc.thePlayer.inventory.getItemStack();
  13.                
  14.                 if (slotstack!=null) { //if there is an item in that slot
  15.                        
  16.                     if(pstack==null) { //if the player is not holding an item with the cursor
  17.                            
  18.                         if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //hotbar slots
  19.                             stackSize = slotstack.stackSize;
  20.                         }
  21.                         ItemStack newstack = new ItemStack(slotstack.itemID, stackSize, slotstack.getItemDamage());
  22.                     mc.thePlayer.inventory.setItemStack(newstack);
  23.                
  24.                     if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //hotbar slots
  25.                             cslot.putStack(null);
  26.                         }
  27.                        
  28.                     } else { //if the player is holding an item with the cursor
  29.                        
  30.                         if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //hotbar slots
  31.                            
  32.                             mc.thePlayer.inventory.setItemStack(slotstack); //switch the held item with the slot item
  33.                             cslot.putStack(pstack);
  34.                            
  35.                             //if they're the same item type and they're stackable and the slot stack isn't already full
  36.                             if (pstack.isItemEqual(cslot.getStack())&&pstack.isStackable()&&cslot.getStack().stackSize<64) {
  37.                                 ItemStack cstack = cslot.getStack();
  38.                                
  39.                                 if (k == 0) { //if left click
  40.                                     while (cslot.getStack().stackSize<64&&pstack.stackSize>=1) {
  41.                                         pstack.stackSize-=1;
  42.                                         cslot.putStack(new ItemStack(cstack.itemID, cstack.stackSize+1, cstack.getItemDamage()));
  43.                                     }
  44.                                 } else { //if right click
  45.                                     pstack.stackSize-=1;
  46.                                     cslot.putStack(new ItemStack(cstack.itemID, cstack.stackSize+1, cstack.getItemDamage()));
  47.                                 }
  48.                                 if (pstack.stackSize==0) {
  49.                                     mc.thePlayer.inventory.setItemStack(null);
  50.                                 }
  51.                             }
  52.                            
  53.                         } else {
  54.                             mc.thePlayer.inventory.setItemStack(null);
  55.                         }
  56.                     }
  57.                    
  58.                 } else { //if there is not an item in that slot
  59.                    
  60.                     if (pstack!=null) { //if the player is holding an item with the cursor
  61.                        
  62.                         if (cslot.slotNumber>=72&&cslot.slotNumber<=80) { //if clicked in hotbar slots
  63.                            
  64.                             if (k == 0) { //if left click
  65.                                 cslot.putStack(pstack);
  66.                                 mc.thePlayer.inventory.setItemStack(null);
  67.                                
  68.                             } else { //if right click
  69.                                 cslot.putStack(new ItemStack(pstack.itemID, 1, pstack.getItemDamage()));
  70.                                 mc.thePlayer.inventory.setItemStack(new ItemStack(pstack.itemID, pstack.stackSize-1, pstack.getItemDamage()));
  71.                             }
  72.                            
  73.                         } else { //if clicked in item selection area
  74.                             mc.thePlayer.inventory.setItemStack(null);
  75.                            
  76.                         }
  77.                            
  78.                     }
  79.                 }
  80.             }
  81.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement