Jump to content

[1.14.4] onBlockActivated deprecated


ZemahZalek

Recommended Posts

The onBlockActivated method in the class Block (along with many other methods) are deprecated, however I need to call them. I read that I need (or should) use this same method but from the class BlockState instead and not use the deprecated one. However I do not know how to access this method. My own block class is a subclass of Block and therefore cannot also be a subclass of BlockState to access the method . The deprecated method in Block has a BlockState parameter but whenever I try to access onBlockActivated through that parameter the game crashes when I right click on my blocks. I also tried to get the blockstate through getBlock().getDefualtBlockstate() but that also resulted in a crash. Is there a specific way to to this? Or should I just use the deprecated method anyways?

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

If you need to call the method then you need to call the one in BlockState. Show your attempt at doing so if thats what you are doing.

If you need to override the method, then thats fine. Mojang abuses @Deprecated in this way.

public class ModBlock extends Block {

    @Override
    public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
        return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
        //return state.onBlockActivated(worldIn, player, handIn, hit);
        //return this.getBlock().getDefaultState().onBlockActivated(worldIn, player, handIn, hit);
    }
}

Here is the onBlockActivated method in my own block class. The two commented lines are the ones I tried, but they resulted in a crash; java.lang.StackOverflowError: null. I guess it's because the BlockState parameter hasn't been instantiated yet? I just don't know how to access the BlockState method.

Link to comment
Share on other sites

8 minutes ago, diesieben07 said:

Well, calling onBlockActivated again from within onBlockActivated will of course result in an infinite loop which causes a stack overflow (onBlockActivated is called, which calls onBlockActivated again, which calls onBlockActivated again, which calls...).

What are you trying to achieve?

I simply want to set up basic functionality when right clicking on a block. 

And the infinite loop makes sense, however I have tried to create my own method and call the BlockState method from that but it doesn't work. Probably because my method is never getting called anywhere, so I don't know how to go about this.

Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

I don't know what you mean by "basic functionality".

To make your block do something when right click you just need to override onBlockActivated and do whatever it is you want it to do in that method.

Well I shouldn't use the onBlockActivated from Block as it is deprecated. But at the same time I cannot access and override the one from BlockState because my block class isn't a subclass of BlockState. So how do I override a method I do not have access to?

Link to comment
Share on other sites

  • 3 months later...
9 minutes ago, Aes123 said:

Hey im having the same problem, could you send me the code which fixed the issue?

 

 

On 1/23/2020 at 2:54 PM, diesieben07 said:

If you need to call the method then you need to call the one in BlockState. Show your attempt at doing so if thats what you are doing.

If you need to override the method, then thats fine. Mojang abuses @Deprecated in this way.

 

On 1/23/2020 at 3:54 PM, diesieben07 said:

The point is that if you want to call onBlockActivated you do it on the BlockState.

 

All of the answers are here, if you are still having a problem, it may be something else.

I would should start a new thread, and post your code, and probably also debug.log.

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.