Jump to content

What do the other parameters in setBlock do?


Turtledove

Recommended Posts

I'm updating my mod from 1.16.3 to 1.16.5, and I noticed that the setBlockState method has been replaced with setBlock, but it has two additional integer parameters apart from the standard blockstate and block position arguments. Looking at the implementation of the method didn't help because all the variable names are obfuscated. Anyone have any idea?

Link to comment
Share on other sites

19 minutes ago, kiou.23 said:

method signatures did not change, only method names, due to the mappings change
if the method has a different signature, it may not be the method that you are looking for

...except it clearly did, here's the snippet from 1.16.3, take a look for yourself if you didn't know:

image.png.0857ffd104b0e9f861f657893f5e5408.png

 

and now in 1.16.5:

image.png.eda8c594afa12bcf9e5378953fcd58c2.png

Link to comment
Share on other sites

Still hasn't changed. You're referencing two different methods with two difference signatures. The first method you shown calls the second method with the argument 3. As for what it does, it dictates what flags to execute when setting the block (a bit field). The list of flags can be found within Constants$BlockFlags.

Link to comment
Share on other sites

1 minute ago, ChampionAsh5357 said:

Still hasn't changed. You're referencing two different methods with two difference signatures. The first method you shown calls the second method with the argument 3. As for what it does, it dictates what flags to execute when setting the block (a bit field). The list of flags can be found within Constants$BlockFlags.

...Again, there is literally no function that takes in just two parameters. But anyways thanks for that, I'll look into the flags, never realized it was a thing when blocks are placed.

image.png.f615cda063246afac27fe9b1937d2238.png

 

Link to comment
Share on other sites

7 minutes ago, Turtledove said:

...Again, there is literally no function that takes in just two parameters. But anyways thanks for that, I'll look into the flags, never realized it was a thing when blocks are placed.

 

Yes there is:

image.png.3160d85645f5403599d31b0e4e956eeb.png

If you expect the method names to be the same across mappings including how they're referenced between methods, you won't find what you are referring to.

Edited by ChampionAsh5357
Link to comment
Share on other sites

5 minutes ago, ChampionAsh5357 said:

Yes there is:

image.png.3160d85645f5403599d31b0e4e956eeb.png

If you expect the method names to be the same across mappings including how they're referenced between methods, you won't find what you are referring to.

I know what it was, I wrote getWorld() as a wrapper method for classes that implement IWorld, but I guess I missed that that method isn't listed as a function in the interface. 0 IQ moment.

Link to comment
Share on other sites

Ok, so I have a question about these functions in 1.16.5.  I'm trying to do world.setBlock() commands from within an Item use() override.  No matter what function I use (setBlockAndUpdate, setBlock with Constants.BlockFlags.DEFAULT, etc) the blocks appear in the client but disappear when interacted with (apart from collusions).  If I quit and restart, none of the changes were saved.  Blocks replacing other blocks (like grass) go back to the previous block.  This is launching from the Forge MDK runClient configuration.

Are there contexts from which you're not supposed to update the world?  Are you supposed to queue updates for some worker thread/task to handle?  Mark things for update?

ie: world.setBlock(pos.offset(i, y, 5), ModBlocks.MYBLOCK.get().defaultBlockState(), Constants.BlockFlags.DEFAULT);

Most people's questions about setBlock() seem quite straightforward and like it just works for them.

It's almost like a problem passing in immediate variables that get deleted when they go out of scope ... but the few examples I find are using defaultBlockState() and aren't calling new or anything... ?

I can use the ModBlocks.MYBLOCK blocks normally within the game otherwise... as in, place them as in game blocks from creative/survival mode, etc.. they only misbehave from the Item.use() override...

Edited by wintermaker
Link to comment
Share on other sites

16 minutes ago, wintermaker said:

Ok, so I have a question about these functions in 1.16.5.  I'm trying to do world.setBlock() commands from within an Item use() override.  No matter what function I use (setBlockAndUpdate, setBlock with Constants.BlockFlags.DEFAULT, etc) the blocks appear in the client but disappear when interacted with (apart from collusions).  If I quit and restart, none of the changes were saved.  Blocks replacing other blocks (like grass) go back to the previous block.  This is launching from the Forge MDK runClient configuration.

you should make your own threads

 

16 minutes ago, wintermaker said:

Are there contexts from which you're not supposed to update the world?  Are you supposed to queue updates for some worker thread/task to handle?  Mark things for update?

no

 

16 minutes ago, wintermaker said:

It's almost like a problem passing in immediate variables that get deleted when they go out of scope ... but the few examples I find are using defaultBlockState() and aren't calling new or anything... ?

I can use the ModBlocks.MYBLOCK blocks normally within the game otherwise... as in, place them as in game blocks from creative/survival mode, etc.. they only misbehave from the Item.use() override...

we need to see your code. but don't post it here, make a new thread

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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