Posted July 31, 201510 yr Hello. I been working on a code all day and looking up information about modding in forge. I run in to a problem and i dont know can i have 2 @SubscribeEvent methods in the same class? what im doing is a way to check if the player breaks a block and the what tool the player use. After that i want to check what item the player gets so i can set what exp he will get from it. Im working on a Adveture mod and im adding skills for mining, lumbering e.t.c Do i have to have 2 methods? Feels wrong. I want to do the check what block the player picksup in my onBlockBreak method. I feel lost at the moment any ideas? if you want to see my code just ask and i add it. No code is needed just a hint of direction so i can find out more about forge and learn more.
July 31, 201510 yr Hi, it depends on what your doing, I believe the way it works is - when you register your events you can have multiple client side events in the same class and register them through your client proxy and vice versa with server side events (I may be wrong on registering them in sperate classes based on server / client side, but I do know for a fact you can use multiple events in same class). It would be redundant if you used multiple events that are exaclty the same with different method names, however. Hope that helps, here's a piece of info on events including a almost full, if not full, kist of events: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]
July 31, 201510 yr Why do you need to get what item the player picks up? Wouldn't the block they broke suffice? I can see getting the items to be quite troublesome when dealing with breaking something like a chest that had multiple items in it. I might be misunderstanding you.
July 31, 201510 yr Author @grand_mind1 What im planing on doing is this. When the player digs dirt he gets x amount of xp depending on what tool he has. So what i was thinking first was to do a if statement on what tool the player using when he breaks the block. That part works. then in lets say if if(hand.getItem() == Items.wooden_shovel){ } I put an if statement on the different blocks and from there i send do the exp calculation of how mutch exp the player gets. But the problem is i dont know how i should get what type of block the player breaks. So i thought that if i check then use the ItemPickupEvent to check what item the player picked up. But i can be on the complete wrong way on coding this. There might be a easier way of doing this. Hope i explained good on what i was coding and what i have problem with.
August 1, 201510 yr The problem with using two different events is I don't think there is any way you can link the two events to make sure that the block they broke is the block they pick up. I'm pretty sure you can get what block is about to be broken in the BlockBreak event.
August 1, 201510 yr Author Thanks grand_mind1! I checked BreakEvent more and found how to do it. Now my code works and i can move on to the next stage to creating this mod. Thanks alot!
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.