net.minecraft.tileentity.TileEntityDispenser Java Examples

The following examples show how to use net.minecraft.tileentity.TileEntityDispenser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockTrap.java    From Artifacts with MIT License 6 votes vote down vote up
/**
 * Called upon block activation (right click on the block.)
 */
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
    if (par1World.isRemote)
    {
        return true;
    }
    else
    {
        TileEntityDispenser tileentitydispenser = (TileEntityDispenser)par1World.getTileEntity(par2, par3, par4);

        if (tileentitydispenser != null)
        {
            par5EntityPlayer.func_146102_a/*displayGUIDispenser*/(tileentitydispenser);
        }

        return true;
    }
}
 
Example #2
Source File: PlaceTraps.java    From Artifacts with MIT License 6 votes vote down vote up
private boolean simpleTrap(Random rand, World world, Vec3 c) {
	boolean nn = false; 
	if(world.isAirBlock(MathHelper.floor_double(c.xCoord), MathHelper.floor_double(c.yCoord), MathHelper.floor_double(c.zCoord))) {
		c.yCoord -=1;
		nn = true;
	}
	world.setBlock(MathHelper.floor_double(c.xCoord), MathHelper.floor_double(c.yCoord), MathHelper.floor_double(c.zCoord), BlockTrap.instance, 1, 3);
	world.setBlockMetadataWithNotify(MathHelper.floor_double(c.xCoord), MathHelper.floor_double(c.yCoord), MathHelper.floor_double(c.zCoord), 1, 3);
	world.setBlock(MathHelper.floor_double(c.xCoord), MathHelper.floor_double(c.yCoord+1), MathHelper.floor_double(c.zCoord), rand.nextInt(5) == 0 ? BlockArtifactsPressurePlate.camoObsidian : BlockArtifactsPressurePlate.invisObsidian);
	
	
	TileEntityTrap dis = (TileEntityTrap)world.getTileEntity(MathHelper.floor_double(c.xCoord), MathHelper.floor_double(c.yCoord), MathHelper.floor_double(c.zCoord));
	if(dis != null) {
		addTrapItem(rand, dis);
	}
	else {
		TileEntityDispenser dis2 = (TileEntityDispenser)world.getTileEntity(MathHelper.floor_double(c.xCoord), MathHelper.floor_double(c.yCoord), MathHelper.floor_double(c.zCoord));
		if(dis2 != null) {
			addTrapItem(rand, dis);
		}
	}
	if(nn) {
		c.yCoord +=1;
	}
	return true;
}
 
Example #3
Source File: GT_TileEntity_Windmill.java    From bartworks with MIT License 5 votes vote down vote up
public boolean addDispenserToOutputSet(TileEntity aTileEntity) {
    if (aTileEntity instanceof TileEntityDispenser) {
        this.tileEntityDispensers.add((TileEntityDispenser) aTileEntity);
        return true;
    }
    return false;
}
 
Example #4
Source File: GT_TileEntity_Windmill.java    From bartworks with MIT License 5 votes vote down vote up
@SuppressWarnings("ALL")
@Override
public boolean addOutput(ItemStack aStack) {
    if (GT_Utility.isStackInvalid(aStack))
        return false;

    for (TileEntityDispenser tHatch : this.tileEntityDispensers) {
        for (int i = tHatch.getSizeInventory() - 1; i >= 0; i--) {
            if (tHatch.getStackInSlot(i) == null || GT_Utility.areStacksEqual(tHatch.getStackInSlot(i), aStack) && aStack.stackSize + tHatch.getStackInSlot(i).stackSize <= 64) {
                if (GT_Utility.areStacksEqual(tHatch.getStackInSlot(i), aStack)) {
                    ItemStack merge = tHatch.getStackInSlot(i).copy();
                    merge.stackSize = aStack.stackSize + tHatch.getStackInSlot(i).stackSize;
                    tHatch.setInventorySlotContents(i, merge);
                } else {
                    tHatch.setInventorySlotContents(i, aStack.copy());
                }

                if (GT_Utility.areStacksEqual(tHatch.getStackInSlot(i), aStack)) {
                    aStack = null;
                    return true;
                } else {
                    tHatch.setInventorySlotContents(i, null);
                    aStack = null;
                    return false;
                }
            }
        }
    }
    return false;
}
 
Example #5
Source File: CraftDispenser.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BlockProjectileSource getBlockProjectileSource() {
    Block block = getBlock();

    if (block.getType() != Material.DISPENSER) {
        return null;
    }

    return new CraftBlockProjectileSource((TileEntityDispenser) this.getTileEntityFromWorld());
}
 
Example #6
Source File: StorageESPMod.java    From ForgeHax with MIT License 5 votes vote down vote up
private int getTileEntityColor(TileEntity tileEntity) {
  if (tileEntity instanceof TileEntityChest
      || tileEntity instanceof TileEntityDispenser
      || tileEntity instanceof TileEntityShulkerBox) {
    return Colors.ORANGE.toBuffer();
  } else if (tileEntity instanceof TileEntityEnderChest) {
    return Colors.PURPLE.toBuffer();
  } else if (tileEntity instanceof TileEntityFurnace) {
    return Colors.GRAY.toBuffer();
  } else if (tileEntity instanceof TileEntityHopper) {
    return Colors.DARK_RED.toBuffer();
  } else {
    return -1;
  }
}
 
Example #7
Source File: Dispenser.java    From minecraft-roguelike with GNU General Public License v3.0 5 votes vote down vote up
public static void add(IWorldEditor editor, Coord pos, int slot, ItemStack item){
	
	TileEntity te = editor.getTileEntity(pos);
	if(te == null) return;
	if(!(te instanceof TileEntityDispenser)) return;
	TileEntityDispenser dispenser = (TileEntityDispenser) te;
	dispenser.setInventorySlotContents(slot, item);
}
 
Example #8
Source File: BlockTrap.java    From Artifacts with MIT License 5 votes vote down vote up
/**
 * Ticks the block if it's been scheduled
 */
@Override
public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
{
	if (!par1World.isRemote)
	{
		TileEntity te = par1World.getTileEntity(par2, par3, par4);
		TileEntityDispenser dis;
		if(te instanceof TileEntityDispenser) {
			dis = ((TileEntityDispenser) te);
 		AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(par2-0.2, par3-0.2, par4-0.2, par2+1.2, par3+1.2, par4+1.2);
 		List<EntitySpecialArrow> arrs = par1World.getEntitiesWithinAABB(EntitySpecialArrow.class, aabb);
 		for(int a = arrs.size()-1; a>=0; a--) {
 			EntityArrow arr = arrs.get(a);
 			for(int s=0; s<9; s++) {
 				ItemStack is = dis.getStackInSlot(s);
 				if(is == null) {
 					dis.setInventorySlotContents(s, new ItemStack(Items.arrow, 1));
 					arr.setDead();
 					break;
 				}
 				else if(is != null && is.getItem() == Items.arrow) {
 					if(is.stackSize < 64) {
 						is.stackSize++;
 						arr.setDead();
 						break;
 					}
 				}
 			}
 		}
 		
 		this.dispense(par1World, par2, par3, par4, par5Random.nextInt(4)+1);
 		this.dispense(par1World, par2, par3, par4, par5Random.nextInt(4)+1);
		}
	}
}
 
Example #9
Source File: BlockTrap.java    From Artifacts with MIT License 5 votes vote down vote up
/**
 * Called when the block is placed in the world.
 */
@Override
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack)
{
    int l = BlockPistonBase.determineOrientation(par1World, par2, par3, par4, par5EntityLiving);
    par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);

    if (par6ItemStack.hasDisplayName())
    {
        ((TileEntityDispenser)par1World.getTileEntity(par2, par3, par4)).func_146018_a/*setCustomName*/(par6ItemStack.getDisplayName());
    }
}
 
Example #10
Source File: CraftDispenser.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftDispenser(final Block block) {
    super(block, TileEntityDispenser.class);
}
 
Example #11
Source File: CraftDispenser.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftDispenser(final Material material, final TileEntityDispenser te) {
    super(material, te);
}
 
Example #12
Source File: CraftBlockProjectileSource.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftBlockProjectileSource(TileEntityDispenser dispenserBlock) {
    this.dispenserBlock = dispenserBlock;
}
 
Example #13
Source File: CraftDispenser.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public CraftDispenser(final Block block) {
    super(block);

    world = (CraftWorld) block.getWorld();
    dispenser = (TileEntityDispenser) world.getTileEntityAt(getX(), getY(), getZ());
}
 
Example #14
Source File: BlockTrap.java    From Artifacts with MIT License 4 votes vote down vote up
/**
 * ejects contained items into the world, and notifies neighbours of an update, as appropriate
 */
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, Block block, int par6)
{
    TileEntityDispenser tileentitydispenser = (TileEntityDispenser)par1World.getTileEntity(par2, par3, par4);

    if (!par1World.isRemote && tileentitydispenser != null)
    {
        for (int j1 = 0; j1 < tileentitydispenser.getSizeInventory(); ++j1)
        {
            ItemStack itemstack = tileentitydispenser.getStackInSlot(j1);

            if (itemstack != null)
            {
                float f = this.random.nextFloat() * 0.8F + 0.1F;
                float f1 = this.random.nextFloat() * 0.8F + 0.1F;
                float f2 = this.random.nextFloat() * 0.8F + 0.1F;

                while (itemstack.stackSize > 0)
                {
                    int k1 = this.random.nextInt(21) + 10;

                    if (k1 > itemstack.stackSize)
                    {
                        k1 = itemstack.stackSize;
                    }

                    itemstack.stackSize -= k1;
                    EntityItem entityitem = new EntityItem(par1World, (double)((float)par2 + f), (double)((float)par3 + f1), (double)((float)par4 + f2), new ItemStack(itemstack.getItem(), k1, itemstack.getItemDamage()));

                    if (itemstack.hasTagCompound())
                    {
                        entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                    }

                    float f3 = 0.05F;
                    entityitem.motionX = (double)((float)this.random.nextGaussian() * f3);
                    entityitem.motionY = (double)((float)this.random.nextGaussian() * f3 + 0.2F);
                    entityitem.motionZ = (double)((float)this.random.nextGaussian() * f3);
                    par1World.spawnEntityInWorld(entityitem);
                }
            }
        }

        par1World.func_147453_f(par2, par3, par4, block);
    }

    super.breakBlock(par1World, par2, par3, par4, block, par6);
}
 
Example #15
Source File: PlaceTraps.java    From Artifacts with MIT License 4 votes vote down vote up
private boolean trapChest(Random rand, World world, Vec3[] c) {
	Vec3 a = Vec3.createVectorHelper(c[0].xCoord, c[0].yCoord, c[0].zCoord);
	
	boolean flag = (world.getBlock(MathHelper.floor_double(a.xCoord+c[1].zCoord*2), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord+c[1].xCoord*2)) != Blocks.air || world.getBlock(MathHelper.floor_double(a.xCoord-c[1].zCoord*2), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord-c[1].xCoord*2)) != Blocks.air);
	if(!flag) {
		if(MathHelper.floor_double(c[1].xCoord) != 0 && MathHelper.floor_double(c[1].zCoord) != 0) {
			if(rand.nextBoolean()) {
				c[1].xCoord = 0;
			}
			else {
				c[1].zCoord = 0;
			}
		}
		
		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord), Blocks.stone_slab, 5, 3);
		world.setBlock(MathHelper.floor_double(a.xCoord+c[1].zCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord+c[1].xCoord), Blocks.stone_slab, 5, 3);
		world.setBlock(MathHelper.floor_double(a.xCoord-c[1].zCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord-c[1].xCoord), Blocks.stone_slab, 5, 3);
		
		a.xCoord += c[1].xCoord;
		a.zCoord += c[1].zCoord;
		
		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord), Blocks.stonebrick);
		world.setBlock(MathHelper.floor_double(a.xCoord+c[1].zCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord+c[1].xCoord), Blocks.stonebrick);
		world.setBlock(MathHelper.floor_double(a.xCoord-c[1].zCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord-c[1].xCoord), Blocks.stonebrick);
		world.setBlock(MathHelper.floor_double(a.xCoord+c[1].zCoord*2), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord+c[1].xCoord*2), Blocks.stone_slab, 5, 3);
		world.setBlock(MathHelper.floor_double(a.xCoord-c[1].zCoord*2), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord-c[1].xCoord*2), Blocks.stone_slab, 5, 3);

		world.setBlock(MathHelper.floor_double(a.xCoord+c[1].zCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord+c[1].xCoord), Blocks.stonebrick);
		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord), Blocks.trapped_chest);
		world.setBlock(MathHelper.floor_double(a.xCoord-c[1].zCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord-c[1].xCoord), Blocks.stonebrick);
		
		if(MathHelper.floor_double(a.xCoord) == 1) {
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord), 2, 3);
		}
		else if(MathHelper.floor_double(a.xCoord) == -1) {
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord), 3, 3);//not 4
		}
		else if(MathHelper.floor_double(a.zCoord) == 1){
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord), 4, 3);//not 4
		}
		else {
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord), 5, 3);
		}

		a.xCoord += c[1].xCoord;
		a.zCoord += c[1].zCoord;

		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord), Blocks.redstone_wire);
		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord), BlockIllusionary.instance);

		a.xCoord += c[1].xCoord;
		a.zCoord += c[1].zCoord;

		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+1), MathHelper.floor_double(a.zCoord), Blocks.redstone_torch, 5, 3);
		world.setBlock(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord), BlockTrap.instance);
		
		if(MathHelper.floor_double(a.xCoord) == 1) {
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord), 2, 3);
		}
		else if(MathHelper.floor_double(a.xCoord) == -1) {
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord), 3, 3);
		}
		else if(MathHelper.floor_double(a.zCoord) == 1){
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord), 4, 3);
		}
		else {
			world.setBlockMetadataWithNotify(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord), 5, 3);
		}
		
		TileEntityTrap dis = (TileEntityTrap)world.getTileEntity(MathHelper.floor_double(a.xCoord), MathHelper.floor_double(a.yCoord+2), MathHelper.floor_double(a.zCoord));
		if(dis != null) {
			addTrapItem(rand, dis);
		}
		else {
			TileEntityDispenser dis2 = (TileEntityDispenser)world.getTileEntity(MathHelper.floor_double(a.xCoord+2), MathHelper.floor_double(a.yCoord), MathHelper.floor_double(a.zCoord));
			if(dis2 != null) {
				addTrapItem(rand, dis);
			}
		}
		
		return true;
	}
	return false;
}
 
Example #16
Source File: PlaceTraps.java    From Artifacts with MIT License 4 votes vote down vote up
private boolean forwardTrap(Random rand, World world, Vec3[] c) {
	Vec3 pos = Vec3.createVectorHelper(c[0].xCoord, c[0].yCoord, c[0].zCoord);
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord), MathHelper.floor_double(pos.zCoord+1), BlockTrap.instance, 0, 3);
	int m = 0;
	if(c[1].xCoord == 0) {
		if(c[1].zCoord == 1) {
			m = 3;
		}
		else {
			m = 2;
		}
	}
	else {
		if(c[1].xCoord == 1) {
			m = 5;
		}
		else {
			m = 4;
		}
	}
	world.setBlockMetadataWithNotify(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord+1), MathHelper.floor_double(pos.zCoord), m, 3);
	TileEntityTrap dis = (TileEntityTrap)world.getTileEntity(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord+1), MathHelper.floor_double(pos.zCoord));
	if(dis != null) {
		addTrapItem(rand, dis);
	}
	else {
		TileEntityDispenser dis2 = (TileEntityDispenser)world.getTileEntity(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord+1), MathHelper.floor_double(pos.zCoord));
		if(dis2 != null) {
			addTrapItem(rand, dis);
		}
	}
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord), MathHelper.floor_double(pos.zCoord), Blocks.unlit_redstone_torch, 5, 3);
	pos.xCoord += c[1].xCoord;
	pos.zCoord += c[1].zCoord;
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord-1), MathHelper.floor_double(pos.zCoord), Blocks.redstone_wire, 15, 3);
	pos.xCoord += c[1].xCoord;
	pos.zCoord += c[1].zCoord;
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord-1), MathHelper.floor_double(pos.zCoord), Blocks.air, 0, 3);
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord-2), MathHelper.floor_double(pos.zCoord), Blocks.redstone_wire, 14, 3);
	pos.xCoord += c[1].xCoord;
	pos.zCoord += c[1].zCoord;
	m = 0;
	if(c[1].xCoord == 0) {
		if(c[1].zCoord == 1) {
			m = 3;
		}
		else {
			m = 4;
		}
	}
	else {
		if(c[1].xCoord == 1) {
			m = 1;
		}
		else {
			m = 2;
		}
	}
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord-2), MathHelper.floor_double(pos.zCoord), Blocks.redstone_torch, m, 3);
	pos.xCoord += c[1].xCoord;
	pos.zCoord += c[1].zCoord;
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord-1), MathHelper.floor_double(pos.zCoord), Blocks.redstone_wire, 0, 3);
	world.setBlock(MathHelper.floor_double(pos.xCoord), MathHelper.floor_double(pos.yCoord+1), MathHelper.floor_double(pos.zCoord), BlockArtifactsPressurePlate.invisObsidian, 0, 3);
	return true;
}