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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have a structure, and sometimes several mobs spawn there. This is a boss and must spawn alone. Here is the code for spawning entities in the structure { "type": "minecraft:jigsaw", "start_pool": "egyptcraft:boss_pyramid/start_pool", "size": 5, "max_distance_from_center": 80, "biomes": "#egyptcraft:has_structure/boss_pyramid", "step": "surface_structures", "start_height": { "absolute": 0 }, "project_start_to_heightmap": "WORLD_SURFACE_WG", "use_expansion_hack": false, "spawn_overrides": { "monster": { "bounding_box": "full", "spawns": [ { "type": "egyptcraft:anubis", "maxCount": 1, "minCount": 1, "weight": 100 } ] } } } Maybe it's something else?
    • I have OreGenEvent.GenerateMinable event, I need to get a chance to spawn (generate) every ore that is processed in this event. Also e.getType().name().toString() is name this is the same block name by which it can be entered in the Block.getByID?  forge 1.12.2 59(recommended)
    • Hello everybody! Out of nowhere my minecraft doesn't allow me to play on forge 1.19.2 I tried to reinstall minecraft, doesn't have any mod right now on the forge version. Tried the newest version of forge, tried recommended version as well. I have the newest version of Java as well...   I dont know why it stopped working but it just stopped completly out of nowhere...   Thank you so much for your help guys ❤️
    • Hello, my world is crashing at 0% loaded and I don't know why. (Forge 43.2.14, 1.19.2) I have two worlds that I play on, and one works and the other doesn't, even with the same mod list. Here's the crash report: https://pastebin.com/AUbRwkGj
    • Minecraft 1.12.2 Very frustrating error. only ever occurs on one device. Started yesterday without prompting (maybe java updated or something?) Says things that have been imported actually arent when running client Reinstalled Intellij, cleared cache, cleaned and rebuilt gradle, redownloaded the entire file from git. Nothing works. (I believe I have the right plugins installed, dependencies OK, and am using corretto 1.8).   One thing I did for more of the below errors was just to explicitly import them, which was working up until this little guy who literally does not exist in forge to import. the class inhereting something inhereting it refers to import net.minecraftforge.registries.IForgeRegistryEntry.Impl, not net.minecraftforge.registries.IForgeRegistryEntry$Impl as the output implies. also I didn't even have to manually import these things for it to work on my other device. (which is just importing the minecraft package that contains them), but here I did have to just to get rid of a few errors--not even make anything work?? I dont know. (edited) here's the aforementioned "below error" (one of many like it): error: cannot access net.minecraftforge.registries.IForgeRegistryEntry.Impl public class BlockBase extends Block {        ^   class file for net.minecraftforge.registries.IForgeRegistryEntry$Impl not found Here's the class BlockBase:   package com.quantum.exodus.common.blocks; import com.quantum.exodus.ExodusMod; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraftforge.registries.IForgeRegistryEntry.Impl; public class BlockBase extends Block { protected String name; public BlockBase(Material material, String name) { super(material); this.name = name; setTranslationKey(name); setRegistryName(name); } public void registerItemModel(Item itemBlock) { ExodusMod.proxy.registerItemRenderer(itemBlock, 0, name); } public Item createItemBlock() { return new ItemBlock(this).setRegistryName(getRegistryName()); } @Override public BlockBase setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } }
  • Topics

×
×
  • Create New...

Important Information

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