Пример #1
0
  @Override
  @SuppressWarnings(
      "deprecation") // Player.updateInventory has been deprecated for a while with no alternative
                     // available yet
  public void onClick(final InventoryClickEvent click) {
    final int last = click.getView().getTopInventory().getSize() - 1;

    // cancel shift clicks on items outside of delivery inventory to prevent indirect moving of
    // items into delivery inventory
    if (click.isShiftClick()
        && (click.getCurrentItem().getTypeId() != Material.AIR.getId())
        && (click.getRawSlot() > last)) click.setCancelled(true);

    // cancel clicks with item on cursor in delivery inventory to prevent direct placement of items
    // into delivery inventory
    if ((click.getCursor().getTypeId() != Material.AIR.getId())
        && (click.getRawSlot() >= 0)
        && (click.getRawSlot() <= last)) click.setCancelled(true);

    if (click.isCancelled()) {
      click.setCursor(click.getCursor());
      ((Player) click.getWhoClicked()).updateInventory();
      this.courier.send((Player) click.getWhoClicked(), "withdraw-only");
    }
  }
 public TARDISCommands(TARDIS plugin) {
   this.plugin = plugin;
   // add transparent blocks
   transparent.add((byte) Material.AIR.getId());
   transparent.add((byte) Material.SNOW.getId());
   transparent.add((byte) Material.LONG_GRASS.getId());
   transparent.add((byte) Material.VINE.getId());
   // add first arguments
   firstArgs.add("chameleon");
   firstArgs.add("save");
   firstArgs.add("removesave");
   firstArgs.add("list");
   firstArgs.add("help");
   firstArgs.add("find");
   firstArgs.add("reload");
   firstArgs.add("add");
   firstArgs.add("remove");
   firstArgs.add("update");
   firstArgs.add("rebuild");
   firstArgs.add("comehere");
   firstArgs.add("direction");
   firstArgs.add("setdest");
   firstArgs.add("hide");
   firstArgs.add("home");
   firstArgs.add("occupy");
   firstArgs.add("namekey");
   firstArgs.add("version");
 }
  public void onPlayerInteract(PlayerInteractEvent pie) {
    if (Action.LEFT_CLICK_BLOCK.equals(pie.getAction())
        || (isValidBlock(pie.getClickedBlock())
            && Action.RIGHT_CLICK_BLOCK.equals(pie.getAction()))) {
      Block clicked = pie.getClickedBlock();
      Block behind = clicked.getRelative(pie.getBlockFace().getOppositeFace());

      SecretDoor door = null;

      if (Material.WOODEN_DOOR.equals(clicked.getType()) && !SecretDoor.isDoubleDoor(clicked)) {
        if (this.plugin.isSecretDoor(SecretDoor.getKeyFromBlock(clicked))) {
          this.plugin.closeDoor(SecretDoor.getKeyFromBlock(clicked));
        } else if (!Material.AIR.equals(behind.getType())) {
          if (SecretDoor.isAdjacentDoor(clicked, pie.getBlockFace()))
            door = new SecretDoor(clicked, behind, SecretDoor.Direction.DOOR_FIRST);
        }

      } else if (Material.WOODEN_DOOR.equals(behind.getType())
          && !SecretDoor.isDoubleDoor(behind)) {
        if (this.plugin.isSecretDoor(SecretDoor.getKeyFromBlock(behind))) {
          this.plugin.closeDoor(SecretDoor.getKeyFromBlock(behind));
        } else if (SecretDoor.isAdjacentDoor(behind, pie.getBlockFace().getOppositeFace()))
          door = new SecretDoor(behind, clicked, SecretDoor.Direction.BLOCK_FIRST);
      }

      if (!(door == null)) {
        plugin.addDoor(door).open();
        pie.getPlayer().sendMessage(ChatColor.RED + "Don't forget to close the door!");
      }
    }
  }
Пример #4
0
 private static void initTransparentBlocks() {
   transparentBlocks.add(((Integer) Material.AIR.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.BREWING_STAND.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.BROWN_MUSHROOM.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.CAKE.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.CROPS.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.DETECTOR_RAIL.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.DIODE_BLOCK_ON.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.DIODE_BLOCK_OFF.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.LADDER.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.LAVA.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.LEVER.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.LONG_GRASS.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.MELON_STEM.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.NETHER_STALK.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.PAINTING.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.PORTAL.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.POWERED_RAIL.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.PUMPKIN_STEM.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.RAILS.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.RED_MUSHROOM.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.RED_ROSE.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.REDSTONE_TORCH_ON.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.REDSTONE_TORCH_OFF.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.REDSTONE_WIRE.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.SAPLING.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.SIGN_POST.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.SNOW.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.TORCH.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.VINE.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.WALL_SIGN.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.WATER.getId()).byteValue());
   transparentBlocks.add(((Integer) Material.YELLOW_FLOWER.getId()).byteValue());
 }
  /**
   * We listen to BlockPlace events for obvious reasons.
   *
   * @param event the event
   */
  @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
  public void onBlockPlace(final BlockPlaceEvent event) {
    /*
     *  ____  _            _      ____  _
     * | __ )| | ___   ___| | __ |  _ \| | __ _  ___ ___
     * |  _ \| |/ _ \ / __| |/ / | |_) | |/ _` |/ __/ _ \
     * | |_) | | (_) | (__|   <  |  __/| | (_| | (_|  __/
     * |____/|_|\___/ \___|_|\_\ |_|   |_|\__,_|\___\___|
     */

    final Block block = event.getBlockPlaced();
    final Block blockAgainst = event.getBlockAgainst();
    // We don't care about null blocks.
    if (block == null || blockAgainst == null) return;

    final Material mat = block.getType();
    final Player player = event.getPlayer();
    boolean cancelled = false;

    // Check if the block may be placed against a certain material.
    // TODO: Maybe make it an extra check after all.
    final int againstId = blockAgainst.getTypeId();
    if (BlockProperties.isLiquid(againstId)) {
      if ((mat != Material.WATER_LILY
              || !BlockProperties.isLiquid(block.getRelative(BlockFace.DOWN).getTypeId()))
          && !player.hasPermission(Permissions.BLOCKPLACE_AGAINST_LIQUIDS)) cancelled = true;
    } else if (againstId == Material.AIR.getId()) {
      if (!player.hasPermission(Permissions.BLOCKPLACE_AGAINST_AIR)) cancelled = true;
    }

    // First, the fast place check.
    if (fastPlace.isEnabled(player)) {
      if (fastPlace.check(player, block)) cancelled = true;
      else // Combined speed:
      if (Improbable.check(player, 1f, System.currentTimeMillis())) cancelled = true;
    }

    // Second, the no swing check (player doesn't swing his arm when placing a lily pad).
    if (!cancelled
        && mat != Material.WATER_LILY
        && noSwing.isEnabled(player)
        && noSwing.check(player)) cancelled = true;

    // Third, the reach check.
    if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation()))
      cancelled = true;

    // Fourth, the direction check.
    if (!cancelled
        && direction.isEnabled(player)
        && direction.check(player, block.getLocation(), blockAgainst.getLocation()))
      cancelled = true;

    // If one of the checks requested to cancel the event, do so.
    if (cancelled) event.setCancelled(cancelled);
  }
 protected void setCellEmpty(int aMazeX, int aMazeY, int aMazeZ) {
   for (int wx = 0; wx < corridorWidth; wx++) {
     for (int wz = 0; wz < corridorWidth; wz++) {
       for (int y = 0; y < corridorHeight; y++) {
         area.get(getX(aMazeX) + wx, getY(aMazeY) + y, getZ(aMazeZ) + wz).id =
             Material.AIR.getId();
       }
     }
   }
 }
 protected void breakWall(int aMazeX, int aMazeY, int aMazeZ, int aMazeDirection) {
   int lDx = fMaze.getDeltaX(aMazeDirection);
   int lDy = fMaze.getDeltaY(aMazeDirection);
   int lDz = fMaze.getDeltaZ(aMazeDirection);
   // normaler gang?
   if (lDy == 0) {
     if (lDz == 0) {
       for (int wd = 0; wd < corridorWidth; wd++) {
         for (int w = 1; w <= wallThickness; w++) {
           for (int y = 0; y < corridorHeight; y++) {
             area.get(getX(aMazeX) + w * lDx, getY(aMazeY) + y, getZ(aMazeZ) + wd).id =
                 Material.AIR.getId();
           }
         }
       }
     } else {
       for (int wd = 0; wd < corridorWidth; wd++) {
         for (int w = 1; w <= wallThickness; w++) {
           for (int y = 0; y < corridorHeight; y++) {
             area.get(getX(aMazeX) + wd, getY(aMazeY) + y, getZ(aMazeZ) + w * lDz).id =
                 Material.AIR.getId();
           }
         }
       }
     }
   } else {
     if (upDownUseCorridorWidth) {
       for (int wz = 0; wz < corridorWidth; wz++) {
         for (int wx = 0; wx < corridorWidth; wx++) {
           for (int w = 1; w <= ceilingThickness; w++) {
             area.get(getX(aMazeX) + wx, getY(aMazeY) + lDy * w, getZ(aMazeZ) + wz).id =
                 Material.AIR.getId();
           }
         }
       }
     } else {
       for (int w = 1; w <= ceilingThickness; w++) {
         area.get(getX(aMazeX), getY(aMazeY) + lDy * w, getZ(aMazeZ)).id = Material.AIR.getId();
       }
     }
   }
 }
Пример #8
0
  public NetherShrine() {
    super("Nether Shrine", "HmmmQuestionMark", 6);

    // Create the main block
    add(new Selection(0, 1, 0, Material.GOLD_BLOCK.name()));

    // Create the ender chest and the block below
    add(new Selection(0, 0, 0, Material.ENDER_CHEST.name()));
    add(new Selection(0, -1, 0, Material.NETHER_BRICK.name()));

    // Create the rest
    add(new Selection(-1, 0, 0, Material.NETHER_BRICK_STAIRS.name()));
    add(new Selection(1, 0, 0, Material.NETHER_BRICK_STAIRS.name(), (byte) 1));
    add(new Selection(0, 0, -1, Material.NETHER_BRICK_STAIRS.name(), (byte) 2));
    add(new Selection(0, 0, 1, Material.NETHER_BRICK_STAIRS.name(), (byte) 3));

    // Safe zone
    add(new Selection(1, -1, 1, Material.NETHER_BRICK.name()));
    add(new Selection(1, 0, 1, Material.AIR.name()));
    add(new Selection(1, 1, 1, Material.AIR.name()));
  }
 public HallTunneler tunnel(int min, int max, XorZRetriever currentAxisValue) {
   int cVal = currentAxisValue.get(current);
   if (nextDir != null) {
     Byte dir = getByteDirection(nextDir);
     Byte opDir = getByteDirection(nextDir.getOppositeFace());
     while (!(cVal >= min && cVal <= max)) {
       current = current.getFace(nextDir);
       current.setTypeId(0);
       current.getFace(BlockFace.UP).setTypeId(0);
       if (by < requester.getMinY()) {
         if (dir != null) {
           current.setTypeIdAndData(67, dir, false);
         }
         current = current.getFace(BlockFace.UP);
         current.getFace(BlockFace.UP).setTypeId(0);
       } else if (by > requester.getMinY()) {
         current = current.getFace(BlockFace.DOWN);
         current.setTypeId(0);
         if (by + BlockFace.DOWN.getModY() >= requester.getMinY()) {
           current.getFace(BlockFace.DOWN).setTypeIdAndData(67, opDir, false);
         }
         if (Material.AIR.equals(current.getFace(nextDir).getType())) {
           current = current.getFace(nextDir);
           while (Material.AIR.equals(current.getFace(BlockFace.DOWN).getType())) {
             current = current.getFace(BlockFace.DOWN);
             current.setTypeIdAndData(Material.LADDER.getId(), opDir, false);
           }
           break;
         }
       }
       cVal = currentAxisValue.get(current);
       by = current.getY();
     }
     nextDir = null;
   }
   return this;
 }
Пример #10
0
 protected void randomizeMaterials() {
   switch (random.nextInt(5)) {
     case 0:
       // lava, sand/sandstone/stone, mushroom stalks
       byteLiquid = (byte) Material.STATIONARY_LAVA.getId();
       byteStone = (byte) Material.STONE.getId();
       byteDirt = (byte) Material.SANDSTONE.getId();
       byteGrass = (byte) Material.SAND.getId();
       intTreeTrunk = Material.HUGE_MUSHROOM_1.getId();
       intTreeLeaves = intAir;
       byteTreeData = (byte) (random.nextInt(2) == 0 ? 10 : 1);
       break;
     case 1:
       // air, sand/sandstone/stone, cactus
       byteLiquid = (byte) Material.AIR.getId();
       byteStone = (byte) Material.STONE.getId();
       byteDirt = (byte) Material.SANDSTONE.getId();
       byteGrass = (byte) Material.SAND.getId();
       intTreeTrunk = Material.CACTUS.getId();
       intTreeLeaves = intAir;
       minTreeHeight = 2;
       maxTreeHeight = 4;
       break;
     case 3:
       // water, glass/glowstone/endstone, crystals
       byteLiquid = (byte) Material.STATIONARY_WATER.getId();
       byteStone = (byte) Material.ENDER_STONE.getId();
       byteDirt = (byte) Material.SOUL_SAND.getId();
       byteGrass = (byte) Material.MYCEL.getId();
       intTreeTrunk = Material.GLOWSTONE.getId();
       intTreeLeaves = Material.THIN_GLASS.getId();
       break;
     default:
       // water, grass/dirt/stone, normal trees are the default
       byteTreeData = (byte) random.nextInt(3);
       break;
   }
 }
Пример #11
0
  public int calculateCost() {
    if (pw.isPlotCostCalculated()) {

      int cost = 0;

      int higherX = Math.max(location1.getBlockX(), location2.getBlockX());
      int lowerX = Math.min(location1.getBlockX(), location2.getBlockX());

      int higherZ = Math.max(location1.getBlockZ(), location2.getBlockZ());
      int lowerZ = Math.min(location1.getBlockZ(), location2.getBlockZ());

      BlockPriceDefinition bpd = pw.getPlotBlockPrices();

      World w = location1.getWorld();
      for (int x = lowerX; x <= higherX; x++) {

        for (int z = lowerZ; z <= higherZ; z++) {

          for (int y = 0; y <= w.getHighestBlockYAt(x, z); y++) {

            Block b = w.getBlockAt(x, y, z);

            if (b.getTypeId() != Material.AIR.getId()) cost += bpd.getBlockPrice(b.getTypeId());
          }
        }
      }

      return cost;

    } else {
      return pw.getUncalculatedCostPerBlock()
          * Math.abs(
              (location1.getBlockX() - location2.getBlockX())
                  * (location1.getBlockZ() - location2.getBlockZ()));
    }
  }
Пример #12
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {

    if (event.getAction() == Action.PHYSICAL) {
      return;
    }

    int mode = 0;
    Player player = event.getPlayer();
    Stick stick = null;

    stick = plugin.getStick(player);

    mode = stick.getMode();

    if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
      if (player.getGameMode() == GameMode.CREATIVE && stick.isEnabled()) {
        event.setCancelled(true);
      }
      return;
    }

    if (event.getAction() == Action.RIGHT_CLICK_BLOCK
        && stick.isThrowBuild()
        && player.getItemInHand().getType() != stick.getTool()) {
      return;
    }

    if (!stick.doRightClickModes()
        && (event.getAction() == Action.RIGHT_CLICK_AIR
            || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
      mode = Stick.REMOVE_MODE;
    }

    if (plugin.canUse(player, stick, mode)) {

      event.setCancelled(true);

      List<Block> targetBlocks =
          player.getLastTwoTargetBlocks(stick.getIgnore(), stick.getDistance());

      // sanity check
      if (targetBlocks.size() != 2) {
        plugin.log(Level.WARNING, "Did not get two blocks to work with");
        return;
      }

      Block targetedBlock = null;
      Block placedAgainstBlock = null;

      Item item = stick.getItem();

      if (!item.isBlock()) {
        item = MaterialUtils.getPlaceableMaterial(item);
        if (!item.isBlock()) {
          if (!stick.isThrowBuild()) {
            MessageUtils.send(player, ChatColor.RED, "Invalid item usage.");
          } else {
            event.setCancelled(false);
          }
          return;
        }
      }

      BlockEvent actionEvent = null;

      if (mode == Stick.REPLACE_MODE || mode == Stick.REMOVE_MODE) {
        targetedBlock = targetBlocks.get(1);
        placedAgainstBlock = targetBlocks.get(0);
      } else if (mode == Stick.BUILD_MODE) {
        targetedBlock = targetBlocks.get(0);
        placedAgainstBlock = targetBlocks.get(1);
      }

      if (targetedBlock.getLocation().getBlockY() == 0 && stick.doProtectBottom()) {
        plugin.log(Level.WARNING, "Player " + player.getDisplayName() + " hit rock bottom!");
        return;
      }

      if (LocationUtil.isSameLocation(player, targetedBlock)) {
        if (stick.isDebug()) {
          MessageUtils.send(player, "** boink **");
        }

        return;
      }

      BlockState after = targetedBlock.getState();
      after.setType(mode == Stick.REMOVE_MODE ? Material.AIR : item.getMaterial());

      MaterialData data = null;
      if (mode == Stick.REMOVE_MODE) {
        data = Material.AIR.getNewData((byte) 0);
      } else if (MaterialUtils.isSameMaterial(item.getMaterial(), Material.LADDER)) {
        BlockFace face = LocationUtil.getFace(player, targetedBlock);
        if (stick.isDebug()) {
          MessageUtils.send(player, "clicked " + face + " face! (" + player.getEyeLocation() + ")");
        }

        Ladder ladder = new Ladder();
        ladder.setFacingDirection(face);
        data = ladder;

      } else {
        data = item.getData();
      }

      if (data != null) after.setData(data);

      BlockState before = targetedBlock.getState();
      if (mode == Stick.REMOVE_MODE) {
        stick.setDoItemSwitch(true);
        actionEvent = new BlockBreakEvent(targetedBlock, player);
      } else if (MaterialUtils.isSameMaterial(item.getMaterial(), Material.FIRE)) {
        actionEvent = new BlockIgniteEvent(targetedBlock, IgniteCause.FLINT_AND_STEEL, player);
      } else {
        actionEvent =
            new BlockPlaceEvent(
                after.getBlock(),
                before,
                placedAgainstBlock,
                new ItemStack(stick.getTool()),
                player,
                true);
      }

      plugin.getServer().getPluginManager().callEvent(actionEvent);

      if (!((Cancellable) actionEvent).isCancelled()) {
        plugin.takeAction(before, after, player);
      }
    }
  }
Пример #13
0
 public void manageDeath(PlayerKilledEvent event) {
   Gamer killed = event.getKilled();
   final Player p = killed.getPlayer();
   p.setHealth(20);
   if (event.isCancelled()) return;
   for (HumanEntity human : p.getInventory().getViewers()) human.closeInventory();
   p.leaveVehicle();
   p.eject();
   p.setLevel(0);
   p.setExp(0F);
   if (event.getDeathMessage().equals(ChatColor.stripColor(event.getDeathMessage())))
     event.setDeathMessage(ChatColor.DARK_RED + event.getDeathMessage());
   event.setDeathMessage(
       this.formatDeathMessage(
           event.getDeathMessage().replace("%Remaining%", "" + (getAliveGamers().size() - 1)), p));
   if (event.getKillerPlayer() != null) {
     event.getKillerPlayer().addKill();
     event.setDeathMessage(
         this.formatDeathMessage(event.getDeathMessage(), event.getKillerPlayer().getPlayer()));
   }
   Bukkit.broadcastMessage(event.getDeathMessage());
   int reward = hg.getPrize(getAliveGamers().size());
   if (reward > 0) killed.addBalance(reward);
   hg.cannon();
   killed.clearInventory();
   World world = p.getWorld();
   for (ItemStack item : event.getDrops()) {
     if (item == null
         || item.getType() == Material.AIR
         || item.containsEnchantment(EnchantmentManager.UNLOOTABLE)) continue;
     else if (item.hasItemMeta())
       world
           .dropItemNaturally(event.getDropsLocation(), item.clone())
           .getItemStack()
           .setItemMeta(item.getItemMeta());
     else world.dropItemNaturally(event.getDropsLocation(), item);
   }
   setSpectator(killed);
   ScoreboardManager.makeScore(
       "Main", DisplaySlot.SIDEBAR, cm.getScoreboardPlayersLength(), getAliveGamers().size());
   hg.checkWinner();
   p.setVelocity(new Vector());
   for (PotionEffect effect : p.getActivePotionEffects()) p.removePotionEffect(effect.getType());
   p.teleport(p.getWorld().getHighestBlockAt(p.getLocation()).getLocation().clone().add(0, 10, 0));
   p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 9), true);
   p.sendBlockChange(p.getLocation(), Material.PORTAL.getId(), (byte) 0);
   p.sendBlockChange(p.getLocation(), Material.AIR.getId(), (byte) 0);
   for (Entity entity : p.getWorld().getEntities()) {
     if (entity instanceof Tameable
         && ((Tameable) entity).isTamed()
         && ((Tameable) entity).getOwner().getName().equals(p.getName())) {
       if (entity instanceof Wolf) ((Wolf) entity).setSitting(true);
       else if (entity instanceof Ocelot) ((Ocelot) entity).setSitting(true);
       else entity.remove();
     }
     if (entity instanceof Creature && ((Creature) entity).getTarget() == p)
       ((Creature) entity).setTarget(null);
   }
   if (HungergamesApi.getConfigManager().getMainConfig().isKickOnDeath()
       && !p.hasPermission("hungergames.spectate"))
     p.kickPlayer(String.format(cm.getKickDeathMessage(), event.getDeathMessage()));
   HungergamesApi.getAbilityManager().unregisterPlayer(p);
   HungergamesApi.getInventoryManager().updateSpectatorHeads();
 }
Пример #14
0
public abstract class BananaWellArchetype extends WellArchetype {

  // normal materials
  protected byte byteLiquid = (byte) Material.STATIONARY_WATER.getId();
  protected byte byteStone = (byte) Material.STONE.getId();
  protected byte byteDirt = (byte) Material.DIRT.getId();
  protected byte byteGrass = (byte) Material.GRASS.getId();
  protected byte byteLog = (byte) Material.LOG.getId();
  protected byte byteLeaves = (byte) Material.LEAVES.getId();
  protected byte byteAir = (byte) Material.AIR.getId();
  protected int intOre = byteStone;
  protected int intTreeBase = byteGrass;
  protected int intTreeTrunk = byteLog;
  protected int intTreeLeaves = byteLeaves;

  protected byte byteTreeData = 0;
  protected int intAir = Material.AIR.getId();
  protected int minTreeHeight = 5;
  protected int maxTreeHeight = 5;

  public BananaWellArchetype(World world, long seed, int wellX, int wellZ) {
    super(world, seed, wellX, wellZ);

    // figure out materials
    calculateMaterials();
  }

  // override this if you want something special
  protected void calculateMaterials() {
    randomizeMaterials();

    //  copy over the "seed" materials used by populateOres and populateFoliage
    intOre = byteStone;
    intTreeBase = byteGrass;
  }

  protected void randomizeMaterials() {
    switch (random.nextInt(5)) {
      case 0:
        // lava, sand/sandstone/stone, mushroom stalks
        byteLiquid = (byte) Material.STATIONARY_LAVA.getId();
        byteStone = (byte) Material.STONE.getId();
        byteDirt = (byte) Material.SANDSTONE.getId();
        byteGrass = (byte) Material.SAND.getId();
        intTreeTrunk = Material.HUGE_MUSHROOM_1.getId();
        intTreeLeaves = intAir;
        byteTreeData = (byte) (random.nextInt(2) == 0 ? 10 : 1);
        break;
      case 1:
        // air, sand/sandstone/stone, cactus
        byteLiquid = (byte) Material.AIR.getId();
        byteStone = (byte) Material.STONE.getId();
        byteDirt = (byte) Material.SANDSTONE.getId();
        byteGrass = (byte) Material.SAND.getId();
        intTreeTrunk = Material.CACTUS.getId();
        intTreeLeaves = intAir;
        minTreeHeight = 2;
        maxTreeHeight = 4;
        break;
      case 3:
        // water, glass/glowstone/endstone, crystals
        byteLiquid = (byte) Material.STATIONARY_WATER.getId();
        byteStone = (byte) Material.ENDER_STONE.getId();
        byteDirt = (byte) Material.SOUL_SAND.getId();
        byteGrass = (byte) Material.MYCEL.getId();
        intTreeTrunk = Material.GLOWSTONE.getId();
        intTreeLeaves = Material.THIN_GLASS.getId();
        break;
      default:
        // water, grass/dirt/stone, normal trees are the default
        byteTreeData = (byte) random.nextInt(3);
        break;
    }
  }

  @Override
  public void populateBlocks(Chunk chunk, int chunkX, int chunkZ) {
    // ores
    populateOres(chunk);

    // foliage
    populateFoliage(chunk);
  }

  /**
   * Populates the world with ores.
   *
   * @author Nightgunner5
   * @author Markus Persson
   */
  private static final int[] iterations = new int[] {10, 20, 20, 2, 8, 1, 1, 1};

  private static final int[] amount = new int[] {32, 16, 8, 8, 7, 7, 6};
  private static final int[] type =
      new int[] {
        Material.GRAVEL.getId(),
        Material.COAL_ORE.getId(),
        Material.IRON_ORE.getId(),
        Material.GOLD_ORE.getId(),
        Material.REDSTONE_ORE.getId(),
        Material.DIAMOND_ORE.getId(),
        Material.LAPIS_ORE.getId()
      };
  private static final int[] maxHeight = new int[] {128, 128, 128, 128, 128, 64, 32, 16, 16, 32};

  protected void populateOres(Chunk chunk) {
    // ores
    for (int i = 0; i < type.length; i++) {
      for (int j = 0; j < iterations[i]; j++) {
        placeOre(
            chunk,
            random.nextInt(16),
            random.nextInt(maxHeight[i]),
            random.nextInt(16),
            amount[i],
            type[i]);
      }
    }
  }

  private void placeOre(Chunk source, int originX, int originY, int originZ, int amount, int type) {
    for (int i = 0; i < amount; i++) {
      int x = originX + random.nextInt(amount / 2) - amount / 4;
      int y = originY + random.nextInt(amount / 4) - amount / 8;
      int z = originZ + random.nextInt(amount / 2) - amount / 4;
      x &= 0xf;
      z &= 0xf;
      if (y > 127 || y < 0) {
        continue;
      }
      Block block = source.getBlock(x, y, z);
      if (block.getTypeId() == intOre) {
        block.setTypeId(type, false);
      }
    }
  }

  private static final int chanceRange = 150;

  protected void populateFoliage(Chunk chunk) {

    //		int centerX = (chunk.getX() << 4) + random.nextInt(16);
    //		int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
    //		if (random.nextBoolean()) {
    //			data = 2;
    //			height = 5 + random.nextInt(3);
    //		}
    //
    //		//EC: tweaked the biome logic a bit
    //		switch (getBiome()) {
    //		case FOREST:
    //			chance = 160;
    //			multiplier = 10;
    //			break;
    //		case PLAINS:
    //			chance = 40;
    //			break;
    //		case RAINFOREST:
    //			chance = 160;
    //			multiplier = 10;
    //			break;
    //		case SAVANNA:
    //			chance = 20;
    //			break;
    //		case SEASONAL_FOREST:
    //			chance = 140;
    //			multiplier = 8;
    //			break;
    //		case SHRUBLAND:
    //			chance = 60;
    //			break;
    //		case SWAMPLAND:
    //			chance = 120;
    //			break;
    //		case TAIGA:
    //			chance = 120;
    //			data = 1;
    //			height = 8 + random.nextInt(3);
    //			multiplier = 3;
    //			break;
    //		case TUNDRA:
    //			chance = 10;
    //			data = 1;
    //			height = 7 + random.nextInt(3);
    //			break;
    //		case SKY:
    //		case DESERT:
    //		case HELL:
    //		case ICE_DESERT:
    //			chance = 5;
    //			return;
    //		}

    byte data = (byte) random.nextInt(3);
    int chance = chanceRange / 2;
    int height = minTreeHeight + random.nextInt(maxTreeHeight);
    int multiplier = 3 + random.nextInt(7);

    for (int i = 0; i < multiplier; i++) {
      int centerX = (chunk.getX() << 4) + random.nextInt(16);
      int centerZ = (chunk.getZ() << 4) + random.nextInt(16);
      if (random.nextInt(chanceRange) < chance) {
        int centerY = world.getHighestBlockYAt(centerX, centerZ) - 1;
        Block sourceBlock = world.getBlockAt(centerX, centerY, centerZ);

        // found a place to put it?
        if (sourceBlock.getTypeId() == intTreeBase) {

          // leaves or leave?
          if (intTreeLeaves != intAir) {
            setBlock(centerX, centerY + height + 1, centerZ, intTreeLeaves, data);
            // world.getBlockAt(centerX, centerY + height + 1, centerZ).setTypeIdAndData(intLeaves,
            // data, true);
            for (int j = 0; j < 4; j++) {
              setBlock(centerX, centerY + height + 1 - j, centerZ - 1, intTreeLeaves, data);
              setBlock(centerX, centerY + height + 1 - j, centerZ + 1, intTreeLeaves, data);
              setBlock(centerX - 1, centerY + height + 1 - j, centerZ, intTreeLeaves, data);
              setBlock(centerX + 1, centerY + height + 1 - j, centerZ, intTreeLeaves, data);
              // world.getBlockAt(centerX, centerY + height + 1 - j, centerZ -
              // 1).setTypeIdAndData(intLeaves, data, true);
              // world.getBlockAt(centerX, centerY + height + 1 - j, centerZ +
              // 1).setTypeIdAndData(intLeaves, data, true);
              // world.getBlockAt(centerX - 1, centerY + height + 1 - j,
              // centerZ).setTypeIdAndData(intLeaves, data, true);
              // world.getBlockAt(centerX + 1, centerY + height + 1 - j,
              // centerZ).setTypeIdAndData(intLeaves, data, true);
            }

            if (random.nextBoolean()) {
              setBlock(centerX + 1, centerY + height, centerZ + 1, intTreeLeaves, data);
              // world.getBlockAt(centerX + 1, centerY + height, centerZ +
              // 1).setTypeIdAndData(intLeaves, data, true);
            }
            if (random.nextBoolean()) {
              setBlock(centerX + 1, centerY + height, centerZ - 1, intTreeLeaves, data);
              // world.getBlockAt(centerX + 1, centerY + height, centerZ -
              // 1).setTypeIdAndData(intLeaves, data, true);
            }
            if (random.nextBoolean()) {
              setBlock(centerX - 1, centerY + height, centerZ + 1, intTreeLeaves, data);
              // world.getBlockAt(centerX - 1, centerY + height, centerZ +
              // 1).setTypeIdAndData(intLeaves, data, true);
            }
            if (random.nextBoolean()) {
              setBlock(centerX - 1, centerY + height, centerZ - 1, intTreeLeaves, data);
              // world.getBlockAt(centerX - 1, centerY + height, centerZ -
              // 1).setTypeIdAndData(intLeaves, data, true);
            }

            setBlock(centerX + 1, centerY + height - 1, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX + 1, centerY + height - 1, centerZ - 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 1, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 1, centerZ - 1, intTreeLeaves, data);
            setBlock(centerX + 1, centerY + height - 2, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX + 1, centerY + height - 2, centerZ - 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 2, centerZ + 1, intTreeLeaves, data);
            setBlock(centerX - 1, centerY + height - 2, centerZ - 1, intTreeLeaves, data);
            // world.getBlockAt(centerX + 1, centerY + height - 1, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX + 1, centerY + height - 1, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 1, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 1, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX + 1, centerY + height - 2, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX + 1, centerY + height - 2, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 2, centerZ +
            // 1).setTypeIdAndData(intLeaves, data, true);
            // world.getBlockAt(centerX - 1, centerY + height - 2, centerZ -
            // 1).setTypeIdAndData(intLeaves, data, true);

            for (int j = 0; j < 2; j++) {
              for (int k = -2; k <= 2; k++) {
                for (int l = -2; l <= 2; l++) {
                  setBlock(centerX + k, centerY + height - 1 - j, centerZ + l, intTreeLeaves, data);
                  // world.getBlockAt(centerX + k, centerY + height
                  //	- 1 - j, centerZ + l).setTypeIdAndData(intLeaves, data, true);
                }
              }
            }

            for (int j = 0; j < 2; j++) {
              if (random.nextBoolean())
                clearBlock(centerX + 2, centerY + height - 1 - j, centerZ + 2);
              if (random.nextBoolean())
                clearBlock(centerX + 2, centerY + height - 1 - j, centerZ - 2);
              if (random.nextBoolean())
                clearBlock(centerX - 2, centerY + height - 1 - j, centerZ + 2);
              if (random.nextBoolean())
                clearBlock(centerX - 2, centerY + height - 1 - j, centerZ - 2);
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX + 2, centerY + height - 1
              //		- j, centerZ + 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX + 2, centerY + height - 1
              //		- j, centerZ - 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX - 2, centerY + height - 1
              //		- j, centerZ + 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
              // if (random.nextBoolean()) {
              //	world.getBlockAt(centerX - 2, centerY + height - 1
              //		- j, centerZ - 2).setTypeIdAndData(intAir, (byte) 0, true);
              // }
            }
          }

          // Trunk
          for (int y = 1; y <= height; y++) {
            world
                .getBlockAt(centerX, centerY + y, centerZ)
                .setTypeIdAndData(intTreeTrunk, data, false);
          }
        }
      }
    }
  }
}
Пример #15
0
public abstract class PlatLot {

  // extremes
  private CachedYs blockYs;
  protected int averageHeight;
  protected int minHeight = Integer.MAX_VALUE;
  protected int minHeightX = 0;
  protected int minHeightZ = 0;
  protected int maxHeight = Integer.MIN_VALUE;
  protected int maxHeightX = 0;
  protected int maxHeightZ = 0;

  protected Random platmapRandom;
  protected Random chunkRandom;

  // styling!
  public enum LotStyle {
    NATURE,
    STRUCTURE,
    ROAD,
    ROUNDABOUT
  };

  public LotStyle style;

  public PlatLot(PlatMap platmap, int chunkX, int chunkZ) {
    super();
    initializeDice(platmap, chunkX, chunkZ);

    style = LotStyle.NATURE;
  }

  protected static final byte airId = (byte) Material.AIR.getId();
  protected static final byte stoneId = (byte) Material.STONE.getId();
  protected static final byte dirtId = (byte) Material.DIRT.getId();
  protected static final byte grassId = (byte) Material.GRASS.getId();
  protected static final byte snowId = (byte) Material.SNOW_BLOCK.getId();
  protected static final byte sandId = (byte) Material.SAND.getId();
  protected static final byte sandstoneId = (byte) Material.SANDSTONE.getId();
  protected static final byte bedrockId = (byte) Material.BEDROCK.getId();
  protected static final byte fenceId = (byte) Material.FENCE.getId();
  protected static final byte cobbleId = (byte) Material.COBBLESTONE.getId();
  protected static final byte stillWaterId = (byte) Material.STATIONARY_WATER.getId();
  protected static final byte stillLavaId = (byte) Material.STATIONARY_LAVA.getId();
  protected static final byte waterId = (byte) Material.WATER.getId();
  protected static final byte lavaId = (byte) Material.LAVA.getId();
  protected static final byte leavesId = (byte) Material.LEAVES.getId();
  protected static final byte glassId = (byte) Material.GLASS.getId();
  protected static final byte paneId = (byte) Material.THIN_GLASS.getId();
  protected static final byte logId = (byte) Material.LOG.getId();
  protected static final byte glowId = (byte) Material.GLOWSTONE.getId();
  protected static final byte stepId = (byte) Material.STEP.getId();
  protected static final byte clayId = (byte) Material.CLAY.getId();
  protected static final byte ironFenceId = (byte) Material.IRON_FENCE.getId();
  protected static final byte endId = (byte) Material.ENDER_STONE.getId();
  protected static final byte netherrackId = (byte) Material.NETHERRACK.getId();
  protected static final byte soulsandId = (byte) Material.SOUL_SAND.getId();

  protected static final int snowMaterialId = Material.SNOW.getId();
  protected static final Material snowMaterial = Material.SNOW;
  protected static final Material airMaterial = Material.AIR;
  protected static final Material stoneMaterial = Material.STONE;
  protected static final Material rootMaterial = Material.GRASS;

  public abstract long getConnectedKey();

  public abstract boolean makeConnected(PlatLot relative);

  public abstract boolean isConnectable(PlatLot relative);

  public abstract boolean isConnected(PlatLot relative);

  protected abstract void generateActualChunk(
      WorldGenerator generator,
      PlatMap platmap,
      ByteChunk chunk,
      BiomeGrid biomes,
      DataContext context,
      int platX,
      int platZ);

  protected abstract void generateActualBlocks(
      WorldGenerator generator,
      PlatMap platmap,
      RealChunk chunk,
      DataContext context,
      int platX,
      int platZ);

  public Biome getChunkBiome() {
    return Biome.PLAINS;
  }

  public boolean isPlaceableAt(WorldGenerator generator, int chunkX, int chunkZ) {
    return generator.settings.inCityRange(chunkX, chunkZ);
  }

  private void initializeDice(PlatMap platmap, int chunkX, int chunkZ) {

    // reset and pick up the dice
    platmapRandom = platmap.getRandomGenerator();
    chunkRandom = platmap.getChunkRandomGenerator(chunkX, chunkZ);
  }

  protected void initializeContext(WorldGenerator generator, SupportChunk chunk) {
    if (blockYs == null) {
      blockYs = new CachedYs(generator, chunk);

      // what was the average height
      minHeight = blockYs.minHeight;
      minHeightX = blockYs.minHeightX;
      minHeightZ = blockYs.minHeightZ;
      maxHeight = blockYs.maxHeight;
      maxHeightX = blockYs.maxHeightX;
      maxHeightZ = blockYs.maxHeightZ;
      averageHeight = blockYs.averageHeight;
    }
  }

  private void deinitializeContext() {
    blockYs = null;
  }

  protected int getBlockY(int x, int z) {
    return blockYs == null ? 0 : blockYs.getBlockY(x, z);
  }

  protected double getPerciseY(int x, int z) {
    return blockYs == null ? 0 : blockYs.getPerciseY(x, z);
  }

  public abstract int getBottomY(WorldGenerator generator);

  public void generateChunk(
      WorldGenerator generator,
      PlatMap platmap,
      ByteChunk chunk,
      BiomeGrid biomes,
      DataContext context,
      int platX,
      int platZ) {
    initializeDice(platmap, chunk.chunkX, chunk.chunkZ);
    initializeContext(generator, chunk);

    // what do we need to first?
    generator.shapeProvider.preGenerateChunk(generator, this, chunk, biomes, blockYs);

    // let the specialized platlot do it's thing
    generateActualChunk(generator, platmap, chunk, biomes, context, platX, platZ);

    // polish things off
    generator.shapeProvider.postGenerateChunk(generator, this, chunk, blockYs);
  }

  public void generateBlocks(
      WorldGenerator generator,
      PlatMap platmap,
      RealChunk chunk,
      DataContext context,
      int platX,
      int platZ) {
    initializeDice(platmap, chunk.chunkX, chunk.chunkZ);
    initializeContext(generator, chunk);

    // what do we need to first?
    generator.shapeProvider.preGenerateBlocks(generator, this, chunk, blockYs);

    // let the specialized platlot do it's thing
    generateActualBlocks(generator, platmap, chunk, context, platX, platZ);

    // polish things off
    generator.shapeProvider.postGenerateBlocks(generator, this, chunk, blockYs);

    // all done
    deinitializeContext();
  }

  private static final int lowestMineSegment = 16;

  public void generateMines(WorldGenerator generator, ByteChunk chunk) {

    // get shafted! (this builds down to keep the support poles happy)
    if (generator.settings.includeMines)
      for (int y = (minHeight / 16 - 1) * 16; y >= lowestMineSegment; y -= 16) {
        if (isShaftableLevel(generator, y)) generateHorizontalMineLevel(generator, chunk, y);
      }
  }

  protected int findHighestShaftableLevel(
      WorldGenerator generator, DataContext context, SupportChunk chunk) {

    // keep going down until we find what we are looking for
    for (int y = (minHeight / 16 - 1) * 16; y >= lowestMineSegment; y -= 16) {
      if (isShaftableLevel(generator, y)
          && generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y, chunk.chunkZ))
        return y + 7;
    }

    // nothing found
    return 0;
  }

  protected boolean isShaftableLevel(WorldGenerator generator, int y) {
    return y >= lowestMineSegment && y < minHeight && minHeight > generator.seaLevel;
  }

  private void generateHorizontalMineLevel(WorldGenerator generator, ByteChunk chunk, int y) {
    int y1 = y + 6;
    int y2 = y1 + 1;

    // draw the shafts/walkways
    boolean pathFound = false;
    if (generator.shapeProvider.isHorizontalNSShaft(chunk.chunkX, y, chunk.chunkZ)) {
      generateMineShaftSpace(chunk, 6, 10, y1, y1 + 4, 0, 6);
      generateMineNSSupport(chunk, 6, y2, 1);
      generateMineNSSupport(chunk, 6, y2, 4);
      generateMineShaftSpace(chunk, 6, 10, y1, y1 + 4, 10, 16);
      generateMineNSSupport(chunk, 6, y2, 11);
      generateMineNSSupport(chunk, 6, y2, 14);
      pathFound = true;
    }
    if (generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y, chunk.chunkZ)) {
      generateMineShaftSpace(chunk, 0, 6, y1, y1 + 4, 6, 10);
      generateMineWESupport(chunk, 1, y2, 6);
      generateMineWESupport(chunk, 4, y2, 6);
      generateMineShaftSpace(chunk, 10, 16, y1, y1 + 4, 6, 10);
      generateMineWESupport(chunk, 11, y2, 6);
      generateMineWESupport(chunk, 14, y2, 6);
      pathFound = true;
    }

    // draw the center bit
    if (pathFound) generateMineShaftSpace(chunk, 6, 10, y1, y1 + 4, 6, 10);
  }

  private static final byte shaftBridgeId = (byte) Material.WOOD.getId();
  private static final byte shaftSupportId = (byte) Material.FENCE.getId();
  private static final byte shaftBeamId = (byte) Material.WOOD.getId();

  private void generateMineShaftSpace(
      ByteChunk chunk, int x1, int x2, int y1, int y2, int z1, int z2) {
    chunk.setEmptyBlocks(x1, x2, y1, z1, z2, shaftBridgeId);
    chunk.setBlocks(x1, x2, y1 + 1, y2, z1, z2, airId);
  }

  private void generateMineNSSupport(ByteChunk chunk, int x, int y, int z) {

    // on a bridge
    if (chunk.getBlock(x, y - 1, z) == shaftBridgeId
        && chunk.getBlock(x + 3, y - 1, z) == shaftBridgeId) {

      // place supports
      generateMineSupport(chunk, x, y - 1, z);
      generateMineSupport(chunk, x + 3, y - 1, z);

      // in a tunnel
    } else {
      chunk.setBlock(x, y, z, shaftSupportId);
      chunk.setBlock(x, y + 1, z, shaftSupportId);
      chunk.setBlock(x + 3, y, z, shaftSupportId);
      chunk.setBlock(x + 3, y + 1, z, shaftSupportId);
      chunk.setBlocks(x, x + 4, y + 2, z, z + 1, shaftBeamId);
    }
  }

  private void generateMineWESupport(ByteChunk chunk, int x, int y, int z) {
    // on a bridge
    if (chunk.getBlock(x, y - 1, z) == shaftBridgeId
        && chunk.getBlock(x, y - 1, z + 3) == shaftBridgeId) {

      // place supports
      generateMineSupport(chunk, x, y - 1, z);
      generateMineSupport(chunk, x, y - 1, z + 3);

      // in a tunnel
    } else {
      chunk.setBlock(x, y, z, shaftSupportId);
      chunk.setBlock(x, y + 1, z, shaftSupportId);
      chunk.setBlock(x, y, z + 3, shaftSupportId);
      chunk.setBlock(x, y + 1, z + 3, shaftSupportId);
      chunk.setBlocks(x, x + 1, y + 2, z, z + 4, shaftBeamId);
    }
  }

  private void generateMineSupport(ByteChunk chunk, int x, int y, int z) {
    int aboveSupport = chunk.findLastEmptyAbove(x, y, z);
    if (aboveSupport < maxHeight) chunk.setBlocks(x, y + 1, aboveSupport + 1, z, shaftSupportId);
  }

  public void generateMines(WorldGenerator generator, RealChunk chunk) {

    // get shafted!
    if (generator.settings.includeMines)
      for (int y = 0; y + 16 < minHeight; y += 16) {
        if (isShaftableLevel(generator, y)) generateVerticalMineLevel(generator, chunk, y);
      }
  }

  private void generateVerticalMineLevel(WorldGenerator generator, RealChunk chunk, int y) {
    int y1 = y + 6;
    boolean stairsFound = false;

    // going down?
    if (isShaftableLevel(generator, y - 16)) {
      if (generator.shapeProvider.isHorizontalNSShaft(chunk.chunkX, y, chunk.chunkZ)
          && generator.shapeProvider.isHorizontalNSShaft(chunk.chunkX, y - 16, chunk.chunkZ)) {

        // draw the going down bit
        placeMineStairBase(chunk, 10, y1, 15);
        placeMineStairStep(chunk, 10, y1, 14, Stair.SOUTH, Stair.NORTHFLIP);
        placeMineStairStep(chunk, 10, y1 - 1, 13, Stair.SOUTH, Stair.NORTHFLIP);
        placeMineStairStep(chunk, 10, y1 - 2, 12, Stair.SOUTH, Stair.NORTHFLIP);
        placeMineStairStep(chunk, 10, y1 - 3, 11, Stair.SOUTH, Stair.NORTHFLIP);
        placeMineStairStep(chunk, 10, y1 - 4, 10, Stair.SOUTH, Stair.NORTHFLIP);
        placeMineStairStep(chunk, 10, y1 - 5, 9, Stair.SOUTH, Stair.NORTHFLIP);
        placeMineStairStep(chunk, 10, y1 - 6, 8, Stair.SOUTH, Stair.NORTHFLIP);
        stairsFound = true;
      }

      if (!stairsFound
          && generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y, chunk.chunkZ)
          && generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y - 16, chunk.chunkZ)) {

        // draw the going down bit
        placeMineStairBase(chunk, 15, y1, 10);
        placeMineStairStep(chunk, 14, y1, 10, Stair.EAST, Stair.WESTFLIP);
        placeMineStairStep(chunk, 13, y1 - 1, 10, Stair.EAST, Stair.WESTFLIP);
        placeMineStairStep(chunk, 12, y1 - 2, 10, Stair.EAST, Stair.WESTFLIP);
        placeMineStairStep(chunk, 11, y1 - 3, 10, Stair.EAST, Stair.WESTFLIP);
        placeMineStairStep(chunk, 10, y1 - 4, 10, Stair.EAST, Stair.WESTFLIP);
        placeMineStairStep(chunk, 9, y1 - 5, 10, Stair.EAST, Stair.WESTFLIP);
        placeMineStairStep(chunk, 8, y1 - 6, 10, Stair.EAST, Stair.WESTFLIP);
      }
    }

    // reset the stairs flag
    stairsFound = false;

    // going up?
    if (isShaftableLevel(generator, y + 32)) {
      if (generator.shapeProvider.isHorizontalNSShaft(chunk.chunkX, y, chunk.chunkZ)
          && generator.shapeProvider.isHorizontalNSShaft(chunk.chunkX, y + 16, chunk.chunkZ)) {

        // draw the going up bit
        placeMineStairBase(chunk, 5, y1, 15);
        placeMineStairStep(chunk, 5, y1 + 1, 14, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 2, 13, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 3, 12, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 4, 11, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 5, 10, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 6, 9, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 7, 8, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairStep(chunk, 5, y1 + 8, 7, Stair.NORTH, Stair.SOUTHFLIP);
        placeMineStairBase(chunk, 5, y1 + 8, 6);
        placeMineStairBase(chunk, 6, y1 + 8, 6);
        placeMineStairBase(chunk, 7, y1 + 8, 6);
        placeMineStairBase(chunk, 8, y1 + 8, 6);
        placeMineStairBase(chunk, 9, y1 + 8, 6);
        placeMineStairBase(chunk, 10, y1 + 8, 6);
        placeMineStairStep(chunk, 10, y1 + 9, 7, Stair.SOUTH, Stair.NORTHFLIP);

        generateMineSupport(chunk, 6, y1 + 7, 7);
        generateMineSupport(chunk, 9, y1 + 7, 7);

        stairsFound = true;
      }

      if (!stairsFound
          && generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y, chunk.chunkZ)
          && generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y + 16, chunk.chunkZ)) {

        // draw the going up bit
        placeMineStairBase(chunk, 15, y1, 5);
        placeMineStairStep(chunk, 14, y1 + 1, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 13, y1 + 2, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 12, y1 + 3, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 11, y1 + 4, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 10, y1 + 5, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 9, y1 + 6, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 8, y1 + 7, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairStep(chunk, 7, y1 + 8, 5, Stair.WEST, Stair.EASTFLIP);
        placeMineStairBase(chunk, 6, y1 + 8, 5);
        placeMineStairBase(chunk, 6, y1 + 8, 6);
        placeMineStairBase(chunk, 6, y1 + 8, 7);
        placeMineStairBase(chunk, 6, y1 + 8, 8);
        placeMineStairBase(chunk, 6, y1 + 8, 9);
        placeMineStairBase(chunk, 6, y1 + 8, 10);
        placeMineStairStep(chunk, 7, y1 + 9, 10, Stair.EAST, Stair.WESTFLIP);

        generateMineSupport(chunk, 7, y1 + 7, 6);
        generateMineSupport(chunk, 7, y1 + 7, 9);
      }
    }

    // make the ceiling pretty
    boolean pathFound = false;
    if (generator.shapeProvider.isHorizontalNSShaft(chunk.chunkX, y, chunk.chunkZ)) {
      generateMineCeiling(chunk, 6, 10, y1 + 3, 0, 6);
      generateMineCeiling(chunk, 6, 10, y1 + 3, 10, 16);

      generateMineAlcove(generator, chunk, 4, y1, 2, 4, 2);
      generateMineAlcove(generator, chunk, 10, y1, 2, 11, 3);

      pathFound = true;
    }
    if (generator.shapeProvider.isHorizontalWEShaft(chunk.chunkX, y, chunk.chunkZ)) {
      generateMineCeiling(chunk, 0, 6, y1 + 3, 6, 10);
      generateMineCeiling(chunk, 10, 16, y1 + 3, 6, 10);

      generateMineAlcove(generator, chunk, 2, y1, 4, 2, 4);
      generateMineAlcove(generator, chunk, 2, y1, 10, 3, 11);

      pathFound = true;
    }

    // draw the center bit
    if (pathFound) generateMineCeiling(chunk, 6, 10, y1 + 3, 6, 10);
  }

  private void generateMineAlcove(
      WorldGenerator generator, RealChunk chunk, int x, int y, int z, int prizeX, int prizeZ) {
    if (chunkRandom.nextDouble() < 0.66) {
      if (!chunk.isEmpty(x, y, z)
          && !chunk.isEmpty(x + 1, y, z)
          && !chunk.isEmpty(x, y, z + 1)
          && !chunk.isEmpty(x + 1, y, z + 1)) {
        chunk.setBlocks(x, x + 2, y + 1, y + 4, z, z + 2, Material.AIR);
        generateMineCeiling(chunk, x, x + 2, y + 3, z, z + 2);
        if (chunkRandom.nextDouble() < 0.66) {
          if (chunkRandom.nextDouble() < 0.33)
            generateMineTreat(generator, chunk, prizeX, y + 1, prizeZ);
          else generateMineTrick(generator, chunk, prizeX, y + 1, prizeZ);
        }
      }
    }
  }

  private void generateMineCeiling(RealChunk chunk, int x1, int x2, int y, int z1, int z2) {
    for (int x = x1; x < x2; x++) {
      for (int z = z1; z < z2; z++) {
        if (chunkRandom.nextBoolean())
          if (!chunk.isEmpty(x, y + 1, z) && chunk.isEmpty(x, y, z))
            chunk.setStoneSlab(x, y, z, Direction.StoneSlab.COBBLESTONEFLIP);
      }
    }
  }

  private void generateMineSupport(RealChunk chunk, int x, int y, int z) {
    int aboveSupport = chunk.findLastEmptyAbove(x, y, z);
    if (aboveSupport < maxHeight) chunk.setBlocks(x, y + 1, aboveSupport + 1, z, Material.FENCE);
  }

  private void placeMineStairBase(RealChunk chunk, int x, int y, int z) {
    chunk.setBlocks(x, y + 1, y + 4, z, Material.AIR);
    chunk.setEmptyBlock(x, y, z, Material.WOOD);
  }

  private void placeMineStairStep(
      RealChunk chunk, int x, int y, int z, Stair direction, Stair flipDirection) {
    chunk.setBlocks(x, y + 1, y + 4, z, Material.AIR);
    chunk.setStair(x, y, z, Material.WOOD_STAIRS, direction);
    if (chunk.isEmpty(x, y - 1, z))
      chunk.setStair(x, y - 1, z, Material.WOOD_STAIRS, flipDirection);
  }

  private void generateMineTreat(WorldGenerator generator, RealChunk chunk, int x, int y, int z) {

    // cool stuff?
    if (generator.settings.treasuresInMines
        && chunkRandom.nextDouble() <= generator.settings.oddsOfTreasureInMines) {
      chunk.setChest(
          x,
          y,
          z,
          Direction.General.SOUTH,
          generator.lootProvider.getItems(generator, chunkRandom, LootLocation.MINE));
    }
  }

  private void generateMineTrick(WorldGenerator generator, RealChunk chunk, int x, int y, int z) {
    // not so cool stuff?
    if (generator.settings.spawnersInMines
        && chunkRandom.nextDouble() <= generator.settings.oddsOfSpawnerInMines) {
      chunk.setSpawner(
          x, y, z, generator.spawnProvider.getEntity(generator, chunkRandom, SpawnerLocation.MINE));
    }
  }

  public boolean isValidStrataY(WorldGenerator generator, int blockX, int blockY, int blockZ) {
    return true;
  }

  public void generateOres(WorldGenerator generator, RealChunk chunk) {

    // shape the world
    if (generator.settings.includeOres || generator.settings.includeUndergroundFluids)
      generator.oreProvider.sprinkleOres(
          generator, this, chunk, blockYs, chunkRandom, OreLocation.CRUST);
  }

  // TODO move this logic to SurroundingLots, add to it the ability to produce SurroundingHeights
  // and SurroundingDepths
  public PlatLot[][] getNeighborPlatLots(
      PlatMap platmap, int platX, int platZ, boolean onlyConnectedNeighbors) {
    PlatLot[][] miniPlatMap = new PlatLot[3][3];

    // populate the results
    for (int x = 0; x < 3; x++) {
      for (int z = 0; z < 3; z++) {

        // which platchunk are we looking at?
        int atX = platX + x - 1;
        int atZ = platZ + z - 1;

        // is it in bounds?
        if (!(atX < 0 || atX > PlatMap.Width - 1 || atZ < 0 || atZ > PlatMap.Width - 1)) {
          PlatLot relative = platmap.getLot(atX, atZ);

          if (!onlyConnectedNeighbors || isConnected(relative)) {
            miniPlatMap[x][z] = relative;
          }
        }
      }
    }

    return miniPlatMap;
  }

  public void generateSurface(WorldGenerator generator, RealChunk chunk, boolean includeTrees) {

    // plant grass or snow
    generator.surfaceProvider.generateSurface(generator, this, chunk, blockYs, includeTrees);
  }
}
Пример #16
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (!event.hasBlock()) return;

    Action action = event.getAction();
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    int type = block.getTypeId();
    BlockFace face = event.getBlockFace();

    if (action == Action.RIGHT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (type == Material.WALL_SIGN.getId()) {
        interactSign(block, player);
        return;
      }

      if (type == Material.CHEST.getId()) {
        // Try at making a 1.7->1.8 chest fixer.
        Lockette.rotateChestOrientation(block, face);
      }

      if ((type == Material.CHEST.getId())
          || (type == Material.DISPENSER.getId())
          || (type == Material.FURNACE.getId())
          || (type == Material.BURNING_FURNACE.getId())
          || (type == Material.BREWING_STAND.getId())
          || Lockette.isInList(type, Lockette.customBlockList)) {

        // Trying something out....
        if (Lockette.directPlacement)
          if (event.hasItem())
            if ((face != BlockFace.UP) && (face != BlockFace.DOWN)) {
              ItemStack item = event.getItem();

              if (item.getTypeId() == Material.SIGN.getId()) {
                Block checkBlock = block.getRelative(face);

                type = checkBlock.getTypeId();

                if (type == Material.AIR.getId()) {
                  boolean place = false;

                  if (Lockette.isProtected(block)) {
                    // Add a users sign only if owner.
                    if (Lockette.isOwner(block, player.getName())) place = true;
                  } else place = true;
                  // if(Lockette.altPrivate == null){}//if(Lockette.altMoreUsers == null){}
                  if (place) {
                    // player.sendMessage(ChatColor.RED + "Lockette: Using a sign on a container");

                    event.setUseItemInHand(Result.ALLOW); // ? seems to work in 568
                    event.setUseInteractedBlock(Result.DENY);
                    return;
                  }
                }
              }
            }

        if (interactContainer(block, player)) return;

        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        return;
      }

      if (type == Material.DIRT.getId())
        if (event.hasItem()) {
          ItemStack item = event.getItem();

          type = item.getTypeId();

          if ((type == Material.DIAMOND_HOE.getId())
              || (type == Material.GOLD_HOE.getId())
              || (type == Material.IRON_HOE.getId())
              || (type == Material.STONE_HOE.getId())
              || (type == Material.WOOD_HOE.getId())) {
            Block checkBlock = block.getRelative(BlockFace.UP);

            type = checkBlock.getTypeId();

            if ((type == Material.WOODEN_DOOR.getId())
                || (type == Material.IRON_DOOR_BLOCK.getId())
                || (type == materialFenceGate)) {
              event.setUseInteractedBlock(Result.DENY);
              return;
            }
          }
        }
    } else if (action == Action.LEFT_CLICK_BLOCK) {
      if (Lockette.protectTrapDoors)
        if (type == Material.TRAP_DOOR.getId()) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }

      if (Lockette.protectDoors)
        if ((type == Material.WOODEN_DOOR.getId())
            || (type == Material.IRON_DOOR_BLOCK.getId())
            || (type == materialFenceGate)) {
          if (interactDoor(block, player)) return;

          event.setUseInteractedBlock(Result.DENY);
          event.setUseItemInHand(Result.DENY);
          return;
        }
    }
  }
Пример #17
0
  // Generate a chunk
  @Override
  public byte[] generate(World world, Random rand, int chunkx, int chunkz) {
    // Create a byte variable to write the chunk inside and return this variable
    byte[] result = new byte[32768];

    // This will set the whole floor to stone (the floor of each chunk)
    for (int y = 30 + 3; y > 0; y--)
      for (int x = 0; x < 16; x++)
        for (int z = 0; z < 16; z++) result[xyzToByte(x, y, z)] = (byte) Material.STONE.getId();

    // Set the lowest layer to bedrock
    for (int x = 0; x < 16; x++)
      for (int z = 0; z < 16; z++) result[xyzToByte(x, 0, z)] = (byte) Material.BEDROCK.getId();

    // The layers for each 5 rooms in the variable y
    for (int y = 30; y < 30 + (7 * 6); y += 6) {

      // The 4 rooms on each layer saved in the variables x and z
      for (int x = 0; x < 16; x += 8) {
        for (int z = 0; z < 16; z += 8) {

          int xr = (rand.nextInt(3) - 1) * (x + 7);
          int zr = (rand.nextInt(3) - 1) * (z + 7);

          int yfloor = rand.nextInt(2);

          // All the y of the room in the variable y2
          for (int y2 = y + yfloor; y2 < y + 8; y2++) {

            // All the x of the room in the variable x2
            for (int x2 = x; x2 < x + 8; x2++) {

              // All the z of the room in the variable z2
              for (int z2 = z; z2 < z + 8; z2++) {

                // Make the bottom of the room
                if (y2 == y + yfloor)
                  for (int xb = x; xb < x + 8; xb++)
                    for (int zb = z; zb < z + 8; zb++)
                      result[xyzToByte(xb, y2, zb)] = (byte) Material.COBBLESTONE.getId();

                // Fill the walls of the place with cobblestone
                if ((x2 == x || x2 == x + 7) && (z2 == z || z2 == z + 7))
                  result[xyzToByte(x2, y2, z2)] = (byte) 98;
                else if (xr == x2) result[xyzToByte(x2, y2, z2)] = (byte) 98;
                else if (zr == z2) result[xyzToByte(x2, y2, z2)] = (byte) 98;
                else result[xyzToByte(x2, y2, z2)] = (byte) Material.AIR.getId();
              }
            }
          }
        }
      }
    }

    // Create the nose generator which generates wave formes to use for the surface.
    Random random = new Random(world.getSeed());
    SimplexOctaveGenerator octave = new SimplexOctaveGenerator(random, 8);
    octave.setScale(1 / 48.0);

    // Generate the ceiling and the grass land
    for (int x = 0; x < 16; x++) {
      for (int z = 0; z < 16; z++) {
        /*int height = getHeight(world, chunkx + x * 0.0625, chunkz + z * 0.0625, 2) + 30+(7*6) + 7;*/
        double height = octave.noise(x + chunkx * 16, z + chunkz * 16, 0.5, 0.5) * 4 + 9;

        result[xyzToByte(x, 30 + (7 * 6), z)] = (byte) Material.COBBLESTONE.getId();
        for (int y = 30 + (7 * 6) + 1; y < 30 + (7 * 6) + 4; y++)
          result[xyzToByte(x, y, z)] = (byte) Material.STONE.getId();

        // Get the current biome
        Biome biome = world.getBiome((chunkx * 16) + x, (chunkz * 16) + z);

        if (biome.equals(Biome.DESERT) || biome.equals(Biome.DESERT_HILLS)) {
          for (int y = 30 + (7 * 6) + 4; y < 30 + (7 * 6) + 2 + height; y++)
            result[xyzToByte(x, y, z)] = (byte) Material.SAND.getId();

        } else if (biome.equals(Biome.MUSHROOM_ISLAND) || biome.equals(Biome.MUSHROOM_ISLAND)) {
          for (int y = 30 + (7 * 6) + 4; y < 30 + (7 * 6) + 2 + height; y++)
            result[xyzToByte(x, y, z)] = (byte) Material.DIRT.getId();
          result[xyzToByte(x, (int) (30 + (7 * 6) + 2 + height), z)] =
              (byte) Material.MYCEL.getId();

        } else {
          for (int y = 30 + (7 * 6) + 4; y < 30 + (7 * 6) + 2 + height; y++)
            result[xyzToByte(x, y, z)] = (byte) Material.DIRT.getId();
          result[xyzToByte(x, (int) (30 + (7 * 6) + 2 + height), z)] =
              (byte) Material.GRASS.getId();
        }
      }
    }

    return result;
  }