The Meaning of Life, the Universe, and Everything.
Location:
Bavaria
Join Date:
4/29/2013
Posts:
166
Location:
Germany
Minecraft:
ThexXTURBOXx
Xbox:
Zocker4Live999
Member Details
Hello guys,
I want to add a new Event-Handler-class. But if I want to execute the event, nothing happens.
Any help?
Hello guys,
I tried to make a class, which registers my EventHandlers (there is only one yet). But I can't get it working. Here is, what I coded until now:
Main Class:
package de.Femtopedia.titantoolbox;
import de.Femtopedia.titantoolbox.Constants.Constants;
import de.Femtopedia.titantoolbox.Skype.skypemethods;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@Mod(modid=Constants.MODID, version=Constants.VERSION, name=Constants.NAME)
public class titantoolbox {
@Instance
public static titantoolbox instance = new titantoolbox();
@EventHandler
public void preInit(FMLPreInitializationEvent e)
{
}
@EventHandler
public void init(FMLInitializationEvent e)
{
FMLCommonHandler.instance().bus().register(new titantoolboxDCHandler());
}
@EventHandler
public void postInit(FMLPostInitializationEvent e)
{
}
}
EventHandler-Class:
package de.Femtopedia.titantoolbox;
import de.Femtopedia.titantoolbox.Constants.Constants;
import de.Femtopedia.titantoolbox.Skype.skypemethods;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
public class titantoolboxDCHandler {
@SubscribeEvent
public void clientConnection(ClientConnectedToServerEvent e)
{
System.out.println("Message");
}
}
Whoa, no, don't do that! Only ever register an event handling class to the bus(es) it needs to be - not to mention how illegible that chunk of code is, unless it's only use is for debugging an event handler.
@OP That's an actual FML event, as in not an event that is handled by the normal public-facing event buses, but internally by FML itself. You already handle some events like that in your main mod class using the @Mod.EventHandler notation above the method, so you could try that, though I have never seen this particular class of events used in that context - it may not be a usable event.
Registering it to any other buses just wastes processing power.
You can have a handler that handles events from multiple buses, in which case yes, you would register it to multiple buses, but again, only the buses it actually needs.
public class MyHandler {
@SubscribeEvent
public void onDeath(LivingDeathEvent event) {}
@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {}
}
Tick events are all on the FML bus, but LivingDeathEvent is still on the regular EVENT_BUS, so you would register it on both, but there would be no point in registering the above handler also on the TERRAIN_GEN and ORE_GEN buses because it doesn't handle any events that are posted to those.
Oh well the code is like that for debugging. Also I am registering each event only on 1 buss with the switch. So no processing power wasted. But yeah the code is really obtuse... It's temporary.
Rollback Post to RevisionRollBack
Not doing mc modding that much anymore because I am making a full blown game that does not have limitations that mc has. (rip Magiology for now)
I may come back if MC fixes it's rendering pipeline.
Hello guys,
I want to add a new Event-Handler-class. But if I want to execute the event, nothing happens.
Any help?
Hello guys,
I tried to make a class, which registers my EventHandlers (there is only one yet). But I can't get it working. Here is, what I coded until now:
Main Class:
EventHandler-Class:
It may be the case that you are registering the event in the wrong bus try some of this https://github.com/LapisSea/Magiology_1.8/blob/master/src/main/java/com/magiology/core/init/MEvents.java#L35-L44
Not doing mc modding that much anymore because I am making a full blown game that does not have limitations that mc has. (rip Magiology for now)
I may come back if MC fixes it's rendering pipeline.
Whoa, no, don't do that! Only ever register an event handling class to the bus(es) it needs to be - not to mention how illegible that chunk of code is, unless it's only use is for debugging an event handler.
@OP That's an actual FML event, as in not an event that is handled by the normal public-facing event buses, but internally by FML itself. You already handle some events like that in your main mod class using the @Mod.EventHandler notation above the method, so you could try that, though I have never seen this particular class of events used in that context - it may not be a usable event.
Wait so you do not register event classes? Have I been doing events wrong all this time?
Not doing mc modding that much anymore because I am making a full blown game that does not have limitations that mc has. (rip Magiology for now)
I may come back if MC fixes it's rendering pipeline.
EDIT: Looked at your code again and you're fine, it's just a VERY obtuse way of writing it...
You DO register, but ONLY to the bus that the events it handles are fired on.
Example:
Both of those events are on the MinecraftForge.EVENT_BUS, so you would only register MyHandler to that bus:
Registering it to any other buses just wastes processing power.
You can have a handler that handles events from multiple buses, in which case yes, you would register it to multiple buses, but again, only the buses it actually needs.
Tick events are all on the FML bus, but LivingDeathEvent is still on the regular EVENT_BUS, so you would register it on both, but there would be no point in registering the above handler also on the TERRAIN_GEN and ORE_GEN buses because it doesn't handle any events that are posted to those.
Oh I managed to solve this myself... Sorry, that I didn't request locking this thread, but please do that!
Thanks anyway for trying to help me
Oh well the code is like that for debugging. Also I am registering each event only on 1 buss with the switch. So no processing power wasted. But yeah the code is really obtuse... It's temporary.
Not doing mc modding that much anymore because I am making a full blown game that does not have limitations that mc has. (rip Magiology for now)
I may come back if MC fixes it's rendering pipeline.