Jump to content

[1.15.2] I revamped some classes and I would like to know, why my stuff broke.


Tavi007

Recommended Posts

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...

Link to comment
Share on other sites

20 minutes ago, Tavi007 said:

that the capability isn't attached properly.

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.

20 minutes ago, Tavi007 said:

All 4 particles behaves basically the same, with the only difference being the texture

Maybe you can put the

ResourceLocation

as a parameter in your constructor? I haven't worked with particles myself, just an assumption.

20 minutes ago, Tavi007 said:

if I should create a topic for each of my issues or not...

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,event_handler.png.d5e57748293574b920cf0770db1bb0cb.png

Edited by Novârch
  • Like 1

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".

Link to comment
Share on other sites

14 minutes ago, 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?

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 by Dzuchun

Everything said above may be absolutely wrong. No rights reserved.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

27 minutes ago, 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?

You never register your capability in FMLCommonSetupEvent using CapabilityManager#register.

Edited by Novârch
  • Like 1

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".

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.