Tavi007 Posted July 15, 2020 Posted July 15, 2020 Hey, I once had a working mod, but I did a few changes to my class structure to be a bit more like MinecraftByExample. However in this process I messed up some parts of my mod and I don't know, why stuff is not working anymore. So please answere my question and maybe give a solution too. I would like to know, why my stuff is broken. Here is my current repository, so you know, what I'm talking about The first thing, that I did was to split the registration into server side and client side (much like minecraftByExample). But when I try to move the registration of my reloadListener from ElementalCombat.java to StartupCommon.java the FMLServerAboutToStartEvent won't get called anymore. What is the reason? Next up are my capabalities. My mod usually fills the ElementalAttack- and ElementalDefenseCapability of a mob whenever it spawns. But when I try to access this data later, I only get the default (empty) capability instead. What is my error? My best guess is, that the capability isn't attached properly. At least I never reach the breakpoint in AttachCapabilityEvent. At last I want to hear your feedback on my particles. It feels like I could do this part better, because there is a lot of code duplication happening. Sadly I couldn't come up with anything working. All 4 particles behaves basically the same, with the only difference being the texture. So is there an easier way to do it? Thanks a lot in advance PS: I didn't know, if I should create a topic for each of my issues or not... Quote
Novârch Posted July 15, 2020 Posted July 15, 2020 (edited) On 7/15/2020 at 2:47 PM, Tavi007 said: that the capability isn't attached properly. Expand https://github.com/Tavi007/ElementalCombat/blob/1390c4b3be278d93c6be25369ac14cb8f7e74b68/1.15.2/src/main/java/Tavi007/ElementalCombat/StartupCommon.java#L26 Your FMLCommonSetupEvent isn't annotated with @SubscribeEvent , it's never called. https://github.com/Tavi007/ElementalCombat/blob/1390c4b3be278d93c6be25369ac14cb8f7e74b68/1.15.2/src/main/java/Tavi007/ElementalCombat/events/AttachCapabilityEvent.java#L14 For events to be called, you have to register them to the event bus by calling IEventBus#register, you never call MinecraftForge.EVENT_BUS.register(new AttachCapabilityEvent), so it doesn't fire. On 7/15/2020 at 2:47 PM, Tavi007 said: All 4 particles behaves basically the same, with the only difference being the texture Expand Maybe you can put the ResourceLocation as a parameter in your constructor? I haven't worked with particles myself, just an assumption. On 7/15/2020 at 2:47 PM, Tavi007 said: if I should create a topic for each of my issues or not... Expand I don't think you should, they're all small issues that can be tackled in one post instead of spamming the forums with small 1 reply threads. Edit: Dzuchun is also correct, though you don't have to use @Mod.EventBusSubscriber if you're methods aren't static, but you still have to register an instance of your class. Edit 2: Btw, you can't really have both FMLCommonSetupEvent and ServerAboutToStartEvent in the same @Mod.EventBusSubscriber annotated class as they fire on separate buses, FMLCommonSetupEvent fires on the mod bus, ServerAboutToStartEvent on the Forge bus. Edit 3: This is from the Forge discord, Edited July 15, 2020 by Novârch 1 Quote It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".
Dzuchun Posted July 15, 2020 Posted July 15, 2020 (edited) On 7/15/2020 at 2:47 PM, Tavi007 said: The first thing, that I did was to split the registration into server side and client side (much like minecraftByExample). But when I try to move the registration of my reloadListener from ElementalCombat.java to StartupCommon.java the FMLServerAboutToStartEvent won't get called anymore. What is the reason? Expand Looks like you're missing StartupCommon class registration for events. You may try to put @Mod.EventBusSubscriber(bus = Bus.MOD, modid = YOUR_MOD_ID) before class declaration. Make sure that StartupCommon class is initialized - execute any method in it. Edited July 15, 2020 by Dzuchun Quote Everything said above may be absolutely wrong. No rights reserved.
Tavi007 Posted July 17, 2020 Author Posted July 17, 2020 Thanks for all your help. Much appreciated! I added the SubscribeEvent annotation and changed the functions to static. I also kept the ServerAboutToStartEvent in my main class, because it is the only event so far, that fires on the forge bus. Now upon starting a world I run into a nullPointer exception in CapabilityProviderEntityAndItem.java (line 42). Apperently ElementalAttackCapability.CAPABILITY_ELEMENTAL_ATTACK is null, which isn't that suprising, cause it is instantiated as null. But minecraftByExample did it the same way and I can't find any difference between his and my code. Any ideas? Quote
Novârch Posted July 17, 2020 Posted July 17, 2020 (edited) On 7/17/2020 at 5:04 PM, Tavi007 said: Thanks for all your help. Much appreciated! I added the SubscribeEvent annotation and changed the functions to static. I also kept the ServerAboutToStartEvent in my main class, because it is the only event so far, that fires on the forge bus. Now upon starting a world I run into a nullPointer exception in CapabilityProviderEntityAndItem.java (line 42). Apperently ElementalAttackCapability.CAPABILITY_ELEMENTAL_ATTACK is null, which isn't that suprising, cause it is instantiated as null. But minecraftByExample did it the same way and I can't find any difference between his and my code. Any ideas? Expand You never register your capability in FMLCommonSetupEvent using CapabilityManager#register. Edited July 17, 2020 by Novârch 1 Quote It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".
Tavi007 Posted July 19, 2020 Author Posted July 19, 2020 Ahh, a rookie mistake... The Capaility is now working as it should, so big thank you . How come, that registering the capability changes the variables from null to something else? All i saw was the null pointer exception and i couldn't deduce, that this is due to the missing registration. Anyway since I have your attention, could you give me advice on another of my issue please? I want to fill the capability from the livingEntity and itemstack with default values (hence the reloadListener. I use it, to load these values from json). For the entities I modify the spawning event, where I use my dataManger to copy the data into the capability. Now I plan on doing something similar for the itemstacks, but I'm not sure, if I can do the same here... So do you have a good idea on how to fill the capability of an itemstack? Quote
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.