Skip to content

Commit

Permalink
Ancient City ported to the new structure system
Browse files Browse the repository at this point in the history
  • Loading branch information
Hex27 committed Dec 31, 2024
1 parent 3d5403b commit 25521ba
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void execute(CommandSender sender, Stack<String> args) {
int y = p.getLocation().getBlockY();
int z = p.getLocation().getBlockZ();
TerraformWorld tw = TerraformWorld.get(p.getWorld());

new AncientCityPopulator().spawnAncientCity(tw, new Random(), data, x, y, z);
p.sendMessage("Unimplemented.");
//new AncientCityPopulator().spawnAncientCity(tw, new Random(), data, x, y, z);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public void execute(CommandSender sender, Stack<String> args) {
int z = p.getLocation().getBlockZ();
TerraformWorld tw = TerraformWorld.get(p.getWorld());

new AncientCityPopulator().spawnAncientCity(tw, new Random(), data, x, y, z);
p.teleport(new Location(p.getWorld(), x, y + 30, z));
p.sendMessage("Done.");
//new AncientCityPopulator().spawnAncientCity(tw, new Random(), data, x, y, z);
//p.teleport(new Location(p.getWorld(), x, y + 30, z));
p.sendMessage("Unimplemented.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.cache.LoadingCache;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.generator.BlockPopulator;
Expand All @@ -28,6 +29,7 @@
import org.terraform.structure.StructureRegistry;
import org.terraform.structure.room.CubeRoom;
import org.terraform.structure.room.PathPopulatorData;
import org.terraform.structure.room.RoomLayoutGenerator;
import org.terraform.structure.room.path.PathState;
import org.terraform.structure.stronghold.StrongholdPopulator;

Expand Down Expand Up @@ -82,17 +84,21 @@ public void populate(@NotNull WorldInfo worldInfo,
PopulatorDataAbstract data = new PopulatorDataSpigotAPI(lr, tw, chunkX, chunkZ);

// Carve each path
HashSet<PathState.PathNode> seenNodes = new HashSet<>();
state.roomPopulatorStates.forEach(roomLayoutGenerator -> {
ArrayList<HashSet<PathState.PathNode>> seenNodes = new ArrayList<>();
for(int i = 0; i < state.roomPopulatorStates.size(); i++)
{
RoomLayoutGenerator roomLayoutGenerator = state.roomPopulatorStates.get(i);
HashSet<PathState.PathNode> nodes = new HashSet<>();
final PathState pathState = roomLayoutGenerator.getOrCalculatePathState(tw);
pathState.nodes.stream()
// Filter to only those inside this chunk
.filter(node -> node.center.getX() >> 4 == chunkX && node.center.getZ() >> 4 == chunkZ)
.forEach(node -> {
pathState.writer.apply(data, tw, node);
seenNodes.add(node);
});
});
// Filter to only those inside this chunk
.filter(node -> node.center.getX() >> 4 == chunkX && node.center.getZ() >> 4 == chunkZ)
.forEach(node -> {
pathState.writer.apply(data, tw, node);
nodes.add(node);
});
seenNodes.add(nodes);
}

// Carve each room
ArrayList<CubeRoom> seenRooms = new ArrayList<>();
Expand All @@ -104,26 +110,29 @@ public void populate(@NotNull WorldInfo worldInfo,
)
.forEach(room -> {
seenRooms.add(room);
roomLayoutGenerator.roomCarver.carveRoom(
data,
room,
roomLayoutGenerator.wallMaterials
);
if(roomLayoutGenerator.roomCarver != null)
roomLayoutGenerator.roomCarver.carveRoom(
data,
room,
roomLayoutGenerator.wallMaterials
);
}));

// Populate the paths
seenNodes.forEach((node) -> {
seenNodes.forEach((nodes)->nodes.forEach((node) -> {
// If the path has a direction of up, it is a crossway.
if (node.populator != null) {
node.populator.populate(new PathPopulatorData(new Wall(
new SimpleBlock(data, node.center),
node.connected.size() == 1 ? node.connected.stream().findAny().get() : BlockFace.UP
), node.pathRadius));
}
});
}));

// Populate the rooms
seenRooms.forEach(room -> room.getPop().populate(data, room));
seenRooms.stream()
.filter(room -> room.getPop() != null)
.forEach(room -> room.getPop().populate(data, room));
}

// OLDER BLOCK POPULATOR API
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/org/terraform/data/Wall.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public Wall getRight(int it) {
return new Wall(super.getRelative(direction.getOppositeFace()), direction);
}

public @NotNull Wall flip(){
return new Wall(this, direction.getOppositeFace());
}
public Wall getRear(int it) {
if (it < 0) {
return getFront(-it);
Expand Down
13 changes: 13 additions & 0 deletions common/src/main/java/org/terraform/structure/EmptyPathWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.terraform.structure;

import org.terraform.coregen.populatordata.PopulatorDataAbstract;
import org.terraform.data.TerraformWorld;
import org.terraform.structure.room.path.PathState;
import org.terraform.structure.room.path.PathWriter;

public class EmptyPathWriter extends PathWriter {
@Override
public void apply(PopulatorDataAbstract popData, TerraformWorld tw, PathState.PathNode node) {
//Do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
import org.jetbrains.annotations.Nullable;
import org.terraform.coregen.populatordata.PopulatorDataAbstract;
import org.terraform.data.SimpleBlock;
import org.terraform.data.SimpleLocation;
import org.terraform.data.TerraformWorld;
import org.terraform.data.Wall;
import org.terraform.structure.room.CarvedRoom;
import org.terraform.structure.room.CubeRoom;
import org.terraform.structure.room.PathPopulatorData;
import org.terraform.structure.room.RoomLayoutGenerator;
import org.terraform.structure.room.RoomPopulatorAbstract;
import org.terraform.structure.room.path.PathState;
import org.terraform.utils.GenUtils;
import org.terraform.utils.StairwayBuilder;
import org.terraform.utils.noise.FastNoise;
import org.terraform.utils.noise.NoiseCacheHandler;
import org.terraform.utils.noise.NoiseCacheHandler.NoiseCacheEntry;

import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Random;

Expand All @@ -27,7 +30,9 @@ public abstract class AncientCityAbstractRoomPopulator extends RoomPopulatorAbst
protected final RoomLayoutGenerator gen;
final TerraformWorld tw;
protected int shrunkenWidth = 0;
protected @Nullable CubeRoom effectiveRoom = null;
protected @NotNull CubeRoom effectiveRoom = null;
protected HashSet<SimpleBlock> containsPaths = new HashSet<>();
protected boolean doCarve = true;

public AncientCityAbstractRoomPopulator(TerraformWorld tw,
RoomLayoutGenerator gen,
Expand Down Expand Up @@ -62,7 +67,8 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room
));

// Clear out space for the room
effectiveRoom.fillRoom(data, Material.CAVE_AIR);
if(doCarve)
effectiveRoom.fillRoom(data, Material.CAVE_AIR);

// Room flooring
int[] lowerCorner = effectiveRoom.getLowerCorner(0);
Expand Down Expand Up @@ -96,36 +102,65 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room
}
}

//Stairs cannot go next to each other as they're width 3
boolean placedStairs = false;
// Connect the paths to the rooms
//This is some scuffed code. In essence, PathNodes are placed in spaced intervals
// of 1 per 5 blocks. So if we check an area 5 times (j), we will find a path node (maybe)
for (Entry<Wall, Integer> entry : room.getFourWalls(data, 0).entrySet()) {
Wall w = entry.getKey().getDown();
for (int i = shrunkenWidth; i < entry.getValue() - shrunkenWidth; i++) {

if (this.gen.getPathPopulators().contains(new PathPopulatorData(w.getRear().getAtY(room.getY()), 3))) {
// w.getUp(3).setType(Material.RED_WOOL);
w.setType(AncientCityUtils.deepslateBricks);
w.getLeft().setType(AncientCityUtils.deepslateBricks);
w.getRight().setType(AncientCityUtils.deepslateBricks);

if (depression < 0) {
new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS).setDownTypes(AncientCityUtils.deepslateBricks)
.setStairwayDirection(BlockFace.DOWN)
.setStopAtY(effectiveRoom.getY())
.build(w.getFront())
.build(w.getFront().getLeft())
.build(w.getFront().getRight());
}
else {
new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS).setDownTypes(AncientCityUtils.deepslateBricks)
.setStairwayDirection(BlockFace.UP)
.setUpwardsCarveUntilNotSolid(false)
.setStopAtY(effectiveRoom.getY())
.build(w.getUp().getFront())
.build(w.getUp().getFront().getLeft())
.build(w.getUp().getFront().getRight());
if(!placedStairs)
for (int j = 1; j <= 7; j++) {
SimpleLocation target = w.getRear(j).getAtY(room.getY()).getLoc();
if (this.gen.getOrCalculatePathState(tw).nodes.contains(
new PathState.PathNode(target, 1, null)))
{
placedStairs = true;
//Room edge is the ledge of the effective room
Wall roomEdge = w.getFront(shrunkenWidth+1).getAtY(effectiveRoom.getY()+1);
containsPaths.add(roomEdge);
containsPaths.add(roomEdge.getLeft());
containsPaths.add(roomEdge.getRight());

if (depression > 0) {
new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS)
.setDownTypes(AncientCityUtils.deepslateBricks)
.setStairwayDirection(BlockFace.DOWN)
.setStopAtY(room.getY())
.build(roomEdge.getDown().getRear().flip())
.build(roomEdge.getDown().getRear().getLeft().flip())
.build(roomEdge.getDown().getRear().getRight().flip());
}
else {
new StairwayBuilder(Material.DEEPSLATE_BRICK_STAIRS)
.setDownTypes(AncientCityUtils.deepslateBricks)
.setStairwayDirection(BlockFace.UP)
.setUpwardsCarveUntilNotSolid(false)
.setStopAtY(room.getY())
.build(roomEdge.getRear().flip())
.build(roomEdge.getRear().getLeft().flip())
.build(roomEdge.getRear().getRight().flip());
}
//Close potential holes between the stairs and the platform
//This is exactly where the effective room's wall is
Wall conn = roomEdge.getUp(-depression-1).getRear(Math.abs(depression)+1);
for(int conni = 0; conni <= 5; conni++)
{
boolean wasBlocked = conn.getRear(conni).lsetType(Material.GRAY_WOOL);
wasBlocked &= conn.getRear(conni).getLeft().lsetType(Material.GRAY_WOOL);
wasBlocked &= conn.getRear(conni).getRight().lsetType(Material.GRAY_WOOL);
//Ignore the corner 2's placement.
conn.getRear(conni).getRight(2).lsetType(AncientCityUtils.deepslateBricks);
conn.getRear(conni).getLeft(2).lsetType(AncientCityUtils.deepslateBricks);
if(wasBlocked) break;
}

break; //BREAK if you see a staircase.
}
}

}
else
placedStairs = false;
w = w.getLeft();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.terraform.main.TerraformGeneratorPlugin;
import org.terraform.schematic.TerraSchematic;
import org.terraform.structure.room.CubeRoom;
import org.terraform.structure.room.PathPopulatorData;
import org.terraform.structure.room.RoomLayoutGenerator;

public class AncientCityAltarPopulator extends AncientCityAbstractRoomPopulator {
Expand All @@ -40,7 +39,7 @@ public void populate(@NotNull PopulatorDataAbstract data, @NotNull CubeRoom room
if (i == entry.getValue() / 2) {
center = w;
}
if (this.gen.getPathPopulators().contains(new PathPopulatorData(w.getRear().getAtY(room.getY()), 3))) {
if (containsPaths.contains(w)) {
shouldPlaceAltar = false;
break;
}
Expand Down
Loading

0 comments on commit 25521ba

Please sign in to comment.