Jump to content

Recommended Posts

Posted

Hello

 

I am aware that this question has probably been asked before but a quick search returned nothing conclusive.

 

How can I do as the title says. Stop a player from breaking a vanilla block with a tool which is at a certain level?

I am quite new to modding with forge so please provide some example code.

 

Thanks for taking the time to read this

Edward.

Posted

You can use BlockEvent.BreakSpeed and set the speed to -1.

 

diesieben07,

 

Thanks for the reply. As I am new to Forge modding, how would I set about doing this, and also, what Event would it be under?

 

Thanks

Edward.

Posted

BlockEvent.BreakSpeed does not exist.

 

I have the following code in an Event Bus yet I am still able to break logs with my fist.

Eclipse reports no errors.

 

import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed;

       

public void onBreakSpeed(BreakSpeed event) {

 

if (event.block == Blocks.log) {

event.newSpeed = -1;

 

}

}

}

 

PS: How do I make this display as code rather than normal text?

Posted

Thanks for telling me about the code tags

 

If I try this code,

import net.minecraftforge.event.world.BlockEvent.BreakSpeed;

 

Eclipse gives me this error:

The import net.minecraftforge.event.world.BlockEvent.BreakSpeed cannot be resolved

 

Any ideas what I am doing wrong?

Posted

They've added a BreakEvent that extends BlockEvent.  I think canceling that will do the trick because the comment for the class says:

 

    /**
     * Event that is fired when an Block is about to be broken by a player
     * Canceling this event will prevent the Block from being broken.
     */
    @Cancelable

 

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

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.