Java Code Examples for net.minecraft.world.World.canMineBlock()

The following are Jave code examples for showing how to use canMineBlock() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: TFCPrimitiveTech   File: WoodenBucket_BasePotashLiquor.java   Source Code and License Vote up 6 votes
@Override
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player)
{
    MovingObjectPosition mop = this.getMovingObjectPositionFromPlayer(world, player, false);

    if (mop == null)
        return is;

    if (mop.typeOfHit == MovingObjectType.BLOCK)
    {
        int x = mop.blockX;
        int y = mop.blockY;
        int z = mop.blockZ;

        if (!world.canMineBlock(player, x, y, z))
            return is;

        return new ItemStack(TFCItems.woodenBucketEmpty);
    }

    return is;
}
 
Example 2
Project: connor41-etfuturum2   File: ItemEntityEgg.java   Source Code and License Vote up 5 votes
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	if (world.isRemote)
		return stack;
	else {
		MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(world, player, true);

		if (movingobjectposition == null)
			return stack;
		else {
			if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
				int i = movingobjectposition.blockX;
				int j = movingobjectposition.blockY;
				int k = movingobjectposition.blockZ;

				if (!world.canMineBlock(player, i, j, k))
					return stack;

				if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, stack))
					return stack;

				if (world.getBlock(i, j, k) instanceof BlockLiquid) {
					Entity entity = spawnEntity(world, stack.getItemDamage(), i, j, k);

					if (entity != null) {
						if (entity instanceof EntityLivingBase && stack.hasDisplayName())
							((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());

						if (!player.capabilities.isCreativeMode)
							stack.stackSize--;
					}
				}
			}

			return stack;
		}
	}
}
 
Example 3
Project: minecraft-quiverbow   File: AquaAccelerator.java   Source Code and License Vote up 5 votes
private void checkReloadFromWater(ItemStack stack, World world, EntityPlayer player)
  {
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true);
FillBucketEvent event = new FillBucketEvent(player, stack, world, movingobjectposition);
      
if (MinecraftForge.EVENT_BUS.post(event)) { return; }

      MovingObjectPosition movObj = this.getMovingObjectPositionFromPlayer(world, player, true);

      if (movObj == null) { return; }	// Didn't click on anything in particular
      else
      {            
          if (movObj.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
          {
              int x = movObj.blockX;
              int y = movObj.blockY;
              int z = movObj.blockZ;

              if (!world.canMineBlock(player, x, y, z)) { return; }					// Not allowed to mine this, getting out of here
              if (!player.canPlayerEdit(x, y, z, movObj.sideHit, stack)) { return; }	// Not allowed to edit this, getting out of here

              Material material = world.getBlock(x, y, z).getMaterial();
              int meta = world.getBlockMetadata(x, y, z);

              // Is this water?
              if (material == Material.water && meta == 0)
              {
              	world.setBlockToAir(x, y, z);
              	stack.setItemDamage(0);
              	
                  return;
              }
              // else, not water
          }
          // else, didn't click on a block
      }
  }