Jump to content

entity.hurt() method not working forge 1.19


blu1980

Recommended Posts

Here is the code I'm working on currently:

@Override
    public void onArmorTick(ItemStack stack, Level level, Player player) {
        super.onArmorTick(stack, level, player);
        if(player.isOnGround() && !onGround) {
            onGround = true;
            if(Minecraft.getInstance().level != null) {
                List<Entity> entities = Utils.getEntities(Minecraft.getInstance().level, player.getBlockX(), player.getBlockZ(), 6);
                for(Entity e : entities) {
                    if(!e.equals(player)) {
                        e.hurtMarked = true;
                        e.hurt(DamageSource.OUT_OF_WORLD, 5f);
                    }
                }
            }
        } else {
            if(!player.isOnGround())
                onGround = false;
        }
    }

My problem is that I can't get e.hurt() to work properly. It doesn't seem to do anything in game.

 

EDIT:

It's working now, I mistakenly used the Minecraft class to get the client level instead of the level provided in the function parameters. oops.

Edited by blu1980
Solved
Link to comment
Share on other sites

11 minutes ago, loordgek said:

you are running your code client side

 

4 minutes ago, Luis_ST said:

this will crash on server, why did you use the client side level and not the given level (second parameter)

Oh I see. So I need to run the code server side instead. How do I do that? Sorry if it's a stupid question, somewhat new to modding.

Link to comment
Share on other sites

7 minutes ago, blu1980 said:

 

Oh I see. So I need to run the code server side instead. How do I do that? Sorry if it's a stupid question, somewhat new to modding.

Wait nevermind you're right the level is literally the second parameter in the function declaration.

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.