コード例 #1
0
  @Override
  public boolean onBlockDestroyed(
      ItemStack stack, World world, int blockID, int x, int y, int z, EntityPlayer player) {
    boolean b = false;
    Block block = Block.blocksList[blockID];
    int plant = (int) ModuleManager.computeModularProperty(stack, PLANT_RADIUS);
    int leaf = (int) ModuleManager.computeModularProperty(stack, LEAF_RADIUS);
    int totalEnergyDrain = 0;

    // Leaves
    if (block != null && block.isLeaves(world, x, y, z)) {
      for (int i = -leaf; i < leaf; i++) {
        for (int j = -leaf; j < leaf; j++) {
          for (int k = -leaf; k < leaf; k++) {
            int id = world.getBlockId(x + i, y + j, z + k);
            int meta = world.getBlockId(x + i, y + j, z + k);
            Block tempBlock = Block.blocksList[id];
            if (tempBlock != null && tempBlock.isLeaves(world, x + i, y + j, z + k)) {
              if (block.canHarvestBlock(player, meta)) {
                block.harvestBlock(world, player, x + i, y + j, z + k, meta);
                totalEnergyDrain +=
                    ModuleManager.computeModularProperty(stack, LEAF_BLOWER_ENERGY_CONSUMPTION);
              }
              world.setBlock(x + i, y + j, z + k, 0);
              b = true;
            }
          }
        }
      }
    }

    for (int i = -plant; i < plant; i++) {
      for (int j = -plant; j < plant; j++) {
        for (int k = -plant; k < plant; k++) {
          int id = world.getBlockId(x + i, y + j, z + k);
          int meta = world.getBlockId(x + i, y + j, z + k);
          Block tempBlock = Block.blocksList[id];
          if (tempBlock != null && tempBlock instanceof BlockFlower) {
            if (block.canHarvestBlock(player, meta)) {
              block.harvestBlock(world, player, x + i, y + j, z + k, meta);
              totalEnergyDrain +=
                  ModuleManager.computeModularProperty(stack, LEAF_BLOWER_ENERGY_CONSUMPTION);
            }
            world.setBlock(x + i, y + j, z + k, 0);
            b = true;
          }
        }
      }
    }
    ElectricItemUtils.drainPlayerEnergy(player, totalEnergyDrain);
    return b;
  }
コード例 #2
0
 @Override
 public void onPlayerTickActive(EntityPlayer player, ItemStack item) {
   double totalEnergy = ElectricItemUtils.getPlayerEnergy(player);
   PotionEffect invis = null;
   Collection<PotionEffect> effects = player.getActivePotionEffects();
   for (PotionEffect effect : effects) {
     if (effect.getAmplifier() == 81 && effect.getPotionID() == Potion.invisibility.id) {
       invis = effect;
       break;
     }
   }
   if (50 < totalEnergy) {
     if (invis == null || invis.getDuration() < 210) {
       player.addPotionEffect(new PotionEffect(Potion.invisibility.id, 500, 81));
       ElectricItemUtils.drainPlayerEnergy(player, 50);
     }
   } else {
     if (invis != null) {
       player.removePotionEffect(Potion.invisibility.id);
     }
   }
 }