| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
| 4 | import net.minecraft.dispenser.IBehaviorDispenseItem;
|
| 5 | import net.minecraft.inventory.IInventory;
|
| 6 | import net.minecraft.item.ItemStack;
|
| 7 | import net.minecraft.tileentity.TileEntity;
|
| 8 | import net.minecraft.tileentity.TileEntityDispenser;
|
| 9 | import net.minecraft.tileentity.TileEntityDropper;
|
| 10 | import net.minecraft.tileentity.TileEntityHopper;
|
| 11 | import net.minecraft.util.BlockPos;
|
| 12 | import net.minecraft.util.EnumFacing;
|
| 13 | import net.minecraft.world.World;
|
| 14 |
|
| 15 | public class BlockDropper extends BlockDispenser
|
| 16 | {
|
| 17 | private final IBehaviorDispenseItem dropBehavior = new BehaviorDefaultDispenseItem();
|
| 18 |
|
| 19 | protected IBehaviorDispenseItem getBehavior(ItemStack stack)
|
| 20 | {
|
| 21 | return this.dropBehavior;
|
| 22 | }
|
| 23 |
|
| 24 | /**
|
| 25 | * Returns a new instance of a block's tile entity class. Called on placing the block.
|
| 26 | */
|
| 27 | public TileEntity createNewTileEntity(World worldIn, int meta)
|
| 28 | {
|
| 29 | return new TileEntityDropper();
|
| 30 | }
|
| 31 |
|
| 32 | protected void dispense(World worldIn, BlockPos pos)
|
| 33 | {
|
| 34 | BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
|
| 35 | TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
|
| 36 |
|
| 37 | if (tileentitydispenser != null)
|
| 38 | {
|
| 39 | int i = tileentitydispenser.getDispenseSlot();
|
| 40 |
|
| 41 | if (i < 0)
|
| 42 | {
|
| 43 | worldIn.playAuxSFX(1001, pos, 0);
|
| 44 | }
|
| 45 | else
|
| 46 | {
|
| 47 | ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
|
| 48 |
|
| 49 | if (itemstack != null)
|
| 50 | {
|
| 51 | EnumFacing enumfacing = (EnumFacing)worldIn.getBlockState(pos).getValue(FACING);
|
| 52 | BlockPos blockpos = pos.offset(enumfacing);
|
| 53 | IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
|
| 54 | ItemStack itemstack1;
|
| 55 |
|
| 56 | if (iinventory == null)
|
| 57 | {
|
| 58 | itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
|
| 59 |
|
| 60 | if (itemstack1 != null && itemstack1.stackSize <= 0)
|
| 61 | {
|
| 62 | itemstack1 = null;
|
| 63 | }
|
| 64 | }
|
| 65 | else
|
| 66 | {
|
| 67 | itemstack1 = TileEntityHopper.putStackInInventoryAllSlots(iinventory, itemstack.copy().splitStack(1), enumfacing.getOpposite());
|
| 68 |
|
| 69 | if (itemstack1 == null)
|
| 70 | {
|
| 71 | itemstack1 = itemstack.copy();
|
| 72 |
|
| 73 | if (--itemstack1.stackSize <= 0)
|
| 74 | {
|
| 75 | itemstack1 = null;
|
| 76 | }
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | itemstack1 = itemstack.copy();
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | tileentitydispenser.setInventorySlotContents(i, itemstack1);
|
| 85 | }
|
| 86 | }
|
| 87 | }
|
| 88 | }
|
| 89 | }
|
| 90 |
|