Jump to content

Recommended Posts

Posted (edited)

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

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

 

Posted
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

Posted
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

Posted (edited)

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.

Posted
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);
    }
}

 

Posted

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? 

Posted (edited)
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
Posted
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.

Posted

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

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