Get Highest Block

Discussion in 'Plugin Development' started by Rival54548545, Apr 4, 2024.

Thread Status:
Not open for further replies.
  1. Offline

    Rival54548545

    Hello, I have problem with getting highest block. How can I solve it?
     

    Attached Files:

  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    Rival54548545

    Console output: -6 and -4
     

    Attached Files:

  4. Online

    timtower Administrator Administrator Moderator

    @Rival54548545 Please post the full function / method.
    By copy pasting, not by making a screenshot of it.
     
  5. Offline

    Rival54548545

    private int getRandomWithNeg(int size) {
    int random = (int) (Math.random() * (size + 1));
    if (Math.random() > 0.5) random *= -1;
    return random;
    }
     
  6. Online

    timtower Administrator Administrator Moderator

    The full function that calls that one.
    So the function from the first screenshot
     
  7. Offline

    Rival54548545

    public void spawnMobs(int size, int mobCap, int spawnTime) {CustomMob[] mobTypes = CustomMob.values();task = new BukkitRunnable() {Set<Entity> spawned = entities.keySet();List<Entity> removal = new ArrayList<>();@Overridepublic void run() {for (Entity entity : spawned) {if (!entity.isValid() || entity.isDead()) removal.add(entity);}spawned.removeAll(removal);// Spawning Algorithmint diff = mobCap - entities.size();if (diff <= 0) return;int spawnAmount = (int) (Math.random() * (diff + 1)), count = 0;while (count <= spawnAmount) {count++;int ranX = getRandomWithNeg(size), ranZ = getRandomWithNeg(size);System.out.println(String.valueOf(ranX) + " ldl " + String.valueOf(ranZ));Block block = world.getHighestBlockAt(ranX, ranZ);double xOffset = getRandomOffset(), zOffset = getRandomOffset();Location loc = block.getLocation().clone().add(xOffset, 1, zOffset);if (!isSpawnable(loc)) continue;double random = Math.random() * 101, previous = 0;CustomMob typeToSpawn = mobTypes[0];for (CustomMob type : mobTypes) {previous += type.getSpawnChance();if (random <= previous) {typeToSpawn = type;break;} }entities.put(typeToSpawn.spawn(loc), typeToSpawn);} } }.runTaskTimer(this, 0L, spawnTime);}
     
  8. Online

    timtower Administrator Administrator Moderator

  9. Offline

    Rival54548545

    private World world;private BukkitTask task;private Map<Entity, Integer> indicators = new HashMap<>();private Map<Entity, CustomMob> entities = new HashMap<>();private DecimalFormat formatter = new DecimalFormat("#.##");@Overridepublic void onEnable() {world = Bukkit.getWorld("world");
     

    Attached Files:

Thread Status:
Not open for further replies.

Share This Page