Avoid min and max y settings for ores. Fixes #91

This commit is contained in:
tastybento 2023-11-26 07:59:48 -08:00
parent 772ece5916
commit 9e51156f87

View File

@ -1,16 +1,22 @@
package world.bentobox.caveblock.generators.populators; package world.bentobox.caveblock.generators.populators;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.LimitedRegion; import org.bukkit.generator.LimitedRegion;
import org.bukkit.generator.WorldInfo; import org.bukkit.generator.WorldInfo;
import world.bentobox.caveblock.Utils; import world.bentobox.caveblock.Utils;
import world.bentobox.caveblock.generators.Ore; import world.bentobox.caveblock.generators.Ore;
import java.util.*;
/** /**
* @author tastybento * @author tastybento
*/ */
@ -75,6 +81,11 @@ public class NewMaterialPopulator extends BlockPopulator {
private final int worldDepth; private final int worldDepth;
/**
* @param worldDepth - Depth. If depth is set smaller than the world height,
* then the area above will be empty. Should not be less than
* cave height.
*/
public NewMaterialPopulator(int worldDepth) { public NewMaterialPopulator(int worldDepth) {
this.worldDepth = worldDepth; this.worldDepth = worldDepth;
} }
@ -82,7 +93,7 @@ public class NewMaterialPopulator extends BlockPopulator {
@Override @Override
public void populate(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, LimitedRegion limitedRegion) { public void populate(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, LimitedRegion limitedRegion) {
final int worldHeight = Math.min(worldInfo.getMaxHeight(), this.worldDepth); final int worldHeight = Math.min(worldInfo.getMaxHeight(), this.worldDepth);
for (int y = worldInfo.getMinHeight(); y < worldHeight - 1; y++) { for (int y = worldInfo.getMinHeight() + 1; y < worldHeight - 1; y++) {
for (Ore o : ORES.get(worldInfo.getEnvironment())) { for (Ore o : ORES.get(worldInfo.getEnvironment())) {
if (y > o.minY() && y < o.maxY() && random.nextInt(100) <= o.chance()) { if (y > o.minY() && y < o.maxY() && random.nextInt(100) <= o.chance()) {
pasteBlob(worldInfo, random, chunkX, chunkZ, limitedRegion, y, o); pasteBlob(worldInfo, random, chunkX, chunkZ, limitedRegion, y, o);
@ -94,11 +105,13 @@ public class NewMaterialPopulator extends BlockPopulator {
} }
} }
private void pasteBlob(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, LimitedRegion limitedRegion, int y, Ore o) { private void pasteBlob(WorldInfo worldInfo, Random random, int chunkX, int chunkZ, LimitedRegion limitedRegion,
int y, Ore o) {
int offset = random.nextInt(16); int offset = random.nextInt(16);
for (int x = Math.max(0, offset - BLOB_SIZE); x < Math.min(16, offset + BLOB_SIZE); x++) { for (int x = Math.max(0, offset - BLOB_SIZE); x < Math.min(16, offset + BLOB_SIZE); x++) {
for (int z = Math.max(0, offset - BLOB_SIZE); z < Math.min(16, offset + BLOB_SIZE); z++) { for (int z = Math.max(0, offset - BLOB_SIZE); z < Math.min(16, offset + BLOB_SIZE); z++) {
for (int yy = Math.max(worldInfo.getMinHeight(), y - BLOB_SIZE); yy < Math.min(worldInfo.getMaxHeight(), y + BLOB_SIZE); yy++) { for (int yy = Math.max(worldInfo.getMinHeight() + 1, y - BLOB_SIZE); yy < Math
.min(worldInfo.getMaxHeight() - 1, y + BLOB_SIZE); yy++) {
Location location = Utils.getLocationFromChunkLocation(x, yy, z, chunkX, chunkZ); Location location = Utils.getLocationFromChunkLocation(x, yy, z, chunkX, chunkZ);
if (!limitedRegion.isInRegion(location)) { if (!limitedRegion.isInRegion(location)) {
continue; continue;