Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

 

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]

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.

  • 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.

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.

 

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.