Jump to content

Destroying a block


itzme1on

Recommended Posts

Well, you could get the position, modify it to get the position of the block underneath, check if that block is air, and then destroy the original block using:

ServerLevel#destroyBlock()

 

Edited by TheElementGuy
Incorrect info.
  • Like 1

Please don't put anything from 1.16.5, 1.12.2, 1.14, 1.15, 1.0, or anything not 1.18.x or 1.19.x!

Link to comment
Share on other sites

override BlockBehaviour.canSurvive() in your block.

See for example DoorBlock.

  • Like 1

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.

Link to comment
Share on other sites

Thank you, guys! I just copy code from TorchBlock:

    @Override
    public BlockState updateShape(@NotNull BlockState state, @NotNull Direction direction, @NotNull BlockState state2,
                                  @NotNull LevelAccessor levelAccessor, @NotNull BlockPos pos, @NotNull BlockPos pos2) {
        return direction == Direction.DOWN && !this.canSurvive(state, levelAccessor, pos) ? Blocks.AIR.defaultBlockState() : super.updateShape(state, direction, state2, levelAccessor, pos, pos2);
    }


Thanks for your ideas!

Edited by itzme1on
Wrong code
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.



×
×
  • Create New...

Important Information

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