I'm trying to trigger an achievement when a particular item is crafted.
I have created a new class called "MyEventListener.java" and this is the code I have in there:
package mymod.handlers;
import mymod.Main;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
public class MyEventListener
{
public void SomethingCrafted(ItemCraftedEvent event)
{
if (event.crafting.getItem() == Main.MySword_1)
{
event.player.addStat(Main.MyAchievement_1, 1);
}
}
}
Then, in my main Mod class, I register this class in the "init" section with this line:
I thought that, perhaps, this was being caused because I didn't have the "@ForgeSubscribe" annotation I used to have before the "SomethingCrafted" event, but when I try to add it, it claims to be an error.
Thanks so much for the response.
Unfortunately, the issue is still not fixed because I believe there's something wrong with my line of code:
MinecraftForge.EVENT_BUS.register(new MyEventListener());
Apparently, this is the "wrong Event Bus" because "ItemCraftedEvent" is an FML event.. Do you have any idea what code I should put in the init() section instead?
Thanks so much for the response.
Unfortunately, the issue is still not fixed because I believe there's something wrong with my line of code:
MinecraftForge.EVENT_BUS.register(new MyEventListener());
Apparently, this is the "wrong Event Bus" because "ItemCraftedEvent" is an FML event..
Do you have any idea what code I should put in the init() section instead?
Much of the code still contains outdated information.
No, it doesn't. The code is for 1.6.4, and there are instructions on how to update everything to 1.7.2. This is intentional so those that are coding for 1.6.4 can still use it, and those updating just have to follow a couple steps. It's a tutorial, not a direct copy/paste piece of code. If you're not going to take the time to understand it, why even bother?
Because I am your generic Forge noob, always seeking quick solutions without regard to common sense or patience.
Surely you're joking... if you are having trouble following the tutorial / updating to 1.7.2, I'd be more than happy to assist you if you post your problem as a new thread or, if it's related specifically to my IExtendedEntityProperties tutorial, on my that thread.
Surely you're joking... if you are having trouble following the tutorial / updating to 1.7.2, I'd be more than happy to assist you if you post your problem as a new thread or, if it's related specifically to my IExtendedEntityProperties tutorial, on my that thread.
I didn't mean to come off brash, I've just been pulling my hair out trying to find a decent tutorial for people with a bit more than basic knowledge of Java and complete novice to Forge modding. I've took bits from your tutorial about a week ago to display a simple string of text at the corner of the screen to display the current coords, but I think I put them in the wrong event, because it screws up a few GUIs like food and inventory.
I didn't mean to come off brash, I've just been pulling my hair out trying to find a decent tutorial for people with a bit more than basic knowledge of Java and complete novice to Forge modding. I've took bits from your tutorial about a week ago to display a simple string of text at the corner of the screen to display the current coords, but I think I put them in the wrong event, because it screws up a few GUIs like food and inventory.
Sorry to hear that. If you're experiencing troubles, you should post a new topic explaining your problem (again :P), including the relevant code. It shouldn't be screwing up any other GUIs, though I did spot an error in that section of the tutorial just now and fixed it. If you are using the BLEND function of openGL, be sure you disable it after you draw your string. If that doesn't fix it, then please follow the above suggestion and start your own thread.
Sorry to hear that. If you're experiencing troubles, you should post a new topic explaining your problem (again ), including the relevant code. It shouldn't be screwing up any other GUIs, though I did spot an error in that section of the tutorial just now and fixed it. If you are using the BLEND function of openGL, be sure you disable it after you draw your string. If that doesn't fix it, then please follow the above suggestion and start your own thread.
Done :3 Though I've since rewritten the code and a different problem exists now.
I'm trying to trigger an achievement when a particular item is crafted.
I have created a new class called "MyEventListener.java" and this is the code I have in there:
Then, in my main Mod class, I register this class in the "init" section with this line:
I thought that, perhaps, this was being caused because I didn't have the "@ForgeSubscribe" annotation I used to have before the "SomethingCrafted" event, but when I try to add it, it claims to be an error.
Any ideas?
Thanks!
Thank you.
Thanks so much for the response.
Unfortunately, the issue is still not fixed because I believe there's something wrong with my line of code:
MinecraftForge.EVENT_BUS.register(new MyEventListener());
Apparently, this is the "wrong Event Bus" because "ItemCraftedEvent" is an FML event..
Do you have any idea what code I should put in the init() section instead?
Thanks!
FMLCommonHandler.instance().bus().register(EVENT_LISTENER);
I really appreciate it - really saved me here.
One more question on this:
Would this same technique apply to a different event, like ItemPickupEvent?
I have another PickupHandler class called "MyPickupHandler.java" with this code:
And then I try to register it with the same technique like:
But this doesn't seem to be working for me...
Any ideas on that?
I wrote a tutorial on this subject some time back, and it's updated with information about 1.7.2. Perhaps it will be of some use.
Much of the code still contains outdated information.
No, it doesn't. The code is for 1.6.4, and there are instructions on how to update everything to 1.7.2. This is intentional so those that are coding for 1.6.4 can still use it, and those updating just have to follow a couple steps. It's a tutorial, not a direct copy/paste piece of code. If you're not going to take the time to understand it, why even bother?
Because I am your generic Forge noob, always seeking quick solutions without regard to common sense or patience.
Surely you're joking... if you are having trouble following the tutorial / updating to 1.7.2, I'd be more than happy to assist you if you post your problem as a new thread or, if it's related specifically to my IExtendedEntityProperties tutorial, on my that thread.
I didn't mean to come off brash, I've just been pulling my hair out trying to find a decent tutorial for people with a bit more than basic knowledge of Java and complete novice to Forge modding. I've took bits from your tutorial about a week ago to display a simple string of text at the corner of the screen to display the current coords, but I think I put them in the wrong event, because it screws up a few GUIs like food and inventory.
Sorry to hear that. If you're experiencing troubles, you should post a new topic explaining your problem (again :P), including the relevant code. It shouldn't be screwing up any other GUIs, though I did spot an error in that section of the tutorial just now and fixed it. If you are using the BLEND function of openGL, be sure you disable it after you draw your string. If that doesn't fix it, then please follow the above suggestion and start your own thread.
Done :3 Though I've since rewritten the code and a different problem exists now.