Skip to content

Commit

Permalink
feat: populators with custom biomes from datapacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Naimadx123 committed Feb 11, 2025
1 parent 2b57c99 commit 82b575e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
34 changes: 19 additions & 15 deletions src/main/java/zone/vao/nexoAddon/NexoAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, String
public void reload() {
reloadConfig();
globalConfig = getConfig();
clearPopulators();
initializePopulators();
Bukkit.getScheduler().runTask(this, () -> {
clearPopulators();
initializePopulators();
});
reloadNexoFiles();
loadComponentsIfSupported();
bossBars.values().forEach(BossBarUtil::removeBar);
Expand Down Expand Up @@ -170,21 +172,23 @@ public void initializePopulators() {
}

private void initializeOres() {
ores = populatorsConfig.loadOresFromConfig();
orePopulator.clearOres();
ores.forEach(orePopulator::addOre);
orePopulator.getOres().forEach(ore -> {
if(ore.getNexoFurniture() != null) return;
for (World world : ore.getWorlds()) {
Bukkit.getScheduler().runTask(this, () -> {
ores = populatorsConfig.loadOresFromConfig();
orePopulator.clearOres();
ores.forEach(orePopulator::addOre);
orePopulator.getOres().forEach(ore -> {
if(ore.getNexoFurniture() != null) return;
for (World world : ore.getWorlds()) {

CustomOrePopulator customOrePopulator = new CustomOrePopulator(orePopulator);
if(!worldPopulators.containsKey(world.getName())) {
worldPopulators.put(world.getName(), new ArrayList<>());
CustomOrePopulator customOrePopulator = new CustomOrePopulator(orePopulator);
if(!worldPopulators.containsKey(world.getName())) {
worldPopulators.put(world.getName(), new ArrayList<>());
}
addPopulatorToWorld(world, customOrePopulator);
worldPopulators.get(world.getName()).add(customOrePopulator);
logPopulatorAdded("BlockPopulator", ore.getId(), world);
}
addPopulatorToWorld(world, customOrePopulator);
worldPopulators.get(world.getName()).add(customOrePopulator);
logPopulatorAdded("BlockPopulator", ore.getId(), world);
}
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.generator.LimitedRegion;
import org.bukkit.generator.WorldInfo;
import org.jetbrains.annotations.NotNull;
import zone.vao.nexoAddon.NexoAddon;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -113,33 +114,37 @@ private int generateVein(WorldInfo worldInfo, Random random, LimitedRegion limit

private PlacementPosition getAdjacentPlacementPosition(PlacementPosition start, Random random, LimitedRegion limitedRegion, Ore ore, boolean below) {
List<int[]> checkedLocations = new ArrayList<>();
int attempts = 0;

for (int i = 0; i < 10; i++) {
int xOffset = random.nextInt(3) - 1;
int yOffset = below ? -1 : (random.nextInt(3) - 1);;
int zOffset = random.nextInt(3) - 1;
try {
for (int i = 0; i < 10 || attempts >= 100; i++) {
attempts++;
int xOffset = random.nextInt(3) - 1;
int yOffset = below ? -1 : (random.nextInt(3) - 1);
int zOffset = random.nextInt(3) - 1;

int x = start.x() + xOffset;
int y = start.y() + yOffset;
int z = start.z() + zOffset;
int x = start.x() + xOffset;
int y = start.y() + yOffset;
int z = start.z() + zOffset;

if(checkedLocations.contains(new int[]{x, y, z})){
i--;
continue;
}
checkedLocations.add(new int[]{x, y, z});
if (!limitedRegion.isInRegion(x, y, z)) continue;
if (checkedLocations.contains(new int[]{x, y, z})) {
i--;
continue;
}
checkedLocations.add(new int[]{x, y, z});
if (!limitedRegion.isInRegion(x, y, z))
continue;

Material blockType = limitedRegion.getType(x, y, z);
Material blockType = limitedRegion.getType(x, y, z);

if ((ore.getPlaceOn().contains(blockType) && (!ore.isOnlyAir() || !blockType.isAir()))
|| ore.getReplace().contains(blockType)
|| (ore.getPlaceBelow().contains(blockType) && (!ore.isOnlyAir() || !blockType.isAir()))
) {
return new PlacementPosition(start.worldInfo, x, y, z, blockType, start.biome(), limitedRegion);
if ((ore.getPlaceOn().contains(blockType) && (!ore.isOnlyAir() || !blockType.isAir())) || ore.getReplace().contains(blockType) || (ore.getPlaceBelow().contains(blockType) && (!ore.isOnlyAir() || !blockType.isAir()))) {
return new PlacementPosition(start.worldInfo, x, y, z, blockType, start.biome(), limitedRegion);
}
}
return null;
}catch(Exception ignored){
return null;
}
return null;
}

private PlacementPosition getRandomPlacementPosition(int chunkX, int chunkZ, LimitedRegion limitedRegion, Ore ore, Random random, WorldInfo worldInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.nexomc.nexo.mechanics.custom_block.CustomBlockMechanic;
import com.nexomc.nexo.mechanics.custom_block.stringblock.StringBlockMechanic;
import com.nexomc.nexo.mechanics.furniture.FurnitureMechanic;
import org.bukkit.*;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.generator.WorldInfo;
import zone.vao.nexoAddon.NexoAddon;
import zone.vao.nexoAddon.classes.populators.orePopulator.Ore;
import zone.vao.nexoAddon.classes.populators.treePopulator.CustomTree;
Expand Down

0 comments on commit 82b575e

Please sign in to comment.