thomasfn

PickupHandler.java

May 28th, 2012
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package ee.core;
  2.  
  3. import ee.item.ItemLootBall;
  4. import forge.ForgeHooks;
  5. import forge.IPickupHandler;
  6. import net.minecraft.server.*;
  7.  
  8. public class PickupHandler
  9.     implements IPickupHandler
  10. {
  11.  
  12.     public PickupHandler()
  13.     {
  14.     }
  15.  
  16.     public boolean onItemPickup(EntityHuman ply, EntityItem item)
  17.     {
  18.         // Get the stack we picked up
  19.         ItemStack stack = item.itemStack;
  20.        
  21.         // Check it's valid
  22.         if(stack != null && stack.count > 0)
  23.         {
  24.             // Check if it's a loot ball
  25.             if(!(item.itemStack.getItem() instanceof ItemLootBall))
  26.                 return true;
  27.            
  28.             // Get the list of items inside the loot ball
  29.             ItemLootBall lootball = (ItemLootBall)stack.getItem();
  30.             ItemStack droplist[] = lootball.getDroplist(stack);
  31.            
  32.             // Check if the items list exists
  33.             if(droplist != null)
  34.             {
  35.                 //EntityItem var6 = new EntityItem(ply.world, ply.locX, ply.locY, ply.locZ, null);
  36.                
  37.                 // Loop through each drop stack
  38.                 int cnt = droplist.length;
  39.                 for(int i = 0; i < cnt; i++)
  40.                 {
  41.                     // Get the drop stack
  42.                     ItemStack drop = droplist[i];
  43.                    
  44.                     // Create a new item
  45.                     EntityItem newitem = new EntityItem(ply.world, ply.locX, ply.locY, ply.locZ, drop);
  46.                    
  47.                     // Drop the item at the player's foot, if not picked up
  48.                     if(ForgeHooks.onItemPickup(ply, newitem) && !ply.inventory.pickup(newitem.itemStack))
  49.                         ply.drop(newitem.itemStack);
  50.                 }
  51.  
  52.             }
  53.            
  54.             // The stack is now empty!
  55.             stack.count = 0;
  56.             return false;
  57.         } else
  58.         {
  59.             return false;
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment