添加entity mixin

This commit is contained in:
17146 2025-02-04 14:06:43 +08:00
parent 24e67ef912
commit 355da3e1f9
2 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,28 @@
package com.atsuishio.superbwarfare.mixins;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(Entity.class)
public class EntityMixin {
// TODO 优化后续逻辑
@Redirect(method = "turn(DD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setXRot(F)V", ordinal = 1))
public void turn(Entity instance, float pXRot) {
if (instance instanceof Player player) {
player.setXRot(player.getXRot());
while (player.getXRot() > 180F) {
player.setXRot(player.getXRot() - 360F);
}
while (player.getYRot() <= -180F) {
player.setXRot(player.getXRot() + 360F);
}
} else {
instance.setXRot(Mth.clamp(instance.getXRot(), -90.0F, 90.0F));
}
}
}

View file

@ -5,6 +5,7 @@
"refmap": "mixins.superbwarfare.refmap.json",
"mixins": [
"ClientboundSetEntityMotionPacketMixin",
"EntityMixin",
"ExplosionMixin",
"LivingEntityMixin",
"PlayerEntityMixin"