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
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult blockHitResult) {
        ItemStack itemstack = player.getItemInHand(hand);


        boolean successfullyDyed = false;

        if (level.isClientSide) {
            if(player.getAbilities().mayBuild == true){
                if(itemstack.getItem() == Items.RED_DYE){
                    level.setBlock(blockPos,blockState.setValue(TYPE,0),0);
                    successfullyDyed = true;
                }
                else if(itemstack.getItem() == Items.ORANGE_DYE){
                    level.setBlock(blockPos,blockState.setValue(TYPE,1),0);
                    successfullyDyed = true;
                }
                else if(itemstack.getItem() == Items.YELLOW_DYE){
                    level.setBlock(blockPos,blockState.setValue(TYPE,2),0);
                    successfullyDyed = true;
                }
                else if(itemstack.getItem() == Items.GREEN_DYE){
                    level.setBlock(blockPos,blockState.setValue(TYPE,3),0);
                    successfullyDyed = true;
                }
                else if(itemstack.getItem() == Items.BLUE_DYE){
                    level.setBlock(blockPos,blockState.setValue(TYPE,4),0);
                    successfullyDyed = true;
                }
                else if(itemstack.getItem() == Items.PURPLE_DYE){
                    level.setBlock(blockPos,blockState.setValue(TYPE,5),0);
                    successfullyDyed = true;
                }
                else{
                    player.displayClientMessage(Component.translatable("block.thingamajigs.lava_lamp.wrong_dye"), true);
                    return InteractionResult.CONSUME;
                }
                // update THIS block, no matter what happens
                if(successfullyDyed == true){
                    level.updateNeighborsAt(blockPos,this);
                    level.playSound(null, blockPos, SoundEvents.DYE_USE, SoundSource.BLOCKS, 1.0F, 1.0F);
                    return InteractionResult.SUCCESS;
                }
                if(!player.isCreative()) {
                    if (itemstack.getCount() > 1) {
                        itemstack.setCount(itemstack.getCount() - 1);
                    } else {
                        itemstack.setCount(0);
                    }
                }
            }
        }
        return InteractionResult.CONSUME;
    }

Hey there, I was working on a block's 'use' method, however the behavior is not quite what I wanted. In-game, the block will flash to the desired state, then revert back to the state it was in previously, and won't actually update. I was wondering if perhaps I was updating the block wrong? The only state I am trying to update is an Integer value called 'TYPE' from 0-5 by using dyes.

Edited by CreativeMasterBonin
solved the problem with simple fix

You only ever set the block on the client.

See HoneycombItem.useOn() for the "correct" logic.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

This is in a block class however, useOn is not in a block class. I am assuming I need to put the updateNeighbor method outside of my condition If(level.isClientSide), because otherwise the level.setBlock() method is ran on the client side because I check for the client side first.

 

Or is perhaps the bug within the setBlock() method itself?

level.setBlock(blockPos,blockState.setValue(TYPE,0),0 // <- here?);

I had set that number to 3 before and the same behavior happened anyways.

Edited by CreativeMasterBonin

Nevermind I switched the case from IS clientside to if it ISN'T clientside. Now the dye-ing process works! Cool! :D

  • Guest changed the title to [SOLVED] 1.19.2 Block reverts to previous state after block update

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.