Jump to content

[SOLVED] [1.19.2] BlockEntity not informing it's surroundings on place


LizNet

Recommended Posts

I have been updating my mod to a newer versions but encountered a very weird bug that I cannot solve: my block does not inform surrounding blocks nor other players when it is placed to ground.

 

For example:

1. I put my block to the ground; no other player can see it but it has collision, so it behaves like a "ghost block". If other player right-clicks the block then it turns visible.

2. I put my block (with fluid capability) to the ground under a pipe, the pipe does not connect to the block. I put pipe top of my block, it connects normally. It seems that the pip doesn't know that my block is there if the block is placed afterwards.

 

I managed to "fix" the second problem by adding this to my BlockEntity class, but it seems just a workaround:

@Override
public void onLoad()
{
  super.onLoad();
  this.level.updateNeighborsAt(getBlockPos(), getBlockState().getBlock());
}

 

Full WIP source available in GitHub.

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Link to comment
Share on other sites

14 hours ago, ChampionAsh5357 said:

I think that's a good enough solution since block entities are updated on the client before they actually get the data from the server iirc. You can try syncing on block update though.

Okay, if that's fine then I'll use it. I already sync on block update because I have custom data with the blocks. Should I still add this:

@Override
public void onLoad()
{
  super.onLoad();
  this.level.updateNeighborsAt(getBlockPos(), getBlockState().getBlock());
  this.level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 2) // Not sure about the 2
}

 

Also, that whole bug seems weird because it seems to be something that needs to be exclusively coded. I'm very confused about how I even broke the vanilla mechanic in the first place..

Edited by LizNet

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Link to comment
Share on other sites

On 6/8/2023 at 3:13 AM, LizNet said:

Okay, if that's fine then I'll use it. I already sync on block update because I have custom data with the blocks. Should I still add this:

 

I think it's fine because you are updating the initial state. The 2 is just a flag bit that says update the client.

 

Link to comment
Share on other sites

Solved the problem with some help from Discord. The problem was in my BaseBinBlock.java file:

I had this in my place logic which was causing the bug:

protected void checkPoweredState(Level level, BlockPos pos, BlockState state) 
{
  boolean flag = level.hasNeighborSignal(pos);
  if (flag != state.getValue(POWERED))
    level.setBlock(pos, state.setValue(POWERED, Boolean.valueOf(flag)), Block.UPDATE_INVISIBLE);
}

and changing it to like this fixed it:

protected void checkPoweredState(Level level, BlockPos pos, BlockState state) 
{
  boolean flag = level.hasNeighborSignal(pos);
  if (flag != state.getValue(POWERED))
    level.setBlock(pos, state.setValue(POWERED, Boolean.valueOf(flag)), Block.UPDATE_ALL);
}

Now the onLoad override is no longer needed either.

 

So in short: I needed to use Block.UPDATE_ALL, not Block.UPDATE_INVISIBLE in Level#setBlock().

Edited by LizNet

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.

Link to comment
Share on other sites

  • LizNet changed the title to [SOLVED] [1.19.2] BlockEntity not informing it's surroundings on place

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.



×
×
  • Create New...

Important Information

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