Skip to content

Commit d03ce14

Browse files
Merge branch '1.20.1' of github.com:LordDeatHunter/FabricWaystones into 1.20.1
2 parents e55ccc6 + db0f41b commit d03ce14

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ dependencies {
4646
modApi "maven.modrinth:pinlib:$project.pinlib_api_version"
4747
modRuntimeOnly "maven.modrinth:pinlib:$project.pinlib_api_version"
4848

49+
modImplementation "maven.modrinth:lithostitched:1.4.4-fabric-1.20"
50+
4951
annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}")
5052
include "io.wispforest:owo-sentinel:${project.owo_version}"
5153
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package wraith.fwaystones.integration.lithostitched;
2+
3+
import dev.worldgen.lithostitched.worldgen.poolelement.legacy.GuaranteedPoolElement;
4+
import dev.worldgen.lithostitched.worldgen.poolelement.legacy.LimitedPoolElement;
5+
import net.minecraft.structure.pool.SinglePoolElement;
6+
import net.minecraft.structure.pool.StructurePool;
7+
import net.minecraft.structure.pool.StructurePoolElement;
8+
9+
import wraith.fwaystones.FabricWaystones;
10+
import wraith.fwaystones.util.FWConfig;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
import java.util.Optional;
15+
16+
/**
17+
* If Lithostitched is present, use its guaranteed/limited pool element system given it bypasses the vanilla system.
18+
*
19+
* @author Apollo
20+
*/
21+
public class LithostitchedPlugin {
22+
/**
23+
* Creates two elements: One to force waystones up to the min count, and one to limit them at the max count.
24+
* Not 1:1 with normal behavior (particularly in modded villages with few house variants) but it's still fairly close.
25+
*/
26+
public static List<StructurePoolElement> createPieces(String name) {
27+
FWConfig.Worldgen config = FabricWaystones.CONFIG.worldgen;
28+
List<StructurePoolElement> elements = new ArrayList<>();
29+
30+
if (config.min_per_village() > 0) {
31+
elements.add(new GuaranteedPoolElement(
32+
SinglePoolElement.ofSingle(name).apply(StructurePool.Projection.RIGID),
33+
Optional.empty(),
34+
config.min_per_village()
35+
));
36+
}
37+
38+
if (config.max_per_village() - config.min_per_village() > 0) {
39+
elements.add(new LimitedPoolElement(
40+
SinglePoolElement.ofSingle(name).apply(StructurePool.Projection.RIGID),
41+
Optional.empty(),
42+
config.max_per_village() - config.min_per_village()
43+
));
44+
}
45+
46+
return elements;
47+
}
48+
}

src/main/java/wraith/fwaystones/util/Utils.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package wraith.fwaystones.util;
22

33
import com.mojang.datafixers.util.Pair;
4+
import net.fabricmc.loader.api.FabricLoader;
45
import net.minecraft.entity.player.PlayerEntity;
56
import net.minecraft.entity.player.PlayerInventory;
67
import net.minecraft.item.Item;
78
import net.minecraft.item.ItemStack;
89
import net.minecraft.registry.Registries;
910
import net.minecraft.registry.RegistryKey;
1011
import net.minecraft.registry.RegistryKeys;
11-
import net.minecraft.registry.entry.RegistryEntry;
1212
import net.minecraft.server.MinecraftServer;
1313
import net.minecraft.structure.pool.StructurePool;
1414
import net.minecraft.structure.pool.StructurePoolElement;
@@ -20,6 +20,7 @@
2020
import net.minecraft.world.World;
2121
import org.jetbrains.annotations.Nullable;
2222
import wraith.fwaystones.FabricWaystones;
23+
import wraith.fwaystones.integration.lithostitched.LithostitchedPlugin;
2324
import wraith.fwaystones.item.LocalVoidItem;
2425
import wraith.fwaystones.mixin.StructurePoolAccessor;
2526
import wraith.fwaystones.screen.AbyssScreenHandler;
@@ -84,11 +85,6 @@ private static String generateUniqueId() {
8485
}
8586

8687
public static void addToStructurePool(MinecraftServer server, Identifier village, Identifier waystone, int weight) {
87-
88-
RegistryEntry<StructureProcessorList> emptyProcessorList = server.getRegistryManager()
89-
.get(RegistryKeys.PROCESSOR_LIST)
90-
.entryOf(EMPTY_PROCESSOR_LIST_KEY);
91-
9288
var poolGetter = server.getRegistryManager()
9389
.get(RegistryKeys.TEMPLATE_POOL)
9490
.getOrEmpty(village);
@@ -99,15 +95,25 @@ public static void addToStructurePool(MinecraftServer server, Identifier village
9995
}
10096
var pool = poolGetter.get();
10197

102-
var pieceList = ((StructurePoolAccessor) pool).getElements();
103-
var piece = StructurePoolElement.ofProcessedSingle(waystone.toString(), emptyProcessorList).apply(StructurePool.Projection.RIGID);
98+
if (FabricLoader.getInstance().isModLoaded("lithostitched")) {
99+
var pieces = LithostitchedPlugin.createPieces(waystone.toString());
100+
for (StructurePoolElement piece : pieces) {
101+
addPieceToPool(piece, ((StructurePoolAccessor)pool), weight);
102+
}
103+
} else {
104+
var piece = StructurePoolElement.ofSingle(waystone.toString()).apply(StructurePool.Projection.RIGID);
105+
addPieceToPool(piece, ((StructurePoolAccessor)pool), weight);
106+
}
107+
}
104108

105-
var list = new ArrayList<>(((StructurePoolAccessor) pool).getElementCounts());
106-
list.add(Pair.of(piece, weight));
107-
((StructurePoolAccessor) pool).setElementCounts(list);
109+
private static void addPieceToPool(StructurePoolElement element, StructurePoolAccessor accessor, int weight) {
110+
var pieceList = accessor.getElements();
111+
var list = new ArrayList<>(accessor.getElementCounts());
112+
list.add(Pair.of(element, weight));
113+
accessor.setElementCounts(list);
108114

109115
for (int i = 0; i < weight; ++i) {
110-
pieceList.add(piece);
116+
pieceList.add(element);
111117
}
112118
}
113119

0 commit comments

Comments
 (0)