Jump to content

event handler testing


gyro42

Recommended Posts

What events are you trying to handle?

 

For testing I use a lot of console statements using System.out.println() then you can check to see if the code is following the path you expect.  It is also interesting to learn how the events fire -- some only fire on Server, some on both Client and Server, etc.  So print out a lot of console statements and watch and learn.

 

Otherwise, for any given event hopefully you have an idea when it should fire.  If you're handling a block harvest event, then go into your game and start harvesting blocks.  And so forth.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

right now im trying to get into a vanilla block harvest event. I am trying to add my mod item to the drop list, and failing at it :D

 

anyways i just want some kind of method that will fire for me when my if statements arent all true that shows in game somehow (damage player, add an effect on block destruction, something)

Link to comment
Share on other sites

right now im trying to get into a vanilla block harvest event. I am trying to add my mod item to the drop list, and failing at it :D

 

anyways i just want some kind of method that will fire for me when my if statements arent all true that shows in game somehow (damage player, add an effect on block destruction, something)

 

From the way you describe it, I think you may be thinking about events wrong.  Normally you don't fire the events (although you can in certain circumstances).  Instead the built-in events are firing whenever things happen in the game and you can intercept them.  So you need to basically register an entity handling method for the event you're interested in, and the event parameter that gets passed into that event will have information (like the drops) and allow you to change some things, and even cancel other vanilla processing from continuing.

 

I have a tutorial on events here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

Events are very powerful because they've made events for most of the common things that modders like to change.  So you can intercept how things render, or how they update, or how they spawn, or how they die, or what they drop, or what they get hurt by, etc.  It is one of the main ways of changing vanilla behavior in cases where a public field or method isn't available from the vanilla class.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

for now i will take your advice use a bunch of console statements and see how my handler is working in the game. To be honest im not really sure if it has been registered properly in init. I will go ahead and check out your tutorial too. thank you.

 

my original question is still unanswered though. I dont know anything to use in an event or otherwise that is immediately apparent in the game.

Link to comment
Share on other sites

Maybe you don't understand what the events are.  There are events being fired off all the time by Forge and FML.  Some events like the tick and update events are fired every tick.  Other events are fired when certain things happen -- like an entity death event, or a block harvest event.

 

So if you make a handler that handles a tick event, and it is registered properly, and you put console statements in the handling method, you should see the console statements come out continuously.

 

If you make a handler that handles a block harvest event, then you'd only see console statement when you harvest something in the game.

 

An "event" isn't necessarily something special in the game, rather it is just an indicator about which part of the vanilla code is running and gives you an opportunity to react at that time and possibly modify how the game continues to execute.

 

What event are you trying to handle?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Well ive gotten it working now. The output tags helped alot.

 

I was trying to handle BlockEvent.HarvestDropsEvent on grass. I was using Blocks.grass which it turns out, isnt actually grass. I found this out when i accidently mined the dirt in front of one while i was testing with the tags.

 

I did read through your walkthrough and found it pretty informative. thanks again for being so helpful

Link to comment
Share on other sites

Like he said jabelar said up there, events can be Forge events or, FML events. But, he didn't mention that each of which need to be registered differently.

 

For Forge events you'd do this:

//Under your init method in your main class.
MinecraftForge.EVENT_BUS.register(new YourFancyEventHandler());

 

For FML events you'd do this:

FMLCommonHandler.instance().bus().register(new YourFancyEventHandler());

 

Remember, there are also CLIENT only events like RenderGameOverlay and ClientTickEvent. Those of which basically require you to not input server code into them (pretty obvious XP). Finally, if you ever want to use:

 

Minecraft mc = Minecraft.getMinecraft(); //Getting the instance of Minecraft

 

You CANNOT use this during server side events or, the game will crash.

 

There's my brief event tutorial! I was taught to separate Forge events and FML events into separate classes such as "EventsFML" and "EventsForge". And for client I do "EventsClientFML" and "EventsClientForge".

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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



×
×
  • Create New...

Important Information

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