Jump to content

[Version 1.18.2, SOLVED] Custom status effect that changes the player's (or any entity's) hitbox size


Recommended Posts

Posted (edited)

Hello,

I am having a little trouble implementing an efficient method of changing the player's size whenever that player gains a certain custom status effect. The player's size would revert back to normal when the effect ends.

This is the class for my custom status effect that makes the player bigger (currently I am focusing on the player's hitbox size rather than its rendered size):

public class BigEffect extends MobEffect {
    public BigEffect(MobEffectCategory mobEffectCategory, int color) {
        super(mobEffectCategory, color);
    }

    @Override
    public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) {
        if (!pLivingEntity.level.isClientSide() && pLivingEntity instanceof Player player) {
             // forcibly trigger an EntityEvent.Size event
             player.setForcedPose(Pose.CROUCHING);
        }
        super.applyEffectTick(pLivingEntity, pAmplifier);
    }

    @Override
    public boolean isDurationEffectTick(int pDuration, int pAmplifier) {
        return true;
    }
}

This is the event handler that takes in a EntityEvent.Size event:

@SubscribeEvent
public static void big(EntityEvent.Size event) {
    if (!event.getEntity().level.isClientSide() && event.getEntity() instanceof Player player) {
        if (player.getActiveEffectsMap() != null && player.hasEffect(ModEffects.BIG.get())) {
            event.setNewSize(new EntityDimensions(5.0F, 3.6F, false), true);
        }
        else {
            event.setNewSize(new EntityDimensions(0.6F, 1.8F, false), true);
        }
    }
}

 

It technically works, but I have a feeling that my current method is too crude, and I don't want that. Plus, the player's size does not go back to normal when the potion effect wears off (I even tried crouching or swimming to trigger the EntityEvent.Size event, but to no avail).

 

Even when the hitbox is enlarged, the rendered bounding box (which shows when I press F3 + B) does not get bigger. Oh, and another thing, when the player touches a block with its enlarged hitbox, it starts shaking and becomes unable to jump unless it moves away.

 

Are EntityEvent.Size events the only way to resize the player's hitbox? Is it even the right thing to use? Should I still use capabilities, despite the fact that I can easily check a player's potion effects with hasEffect()/getEffect()?

Edited by LeeCrafts
Posted (edited)

---------------------------------------

CLEANER, MORE EFFICIENT IMPLEMENTATION FOR ALL LIVING ENTITIES, NOT JUST PLAYERS:

https://forums.minecraftforge.net/topic/111159-version-1182-solved-custom-status-effect-that-changes-the-players-or-any-entitys-size-part-ii/

(If you just want to increase the hitbox size) https://forums.minecraftforge.net/topic/111362-version-1182-solved-increased-hitbox-size-only-works-for-entity-collision-but-not-for-block-collision/

---------------------------------------

 

Solved. Turns out that I should not be using EntityEvent.Size. Instead, I have to use the AABB class and call setBoundingBox(). Here is the code in a nutshell if any of you were wondering:

public class BigEffect extends MobEffect {
    public BigEffect(MobEffectCategory mobEffectCategory, int color) {
        super(mobEffectCategory, color);
    }

    @Override
    public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) {
        // (This if-statement makes it not work)
        // if (!pLivingEntity.level.isClientSide()) {
            pLivingEntity.setBoundingBox(new AABB(pLivingEntity.getX()+2.5, pLivingEntity.getY()+3.6, pLivingEntity.getZ()+2.5, pLivingEntity.getX()-2.5, pLivingEntity.getY(), pLivingEntity.getZ()-2.5));
        // }
        super.applyEffectTick(pLivingEntity, pAmplifier);
    }

    @Override
    public boolean isDurationEffectTick(int pDuration, int pAmplifier) {
        return true;
    }
}

 

As you can see, no capabilities are needed. And there is no need to check if the player does NOT have the custom status effect because setBoundingBox() is temporary for only 1 tick (or so it seems).

 

As mentioned in the comment in my code above, it does not work if I make sure that the entity is not in the client side. I guess that's just the nature of AABBs.

 

(Side note, but I just don't know how to use setNewSize() from EntityEvent.Size. I don't really need it anymore, but what kinda confuses me is that I see other people using it and that it works for them. Not a big deal though.)

Edited by LeeCrafts
update solution
  • LeeCrafts changed the title to [Version 1.18.2, SOLVED] Custom status effect that changes the player's (or any entity's) hitbox size

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I should have specified in my last post, the current build is the latest that Ars Nouvaeu supports. Sorry for the trouble!
    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
    • Try other builds: https://www.curseforge.com/minecraft/mc-mods/geckolib/files/all?page=1&pageSize=20&version=1.16.5&gameVersionTypeId=1 Currently, you are using build 96 - the latest one that I linked is build 106 So try 97 to 105  
    • New users at Temu receive a $100 discount on orders over $100 Use the code [aci789589] during checkout to get Temu Coupon Code $100 off For New Users. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. Temu 100% Off coupon code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers $100 off coupon code “aci789589” for first-time users. You can get a$100 bonus plus 30% off any purchase at Temu with the$100 Coupon Bundle at Temu if you sign up with the referral code [aci789589] and make a first purchase of$50 or more. The Temu $100 Off coupon code (aci789589) will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Yes Temu offers $100 Off Coupon Code “aci789589” for First Time Users. Yes, Temu offers $100 off coupon code {aci789589} for first-time users. You can get a $100 bonus plus 100% off any purchase at Temu with the $100 Coupon Bundle if you sign up with the referral code [aci789589] and make a first purchase of $100 or more. If you are who wish to join Temu, then you should use this exclusive Temu coupon code $100 off (aci789589) and get $100 off on your purchase with Temu. You can get a $100 discount with Temu coupon code {aci789589}. This exclusive offer is for existing customers and can be used for a $100 reduction on your total purchase. Enter coupon code {aci789589} at checkout to avail of the discount. You can use the code {aci789589} to get a $100 off Temu coupon as a new customer. Apply this Temu coupon code $100 off (aci789589) to get a $100 discount on your shopping with Temu. If you’re a first-time user and looking for a Temu coupon code $100 first time user(aci789589) then using this code will give you a flat $100 Off and a 90% discount on your Temu shopping. Temu $100% Off Coupon Code "aci789589" will save you $100 on your order. To get a discount, click on the item to purchase and enter the code. Temu coupon code$100off-{aci789589} Temu coupon code -{aci789589} Temu coupon code$50 off-{aci789589} Temu Coupon code [aci789589] for existing users can get up to 50% discount on product during checkout. Temu Coupon Codes for Existing Customers-aci789589 Temu values its loyal customers and offers various promo codes, including the Legit Temu Coupon Code (aci789589]) or (aci789589), which existing users can use. This ensures that repeat shoppers can also benefit from significant discounts on their purchases. Keep an eye out for special promotions and offers that are periodically available to enhance your shopping experience.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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