Ejemplo n.º 1
0
 private void forMelee(Creeper creeper) {
   Location lcreeper = creeper.getLocation();
   LivingEntity player = creeper.getTarget();
   Location lplayer = player.getLocation();
   Vector vcreeper = new Vector(lcreeper.getX(), lcreeper.getY(), lcreeper.getZ());
   Vector vplayer = new Vector(lplayer.getX(), lplayer.getY(), lplayer.getZ());
   if (vplayer.isInSphere(vcreeper, 3d)) {
     switch (lplayer.getWorld().getDifficulty()) {
       case EASY:
         player.damage(3, creeper);
       case NORMAL:
         player.damage(4, creeper);
       case HARD:
         player.damage(6, creeper);
     }
   }
 }
Ejemplo n.º 2
0
  protected void lightArea(Player player, int intensity, int falloff) {
    assert (intensity >= 0);
    assert (intensity <= 15);
    assert (falloff > 0);
    assert (falloff <= 15);
    CraftWorld world = (CraftWorld) player.getWorld();
    int radius = intensity / falloff;
    int blockX = player.getLocation().getBlockX();
    int blockY = player.getLocation().getBlockY();
    int blockZ = player.getLocation().getBlockZ();

    // first reset all light around
    if (playerBlocks.containsKey(player)) {
      unLightarea(player);
      playerBlocks.remove(player);
    }

    List<Location> blockList = new ArrayList<Location>();

    for (int x = -radius; x <= radius; x++)
      for (int y = -radius; y <= radius; y++)
        for (int z = -radius; z <= radius; z++) {
          int newIntensity;
          int curIntensity = world.getHandle().getLightLevel(blockX + x, blockY + y, blockZ + z);

          if (fastServer == false) {
            // this is fast
            newIntensity =
                (intensity - (Math.abs(x) + Math.abs(y) + Math.abs(z))) < 0
                    ? 0
                    : intensity - (Math.abs(x) + Math.abs(y) + Math.abs(z));
          } else {
            // this is slow, but nicer
            Vector origin = new Vector(blockX, blockY, blockZ);
            Vector v = new Vector(blockX + x, blockY + y, blockZ + z);
            if (v.isInSphere(origin, radius)) {
              // looks like the entry is within the radius
              double distanceSq = v.distanceSquared(origin);
              newIntensity =
                  (int) (((intensity - Math.sqrt(distanceSq) * falloff) * 100 + 0.5) / 100);
            } else {
              newIntensity = curIntensity;
            }
          }

          TorchBurnLightLevelOwner prevIntensity;
          Location l = new Location(world, blockX + x, blockY + y, blockZ + z);
          prevIntensity = TorchBurn.prevState.get(l);
          int worldIntensity = world.getHandle().getLightLevel(blockX + x, blockY + y, blockZ + z);
          if (prevIntensity != null) {
            // this area was in the map already. see if we are brightening and if it belongs to us
            if (prevIntensity.getLevel() < newIntensity
                && !(prevIntensity.getPlayer().equals(player))) {
              // we are brightening, remove the other guy's entry and add our own
              TorchBurn.prevState.remove(l);
              TorchBurn.prevState.put(l, new TorchBurnLightLevelOwner(player, worldIntensity));
            }
          } else {
            // add the current world's light level to the map
            TorchBurn.prevState.put(
                l,
                new TorchBurnLightLevelOwner(
                    player, world.getHandle().getLightLevel(blockX + x, blockY + y, blockZ + z)));
          }
          // light 'em up!
          if (newIntensity > worldIntensity) {
            //						if my pull request to bukkit gets accepted
            //						l.getBlock().setLightLevel(newIntensity);
            world
                .getHandle()
                .a(EnumSkyBlock.BLOCK, blockX + x, blockY + y, blockZ + z, newIntensity);
          }

          blockList.add(l);
        }
    playerBlocks.put(player, blockList);
  }