private boolean isSolid(World world, int x, int y, int z) {
   if (World.doesBlockHaveSolidTopSurface(world, x, y, z)) {
     return true;
   } else {
     Block block = world.getBlock(x, y, z);
     return block.canPlaceTorchOnTop(world, x, y, z);
   }
 }
Example #2
0
  public static McBlockPart placement(World world, BlockCoord pos, int side) {
    if (side == 0) return null;
    pos = pos.copy().offset(side ^ 1);
    Block block = world.getBlock(pos.x, pos.y, pos.z);
    if (!block.isBlockSolid(world, pos.x, pos.y, pos.z, side)
        && (side != 1 || block.canPlaceTorchOnTop(world, pos.x, pos.y, pos.z))) return null;

    return new TorchPart(sideMetaMap[side ^ 1]);
  }
  // 右クリック効果
  @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;
  }