Java Code Examples for net.minecraft.block.Block#dropBlockAsItem()

The following examples show how to use net.minecraft.block.Block#dropBlockAsItem() . 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: TrackInstanceBase.java    From NEI-Integration with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(Block blockChanged) {
    int meta = tileEntity.getBlockMetadata();
    boolean valid = isRailValid(getWorld(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, meta);
    if (!valid) {
        Block blockTrack = getBlock();
        blockTrack.dropBlockAsItem(getWorld(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 0, 0);
        getWorld().setBlockToAir(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
        return;
    }

    if (blockChanged != null && blockChanged.canProvidePower()
            && isFlexibleRail() && RailTools.countAdjecentTracks(getWorld(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == 3)
        switchTrack(false);
    testPower();
}
 
Example 2
Source File: HayCrook.java    From Ex-Aliquo with MIT License 6 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack item, int X, int Y, int Z, EntityPlayer player)
{
	World world = player.worldObj;
	int blockID = world.getBlockId(X,Y,Z);
	int meta = world.getBlockMetadata(X, Y, Z);
	boolean validTarget = false;
	
	Block block = Block.blocksList[blockID];
	
	if (block.isBlockReplaceable(null, 0, 0, 0))
	{
		block.dropBlockAsItem(world, X, Y, Z, meta, 2);
	}
	
	return true;
}
 
Example 3
Source File: ComponentExcavation.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack itemStack, World world, Block destroyedBlock, int x, int y, int z, EntityLivingBase player) {
	//System.out.println("Test (" + x + "," + y + "," + z + ")");
	//player.getLookVec();
	int numBlocks = 0;
	for(int i=-1;i<=1;i++) {
		for(int j=-1;j<=1;j++) {
			for(int k=-1;k<=1;k++) {
				Block block = world.getBlock(x+i, y+j, z+k);
				if(block != null) {
					System.out.println("block: " + block.getUnlocalizedName());
					System.out.println("can:  " + itemStack.getItem().canHarvestBlock(block, itemStack));
					if(this.canHarvestBlock(block, itemStack)) {
						int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemStack);
						block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x+i, y+j, z+k), fortuneLevel);
						world.setBlockToAir(x+i, y+j, z+k);
						numBlocks++;
					}
				}
			}
		}
	}
	itemStack.damageItem(numBlocks/3, player);
	//Block block = Block.blocksList[l]
	return false;
}
 
Example 4
Source File: ComponentHarvesting.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack itemStack, World world, Block block, int x, int y, int z, EntityLivingBase player) {
	if (block != Blocks.coal_ore && block != Blocks.iron_ore && block != Blocks.emerald_ore && block != Blocks.gold_ore && block != Blocks.diamond_ore && block != Blocks.quartz_ore && block != Blocks.lapis_ore && block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore)
	{
		return false;
       }
	else if(world.rand.nextInt(4) == 0) {
		//drop another
		/*ItemStack is = new ItemStack(Block.blocksList[blockID], 1);
		EntityItem ei = new EntityItem(world, x, y, z, is);
		world.spawnEntityInWorld(ei);*/
		itemStack.damageItem(1, player);
		block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
	}
	return true;
}
 
Example 5
Source File: EntityShip.java    From archimedes-ships with MIT License 5 votes vote down vote up
public void dropAsItems()
{
	TileEntity tileentity;
	Block block;
	for (int i = shipChunk.minX(); i < shipChunk.maxX(); i++)
	{
		for (int j = shipChunk.minY(); j < shipChunk.maxY(); j++)
		{
			for (int k = shipChunk.minZ(); k < shipChunk.maxZ(); k++)
			{
				tileentity = shipChunk.getTileEntity(i, j, k);
				if (tileentity instanceof IInventory)
				{
					IInventory inv = (IInventory) tileentity;
					for (int it = 0; it < inv.getSizeInventory(); it++)
					{
						ItemStack is = inv.getStackInSlot(it);
						if (is != null)
						{
							entityDropItem(is, 0F);
						}
					}
				}
				block = shipChunk.getBlock(i, j, k);
				
				if (block != Blocks.air)
				{
					int meta = shipChunk.getBlockMetadata(i, j, k);
					block.dropBlockAsItem(worldObj, MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ), meta, 0);
				}
			}
		}
	}
}
 
Example 6
Source File: ComponentExplosive.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack par1ItemStack, World world, Block block, int x, int y, int z, EntityLivingBase par7EntityLivingBase) {
	Block i = world.getBlock(x, y, z);
	int m = world.getBlockMetadata(x, y, z);
	i.dropBlockAsItem(world, x, y, z, m, 0);
	world.setBlockToAir(x, y, z);
	world.newExplosion(par7EntityLivingBase, x, y, z, 3F, false, true);
	par1ItemStack.damageItem(3, par7EntityLivingBase);
	return false;
}
 
Example 7
Source File: GoldCrook.java    From Ex-Aliquo with MIT License 4 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack item, int X, int Y, int Z, EntityPlayer player)
{
	World world = player.worldObj;
	int blockID = world.getBlockId(X,Y,Z);
	int meta = world.getBlockMetadata(X, Y, Z);
	boolean validTarget = false;
	boolean extraDropped = false;

	Block block = Block.blocksList[blockID];

	if (block.isLeaves(null, 0, 0, 0))
	{
		if (!world.isRemote)
		{
			if (forestryrefcheck && ModsLoaded.isForestryLoaded)
			{
				ForestryLeaves(world, block, meta, X, Y, Z);
				ForestryLeaves(world, block, meta, X, Y, Z);
				ForestryLeaves(world, block, meta, X, Y, Z);
			}

			if (!extras)
			{
				block.dropBlockAsItem(world, X, Y, Z, meta, 0);
				block.dropBlockAsItem(world, X, Y, Z, meta, 0);
				block.dropBlockAsItem(world, X, Y, Z, meta, 0);
			}

			if (ModData.ALLOW_SILKWORMS && world.rand.nextInt(75) == 0)
			{
				world.spawnEntityInWorld(new EntityItem(world, X + 0.5D, Y + 0.5D, Z + 0.5D, new ItemStack(getItem(Info.silkworm), 1, 0)));
			}
		}
	}

	if (blockID == getIDs(Info.silkleaves))
	{
		if (!world.isRemote)
		{
			if (ModData.ALLOW_SILKWORMS && world.rand.nextInt(10) == 0)
			{
				world.spawnEntityInWorld(new EntityItem(world, X + 0.5D, Y + 0.5D, Z + 0.5D, new ItemStack(getItem(Info.silkworm), 1, 0)));
			}
		}
	}
	
	return false;
}