Пример #1
0
  @Override
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      BlockPos pos,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (ItemDye.applyBonemeal(par1ItemStack, par3World, pos, par2EntityPlayer)) {
      if (!par3World.isRemote) {
        par3World.playAuxSFX(2005, pos, 0);
      }
      return true;
    }

    IBlockState blockState = par3World.getBlockState(pos);
    if (blockState.getBlock() instanceof IGrowable) {
      IGrowable plant = (IGrowable) blockState.getBlock();
      plant.grow(par3World, new Random(), pos, blockState);
    }

    return true;
  }
  // 右クリック効果
  @Override
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    Block block = par3World.getBlock(par4, par5, par6);
    TileEntity tile = par3World.getTileEntity(par4, par5, par6);
    int meta = par3World.getBlockMetadata(par4, par5, par6);

    if (par2EntityPlayer == null) return false;
    boolean se = false;

    // charge
    if (tile instanceof MachineBase) {
      MachineBase machine = (MachineBase) tile;
      if (!machine.isFullCharged()) {
        int max = machine.getMaxChargeAmount();
        int ret = machine.getChargeAmount() + 800;
        ret = MathHelper.clamp_int(ret, 0, max);
        machine.setChargeAmount(ret);
        se = true;
      }
    } else if (tile instanceof TileChargerDevice) {
      TileChargerDevice device = (TileChargerDevice) tile;
      if (!device.isFullCharged()) {
        int max = device.getMaxChargeAmount();
        int ret = device.getChargeAmount() + 800;
        ret = MathHelper.clamp_int(ret, 0, max);
        device.setChargeAmount(ret);
        se = true;
      }
    }
    // RF
    else if (ModAPIManager.INSTANCE.hasAPI("CoFHAPI|energy") && RFDeviceHandler.isRFDevice(tile)) {
      se = RFDeviceHandler.inputEnergy(ForgeDirection.UP, tile, 1000, false) > 0;
    }

    // Barrel
    if (tile instanceof TileBrewingBarrel) {
      TileBrewingBarrel barrel = (TileBrewingBarrel) tile;
      if (!barrel.getAged() && !barrel.productTank.isEmpty()) {
        barrel.setAgingStage(4);
        se = true;
      }
    }

    // 骨粉
    if (ItemDye.applyBonemeal(par1ItemStack, par3World, par4, par5, par6, par2EntityPlayer)) {
      if (!par3World.isRemote) {
        par3World.playAuxSFX(2005, par4, par5, par6, 0);
        se = true;
      }
    }

    // どれでもなかった場合
    if (!se) {
      if (block.canPlaceTorchOnTop(par3World, par4, par5, par6)
          && par3World.isAirBlock(par4, par5 + 1, par6)) {
        if (!par3World.isRemote) par3World.setBlock(par4, par5 + 1, par6, Blocks.torch);
        se = true;
      }
    }

    if (se) {
      par3World.playSoundAtEntity(par2EntityPlayer, "random.pop", 0.4F, 1.8F);
    }
    return true;
  }