Advertisement
Guest User

AlmostDropper

a guest
Dec 9th, 2013
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.89 KB | None | 0 0
  1. package almostMinecraft;
  2.  
  3. import net.minecraft.block.BlockDropper;
  4. import net.minecraft.block.BlockSourceImpl;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.inventory.IInventory;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.tileentity.TileEntityDispenser;
  10. import net.minecraft.tileentity.TileEntityHopper;
  11. import net.minecraft.util.ChatMessageComponent;
  12. import net.minecraft.util.ChunkCoordinates;
  13. import net.minecraft.util.Facing;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.event.entity.player.PlayerEvent;
  16.  
  17. public class BlockAlmostDropper extends BlockDropper{
  18.  
  19.  
  20.     public static final int Default_ID = 2935;
  21.    
  22.     protected BlockAlmostDropper(int par1) {
  23.         super(par1);
  24.     }
  25.    
  26.     @Override
  27.     protected void dispense(World par1World, int x, int y, int z)
  28.     {
  29.         //source block
  30.         BlockSourceImpl blocksourceimpl = new BlockSourceImpl(par1World, x, y, z);
  31.        
  32.         //this dispenser
  33.         TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
  34.  
  35.         //if this is not null
  36.         if (tileentitydispenser != null)
  37.         {
  38.             //select one of the used inventory slots randomly
  39.             int l = tileentitydispenser.getRandomStackFromInventory();
  40.  
  41.             //if there is nothing (l returned -1)
  42.             if (l < 0)
  43.             {
  44.                 //play the "nothing there" sound
  45.                 par1World.playAuxSFX(1001, x, y, z, 0);
  46.             }
  47.             else
  48.             {
  49.                 //otherwise, get an actual item from that slot.
  50.                 ItemStack itemstack = tileentitydispenser.getStackInSlot(l);
  51.                
  52.                 //this is the block metadata with a four bit bitmask
  53.                 //because of the &7, only the last four bits of the number are stored
  54.                 //this is the same as:
  55.                 //int i1 = par1World.getBlockMetadata(x, y, z) % 8;
  56.                 //this metadata is the direction the block is facing
  57.                 int i1 = par1World.getBlockMetadata(x, y, z) & 7;
  58.                
  59.                 //get the inventory of the block to the direction
  60.                 IInventory iinventory = TileEntityHopper.getInventoryAtLocation(par1World, (double)(x + Facing.offsetsXForSide[i1]), (double)(y + Facing.offsetsYForSide[i1]), (double)(z + Facing.offsetsZForSide[i1]));
  61.                 ItemStack itemstack1;
  62.                
  63.                 //if there is an inventory in this direction, fill it
  64.                 if (iinventory != null)
  65.                 {
  66.                     itemstack1 = TileEntityHopper.insertStack(iinventory, itemstack.copy().splitStack(1), Facing.oppositeSide[i1]);
  67.  
  68.                     if (itemstack1 == null)
  69.                     {
  70.                         itemstack1 = itemstack.copy();
  71.  
  72.                         if (--itemstack1.stackSize == 0)
  73.                         {
  74.                             itemstack1 = null;
  75.                         }
  76.                     }
  77.                     else
  78.                     {
  79.                         itemstack1 = itemstack.copy();
  80.                     }
  81.                 }
  82.                 else
  83.                 {//otherwise, perform default dispense!
  84.                    
  85.                     //first, we parasitically use the first player in the world list.
  86.                     //(change this later)
  87.                     World world=Minecraft.getMinecraft().theWorld;
  88.                     int tarx=x + Facing.offsetsXForSide[i1],
  89.                         tary=y + Facing.offsetsYForSide[i1],
  90.                         tarz=z + Facing.offsetsZForSide[i1];
  91.                     float   f1=1, f2=1, f3=1;
  92.                     boolean used = false;
  93.                     if (world.playerEntities.size()>0)
  94.                     {
  95.                         EntityPlayer oddballPlayer = (EntityPlayer) world.playerEntities.get(0);
  96.                         used = itemstack.getItem().onItemUse(itemstack, oddballPlayer, world, tarx, tary, tarz, 1, f1, f2, f3);
  97.                         if (used){
  98.                             System.out.println("I PLANTED!");
  99.                         }else{
  100.                             System.out.println("I tried...");
  101.                         }
  102.                     }
  103.                    
  104.                     if (used){
  105.                         itemstack1 = itemstack.copy();
  106.  
  107.                         if (--itemstack1.stackSize == 0)
  108.                         {
  109.                             itemstack1 = null;
  110.                         }  
  111.                     }else{
  112.                         itemstack1 = getBehaviorForItemStack(itemstack).dispense(blocksourceimpl, itemstack);
  113.                     }
  114.                    
  115.                     if (itemstack1 != null && itemstack1.stackSize == 0)
  116.                     {
  117.                         itemstack1 = null;
  118.                     }
  119.                    
  120.                 }
  121.  
  122.                 tileentitydispenser.setInventorySlotContents(l, itemstack1);
  123.             }
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement