Jump to content

[1.8.9] Stopping a player from harvesting a block


blahblahbal

Recommended Posts

So I've set bedrock to breakable, but I only want it breakable with one tool. I know I have to subscribe to PlayerEvent.BreakSpeed, and I've looked at it in the source, but how do I cancel the event? (It says it's 'Cancelable')

 

And what file should I put the code for this in? I have a ModEventHandler.java, I'm assuming there?

Link to comment
Share on other sites

If I recall correctly, you set the event's newSpeed to zero to prevent the player from breaking the block (he never makes any progress). I don't think you need to cancel the event.

 

Put the event handler with its @SubscribeEvent annotation into a listener class, which may have multiple events. Your main postInit method needs to register an instance of each listener class with the bus(es) firing its event(s).

 

Example:

  @EventHandler
  public void postInit(FMLPostInitializationEvent e) {
    NethergemEventSubs ES = new NethergemEventSubs ();

    super.postInit (e);
    MinecraftForge.EVENT_BUS.register (ES);
    FMLCommonHandler.instance ().bus ().register (ES);
}

 

If you have events from multiple busses, then you could be very clever and create a separate listener class for each bus. I'm too lazy to do that, so I bundle all my events into one class and then register its instance on every possible bus until all of my events work.

 

Each registration's reflection code seems to be smart enough to pick out its own events without interference from other methods. You might even be able to nest an event handler method inside a block or item class and then register its instance with a bus.  Then your method would have field and method visibility from inside the block or item. I'll have to try that sometime to see "What could possibly go wrong?"

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Well the PlayerEvent.BreakSpeed is a Player event, so it will naturally give you the player involved.  From that you can figure out what item they're holding.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.