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.
Thank You SO MUCH! I've been trying to figure this out for so long. Now if only Lex would realize that his lack of documentation is not justified and is needed. Particularly for stuff like this.
I like the wording there The problem with us making a doc is that we didn't make the class, so if we screw up, it's on us for it not being right. Some of the mappings in MCP are wrong already (see world.isRemote() :P), which is a pain, and it would suck for people to just start making docs and they end up being broken.
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.
one question whats this for? like whats a forge event?
Forge is a API that has replaced ModLoader, and ModLoaderMP (it provides backwards compatibility with ModLoader mods, is much better than ModLoaderMP in the way it handles networking and has a billion (exageration) more hooks/calls that a mod can use. Most mods now don't even need to be installed into the jar thanks to Forge).
A forge event can be any event that occurs in the Minecraft world. For example an entityLiving (eg a pig) dying. Say you wanted to make a mod that made pigs explode on death, you would use the EntityLivingDeath event (or something similar) and check if the entity was a pig if it was you could create an explosion at the co-ordinates of the pig.
Rollback Post to RevisionRollBack
"Terminator like robots may one day rule the world, as long as they don't run Windows Vista"
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.
Thanks for the great tutorial on registering events! In your example, don't you need the following line? If not, why? I had to add it to make this example work. Maybe it was supposed to be obvious but I'm new to Forge so it wasn't to me.
im trying to get pigs to drop bacon, and so far they drop 1 bacon every single time. how can i randomize the amount of bacon dropped from 0-3?
package lecapria.main.common.item;
import lecapria.main.modMain;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.item.Item;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
public class ModLivingDropEvent
{
public static double rand;
@ForgeSubscribe
public void onEntityDrop(LivingDropsEvent event)
{
if (event.source.getDamageType().equals("player"))
{
rand = Math.random();
if (event.entityLiving instanceof EntityPig)
{
if (rand < 0.33d)
{
//The integer at the end relates to how many potato will be dropped.
event.entityLiving.dropItem(modMain.baconRaw.itemID, 1);
}
}
}
if (event.source.getDamageType().equals("fire"))
{
rand = Math.random();
if (event.entityLiving instanceof EntityPig)
{
if (rand < 0.33d)
{
//The integer at the end relates to how many potato will be dropped.
event.entityLiving.dropItem(modMain.baconCooked.itemID, 1);
}
}
}
}
}
MinecraftForge.EVENT_BUS.register(new EventHookContainerClass());
Whenever I put this, I get an error under register. It says :Syntax error on token "register", = expected after this token
im trying to get pigs to drop bacon, and so far they drop 1 bacon every single time. how can i randomize the amount of bacon dropped from 0-3?
package lecapria.main.common.item;
import lecapria.main.modMain;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.item.Item;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
public class ModLivingDropEvent
{
public static double rand;
@ForgeSubscribe
public void onEntityDrop(LivingDropsEvent event)
{
if (event.source.getDamageType().equals("player"))
{
rand = Math.random();
if (event.entityLiving instanceof EntityPig)
{
if (rand < 0.33d)
{
//The integer at the end relates to how many potato will be dropped.
event.entityLiving.dropItem(modMain.baconRaw.itemID, 1);
}
}
}
if (event.source.getDamageType().equals("fire"))
{
rand = Math.random();
if (event.entityLiving instanceof EntityPig)
{
if (rand < 0.33d)
{
//The integer at the end relates to how many potato will be dropped.
event.entityLiving.dropItem(modMain.baconCooked.itemID, 1);
}
}
}
}
}
You could make a random int ("n" maybe) and use that as the number
MinecraftForge.EVENT_BUS.register(new EventHookContainerClass());
Whenever I put this, I get an error under register. It says :Syntax error on token "register", = expected after this token
You could make a random int ("n" maybe) and use that as the number
i tried but t wont compile. and if it compiles it stops dropping entirely
I actually made one for several events, but it was part of another pull request which didnt get in, so...
I like the wording there The problem with us making a doc is that we didn't make the class, so if we screw up, it's on us for it not being right. Some of the mappings in MCP are wrong already (see world.isRemote() :P), which is a pain, and it would suck for people to just start making docs and they end up being broken.
You can always EXACTLY determine what a hook/event does by tracing it and how it behaves ... mcp 4tw
Forge is a API that has replaced ModLoader, and ModLoaderMP (it provides backwards compatibility with ModLoader mods, is much better than ModLoaderMP in the way it handles networking and has a billion (exageration) more hooks/calls that a mod can use. Most mods now don't even need to be installed into the jar thanks to Forge).
A forge event can be any event that occurs in the Minecraft world. For example an entityLiving (eg a pig) dying. Say you wanted to make a mod that made pigs explode on death, you would use the EntityLivingDeath event (or something similar) and check if the entity was a pig if it was you could create an explosion at the co-ordinates of the pig.
Thanks for the great tutorial on registering events! In your example, don't you need the following line? If not, why? I had to add it to make this example work. Maybe it was supposed to be obvious but I'm new to Forge so it wasn't to me.
https://github.com/SirSengir/BuildCraft/blob/master/common/buildcraft/energy/OilPopulate.java
My Planetminecraft Page
Whenever I put this, I get an error under register. It says :Syntax error on token "register", = expected after this token You could make a random int ("n" maybe) and use that as the number
My Planetminecraft Page