/**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  public ItemStack onItemRightClick(
      ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    MovingObjectPosition movingobjectposition =
        this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

    if (movingobjectposition == null) {
      return par1ItemStack;
    } else {
      if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
        int i = movingobjectposition.blockX;
        int j = movingobjectposition.blockY;
        int k = movingobjectposition.blockZ;

        if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) {
          return par1ItemStack;
        }

        if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
          return par1ItemStack;
        }

        if (par2World.getBlockMaterial(i, j, k) == Material.water
            && par2World.getBlockMetadata(i, j, k) == 0
            && par2World.isAirBlock(i, j + 1, k)) {
          par2World.setBlock(i, j + 1, k, Block.waterlily.blockID);

          if (!par3EntityPlayer.capabilities.isCreativeMode) {
            --par1ItemStack.stackSize;
          }
        }
      }

      return par1ItemStack;
    }
  }
Example #2
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  @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;
  }
  public boolean remove() {
    if (!world.blockExists(x, y, z)) return false;

    if (spawnProtection) {
      if (!world.canMineBlock(player, x, y, z)) return false;
    }

    if (eventCheck) {
      final Block block = world.getBlock(x, y, z);
      final int meta = world.getBlockMetadata(x, y, z);
      BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
      event.setExpToDrop(0);

      MinecraftForge.EVENT_BUS.post(event);

      if (event.isCanceled()) return false;
    }

    if (silentTeRemove) world.removeTileEntity(x, y, z);

    return world.setBlockToAir(x, y, z);
  }
  public boolean place(Block block, int meta) {
    if (!world.blockExists(x, y, z)) return false;

    if (spawnProtection) {
      if (!world.canMineBlock(player, x, y, z)) return false;
    }

    final BlockSnapshot snapshot =
        net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(world, x, y, z);

    if (!world.setBlock(x, y, z, block, meta, blockPlaceFlags)) return false;

    if (ForgeEventFactory.onPlayerBlockPlace(
            player, snapshot, net.minecraftforge.common.util.ForgeDirection.UNKNOWN)
        .isCanceled()) {
      world.restoringBlockSnapshots = true;
      snapshot.restore(true, false);
      world.restoringBlockSnapshots = false;
      return false;
    }

    return true;
  }
Example #5
0
  @Override
  public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) {
    // TODO Auto-generated method stub
    MovingObjectPosition movingobjectposition =
        this.getMovingObjectPositionFromPlayer(world, player, true);

    if (movingobjectposition == null) {
      return item;
    } else {
      FillBucketEvent event = new FillBucketEvent(player, item, world, movingobjectposition);
      if (MinecraftForge.EVENT_BUS.post(event)) {
        return item;
      }

      if (event.getResult() == Event.Result.ALLOW) {
        if (player.capabilities.isCreativeMode) {
          return item;
        }

        if (--item.stackSize <= 0) {
          return event.result;
        }

        if (!player.inventory.addItemStackToInventory(event.result)) {
          player.dropPlayerItem(event.result);
        }

        return item;
      }

      if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) {
        int x = movingobjectposition.blockX;
        int y = movingobjectposition.blockY;
        int z = movingobjectposition.blockZ;

        if (!world.canMineBlock(player, x, y, z)) {
          return item;
        }

        if (movingobjectposition.sideHit == 0) {
          --y;
        }

        if (movingobjectposition.sideHit == 1) {
          ++y;
        }

        if (movingobjectposition.sideHit == 2) {
          --z;
        }

        if (movingobjectposition.sideHit == 3) {
          ++z;
        }

        if (movingobjectposition.sideHit == 4) {
          --x;
        }

        if (movingobjectposition.sideHit == 5) {
          ++x;
        }

        if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, item)) {
          return item;
        }

        if (this.tryPlaceContainedLiquid(world, x, y, z) && !player.capabilities.isCreativeMode) {
          return new ItemStack(Item.bucketEmpty);
        }
      }

      return item;
    }
  }
Example #6
0
  /**
   * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack,
   * world, entityPlayer
   */
  @Override
  public ItemStack onItemRightClick(ItemStack bucket, World world, EntityPlayer user) {
    boolean flag = this.isFull == Blocks.air;
    MovingObjectPosition movingobjectposition =
        this.getMovingObjectPositionFromPlayer(world, user, flag);

    if (movingobjectposition == null) {
      return bucket;
    } else {
      if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
        int x = movingobjectposition.blockX;
        int y = movingobjectposition.blockY;
        int z = movingobjectposition.blockZ;

        if (!world.canMineBlock(user, x, y, z)) {
          return bucket;
        }

        if (flag) {
          if (!user.canPlayerEdit(x, y, z, movingobjectposition.sideHit, bucket)) {
            return bucket;
          }

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

          if (material == Material.water && l == 0) {
            world.setBlockToAir(x, y, z);
            return this.createNewInstance(bucket, user, ToolListMF.bucketwood_water, 0);
          }

          if (material == Material.lava && l == 0) {
            world.playSound(x + 0.5, y + 0.5, z + 0.5, "random.fizz", 1.0F, 1.0F, true);
            world.spawnParticle("largeSmoke", x + 0.5, y + 1F, z + 0.5, 0F, 0.5F, 0F);
            return this.createNewInstance(bucket, user, Items.coal, 1);
          }
        } else {
          if (this.isFull == Blocks.air) {
            return new ItemStack(ToolListMF.bucketwood_empty);
          }

          if (movingobjectposition.sideHit == 0) {
            --y;
          }

          if (movingobjectposition.sideHit == 1) {
            ++y;
          }

          if (movingobjectposition.sideHit == 2) {
            --z;
          }

          if (movingobjectposition.sideHit == 3) {
            ++z;
          }

          if (movingobjectposition.sideHit == 4) {
            --x;
          }

          if (movingobjectposition.sideHit == 5) {
            ++x;
          }

          if (!user.canPlayerEdit(x, y, z, movingobjectposition.sideHit, bucket)) {
            return bucket;
          }

          if (this.tryPlaceContainedLiquid(world, x, y, z) && !user.capabilities.isCreativeMode) {
            return new ItemStack(ToolListMF.bucketwood_empty);
          }
        }
      }

      return bucket;
    }
  }