Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved] world.setBlockState not updating all blocks


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
Link to post
Share on other sites
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.

Link to post
Share on other sites
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. 

 

Link to post
Share on other sites
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

Link to post
Share on other sites
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

Link to post
Share on other sites
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.

Link to post
Share on other sites
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);
    }
}

 

Link to post
Share on other sites

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? 

Link to post
Share on other sites
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
Link to post
Share on other sites
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.

Link to post
Share on other sites

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.

Link to post
Share on other sites
  • 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.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I'm currently trying to make a new cauldron-type block, and I'm having difficulty implementing blockstates. Here's the relevant part of the alchemical cauldron's code:   public class AlchemicalCauldronBlock extends Block { public static final IntegerProperty LEVEL = IntegerProperty.create("level", 1, 3); private static final VoxelShape INSIDE = box(2.0D, 4.0D, 2.0D, 14.0D, 16.0D, 14.0D); protected static final VoxelShape SHAPE = VoxelShapes.join(VoxelShapes.block(), VoxelShapes.or(box(0.0D, 0.0D, 4.0D, 16.0D, 3.0D, 12.0D), box(4.0D, 0.0D, 0.0D, 12.0D, 3.0D, 16.0D), box(2.0D, 0.0D, 2.0D, 14.0D, 3.0D, 14.0D), INSIDE), IBooleanFunction.ONLY_FIRST); public AlchemicalCauldronBlock() { super(Properties.of(Material.METAL).sound(SoundType.METAL).harvestLevel(3).strength(2F,2F)); // this.registerDefaultState(this.stateDefinition.any().setValue(LEVEL, 0)); // this.registerDefaultState(this.stateDefinition.any().setValue(LEVEL, Integer.valueOf(0))); } ... When I try to run this with either of the two attempts at registerDefaultState uncommented, I get this error: https://pastebin.com/vPf3UryC. For convenience, I believe this part is most relevant: How can I avoid this? My registry classes look like this, if it helps: public class registry { public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, AlchemyPlus.MODID); public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AlchemyPlus.MODID); public static void register() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); BLOCKS.register(modEventBus); ITEMS.register(modEventBus); registerItems.register(); registerBlocks.register(); } } public class registerBlocks { public static final RegistryObject<Block> ALCHEMICAL_CAULDRON = register("alchemical_cauldron", AlchemicalCauldronBlock::new); static void register() {} private static <T extends Block> RegistryObject<T> registerNoItem(String name, Supplier<T> block) { return registry.BLOCKS.register(name, block); } private static <T extends Block> RegistryObject<T> register(String name, Supplier<T> block) { RegistryObject<T> ret = registerNoItem(name, block); registry.ITEMS.register(name, () -> new BlockItem(ret.get(), new Item.Properties().tab(ItemGroup.TAB_BREWING))); return ret; } } Full GitHub repository available here.   (Other minor problem(?):  I copied the methods getShape and getInteractionShape from net.minecraft.block.CauldronBlock and I'm getting these weird warnings. What's up with that? Do I need to worry about it?)  
    • Personally I use IForgeRegistryEntry#getRegistryName and then ResourceLocation#getNameSpace to get the id of the object.
    • you can get a block form a ResourceLocation, take a look at NBTUtil#readBlockState, do somthing like that
    • I am running forge version 1.16.5 36.1.31 on a server with a lot of mods and when a player refreshes the server list, it sends a long error in the server console. Additionally, the server list displays "Can't connect to server", despite refreshing and actually being able to connect to the server. here's the links to the logs: https://gist.github.com/WaffleTraits/83885b1539d5711fabff73a91924e665 https://gist.github.com/WaffleTraits/5ae78e6eaa330422bbc9f7226faf60ce Here's what's displayed in console when a player refreshes server listing: https://hastebin.com/ativexeyoy.properties server is running on ubuntu 20.04 and is using java 8 for this forge instance.
    • I kept getting this error whenever I tried joining my modded server I want to find a solution to this I checked every mod and it all matched Client : https://mclo.gs/Q39SSu5 server : https://mclo.gs/UO2kbDz
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.