Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package almostMinecraft;
- import net.minecraft.block.BlockDropper;
- import net.minecraft.block.BlockSourceImpl;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntityDispenser;
- import net.minecraft.tileentity.TileEntityHopper;
- import net.minecraft.util.ChatMessageComponent;
- import net.minecraft.util.ChunkCoordinates;
- import net.minecraft.util.Facing;
- import net.minecraft.world.World;
- import net.minecraftforge.event.entity.player.PlayerEvent;
- public class BlockAlmostDropper extends BlockDropper{
- public static final int Default_ID = 2935;
- protected BlockAlmostDropper(int par1) {
- super(par1);
- }
- @Override
- protected void dispense(World par1World, int x, int y, int z)
- {
- //source block
- BlockSourceImpl blocksourceimpl = new BlockSourceImpl(par1World, x, y, z);
- //this dispenser
- TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
- //if this is not null
- if (tileentitydispenser != null)
- {
- //select one of the used inventory slots randomly
- int l = tileentitydispenser.getRandomStackFromInventory();
- //if there is nothing (l returned -1)
- if (l < 0)
- {
- //play the "nothing there" sound
- par1World.playAuxSFX(1001, x, y, z, 0);
- }
- else
- {
- //otherwise, get an actual item from that slot.
- ItemStack itemstack = tileentitydispenser.getStackInSlot(l);
- //this is the block metadata with a four bit bitmask
- //because of the &7, only the last four bits of the number are stored
- //this is the same as:
- //int i1 = par1World.getBlockMetadata(x, y, z) % 8;
- //this metadata is the direction the block is facing
- int i1 = par1World.getBlockMetadata(x, y, z) & 7;
- //get the inventory of the block to the direction
- IInventory iinventory = TileEntityHopper.getInventoryAtLocation(par1World, (double)(x + Facing.offsetsXForSide[i1]), (double)(y + Facing.offsetsYForSide[i1]), (double)(z + Facing.offsetsZForSide[i1]));
- ItemStack itemstack1;
- //if there is an inventory in this direction, fill it
- if (iinventory != null)
- {
- itemstack1 = TileEntityHopper.insertStack(iinventory, itemstack.copy().splitStack(1), Facing.oppositeSide[i1]);
- if (itemstack1 == null)
- {
- itemstack1 = itemstack.copy();
- if (--itemstack1.stackSize == 0)
- {
- itemstack1 = null;
- }
- }
- else
- {
- itemstack1 = itemstack.copy();
- }
- }
- else
- {//otherwise, perform default dispense!
- //first, we parasitically use the first player in the world list.
- //(change this later)
- World world=Minecraft.getMinecraft().theWorld;
- int tarx=x + Facing.offsetsXForSide[i1],
- tary=y + Facing.offsetsYForSide[i1],
- tarz=z + Facing.offsetsZForSide[i1];
- float f1=1, f2=1, f3=1;
- boolean used = false;
- if (world.playerEntities.size()>0)
- {
- EntityPlayer oddballPlayer = (EntityPlayer) world.playerEntities.get(0);
- used = itemstack.getItem().onItemUse(itemstack, oddballPlayer, world, tarx, tary, tarz, 1, f1, f2, f3);
- if (used){
- System.out.println("I PLANTED!");
- }else{
- System.out.println("I tried...");
- }
- }
- if (used){
- itemstack1 = itemstack.copy();
- if (--itemstack1.stackSize == 0)
- {
- itemstack1 = null;
- }
- }else{
- itemstack1 = getBehaviorForItemStack(itemstack).dispense(blocksourceimpl, itemstack);
- }
- if (itemstack1 != null && itemstack1.stackSize == 0)
- {
- itemstack1 = null;
- }
- }
- tileentitydispenser.setInventorySlotContents(l, itemstack1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement