From 50344925b3edbd17ff52d31e4afcfe1fa195ba92 Mon Sep 17 00:00:00 2001 From: Ben Forge <74168521+BenCheung0422@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:49:28 +0800 Subject: [PATCH] Update Level.java --- src/client/java/minicraft/level/Level.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/client/java/minicraft/level/Level.java b/src/client/java/minicraft/level/Level.java index f2e34cc59..db0e82861 100644 --- a/src/client/java/minicraft/level/Level.java +++ b/src/client/java/minicraft/level/Level.java @@ -324,18 +324,17 @@ private void checkChestCount(boolean check) { while (!addedchest) { // Keep running until we successfully add a DungeonChest // Pick a random tile: - int x2 = random.nextInt(16 * w) / 16; - int y2 = random.nextInt(16 * h) / 16; + int x2 = random.nextInt(w); + int y2 = random.nextInt(h); if (getTile(x2, y2) == Tiles.get("Grass")) { - boolean xaxis = random.nextBoolean(); - if (xaxis) { + if (random.nextBoolean()) { // x-axis for (int s = x2; s < w - s; s++) { if (getTile(s, y2) == Tiles.get("Obsidian Wall") || getTile(s, y2) == Tiles.get("Ornate Obsidian")) { d.x = s * 20 - 16; d.y = y2 * 24 - 14; } } - } else { // y axis + } else { // y-axis for (int s = y2; s < h - s; s++) { if (getTile(x2, s) == Tiles.get("Obsidian Wall") || getTile(x2, s) == Tiles.get("Ornate Obsidian")) { d.x = x2 * 23 - 14; @@ -348,6 +347,12 @@ private void checkChestCount(boolean check) { d.y = (y2 << 4) - 8; } + // Target place may not exist a dungeon chest + if (!getEntitiesInTiles(d.x >> 4, d.y >> 4, 0, true, DungeonChest.class).isEmpty()) continue; + // If target place is blocking wall, remove it + if (getTile(d.x >> 4, d.y >> 4) == Tiles.get("Obsidian Wall")) + setTile(d.x >> 4, d.y >> 4, Tiles.get("Raw Obsidian")); + add(d); chestCount++; addedchest = true;