Jump to content

Get the state of another block?


Recommended Posts

Hello. I want to use the replaceBlock function, to change the block when it's right clicked with a certain item. I have it @Override onBlockActivated, then check the item in the player's hand. The problem I've run into i getting the other blocks state. I've tried creating a variable in the other block with this.getDefaultState, but when I use it somewhere else, I get an unclassified usage. So I made a new variable, that simply is the same as the other one, only this one is created inside the block being replace's class. However, it says that the variable in the other class needs to be static, but when I make it static, this.getDefaultState doesn't work. How would I get the other blocks state into my block?

Here's my @Override code:

public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {

    if (player.getHeldItemMainhand().getItem() == RegistryHandler.WRENCH.get()) {

        RightCurvedBelt.replaceBlock(state, NEWSTATE, worldIn, pos, getHarvestLevel(state));

And here's the 2 variables I've tried to make

public static final BlockState RSTATE = this.getDefaultState();
private static final BlockState NEWSTATE = RightCurvedBelt.RSTATE;


Edited by MrInfinity
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.

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.


  • Create New...

Important Information

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