Posted June 6, 20232 yr 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.
June 7, 20232 yr 19 hours ago, LizNet said: I managed to "fix" the second problem by adding this to my BlockEntity class, but it seems just a workaround: 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.
June 8, 20232 yr Author 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 June 8, 20232 yr 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.
June 9, 20232 yr 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.
June 11, 20232 yr Author 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 June 11, 20232 yr 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.
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.