As of 4.x, Forge drops a number of things, including several old Interfaces for Forge Hooks.
[As of Forge 6.4, this tutorial is still up to date]
The new way of doing these things is using Event classes and methods, then registering them to an Event Bus, which uses asm bouncer classes to dynamically distribute the Event calls.
So, how to use those?
For starters, open up your correctly installed Forge in eclipse and check out the net.minecraftforge.event package and all the Event* classes found in it and subpackages. There, you will see all the events you have access to, and by their contents what you can do with them.
For this example i'll be using net.minecraftforge.event.entity.living.LivingAttackEvent to hook attacks on any EntityLiving.
First, create a class which will contain your Hooks - you do not have to keep your hooks seperate anymore, you can register a single class for all events - you'll see what i mean.
This is the class i wrote as an example
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
/**
* Name and cast of this class are irrelevant
*/
public class EventHookContainerClass
{
/**
* The key is the @ForgeSubscribe annotation and the cast of the Event you put in as argument.
* The method name you pick does not matter. Method signature is public void, always.
*/
@ForgeSubscribe
public void entityAttacked(LivingAttackEvent event)
{
/*
* You can then proceed to read and change the Event's fields where possible
*/
EntityLiving attackedEnt = event.entityLiving;
DamageSource attackSource = event.source;
/*
* Note this possibility to interrupt certain (not all) events
*/
if (event.isCancelable())
{
event.setCanceled(true);
}
/*
* Events may offer further fields and methods. Just read them, it should be obvious.
*/
}
/**
* To make sure you understand: You can mash together any events in a single class!
*/
@ForgeSubscribe
public void onSleepyTime(PlayerSleepInBedEvent event)
{
event.result = EnumStatus.NOT_POSSIBLE_NOW;
}
}
The class you "register" is then parsed for methods with the @ForgeSubscribe annotation and which have Event classes in their signatures. You can also unregister classes (with all contained methods) if you keep the instance saved.
Note the Event class hierarchy. A super class will, if you register it, call every Event that extends it!! For example, if you registered LivingEvent, your method would be called for {PlaySoundAtEntityEvent, LivingAttackEvent, LivingDeathEvent, LivingDropsEvent ...} and so on. If you registered "Event", your @ForgeSubscribe method would be called for EVERY SINGLE EVENT THERE IS (Hint: do not do that).
speaking of forge events and mod making the tutorial on the forge wiki is outdated , badly. is there a good tutorial for mc 1.3.1 and the new forge setup ?
speaking of forge events and mod making the tutorial on the forge wiki is outdated , badly. is there a good tutorial for mc 1.3.1 and the new forge setup ?
Not yet, soon people will start getting stuff together. There isn't a recommended build out yet, once that's out more examples/tuts/documentation is sure to start trickling out.
is there a link that does'nt require dl ilivid?i dont want that crap, and would hate to have to restore my computer to eliminate all the invasive programs....
is there a link that does'nt require dl ilivid?i dont want that crap, and would hate to have to restore my computer to eliminate all the invasive programs....
DON'T install iLivid. Wait 5 seconds, and click the "Skip Ad" button in the top right.
Rollback Post to RevisionRollBack
Learn some Java before you mod, and skip over the chapter on ModLoader, straight to MinecraftForge. It's better. Trust me.
is there a link that does'nt require dl ilivid?i dont want that crap, and would hate to have to restore my computer to eliminate all the invasive programs....
Oh, ad.fly...yeah...just click the skip ad when the timer runs down.
Thanks for this.
And to anybody who registers for all events, if you come crying here saying:
"It didn't work when I registered for the Event class!", you're just asking for what you get.
As it turns out, some people are dumb enough to do that.
I dont know if this is the right place to post this, but I can't seem to find anyone else having the same issue I am. When I add the forge files to my jar Minecraft will not load. At the inital screen where it says "updateing" with the green load bar underneath everything just stops and never continues. At first I thought it was mod incompatibility, but then i tried with a fresh jar. Nothing I do seems to change this. I loved forge for 1.2.5 and I want to love it for 1.3.1 as well... Please help!
I dont know if this is the right place to post this, but I can't seem to find anyone else having the same issue I am. When I add the forge files to my jar Minecraft will not load. At the inital screen where it says "updateing" with the green load bar underneath everything just stops and never continues. At first I thought it was mod incompatibility, but then i tried with a fresh jar. Nothing I do seems to change this. I loved forge for 1.2.5 and I want to love it for 1.3.1 as well... Please help!
I had the same issue myself, but then I also have the same thing happen anytime Minecraft itself updates. I just retried several times until the download finally completes. If anyone else knows how to fix this or even why it happens please reply. Thank you in advance.
Can you perhaps give a list of the different events and how to use them? I'm wondering if I can use the new forge events to add world generation and crafting handlers, most of the I*Handler classes in cpw.mods.fml.common (they're still there even though you said they're not). I'm not sure whether to use WorldEvent, ChunkEvent, or ChunkDataEvent for world generation.
That's because the NetworkMod (eg MLMP) part of Forge was stripped out and is now contained in FML. Forge doesnt have them anymore, just as i said. FML on the other hand now does
That's because the NetworkMod (eg MLMP) part of Forge was stripped out and is now contained in FML. Forge doesnt have them anymore, just as i said. FML on the other hand now does
What you want is IWorldGenerator, of FML
one question whats this for? like whats a forge event?
[As of Forge 6.4, this tutorial is still up to date]
The new way of doing these things is using Event classes and methods, then registering them to an Event Bus, which uses asm bouncer classes to dynamically distribute the Event calls.
So, how to use those?
For starters, open up your correctly installed Forge in eclipse and check out the net.minecraftforge.event package and all the Event* classes found in it and subpackages. There, you will see all the events you have access to, and by their contents what you can do with them.
For this example i'll be using net.minecraftforge.event.entity.living.LivingAttackEvent to hook attacks on any EntityLiving.
First, create a class which will contain your Hooks - you do not have to keep your hooks seperate anymore, you can register a single class for all events - you'll see what i mean.
This is the class i wrote as an example
And this is how you register it
The class you "register" is then parsed for methods with the @ForgeSubscribe annotation and which have Event classes in their signatures. You can also unregister classes (with all contained methods) if you keep the instance saved.
Note the Event class hierarchy. A super class will, if you register it, call every Event that extends it!! For example, if you registered LivingEvent, your method would be called for {PlaySoundAtEntityEvent, LivingAttackEvent, LivingDeathEvent, LivingDropsEvent ...} and so on. If you registered "Event", your @ForgeSubscribe method would be called for EVERY SINGLE EVENT THERE IS (Hint: do not do that).
That should be it. You are now educated!
Yes, this is Forge for 1.3.1. You can find it here.
Thank you for this explanation!
Not yet, soon people will start getting stuff together. There isn't a recommended build out yet, once that's out more examples/tuts/documentation is sure to start trickling out.
DON'T install iLivid. Wait 5 seconds, and click the "Skip Ad" button in the top right.
Oh, ad.fly...yeah...just click the skip ad when the timer runs down.
And to anybody who registers for all events, if you come crying here saying:
"It didn't work when I registered for the Event class!", you're just asking for what you get.
As it turns out, some people are dumb enough to do that.
I had the same issue myself, but then I also have the same thing happen anytime Minecraft itself updates. I just retried several times until the download finally completes. If anyone else knows how to fix this or even why it happens please reply. Thank you in advance.
im gay
Huh? works perfectly fine.
Condemnant quod non intellegunt...
What you want is IWorldGenerator, of FML
one question whats this for? like whats a forge event?