Jump to content

Help with explosions (and sides)


Syric

Recommended Posts

I'm trying to make a block that has a chance of exploding when the player steps on it or mines it. However, I have an issue: if I allow the code to run on either side, then if the block explodes on the client side only it produces block glitches (as it's still there serverside). On the other hand, if I only allow the code to run on the server side, the block glitches vanish but the player takes no damage from the explosion. How can I resolve this?

Apologies if this is a basic question, I'm still a little wobbly on how to properly manage sides.

Link to comment
Share on other sites

In general, the server is the correct side for non gui processing.

Doing things on the client means other players and the server won't know what you have done and will disagree about the state of the world, like your "glitch".

The client is only there to provide data for rendering and give the user "proxy" objects to the server to interact with.

Though you can do optimisations/logic on the client, e.g. ignoring the user if they try to  "strip bark" on stone. No need to ask the server for this.

  • 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

explode() is called from a few other places as well, all with the same !level.isClientSide() wrapping.

public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) {
        if (!level.isClientSide()) {
            explode(level, pos, state,0.1F);
        }
        super.stepOn(level, pos, state, entity);
    }

    private void explode(Level level, BlockPos pos, BlockState state, float chance) {
        RandomSource rdm = RandomSource.create();
        chatPrint("Checking explosion with chance " + chance, level);
        if (rdm.nextFloat() < chance) {
            chatPrint("Exploding!", level);
            if (state.getValue(WEAK_VERSION)) {
                level.explode(null, pos.getX(), pos.getY(), pos.getZ(), 1.5F, Explosion.BlockInteraction.BREAK);
            } else {
                level.explode(null, pos.getX(), pos.getY(), pos.getZ(), 2.5F, Explosion.BlockInteraction.BREAK);
            }

        }

    }

 

Edited by Syric
Link to comment
Share on other sites

Are you sure the pos is correct?

Forge has a ExplosionEvent.Detonate that will pass a list of potential entity targets.

Does your player appear in that list? You might also check some of the other data in the Explosion object passed on that event.

 

However:

There's also a piece of code in the Explosion class that looks like it checks the entity's distance to the explosion, if it is zero they are excluded from damage!

It looks like this is done to avoid a divide by zero issue?

If you are using the player's position for the explosion you might be getting caught by this? Try moving the explosion position upwards by half a block.

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

Quote

checks the entity's distance to the explosion

Actually it is with the entity's eye position.

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

I found the error. The explosions were being spawned at the block's small corner, while the block was still present. This frequently meant that the block absorbed the majority of the explosion and shielded the player from damage.

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



×
×
  • Create New...

Important Information

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