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'
I see the issues. The API for structure pools has changed significantly in Minecraft 1.20.1, and the registry system is much more restrictive. Let me provide you with the correct approach for this version.
In Minecraft 1.20.1, the structure pool registry is loaded from data packs and then frozen, making runtime modifications very difficult or impossible through normal means. The methods and registries you're trying to use either don't exist or work differently.
Since you already have NBT files in resources/data/minecraft/structures/village/plains/houses, the easiest and most reliable way is to use a JSON data pack to override the village pool:
Create this file: resources/data/minecraft/worldgen/template_pool/village/plains/houses.json
{
"name": "minecraft:village/plains/houses",
"fallback": "minecraft:empty",
"elements": [
{
"weight": 5,
"element": {
"element_type": "minecraft:legacy_single_pool_element",
"location": "minecraft:village/plains/houses/plains_armorer_house_1",
"projection": "rigid",
"processors": "minecraft:empty"
}
},
{
"weight": 3,
"element": {
"element_type": "minecraft:legacy_single_pool_element",
"location": "minecraft:village/plains/houses/plains_small_house_5",
"projection": "rigid",
"processors": "minecraft:empty"
}
},
{
"weight": 4,
"element": {
"element_type": "minecraft:legacy_single_pool_element",
"location": "minecraft:village/plains/houses/plains_tannery_1",
"projection": "rigid",
"processors": "minecraft:empty"
}
}
// Add more structures as needed
]
}
This will automatically use your custom NBT files since they're in the vanilla namespace.
If you absolutely need to do this through code, here's a working approach using reflection to modify the frozen registry:
package net.mattias.marloevillages.registry;
import com.google.common.collect.ImmutableList;
import net.mattias.marloevillages.MarloeVillages;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.levelgen.structure.pools.SinglePoolElement;
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
import net.minecraftforge.event.server.ServerAboutToStartEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Mod.EventBusSubscriber(modid = MarloeVillages.MOD_ID)
public class ModStructurePools {
@SubscribeEvent
public static void onServerAboutToStart(ServerAboutToStartEvent event) {
modifyPlainsVillage(event.getServer());
}
private static void modifyPlainsVillage(MinecraftServer server) {
try {
// Get the structure pool registry
Registry<StructureTemplatePool> poolRegistry = server.registryAccess()
.registryOrThrow(Registries.TEMPLATE_POOL);
// Get the vanilla plains houses pool
ResourceLocation poolId = new ResourceLocation("minecraft", "village/plains/houses");
Optional<StructureTemplatePool> optionalPool = poolRegistry.getOptional(poolId);
if (optionalPool.isEmpty()) {
MarloeVillages.LOGGER.error("Plains village houses pool not found!");
return;
}
StructureTemplatePool originalPool = optionalPool.get();
// Create new pool elements
List<StructurePoolElement> newElements = new ArrayList<>();
// Add vanilla structures with your custom NBTs (since you're replacing them)
addPoolElement(newElements, "minecraft:village/plains/houses/plains_armorer_house_1", 5);
addPoolElement(newElements, "minecraft:village/plains/houses/plains_small_house_5", 3);
addPoolElement(newElements, "minecraft:village/plains/houses/plains_tannery_1", 4);
// Add more as needed...
// Use reflection to modify the pool's elements
Field elementsField = StructureTemplatePool.class.getDeclaredField("templates");
elementsField.setAccessible(true);
elementsField.set(originalPool, newElements);
MarloeVillages.LOGGER.info("Successfully modified plains village pool!");
} catch (Exception e) {
MarloeVillages.LOGGER.error("Failed to modify plains village pool", e);
}
}
private static void addPoolElement(List<StructurePoolElement> elements, String location, int weight) {
// Create a single pool element using the public static method
StructurePoolElement element = SinglePoolElement.single(location)
.apply(StructureTemplatePool.Projection.RIGID);
// Add the element multiple times based on weight
for (int i = 0; i < weight; i++) {
elements.add(element);
}
}
}
If you need more control, you could use Mixins to intercept the pool loading:
First, add Mixin to your build.gradle:
dependencies {
// ... other dependencies
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}
Then create a Mixin class:
package net.mattias.marloevillages.mixin;
import net.mattias.marloevillages.MarloeVillages;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.structure.pools.StructureTemplatePool;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(StructureTemplatePool.class)
public class StructureTemplatePoolMixin {
@ModifyVariable(
method = "<init>",
at = @At("HEAD"),
argsOnly = true,
index = 3
)
private static List<StructurePoolElement> modifyPoolElements(
List<StructurePoolElement> elements,
ResourceLocation name) {
if (name.toString().equals("minecraft:village/plains/houses")) {
// Return your custom elements list
return createCustomElements();
}
return elements;
}
private static List<StructurePoolElement> createCustomElements() {
// Create your custom elements here
return List.of(/* your elements */);
}
}
I strongly recommend using Solution 1 (the JSON data pack approach) because:
Your existing NBT files in data/minecraft/structures/ will automatically be used when referenced in the JSON pool file.