package net.mattias.marloevillages.registry; import…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
package net.mattias.marloevillages.registry;
import net.mattias.marloevillages.MarloeVillages; import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.structure.pools.LegacySinglePoolElement; import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement; import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool; import net.mattias.marloevillages.util.ModConstants;
import java.util.List;
public class ModStructurePools { public static void register() { modifyPlainsVillage(); }
private static void modifyPlainsVillage() {
// 1. Get the vanilla plains village pool from the CORRECT registry
ResourceLocation poolLocation = new ResourceLocation("minecraft:village/plains/houses");
StructureTemplatePool originalPool = BuiltInRegistries.STRUCTURE_POOL.get(poolLocation); // Fixed: Use STRUCTURE_POOL, not STRUCTURE_POOL_ELEMENT
if (originalPool == null) {
MarloeVillages.LOGGER.error("Vanilla plains village pool not found!");
return;
}
// 2. Define custom structure elements with proper builder methods
List<StructurePoolElement> customElements = List.of(
// Use LegacySinglePoolElement.builder() to ensure correct method chaining
LegacySinglePoolElement.builder(
new ResourceLocation(ModConstants.MOD_ID, "village/plains/marloe_house_1")
)
.projection(StructureTemplatePool.Projection.RIGID)
.weight(5)
.build(),
LegacySinglePoolElement.builder(
new ResourceLocation(ModConstants.MOD_ID, "village/plains/marloe_house_2")
)
.projection(StructureTemplatePool.Projection.RIGID)
.weight(3)
.build()
);
// 3. Create modified pool with the correct constructor parameters
Holder<StructureTemplatePool> fallback = originalPool.getFallback(); // Fallback is a Holder, not a ResourceLocation
StructureTemplatePool modifiedPool = new StructureTemplatePool(
poolLocation, // Pool name (same as vanilla to override)
fallback, // Keep vanilla fallback pool
customElements, // Your custom structures
StructureTemplatePool.Projection.RIGID // Projection type
);
// 4. Register the modified pool to the CORRECT registry
BuiltInRegistries.STRUCTURE_POOL.register(poolLocation, modifiedPool); // Fixed: Use STRUCTURE_POOL registry
MarloeVillages.LOGGER.info("Replaced vanilla plains village pool with custom structures!");
}
} Cannot resolve symbol 'STRUCTURE_POOL' Cannot resolve method 'builder' in 'LegacySinglePoolElement' Cannot resolve method 'builder' in 'LegacySinglePoolElement' Cannot resolve constructor 'StructureTemplatePool(ResourceLocation, Holder, List, Projection)' Cannot resolve symbol 'STRUCTURE_POOL'
Below is the version that actually matches the 1.20.1 (Mojang-mapped / Forge) API.
The main things that changed compared with earlier replies are:
LegacySinglePoolElement has no builder – you obtain an element withLegacySinglePoolElement.single(id).apply(projection).StructureTemplatePool wants a List<Pair<StructurePoolElement,Integer>>,List<StructurePoolElement>.BuiltInRegistries.TEMPLATE_POOL.FMLCommonSetupEvent after the freeze.)The snippet below therefore:
• fetches the vanilla pool;
• empties its template lists;
• adds your own two houses (with weights 5 & 3).
package net.mattias.marloevillages.registry;
import com.mojang.datafixers.util.Pair;
import net.mattias.marloevillages.MarloeVillages;
import net.mattias.marloevillages.util.ModConstants;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.structure.pools.LegacySinglePoolElement;
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
import java.util.ArrayList;
import java.util.List;
public class ModStructurePools {
public static void register() {
replacePlainsHousesPool();
}
/** Replace the vanilla plains‐village houses pool with our own entries. */
private static void replacePlainsHousesPool() {
// 1) Grab the already-registered vanilla pool
ResourceLocation poolId = new ResourceLocation("minecraft:village/plains/houses");
StructureTemplatePool pool = BuiltInRegistries.TEMPLATE_POOL.get(poolId);
if (pool == null) {
MarloeVillages.LOGGER.error("Could not find vanilla pool {}", poolId);
return;
}
/* ------------------------------------------------------------------
2) Build our custom elements
------------------------------------------------------------------ */
StructurePoolElement house1 = LegacySinglePoolElement
.single(new ResourceLocation(ModConstants.MOD_ID,
"village/plains/marloe_house_1").toString())
.apply(StructureTemplatePool.Projection.RIGID);
StructurePoolElement house2 = LegacySinglePoolElement
.single(new ResourceLocation(ModConstants.MOD_ID,
"village/plains/marloe_house_2").toString())
.apply(StructureTemplatePool.Projection.RIGID);
List<Pair<StructurePoolElement, Integer>> replacements = List.of(
Pair.of(house1, 5),
Pair.of(house2, 3)
);
/* ------------------------------------------------------------------
3) Mutate the pool (both raw and shuffled lists must match!)
------------------------------------------------------------------ */
// These lists are *mutable*, so we can clear & refill them.
pool.templates().clear(); // raw weighted list
pool.shuffledTemplates().clear(); // list expanded by weight
// copy the weighted pairs
pool.templates().addAll(replacements);
// rebuild the shuffled (expanded) list
for (Pair<StructurePoolElement, Integer> pair : replacements) {
StructurePoolElement elem = pair.getFirst();
int weight = pair.getSecond();
for (int i = 0; i < weight; ++i) {
pool.shuffledTemplates().add(elem);
}
}
MarloeVillages.LOGGER.info("Re-wired pool {} → {} custom houses!",
poolId, pool.templates().size());
}
}
Where to call it
// in your main mod class
private void commonSetup(final FMLCommonSetupEvent evt) {
evt.enqueueWork(ModStructurePools::register);
}
Folder layout for the structures
resources/
└─ data/
└─ marloevillages/
└─ structures/
└─ village/
└─ plains/
├─ marloe_house_1.nbt
└─ marloe_house_2.nbt
No JSON or extra registration is required; NBT files are picked up automatically.
Create a new world after recompiling, run /locate village_plains, and the
generated village should now contain only the two custom houses with the given
weights.