Résolu Ajout d'une Structure
-
Bonjour, j’essaie de générer une nouvelle structure de manière aléatoire (pour le moment elle génère pas grand chose), je me suis basé sur le code du jeu afin de le faire mais lorsque je lance le jeu, il me dit que mon Mod a un problème au niveau du CommonSetup event et en lisant les logs il me dit que je rajoute ma structure trop tard
[27mars2020 12:39:46.305] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmluserdevclient, --fml.mcpVersion, 20190829.143755, --fml.mcVersion, 1.14.4, --fml.forgeGroup, net.minecraftforge, --fml.forgeVersion, 28.2.0, --version, MOD_DEV, --assetIndex, 1.14, --assetsDir, C:\Users\Turpin\.gradle\caches\forge_gradle\assets, --username, Dev, --accessToken, ????????, --userProperties, {}] [27mars2020 12:39:46.311] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 4.1.0+62+5bfa59b starting: java version 1.8.0_161 by Oracle Corporation [27mars2020 12:39:47.113] [main/INFO] [net.minecraftforge.fml.loading.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust [27mars2020 12:39:49.042] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'fmluserdevclient' with arguments [--version, MOD_DEV, --gameDir, ., --assetsDir, C:\Users\Turpin\.gradle\caches\forge_gradle\assets, --assetIndex, 1.14, --username, Dev, --accessToken, ????????, --userProperties, {}] [27mars2020 12:39:53.683] [Client thread/INFO] [net.minecraft.client.Minecraft/]: Setting user: Dev [27mars2020 12:40:21.102] [Client thread/WARN] [net.minecraft.client.GameSettings/]: Skipping bad option: lastServer: [27mars2020 12:40:21.289] [Client thread/INFO] [net.minecraft.client.Minecraft/]: LWJGL Version: 3.2.2 build 10 [27mars2020 12:40:25.318] [modloading-worker-3/INFO] [net.minecraftforge.common.ForgeMod/FORGEMOD]: Forge mod loading, version 28.2.0, for MC 1.14.4 with MCP 20190829.143755 [27mars2020 12:40:25.318] [modloading-worker-3/INFO] [net.minecraftforge.common.MinecraftForge/FORGE]: MinecraftForge v28.2.0 Initialized [27mars2020 12:40:35.017] [Client thread/INFO] [com.mojang.text2speech.NarratorWindows/]: Narrator library for x64 successfully loaded [27mars2020 12:40:39.887] [modloading-worker-2/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: null Index: 1 Listeners: 0: NORMAL 1: net.minecraftforge.eventbus.EventBus$$Lambda$2001/940454178@1ad9bf9b java.lang.ExceptionInInitializerError at fr.swordeus.spellz.world.StructureGeneration.setupStructures(StructureGeneration.java:14) at fr.swordeus.spellz.SpellzMod.setup(SpellzMod.java:34) at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:134) at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291) at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:401) at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734) at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583) at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$11(ModList.java:134) at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) Caused by: java.lang.IllegalStateException: The object fr.swordeus.spellz.world.structure.RuinedCastleStructure@3eaad85 (name spellz:ruined_castle) is being added too late. at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:348) at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:308) at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:56) at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:65) at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:34) at net.minecraft.util.registry.Registry.register(Registry.java:240) at net.minecraft.util.registry.Registry.register(Registry.java:236) at fr.swordeus.spellz.world.structure.CustomFeature.<clinit>(CustomFeature.java:19) ... 29 more [27mars2020 12:40:39.896] [modloading-worker-2/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/LOADING]: Caught exception during event FMLCommonSetupEvent dispatch for modid spellz java.lang.ExceptionInInitializerError: null at fr.swordeus.spellz.world.StructureGeneration.setupStructures(StructureGeneration.java:14) ~[main/:?] at fr.swordeus.spellz.SpellzMod.setup(SpellzMod.java:34) ~[main/:?] at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212) ~[eventbus-1.0.0-service.jar:?] at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204) ~[eventbus-1.0.0-service.jar:?] at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) ~[eventbus-1.0.0-service.jar:?] at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) ~[?:28.2] at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_161] at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[?:1.8.0_161] at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) ~[?:?] at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:134) ~[?:?] at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[?:1.8.0_161] at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) ~[?:1.8.0_161] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[?:1.8.0_161] at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291) ~[?:1.8.0_161] at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731) ~[?:1.8.0_161] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[?:1.8.0_161] at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:401) ~[?:1.8.0_161] at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734) ~[?:1.8.0_161] at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160) ~[?:1.8.0_161] at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174) ~[?:1.8.0_161] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) ~[?:1.8.0_161] at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[?:1.8.0_161] at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583) ~[?:1.8.0_161] at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$11(ModList.java:134) ~[?:?] at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386) [?:1.8.0_161] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_161] at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [?:1.8.0_161] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [?:1.8.0_161] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [?:1.8.0_161] Caused by: java.lang.IllegalStateException: The object fr.swordeus.spellz.world.structure.RuinedCastleStructure@3eaad85 (name spellz:ruined_castle) is being added too late. at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:348) ~[?:?] at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:308) ~[?:?] at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:56) ~[?:?] at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:65) ~[?:?] at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:34) ~[?:?] at net.minecraft.util.registry.Registry.register(Registry.java:240) ~[?:?] at net.minecraft.util.registry.Registry.register(Registry.java:236) ~[?:?] at fr.swordeus.spellz.world.structure.CustomFeature.<clinit>(CustomFeature.java:19) ~[?:?] ... 29 more
Le code de la classe principale :
package fr.swordeus.spellz; import java.util.logging.Logger; import fr.swordeus.spellz.init.ModBlocks; import fr.swordeus.spellz.init.ModItems; import fr.swordeus.spellz.world.OreGeneration; import fr.swordeus.spellz.world.StructureGeneration; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @Mod(SpellzMod.MODID) public class SpellzMod { public static final String MODID = "spellz"; public static final Logger logger = Logger.getLogger(MODID); public SpellzMod(){ FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); MinecraftForge.EVENT_BUS.register(ModItems.INSTANCE); MinecraftForge.EVENT_BUS.register(ModBlocks.INSTANCE); } public void setup(final FMLCommonSetupEvent e) { logger.info("Mod setup Loading"); StructureGeneration.setupStructures(); OreGeneration.setupGeneration(); } public void clientSetup(final FMLClientSetupEvent e) { logger.info("Mod Client setup Loading"); } }
J’ai essayé de placer l’instruction StructureGenerator.setupStructures() après la génération des minerais ou encore dans le clientSetup mais cela ne marche toujours pas
Le code de la classe StructureGenerator :
package fr.swordeus.spellz.world; import fr.swordeus.spellz.world.structure.CustomFeature; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.feature.IFeatureConfig; import net.minecraftforge.registries.ForgeRegistries; public class StructureGeneration { public static void setupStructures() { for(Biome biome : ForgeRegistries.BIOMES) { biome.addStructure(CustomFeature.RUINED_CASTLE, IFeatureConfig.NO_FEATURE_CONFIG); } } }
-
Bonjour,
Il faut passer par les événements d’enregistrement.@SubscribeEvent public static void registerBiome(RegistryEvent.Register<Biome> event) { // code ici }
Normalement le biome de base devrait déjà être enregistré au moment où l’event est appelé dans ton mod.
-
package fr.swordeus.spellz.world; import fr.swordeus.spellz.SpellzMod; import fr.swordeus.spellz.world.structure.CustomFeature; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.feature.IFeatureConfig; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ForgeRegistries; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = SpellzMod.MODID) public class StructureGeneration { public static final Object INSTANCE = new StructureGeneration(); @SubscribeEvent public static void registerBiome(RegistryEvent.Register<Biome> event) { for(Biome biome : ForgeRegistries.BIOMES) { biome.addStructure(CustomFeature.RUINED_CASTLE, IFeatureConfig.NO_FEATURE_CONFIG); } } }
Si je fais comme ceci j’ai une erreur au moment de passer dans l’event
-
[27mars2020 17:26:47.149] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmluserdevclient, --fml.mcpVersion, 20190829.143755, --fml.mcVersion, 1.14.4, --fml.forgeGroup, net.minecraftforge, --fml.forgeVersion, 28.2.0, --version, MOD_DEV, --assetIndex, 1.14, --assetsDir, C:\Users\Turpin\.gradle\caches\forge_gradle\assets, --username, Dev, --accessToken, ????????, --userProperties, {}] [27mars2020 17:26:47.154] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 4.1.0+62+5bfa59b starting: java version 1.8.0_161 by Oracle Corporation [27mars2020 17:26:48.195] [main/INFO] [net.minecraftforge.fml.loading.FixSSL/CORE]: Added Lets Encrypt root certificates as additional trust [27mars2020 17:26:50.385] [main/INFO] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Launching target 'fmluserdevclient' with arguments [--version, MOD_DEV, --gameDir, ., --assetsDir, C:\Users\Turpin\.gradle\caches\forge_gradle\assets, --assetIndex, 1.14, --username, Dev, --accessToken, ????????, --userProperties, {}] [27mars2020 17:26:58.909] [Client thread/INFO] [net.minecraft.client.Minecraft/]: Setting user: Dev [27mars2020 17:27:21.863] [Client thread/WARN] [net.minecraft.client.GameSettings/]: Skipping bad option: lastServer: [27mars2020 17:27:21.930] [Client thread/INFO] [net.minecraft.client.Minecraft/]: LWJGL Version: 3.2.2 build 10 [27mars2020 17:27:28.301] [modloading-worker-3/INFO] [net.minecraftforge.common.ForgeMod/FORGEMOD]: Forge mod loading, version 28.2.0, for MC 1.14.4 with MCP 20190829.143755 [27mars2020 17:27:28.301] [modloading-worker-3/INFO] [net.minecraftforge.common.MinecraftForge/FORGE]: MinecraftForge v28.2.0 Initialized [27mars2020 17:27:29.551] [Client thread/INFO] [net.minecraftforge.registries.GameData/]: Potentially Dangerous alternative prefix `minecraft` for name `ruined_castle`, expected `spellz`. This could be a intended override, but in most cases indicates a broken mod. [27mars2020 17:27:29.558] [Client thread/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: null Index: 4 Listeners: 0: NORMAL 1: ASM: class fr.swordeus.spellz.init.ModBlocks registerBlockItems(Lnet/minecraftforge/event/RegistryEvent$Register;)V 2: ASM: class fr.swordeus.spellz.init.ModBlocks registerBlocks(Lnet/minecraftforge/event/RegistryEvent$Register;)V 3: ASM: class fr.swordeus.spellz.init.ModItems registerItems(Lnet/minecraftforge/event/RegistryEvent$Register;)V 4: ASM: class fr.swordeus.spellz.world.StructureGeneration registerBiome(Lnet/minecraftforge/event/RegistryEvent$Register;)V java.lang.ExceptionInInitializerError at fr.swordeus.spellz.world.StructureGeneration.registerBiome(StructureGeneration.java:22) at net.minecraftforge.eventbus.ASMEventHandler_3_StructureGeneration_registerBiome_Register.invoke(.dynamic) at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258) at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106) at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112) at net.minecraftforge.fml.ModList.lambda$dispatchSynchronousEvent$5(ModList.java:125) at java.util.ArrayList.forEach(ArrayList.java:1257) at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:125) at net.minecraftforge.fml.ModList.lambda$static$1(ModList.java:96) at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:71) at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:197) at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$24(ModLoader.java:189) at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:969) at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:189) at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$2(ClientModLoader.java:97) at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:113) at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:97) at net.minecraft.client.Minecraft.init(Minecraft.java:457) at net.minecraft.client.Minecraft.run(Minecraft.java:365) at net.minecraft.client.main.Main.main(Main.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102) Caused by: java.lang.NullPointerException at net.minecraftforge.registries.GameData$FeatureCallbacks.onAdd(GameData.java:632) at net.minecraftforge.registries.GameData$FeatureCallbacks.onAdd(GameData.java:622) at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:376) at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:308) at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:56) at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:65) at net.minecraftforge.registries.NamespacedWrapper.register(NamespacedWrapper.java:34) at net.minecraft.util.registry.Registry.register(Registry.java:240) at net.minecraft.util.registry.Registry.register(Registry.java:236) at fr.swordeus.spellz.world.structure.CustomFeature.<clinit>(CustomFeature.java:12) ... 34 more
Le log après avoir lancé le jeu avec ce code
-
C’est bon j’avais oublié de renvoyer le nom de ma structure dans la classe de ma structure
Merci beaucoup de l’aide @robin4002 ^^