Jump to content

Recommended Posts

Posted (edited)

Hi,

 

i wrote a mod which can grow and shrink the player but if the player is shrinked they crawl if they are inside a 1 block gap or if they jump inside a 2 block gap. 

2021-03-18_15_13_46.png.a641ed14073055c53603d6e56609eec3.png2021-03-18_15_13_29.png.fb2c90ec0044395518bac8561ab4acc2.png

How can i prevent them from doing that? 


I tried using the EntityEvent.Size and check if the event.getPose is Swimming (since this is the pose the player is using while crawling) but the entity isn't inside water. But it doesn't seems to work.

Any ideas?

Edited by Skyriis
Posted
@Mixin(Entity.class)
public abstract class MixinEntity {
    @Shadow
    public abstract EntityType<?> getType();

    @Shadow
    public World level;

    @Shadow
    public abstract int getId();

    @Inject(method = "getBoundingBoxForPose", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/Entity;getDimensions(Lnet/minecraft/entity/Pose;)Lnet/minecraft/entity/EntitySize;"), cancellable = true)
    private void getBoundingBoxForPose(Pose pose, CallbackInfoReturnable<AxisAlignedBB> cir) {
        if (!this.getType().equals(EntityType.PLAYER)) return;
        Entity entity = level.getEntity(getId());
        if (entity == null) return;
        entity.getCapability(CapabilityHelper.RACE_CAPABILITY).ifPresent(iRaceProvider -> {
            final AxisAlignedBB axisAlignedBB = iRaceProvider.getRace().getPlayerBoundingBox(entity, pose);
            cir.setReturnValue(axisAlignedBB);
        });
    }
}

i've used mixin to fix my problem but since i have no clue what i'm doing here i would be grateful for alternatives!

Posted
4 minutes ago, diesieben07 said:

You can use setForcedPose to set the pose.

I tried using the setForcePose method within the PlayerTickEvent (set the pose on pre tick event and remove the pose on post tick event) but somehow it's bugging between both poses.

 

I guess the source of my problem is that Entity.getBoundingBoxForPose returns a bounding box for the default EntityType.PLAYER which is not what i need since i'm resizing the player inside of the EntityEvent.Size event.

#Entity.class

public EntitySize getDimensions(Pose p_213305_1_) {
      return this.type.getDimensions();
   }

protected AxisAlignedBB getBoundingBoxForPose(Pose p_213321_1_) {
      EntitySize entitysize = this.getDimensions(p_213321_1_);
      float f = entitysize.width / 2.0F;
      Vector3d vector3d = new Vector3d(this.getX() - (double)f, this.getY(), this.getZ() - (double)f);
      Vector3d vector3d1 = new Vector3d(this.getX() + (double)f, this.getY() + (double)entitysize.height, this.getZ() + (double)f);
      return new AxisAlignedBB(vector3d, vector3d1);
   }

 

getDimensions(Pose) should return the set EntitySize from the EntityEvent.Size event to make it work without mixin. Or am i wrong with that?

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.