Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update random dungeon chest spawning conditions #723

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/client/java/minicraft/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading