Skip to content

Commit

Permalink
Updated to v18.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hex27 committed Jan 19, 2025
1 parent 73f4362 commit 19a9068
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public void populate(TerraformWorld tw, Random random, @NotNull SimpleBlock ceil
center = new SimpleBlock(ceil.getPopData(), ceil.getX(), (ceil.getY() + floor.getY()) / 2, ceil.getZ());
int lowest = center.getY();

// If this is too close with a structure with a cave cluster suppressant, don't
// populate.


// Perform a breadth-first search from the center.

HashMap<SimpleBlock, Wall[]> seen = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class MasterCavePopulatorDistributor {

private static final ArrayList<Class<?>> populatedBefore = new ArrayList<>();

public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data) {
HashMap<SimpleLocation, CaveClusterRegistry> clusters = calculateClusterLocations(
public void populate(@NotNull TerraformWorld tw, @NotNull Random random, @NotNull PopulatorDataAbstract data, boolean generateClusters) {
HashMap<SimpleLocation, CaveClusterRegistry> clusters = generateClusters ? calculateClusterLocations(
random,
tw,
data.getChunkX(),
data.getChunkZ()
);
) : new HashMap<>();

for (int x = data.getChunkX() * 16; x < data.getChunkX() * 16 + 16; x++) {
for (int z = data.getChunkZ() * 16; z < data.getChunkZ() * 16 + 16; z++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract
for (OrePopulator ore : ORE_POPS) {
ore.populate(tw, random, data);
}

// Amethysts
amethystGeodePopulator.populate(tw, random, data);


// Get all biomes in a chunk
EnumSet<BiomeBank> banks = EnumSet.noneOf(BiomeBank.class);

boolean canDecorate = StructureBufferDistanceHandler.canDecorateChunk(tw, data.getChunkX(), data.getChunkZ());
boolean[] canDecorate = StructureBufferDistanceHandler.canDecorateChunk(tw, data.getChunkX(), data.getChunkZ());

// Amethysts
if(canDecorate[1])
amethystGeodePopulator.populate(tw, random, data);

// Small Populators run per block.
for (int rawX = data.getChunkX() * 16; rawX <= data.getChunkX() * 16 + 16; rawX++) {
Expand All @@ -244,7 +245,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract
}

// Only decorate disruptive features if the structures allow for them
if (canDecorate) {
if (canDecorate[0]) {
for (BiomeBank bank : banks) {
bank.getHandler().populateLargeItems(tw, random, data);
}
Expand All @@ -253,7 +254,7 @@ public void populate(@NotNull TerraformWorld tw, @NotNull PopulatorDataAbstract

// Cave populators
// They will recalculate biomes per block.
caveDistributor.populate(tw, random, data);
caveDistributor.populate(tw, random, data, canDecorate[1]);

// Multi-megachunk structures
for (MultiMegaChunkStructurePopulator spop : StructureRegistry.smallStructureRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ public void populate(@NotNull WorldInfo worldInfo,
ArrayList<CubeRoom> seenRooms = new ArrayList<>();
state.roomPopulatorStates.forEach(roomLayoutGenerator -> roomLayoutGenerator.getRooms()
.stream()
.filter(room -> chunkX == room.getX() >> 4 //Ensure that the center of the lr is the same chunk
&& chunkZ == room.getZ() >> 4
&& room.isInRegion(lr) // No rooms that have bounds beyond LR
)
.filter(room -> room.canLRCarve(chunkX,chunkZ,lr))
.forEach(room -> {
seenRooms.add(room);
if(roomLayoutGenerator.roomCarver != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ public void setBlockData(int x, int y, int z, @NotNull BlockData data) {

@Override
public Biome getBiome(int rawX, int rawZ) {
if (!lr.isInRegion(rawX, 50, rawZ)) {
TerraformGeneratorPlugin.logger.error("Tried to access biome outside of LR bounds at: "+rawX + "," + rawZ + " from LR centered at chunk " + chunkX + "," + chunkZ);
return Biome.PLAINS;
}
return lr.getBiome(rawX, 50, rawZ);
}

@Override
public void addEntity(int rawX, int rawY, int rawZ, @NotNull EntityType type) {
if (!lr.isInRegion(rawX, rawY, rawZ)) {
TerraformGeneratorPlugin.logger.error("Tried to add entity outside of LR bounds at: "+rawX + "," + rawZ + " from LR centered at chunk " + chunkX + "," + chunkZ);
return;
}
lr.spawnEntity(new Location(tw.getWorld(), rawX, rawY, rawZ), type);
}

Expand All @@ -99,6 +107,10 @@ public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) {
if (!TConfig.areAnimalsEnabled()) {
return;
}
if (!lr.isInRegion(rawX, 50, rawZ)) {
TerraformGeneratorPlugin.logger.error("Tried to set spawner outside of LR bounds at: "+rawX + "," + rawZ + " from LR centered at chunk " + chunkX + "," + chunkZ);
return;
}

setType(rawX, rawY, rawZ, Material.SPAWNER);
try {
Expand All @@ -116,6 +128,10 @@ public void setSpawner(int rawX, int rawY, int rawZ, @NotNull EntityType type) {

@Override
public void lootTableChest(int x, int y, int z, @NotNull TerraLootTable table) {
if (!lr.isInRegion(x, y, z)) {
TerraformGeneratorPlugin.logger.error("Tried to lootTableChest outside of LR bounds at: "+x + "," + z + " from LR centered at chunk " + chunkX + "," + chunkZ);
return;
}
BlockState s = lr.getBlockState(x, y, z);
if (s instanceof Lootable t) {
t.setLootTable(table.bukkit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ public class StructureBufferDistanceHandler {
* Called from decorators to determine whether or not they
* can place large trees and obstructive decorations, or if
* they must make way for structures.
*
* @return index 0 is Decoration buffer, index 1 is cave cluster buffer
*/
public static boolean canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, int chunkZ) {
public static boolean[] canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, int chunkZ) {

// Within radius
// Within radius, no surface decorations, but there can be cave decorations
if (Math.pow(chunkX * 16, 2) + Math.pow(chunkZ * 16, 2) < HeightMap.spawnFlatRadiusSquared) {
return false;
return new boolean[]{false,true};
}

boolean[] canDecorate = new boolean[]{true,true};
MegaChunk mc = new MegaChunk(chunkX, chunkZ);
BiomeBank biome = mc.getCenterBiomeSection(tw).getBiomeBank();
for (StructurePopulator structPop : StructureRegistry.getLargeStructureForMegaChunk(tw, mc)) {
Expand All @@ -32,7 +35,7 @@ public static boolean canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, i
continue;
}
int chunkBufferRadius = spop.getChunkBufferDistance();
if (chunkBufferRadius <= 0) {
if (chunkBufferRadius <= 0 && spop.getCaveClusterBufferDistance() <= 0) {
continue;
}
// No need to account for strongholds, which have a different way of
Expand All @@ -43,13 +46,15 @@ public static boolean canDecorateChunk(@NotNull TerraformWorld tw, int chunkX, i
if (TConfig.areStructuresEnabled() && spop.canSpawn(tw, chunkCoords[0], chunkCoords[1], biome)) {
// If the structure will spawn, calculate distance to it.
int dist = (int) (Math.pow(chunkCoords[0] - chunkX, 2) + Math.pow(chunkCoords[1] - chunkZ, 2));
if (Math.sqrt(dist) <= chunkBufferRadius) {
return false;
}
double rootedDist = Math.max(Math.sqrt(dist),0.002); //nonzero
canDecorate[0] &= rootedDist > chunkBufferRadius;
canDecorate[1] &= rootedDist > spop.getCaveClusterBufferDistance();
//Short out if both are already false
if(!canDecorate[0] && !canDecorate[1]) return canDecorate;
}
}

return true;
return canDecorate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ public abstract class StructurePopulator {
public int getChunkBufferDistance() {
return 3;
}


/**
* Refers to the buffer distance for cave cluster decorations.
* Things like Large Caves and Ancient Cities deal badly with them
* due to the large holes they carve. This leads to floating decorations.
* This suppresses cave decorations near the structure.
*/
public int getCaveClusterBufferDistance() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@ public boolean isEnabled() {
return TConfig.areStructuresEnabled() && TConfig.c.STRUCTURES_ANCIENTCITY_ENABLED;
}

// Underground structures don't need a decorative buffer
// Underground structures don't need a decorative buffer on the surface
@Override
public int getChunkBufferDistance() {
return 0;
}

//But no cave decorations.
@Override
public int getCaveClusterBufferDistance() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,8 @@ public boolean isEnabled() {
public int getChunkBufferDistance() {
return 0;
}
@Override
public int getCaveClusterBufferDistance() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.terraform.coregen.populatordata.PopulatorDataAbstract;
import org.terraform.data.SimpleBlock;
import org.terraform.data.SimpleLocation;
import org.terraform.structure.room.CubeRoom;
import org.terraform.structure.room.carver.RoomCarver;
Expand All @@ -29,7 +30,9 @@ public void carveRoom(@NotNull PopulatorDataAbstract data, CubeRoom room, Materi
}
else {
// Ensure no fluid flows out
if (loc.getY() <= waterLevel) {
if (loc.getY() <= waterLevel
|| BlockUtils.isWet(new SimpleBlock(data,loc))
|| BlockUtils.isWet(new SimpleBlock(data,loc.getUp()))) {
data.setType(loc.getX(), loc.getY(), loc.getZ(), BlockUtils.stoneOrSlate(loc.getY()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ public void setZ(int z) {
this.z = z;
}

public boolean canLRCarve(int chunkX, int chunkZ, LimitedRegion lr){
return chunkX == x >> 4 //Ensure that the center of the lr is the same chunk
&& chunkZ == z >> 4
&& isInRegion(lr); // No rooms that have bounds beyond LR
}

public void debugRedGround(@NotNull PopulatorDataAbstract data) {
int[] lowerCorner = getLowerCorner();
int[] upperCorner = getUpperCorner();
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: TerraformGenerator
author: Hex_27
version: 18.1.1
version: 18.1.2
api-version: 1.18
description: World Generator
main: org.terraform.main.TerraformGeneratorPlugin
Expand Down

0 comments on commit 19a9068

Please sign in to comment.