Fabric Waystones

Fabric Waystones

16M Downloads

Villages can turn out a little bit smaller due to structure removal

Fourmisain opened this issue · 1 comments

commented

While debugging the issue of #73 I found another small one.

There's this code here which ensures waystones are unique in each village:

for (int i = 0; i < StructureFeature.LAND_MODIFYING_STRUCTURES.size(); ++i) {
var structureFeature = StructureFeature.LAND_MODIFYING_STRUCTURES.get(i);
var waystones = new AtomicInteger(0);
accessor.getStructuresWithChildren(ChunkSectionPos.from(chunkPos, 0), structureFeature).forEach((structures) -> {
int pre = structures.getChildren().size();
ArrayList<Integer> toRemove = new ArrayList<>();
for (int j = 0; j < pre; ++j) {
StructurePiece structure = structures.getChildren().get(j);
if (structure instanceof PoolStructurePiece poolStructurePiece &&
((PoolStructurePiece) structure).getPoolElement() instanceof SinglePoolElement &&
WaystonesWorldgen.WAYSTONE_STRUCTURES.contains(((SinglePoolElementAccessor)(poolStructurePiece).getPoolElement()).getLocation().left().get()) &&
waystones.getAndIncrement() > 0) {
toRemove.add(j);
}
}
toRemove.sort(Collections.reverseOrder());
for(int remove : toRemove) {
structures.getChildren().remove(remove);
}
});
}

It does this by removing all structures that contain waystones except 1.

This means if a village were to generate with multiple waystones, because those structures are getting removed without replacement, the village will actually be smaller than intended.

To demonstrate this I boosted the weighting of waystone structures from 5 to 500 here:

Utils.addToStructurePool(server, village, waystone, 5);

Here's a village without waystone generation:
without
Here's the same village with the boosted waystone generation:
with500

Of course this comparison is heavily exaggerated, but it's still an issue to a lesser degree.

commented

Finally fixed.