001package net.minecraft.block; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import net.minecraft.client.renderer.texture.IconRegister; 006import net.minecraft.dispenser.BehaviorDefaultDispenseItem; 007import net.minecraft.dispenser.IBehaviorDispenseItem; 008import net.minecraft.inventory.IInventory; 009import net.minecraft.item.ItemStack; 010import net.minecraft.tileentity.TileEntity; 011import net.minecraft.tileentity.TileEntityDispenser; 012import net.minecraft.tileentity.TileEntityDropper; 013import net.minecraft.tileentity.TileEntityHopper; 014import net.minecraft.util.Facing; 015import net.minecraft.world.World; 016 017public class BlockDropper extends BlockDispenser 018{ 019 private final IBehaviorDispenseItem field_96474_cR = new BehaviorDefaultDispenseItem(); 020 021 protected BlockDropper(int par1) 022 { 023 super(par1); 024 } 025 026 @SideOnly(Side.CLIENT) 027 028 /** 029 * When this method is called, your block should register all the icons it needs with the given IconRegister. This 030 * is the only chance you get to register icons. 031 */ 032 public void registerIcons(IconRegister par1IconRegister) 033 { 034 this.blockIcon = par1IconRegister.registerIcon("furnace_side"); 035 this.field_94463_c = par1IconRegister.registerIcon("furnace_top"); 036 this.field_94462_cO = par1IconRegister.registerIcon("dropper_front"); 037 this.field_96473_e = par1IconRegister.registerIcon("dropper_front_vertical"); 038 } 039 040 protected IBehaviorDispenseItem func_96472_a(ItemStack par1ItemStack) 041 { 042 return this.field_96474_cR; 043 } 044 045 /** 046 * Returns a new instance of a block's tile entity class. Called on placing the block. 047 */ 048 public TileEntity createNewTileEntity(World par1World) 049 { 050 return new TileEntityDropper(); 051 } 052 053 protected void dispense(World par1World, int par2, int par3, int par4) 054 { 055 BlockSourceImpl blocksourceimpl = new BlockSourceImpl(par1World, par2, par3, par4); 056 TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity(); 057 058 if (tileentitydispenser != null) 059 { 060 int l = tileentitydispenser.getRandomStackFromInventory(); 061 062 if (l < 0) 063 { 064 par1World.playAuxSFX(1001, par2, par3, par4, 0); 065 } 066 else 067 { 068 ItemStack itemstack = tileentitydispenser.getStackInSlot(l); 069 int i1 = par1World.getBlockMetadata(par2, par3, par4) & 7; 070 IInventory iinventory = TileEntityHopper.func_96117_b(par1World, (double)(par2 + Facing.offsetsXForSide[i1]), (double)(par3 + Facing.offsetsYForSide[i1]), (double)(par4 + Facing.offsetsZForSide[i1])); 071 ItemStack itemstack1; 072 073 if (iinventory != null) 074 { 075 itemstack1 = TileEntityHopper.func_94117_a(iinventory, itemstack.copy().splitStack(1), Facing.faceToSide[i1]); 076 077 if (itemstack1 == null) 078 { 079 itemstack1 = itemstack.copy(); 080 081 if (--itemstack1.stackSize == 0) 082 { 083 itemstack1 = null; 084 } 085 } 086 else 087 { 088 itemstack1 = itemstack.copy(); 089 } 090 } 091 else 092 { 093 itemstack1 = this.field_96474_cR.dispense(blocksourceimpl, itemstack); 094 095 if (itemstack1 != null && itemstack1.stackSize == 0) 096 { 097 itemstack1 = null; 098 } 099 } 100 101 tileentitydispenser.setInventorySlotContents(l, itemstack1); 102 } 103 } 104 } 105}