Jump to content

Recommended Posts

Posted (edited)

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
Posted
  On 6/17/2022 at 7:52 PM, loordgek said:

you are running your code client side

Expand  

 

  On 6/17/2022 at 7:59 PM, Luis_ST said:

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

Expand  

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.

Posted
  On 6/17/2022 at 8:04 PM, 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.

Expand  

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

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.