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 dropperDefaultBehaviour = 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.furnaceTopIcon = par1IconRegister.registerIcon("furnace_top"); 036 this.furnaceFrontIcon = par1IconRegister.registerIcon("dropper_front"); 037 this.field_96473_e = par1IconRegister.registerIcon("dropper_front_vertical"); 038 } 039 040 /** 041 * Returns the behavior for the given ItemStack. 042 */ 043 protected IBehaviorDispenseItem getBehaviorForItemStack(ItemStack par1ItemStack) 044 { 045 return this.dropperDefaultBehaviour; 046 } 047 048 /** 049 * Returns a new instance of a block's tile entity class. Called on placing the block. 050 */ 051 public TileEntity createNewTileEntity(World par1World) 052 { 053 return new TileEntityDropper(); 054 } 055 056 protected void dispense(World par1World, int par2, int par3, int par4) 057 { 058 BlockSourceImpl blocksourceimpl = new BlockSourceImpl(par1World, par2, par3, par4); 059 TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity(); 060 061 if (tileentitydispenser != null) 062 { 063 int l = tileentitydispenser.getRandomStackFromInventory(); 064 065 if (l < 0) 066 { 067 par1World.playAuxSFX(1001, par2, par3, par4, 0); 068 } 069 else 070 { 071 ItemStack itemstack = tileentitydispenser.getStackInSlot(l); 072 int i1 = par1World.getBlockMetadata(par2, par3, par4) & 7; 073 IInventory iinventory = TileEntityHopper.getInventoryAtLocation(par1World, (double)(par2 + Facing.offsetsXForSide[i1]), (double)(par3 + Facing.offsetsYForSide[i1]), (double)(par4 + Facing.offsetsZForSide[i1])); 074 ItemStack itemstack1; 075 076 if (iinventory != null) 077 { 078 itemstack1 = TileEntityHopper.insertStack(iinventory, itemstack.copy().splitStack(1), Facing.oppositeSide[i1]); 079 080 if (itemstack1 == null) 081 { 082 itemstack1 = itemstack.copy(); 083 084 if (--itemstack1.stackSize == 0) 085 { 086 itemstack1 = null; 087 } 088 } 089 else 090 { 091 itemstack1 = itemstack.copy(); 092 } 093 } 094 else 095 { 096 itemstack1 = this.dropperDefaultBehaviour.dispense(blocksourceimpl, itemstack); 097 098 if (itemstack1 != null && itemstack1.stackSize == 0) 099 { 100 itemstack1 = null; 101 } 102 } 103 104 tileentitydispenser.setInventorySlotContents(l, itemstack1); 105 } 106 } 107 } 108}