KristenStuffs Posted August 23, 2022 Share Posted August 23, 2022 (edited) Specifics: I created an underwater plant called, "Living Sponge" based on Kelp which I have confirmed working in game and works as fully intended, now I am trying to get register generation for the plant. The LivingSpongeGeneration class has no errors attached to it, though I expect there to be depending on how much I need to change in my ModWorldEventAlts class which I'm currently using to register LivingSpongeGeneration. I have tried fixing it multiple times, but when I do another error will popup. Error message in console: "Exception message: java.lang.IllegalStateException: Can not register to a locked registry. Modder should use Forge Register methods." This only displays in the console as the game will say, "null". Project Github: https://github.com/KristenStuffs/ALMTS Edited August 25, 2022 by KristenStuffs Quote Link to comment Share on other sites More sharing options...
vemerion Posted August 23, 2022 Share Posted August 23, 2022 4 hours ago, KristenStuffs said: Error message in console: "Exception message: java.lang.IllegalStateException: Can not register to a locked registry. Modder should use Forge Register methods." You should use the Forge registry when registering features. You can read more about how to do it here. Quote Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 23, 2022 Author Share Posted August 23, 2022 I have looked at the page even before I posted this question, I've gone through the forge external libraries as well. I simply cannot see what else I could do which I haven't yet done. Quote Link to comment Share on other sites More sharing options...
Luis_ST Posted August 23, 2022 Share Posted August 23, 2022 ConfiguredFeatures and PlacedFeatures should also be registered with DeferredRegister. Quote Link to comment Share on other sites More sharing options...
warjort Posted August 23, 2022 Share Posted August 23, 2022 Use DeferredRegister with Registry.CONFIGURED_FEATURE_REGISTRY and Registry.PLACED_FEATURE_REGISTRY Here's an example from a different thread that makes diamond blocks "ores": public class ModFeatures { private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, ExampleMod.MODID); private static final DeferredRegister<PlacedFeature> PLACED_FEATURES = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, ExampleMod.MODID); public static final RegistryObject<ConfiguredFeature<?, ?>> DIAMOND_BLOCKS_CONFIGURED = CONFIGURED_FEATURES.register("diamond_blocks", () -> { var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("minecraft:diamond_block")); var target = List.of(OreConfiguration.target(OreFeatures.NATURAL_STONE, block.defaultBlockState())); return new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(target, 64)); }); public static final RegistryObject<PlacedFeature> DIAMOND_BLOCKS_PLACED = PLACED_FEATURES.register("diamond_blocks", () -> new PlacedFeature(DIAMOND_BLOCKS_CONFIGURED.getHolder().get(), commonOrePlacement(10, HeightRangePlacement.triangle(VerticalAnchor.absolute(-24), VerticalAnchor.absolute(56))))); public static void register(IEventBus bus) { CONFIGURED_FEATURES.register(bus); PLACED_FEATURES.register(bus); } } Obviously the ModFeatures.register() needs to be called from your main mod class. Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 23, 2022 Author Share Posted August 23, 2022 14 hours ago, warjort said: Use DeferredRegister with Registry.CONFIGURED_FEATURE_REGISTRY and Registry.PLACED_FEATURE_REGISTRY Here's an example from a different thread that makes diamond blocks "ores": public class ModFeatures { private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, ExampleMod.MODID); private static final DeferredRegister<PlacedFeature> PLACED_FEATURES = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, ExampleMod.MODID); public static final RegistryObject<ConfiguredFeature<?, ?>> DIAMOND_BLOCKS_CONFIGURED = CONFIGURED_FEATURES.register("diamond_blocks", () -> { var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("minecraft:diamond_block")); var target = List.of(OreConfiguration.target(OreFeatures.NATURAL_STONE, block.defaultBlockState())); return new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(target, 64)); }); public static final RegistryObject<PlacedFeature> DIAMOND_BLOCKS_PLACED = PLACED_FEATURES.register("diamond_blocks", () -> new PlacedFeature(DIAMOND_BLOCKS_CONFIGURED.getHolder().get(), commonOrePlacement(10, HeightRangePlacement.triangle(VerticalAnchor.absolute(-24), VerticalAnchor.absolute(56))))); public static void register(IEventBus bus) { CONFIGURED_FEATURES.register(bus); PLACED_FEATURES.register(bus); } } Obviously the ModFeatures.register() needs to be called from your main mod class. How does this work with NoneFeatureConfiguration which is used in the default KelpFeature Registry? Quote Link to comment Share on other sites More sharing options...
warjort Posted August 23, 2022 Share Posted August 23, 2022 Isn't that trivial? Maybe I don't understand your question. Why you would need your own configured feature for this (it is the same as the vanilla one) unless you intend to use your own/different Feature. public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(Feature.KELP, NoneFeatureConfiguration.INSTANCE)); Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 23, 2022 Author Share Posted August 23, 2022 16 minutes ago, warjort said: Isn't that trivial? Maybe I don't understand your question. Why you would need your own configured feature for this (it is the same as the vanilla one) unless you intend to use your own/different Feature. public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(Feature.KELP, NoneFeatureConfiguration.INSTANCE)); Sorry, I've never worked with this in particular before so this is a first time experience for me as I took a few years break from modding. I don't see where I would reference my own custom class (LivingSpongeGeneration), where would I register that within the code? Quote Link to comment Share on other sites More sharing options...
warjort Posted August 23, 2022 Share Posted August 23, 2022 That's a feature correct? Continuing the theme of reinventing vanilla 🙂 Something like (untested code): private static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(Registry.FEATURE_REGISTRY, ExampleMod.MODID); public static final RegistryObject<Feature<NoneFeatureConfiguration>> MY_KELP = FEATURES.register("my_kelp", () -> new KelpFeature(NoneFeatureConfiguration.CODEC)); public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(MY_KELP.get(), NoneFeatureConfiguration.INSTANCE)); Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 23, 2022 Author Share Posted August 23, 2022 52 minutes ago, warjort said: That's a feature correct? Continuing the theme of reinventing vanilla 🙂 Something like (untested code): private static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(Registry.FEATURE_REGISTRY, ExampleMod.MODID); public static final RegistryObject<Feature<NoneFeatureConfiguration>> MY_KELP = FEATURES.register("my_kelp", () -> new KelpFeature(NoneFeatureConfiguration.CODEC)); public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(MY_KELP.get(), NoneFeatureConfiguration.INSTANCE)); I have something quite similar to this class and there's no errors at all in it, but nothing spawns in game. My code looks like this, is there anything wrong with it? package com.kristen.almts.world; import com.kristen.almts.ALMTS; import com.kristen.almts.world.gen.plants.LivingSpongeGeneration; import net.minecraft.core.Registry; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.RegistryObject; public class ModWorldEventsAlt { private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, ALMTS.MOD_ID); private static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(Registry.FEATURE_REGISTRY, ALMTS.MOD_ID); // Placement public static final RegistryObject<Feature<NoneFeatureConfiguration>> MY_KELP = FEATURES.register("my_kelp", () -> new LivingSpongeGeneration(NoneFeatureConfiguration.CODEC)); // Configuration public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(MY_KELP.get(), NoneFeatureConfiguration.INSTANCE)); public static void register(IEventBus bus) { CONFIGURED_FEATURES.register(bus); FEATURES.register(bus); } } Quote Link to comment Share on other sites More sharing options...
warjort Posted August 23, 2022 Share Posted August 23, 2022 You need a placed feature as well. Feature = the thing that places blocks ConfiguredFeature = Configuration(s) of that feature, e.g. how big an ore vein or which ore PlacedFeature = PlacementModifier(s) that decides where to put it, e.g. cactus goes on sand, diamonds generate at the bottom of the world But more importantly you need a Biome that uses it. To modify vanilla biomes see: https://forge.gemwire.uk/wiki/Biome_Modifiers or before 1.19 you use the BiomeLoadingEvent Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 24, 2022 Author Share Posted August 24, 2022 20 minutes ago, warjort said: You need a placed feature as well. Feature = the thing that places blocks ConfiguredFeature = Configuration(s) of that feature, e.g. how big an ore vein or which ore PlacedFeature = PlacementModifier(s) that decides where to put it, e.g. cactus goes on sand, diamonds generate at the bottom of the world But more importantly you need a Biome that uses it. To modify vanilla biomes see: https://forge.gemwire.uk/wiki/Biome_Modifiers or before 1.19 you use the BiomeLoadingEvent So a couple of things (sorry, you have been helping me a lot already) I added in a Placed Features Section private static final DeferredRegister<PlacedFeature> PLACED_FEATURES = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, ALMTS.MOD_ID); public static final RegistryObject<PlacedFeature> MY_KELP_PLACED = PLACED_FEATURES.register("my_kelp", () -> new PlacedFeature(MY_KELP_CONFIGURED.getHolder().get())))); However it is telling me: The constructor PlacedFeature(Holder<ConfiguredFeature<?,?>>) is undefined 1 quick fix avaiable: + Add Arguement to match 'PlacedFeature(Holder<ConfiguredFeature<?, ?>>, List<PlacementModifier>)' I've also tried implementing the biomeLoadingEvent as you've told me to do since I am using 1.18.2, but I've been getting an error with that as well and admittedly I have a lack of understanding with the biomeLoadingEvent in general. This is what I currently have: @SubscribeEvent public static void biomeLoadingEvent(final BiomeLoadingEvent event) { if (event.getCategory() == Biome.BiomeCategory.OCEAN) { event.getGeneration().addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, MY_KELP_PLACED); } } The error is: The method addFeature(GenerationStep.Decoration, Holder<PlacedFeature>) in the type BiomeGenerationSettings.Builder is not applicable for the arguments (GenerationStep.Decoration, RegistryObject<PlacedFeature>) 1 quick fix avaiable: Change type of 'My_KELP_PLACED' to 'Holder<PlacedFeature>' Here is my whole class if you need to need to see anything else: package com.kristen.almts.world; import com.kristen.almts.ALMTS; import com.kristen.almts.world.gen.plants.LivingSpongeGeneration; import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraftforge.event.world.BiomeLoadingEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.RegistryObject; public class ModWorldEventsAlt { private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, ALMTS.MOD_ID); private static final DeferredRegister<PlacedFeature> PLACED_FEATURES = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, ALMTS.MOD_ID); private static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(Registry.FEATURE_REGISTRY, ALMTS.MOD_ID); // Feature public static final RegistryObject<Feature<NoneFeatureConfiguration>> MY_KELP = FEATURES.register("my_kelp", () -> new LivingSpongeGeneration(NoneFeatureConfiguration.CODEC)); // Configuration public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(MY_KELP.get(), NoneFeatureConfiguration.INSTANCE)); // Placement public static final RegistryObject<PlacedFeature> MY_KELP_PLACED = PLACED_FEATURES.register("my_kelp", () -> new PlacedFeature(MY_KELP_CONFIGURED.getHolder().get())))); public static void register(IEventBus bus) { CONFIGURED_FEATURES.register(bus); PLACED_FEATURES.register(bus); FEATURES.register(bus); } @SubscribeEvent public static void biomeLoadingEvent(final BiomeLoadingEvent event) { if (event.getCategory() == Biome.BiomeCategory.OCEAN) { event.getGeneration().addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, MY_KELP_PLACED); } } } Quote Link to comment Share on other sites More sharing options...
warjort Posted August 24, 2022 Share Posted August 24, 2022 These aren't forge/minecraft questions, these are java questions. We don't really answer those here. Knowing java is a prerequisite for minecraft modding. But since one of them is partly minecraft related I will answer them. Your main problem is you are not passing the correct parameter types or not passing parameters at all. (basic java). () -> new PlacedFeature(MY_KELP_CONFIGURED.getHolder().get())))); This constructor takes 2 parameters, you are missing the List of PlacementModifers which is the whole point of this class. You can see what is done for kelp in AquaticPlacements. event.getGeneration().addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, MY_KELP_PLACED); This methods wants a PlacedFeature not a RegistryObject<PlacedFeature>, use MY_KELP_PLACED.get() - which gives you the real object. Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 24, 2022 Author Share Posted August 24, 2022 16 hours ago, warjort said: These aren't forge/minecraft questions, these are java questions. We don't really answer those here. Knowing java is a prerequisite for minecraft modding. But since one of them is partly minecraft related I will answer them. Your main problem is you are not passing the correct parameter types or not passing parameters at all. (basic java). () -> new PlacedFeature(MY_KELP_CONFIGURED.getHolder().get())))); This constructor takes 2 parameters, you are missing the List of PlacementModifers which is the whole point of this class. You can see what is done for kelp in AquaticPlacements. event.getGeneration().addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, MY_KELP_PLACED); This methods wants a PlacedFeature not a RegistryObject<PlacedFeature>, use MY_KELP_PLACED.get() - which gives you the real object. Sorry if my first question came across as basic Java, I was basically just trying to ask where there would be example placements, albeit in a pretty round about way. I've gotten to another point, where there is no errors anywhere within the code from what I can tell. I also used the AquaticFeatures class as an example. Minecraft launches, though I don't see any of the Sponges which should be generating. I ran the debug tool and can confirm, it is being called. Currently this is how the code looks. package com.kristen.almts.world; import java.util.List; import com.kristen.almts.ALMTS; import com.kristen.almts.world.gen.plants.LivingSpongeGeneration; import net.minecraft.core.Registry; import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.placement.BiomeFilter; import net.minecraft.world.level.levelgen.placement.InSquarePlacement; import net.minecraft.world.level.levelgen.placement.NoiseBasedCountPlacement; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraftforge.event.world.BiomeLoadingEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.RegistryObject; public class ModWorldEventsAlt { private static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(Registry.FEATURE_REGISTRY, ALMTS.MOD_ID); private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, ALMTS.MOD_ID); private static final DeferredRegister<PlacedFeature> PLACED_FEATURES = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, ALMTS.MOD_ID); // Feature public static final RegistryObject<Feature<NoneFeatureConfiguration>> MY_KELP = FEATURES.register("my_kelp", () -> new LivingSpongeGeneration(NoneFeatureConfiguration.CODEC)); public static final RegistryObject<ConfiguredFeature<?, ?>> MY_KELP_CONFIGURED = CONFIGURED_FEATURES.register("my_kelp", () -> new ConfiguredFeature<>(MY_KELP.get(), NoneFeatureConfiguration.INSTANCE)); // Placement public static final RegistryObject<PlacedFeature> MY_KELP_PLACED = PLACED_FEATURES.register("my_kelp", () -> new PlacedFeature(MY_KELP_CONFIGURED.getHolder().get(), List.of(NoiseBasedCountPlacement.of(73, 730D, 0.0D), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP_TOP_SOLID, BiomeFilter.biome()))))); public static void register(IEventBus bus) { CONFIGURED_FEATURES.register(bus); PLACED_FEATURES.register(bus); FEATURES.register(bus); } @SubscribeEvent public static void biomeLoadingEvent(final BiomeLoadingEvent event) { if (event.getCategory() == Biome.BiomeCategory.OCEAN) { event.getGeneration().addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, MY_KELP_PLACED.getHolder().get()); } } } Quote Link to comment Share on other sites More sharing options...
warjort Posted August 25, 2022 Share Posted August 25, 2022 @Mod.EventBusSubscriber(modid = ALMTS.MOD_ID) // ** ADD THIS ** public class ModWorldEventsAlt { -- snip -- @SubscribeEvent public static void biomeLoadingEvent(final BiomeLoadingEvent event) { You don't have a subscriber annotation. See the comment above. I assume you don't have other (not shown) code registering that event handler? Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
KristenStuffs Posted August 25, 2022 Author Share Posted August 25, 2022 40 minutes ago, warjort said: @Mod.EventBusSubscriber(modid = ALMTS.MOD_ID) // ** ADD THIS ** public class ModWorldEventsAlt { -- snip -- @SubscribeEvent public static void biomeLoadingEvent(final BiomeLoadingEvent event) { You don't have a subscriber annotation. See the comment above. I assume you don't have other (not shown) code registering that event handler? Well I got it working, thank you a lot for your time helping me. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.