Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi, I have an AABB that I want to set all of the blocks in to a different block. 

final Stream<BlockPos> blocksBetweenPlayerLookingAndDowsingEffect = BlockPos.betweenClosedStream(
        WorldHelper.getAABBInDirectionWithOffset(
                itemUseContext.getClickedPos(),
                itemUseContext.getClickedFace(),
                0,
                1,
                1
        )
);

blocksBetweenPlayerLookingAndDowsingEffect.forEach( blockPos -> {
    world.setBlockAndUpdate(blockPos, Blocks.CYAN_WOOL.defaultBlockState());
});

I think there were different names for both of betweenClosedStream and setBlockAndUpdate in the MCP mappings. So it's been hard to find exactly the fix I'm looking for.

 

The problem I'm facing now is that when I call setBlockAndUpdate, only the first clicked on block updates. The rest don't update until I restart the world.

I assume this has something to do with being used in a stream, or the flag that's used on setBlock? I'm not entirely sure. 

Thanks!

Edited by Tut
Fix formatting

7 hours ago, Tut said:

or the flag that's used on setBlock?

Probably this.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
40 minutes ago, Draco18s said:

Probably this.

setBlockAndUpdate uses flag 3, but I've tried 1, 2, and 4 with no success. Is there any documentation on what these flags do? I found this thread but since I'm using the mojang mappings I don't think I have the same javadocs. 

 

1 hour ago, Tut said:

setBlockAndUpdate uses flag 3, but I've tried 1, 2, and 4 with no success. Is there any documentation on what these flags do? I found this thread but since I'm using the mojang mappings I don't think I have the same javadocs. 

Constants.BlockFlags, in this class all BlockFlags are listed with an explanation

  • Author
12 minutes ago, Luis_ST said:

Constants.BlockFlags, in this class all BlockFlags are listed with an explanation

Thank you for letting me know! Unfortunately still having issues. I'm not sure why this code isn't working..

blocksBetweenPlayerLookingAndDowsingEffect.forEach( blockPos -> {
                world.setBlock(blockPos, Blocks.CYAN_WOOL.defaultBlockState(), ( Constants.BlockFlags.DEFAULT_AND_RERENDER ) );
            });

Here's an example of the behavior I'm experiencing..
https://files.catbox.moe/z4ov1m.m4v

Yes we know what it looks like. The client and server have desync'd.

We need more of your code.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
Just now, Draco18s said:

Yes we know what it looks like.

We need more of your code.

Here's the whole class.

 

public class ShungiteDowsingRod extends Item implements IForgeItem {
    public ShungiteDowsingRod(Properties properties) { super(properties); }

    @Override
    public ActionResultType useOn(ItemUseContext itemUseContext) {
        final World world = itemUseContext.getLevel();

        if (!world.isClientSide()) {
            final Stream<BlockPos> blocksBetweenPlayerLookingAndDowsingEffect = BlockPos.betweenClosedStream(
                    WorldHelper.getAABBInDirectionWithOffset(
                            itemUseContext.getClickedPos(),
                            itemUseContext.getClickedFace(),
                            0,
                            1,
                            1
                    )
            );

            blocksBetweenPlayerLookingAndDowsingEffect.forEach( blockPos -> {
                world.setBlock(blockPos, Blocks.CYAN_WOOL.defaultBlockState(), ( Constants.BlockFlags.DEFAULT_AND_RERENDER ) );
            });
        }

        return super.useOn(itemUseContext);
    }
}

 

  • Author

I see the issue. But I'm not sure why being on the server means the client isn't being updated, if the setBlock event should update the client? 

3 minutes ago, Tut said:

if (!world.isClientSide()) {

you should remove this because you are checking here if you are on the server (not on client)
and the video shows that the server receives the changes but the client doesn't

 

Edited by Luis_ST

2 minutes ago, Tut said:

I see the issue. But I'm not sure why being on the server means the client isn't being updated, if the setBlock event should update the client? 

Because the server is not the client. They are different threads (and in the case of multiplayer, may be on different machines!)

 

I'm not sure why the usual block state change isn't being propagated as normal, but I would do as Luis says and just remove the side check.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I guess I was just confused as to how things were getting handled when something is updated on the server. Not sure how I didn't see it before, thanks all.

  • Tut changed the title to [Solved] world.setBlockState not updating all blocks

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.