Skip to content

Commit

Permalink
Fix suffocation with small hitbox
Browse files Browse the repository at this point in the history
  • Loading branch information
WenXin20 committed Jan 1, 2025
1 parent 3c55ebe commit 1dd88d2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/com/wenxin2/marioverse/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -176,6 +178,42 @@ private void getBbWidth(CallbackInfoReturnable<Float> cir) {
}
}

@Inject(method = "isInWall", at = @At("HEAD"), cancellable = true)
public void modifyIsInWall(CallbackInfoReturnable<Boolean> cir) {
Entity entity = (Entity) (Object) this;
if (entity.noPhysics) {
cir.setReturnValue(false);
return;
}

if (entity instanceof LivingEntity livingEntity) {
AttributeMap attributeMap = livingEntity.getAttributes();
if (attributeMap != null) {
float widthScale = (float) attributeMap.getValue(AttributesRegistry.WIDTH_SCALE);

if (widthScale != 1.0F) {
float scaledWidth = entity.getDimensions(entity.getPose()).width() * 0.8F * widthScale;
AABB aabb = AABB.ofSize(entity.getEyePosition(), scaledWidth, 1.0E-6, scaledWidth);

boolean isInWall = BlockPos.betweenClosedStream(aabb)
.anyMatch(
pos -> {
BlockState blockState = entity.level().getBlockState(pos);
return !blockState.isAir()
&& blockState.isSuffocating(entity.level(), pos)
&& Shapes.joinIsNotEmpty(
blockState.getCollisionShape(entity.level(), pos)
.move(pos.getX(), pos.getY(), pos.getZ()),
Shapes.create(aabb), BooleanOp.AND
);
}
);
cir.setReturnValue(isInWall);
} else cir.setReturnValue(cir.getReturnValue());
}
}
}

@Unique
public int marioverse$getWarpCooldown() {
return marioverse$warpCooldown;
Expand Down

0 comments on commit 1dd88d2

Please sign in to comment.