提取载具乘客旋转方法

This commit is contained in:
17146 2025-05-14 13:48:25 +08:00 committed by Light_Quanta
parent 9ea44d7b8d
commit 4e8fae569d
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
7 changed files with 70 additions and 18 deletions

View file

@ -12,6 +12,7 @@ import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage;
import com.atsuishio.superbwarfare.tools.*; import com.atsuishio.superbwarfare.tools.*;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.Pair;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@ -49,6 +50,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector4f; import org.joml.Vector4f;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -1099,4 +1101,10 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
public boolean useFixedCameraPos(Entity entity) { public boolean useFixedCameraPos(Entity entity) {
return true; return true;
} }
@OnlyIn(Dist.CLIENT)
@Nullable
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
return Pair.of(Axis.XP.rotationDegrees(-this.getViewXRot(tickDelta)), Axis.ZP.rotationDegrees(-this.getRoll(tickDelta)));
}
} }

View file

@ -21,6 +21,7 @@ import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.Pair;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
@ -40,10 +41,14 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector4f; import org.joml.Vector4f;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -702,4 +707,15 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
public double getSensitivity(double original, boolean zoom, int seatIndex, boolean isOnGround) { public double getSensitivity(double original, boolean zoom, int seatIndex, boolean isOnGround) {
return seatIndex == 0 && !isOnGround ? 0.33 : original; return seatIndex == 0 && !isOnGround ? 0.33 : original;
} }
@OnlyIn(Dist.CLIENT)
@Nullable
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
if (this.getSeatIndex(entity) == 2) {
return Pair.of(Axis.XP.rotationDegrees(-this.getRoll(tickDelta)), Axis.ZP.rotationDegrees(this.getViewXRot(tickDelta)));
} else if (this.getSeatIndex(entity) == 3) {
return Pair.of(Axis.XP.rotationDegrees(this.getRoll(tickDelta)), Axis.ZP.rotationDegrees(-this.getViewXRot(tickDelta)));
}
return Pair.of(Axis.XP.rotationDegrees(-this.getViewXRot(tickDelta)), Axis.ZP.rotationDegrees(-this.getRoll(tickDelta)));
}
} }

View file

@ -18,6 +18,7 @@ import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.InventoryTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.Pair;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -43,6 +44,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector4f; import org.joml.Vector4f;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -603,4 +605,10 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
public boolean useFixedCameraPos(Entity entity) { public boolean useFixedCameraPos(Entity entity) {
return this.getSeatIndex(entity) == 0; return this.getSeatIndex(entity) == 0;
} }
@OnlyIn(Dist.CLIENT)
@Nullable
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
return Pair.of(Axis.XP.rotationDegrees(-this.getViewXRot(tickDelta)), Axis.ZP.rotationDegrees(-this.getRoll(tickDelta)));
}
} }

View file

@ -12,6 +12,7 @@ import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.Pair;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
@ -32,10 +33,14 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector4f; import org.joml.Vector4f;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -372,4 +377,10 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
public double getSensitivity(double original, boolean zoom, int seatIndex, boolean isOnGround) { public double getSensitivity(double original, boolean zoom, int seatIndex, boolean isOnGround) {
return 0.3; return 0.3;
} }
@OnlyIn(Dist.CLIENT)
@Nullable
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
return Pair.of(Axis.XP.rotationDegrees(-this.getViewXRot(tickDelta)), Axis.ZP.rotationDegrees(-this.getRoll(tickDelta)));
}
} }

View file

@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.Pair;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -30,10 +31,14 @@ import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector4f; import org.joml.Vector4f;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -317,4 +322,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
return Mod.loc("textures/vehicle_icon/wheel_chair_icon.png"); return Mod.loc("textures/vehicle_icon/wheel_chair_icon.png");
} }
@OnlyIn(Dist.CLIENT)
@Nullable
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
return Pair.of(Axis.XP.rotationDegrees(-this.getViewXRot(tickDelta)), Axis.ZP.rotationDegrees(-this.getRoll(tickDelta)));
}
} }

View file

@ -16,6 +16,7 @@ import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.gui.Font; import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
@ -61,6 +62,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector4f; import org.joml.Vector4f;
import java.util.ArrayList; import java.util.ArrayList;
@ -1055,4 +1057,15 @@ public abstract class VehicleEntity extends Entity {
public boolean useFixedCameraPos(Entity entity) { public boolean useFixedCameraPos(Entity entity) {
return false; return false;
} }
/**
* 获取载具上玩家的旋转
*
* @return X轴旋转Z轴旋转
*/
@OnlyIn(Dist.CLIENT)
@Nullable
public Pair<Quaternionf, Quaternionf> getPassengerRotation(Entity entity, float tickDelta) {
return null;
}
} }

View file

@ -1,6 +1,5 @@
package com.atsuishio.superbwarfare.mixins; package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.vehicle.*;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis; import com.mojang.math.Axis;
@ -19,27 +18,14 @@ public class LivingEntityRendererMixin<T extends LivingEntity> {
@Inject(method = "setupRotations", at = @At("TAIL")) @Inject(method = "setupRotations", at = @At("TAIL"))
public void render(T entity, PoseStack poseStack, float bob, float yBodyRot, float partialTick, float scale, CallbackInfo ci) { public void render(T entity, PoseStack poseStack, float bob, float yBodyRot, float partialTick, float scale, CallbackInfo ci) {
if (entity.getRootVehicle() != entity && entity.getRootVehicle() instanceof VehicleEntity vehicle) { if (entity.getRootVehicle() != entity && entity.getRootVehicle() instanceof VehicleEntity vehicle) {
if (vehicle instanceof Tom6Entity || vehicle instanceof WheelChairEntity || vehicle instanceof SpeedboatEntity || vehicle instanceof A10Entity) { var rotation = vehicle.getPassengerRotation(entity, partialTick);
poseStack.mulPose(Axis.XP.rotationDegrees(-vehicle.getViewXRot(partialTick))); if (rotation != null) {
poseStack.mulPose(Axis.ZP.rotationDegrees(-vehicle.getRoll(partialTick))); poseStack.mulPose(rotation.first());
} else if (vehicle instanceof Ah6Entity ah6Entity) { poseStack.mulPose(rotation.second());
if (entity == ah6Entity.getNthEntity(2)) {
poseStack.mulPose(Axis.XP.rotationDegrees(-ah6Entity.getRoll(partialTick)));
poseStack.mulPose(Axis.ZP.rotationDegrees(ah6Entity.getViewXRot(partialTick)));
} else if (entity == ah6Entity.getNthEntity(3)) {
poseStack.mulPose(Axis.XP.rotationDegrees(ah6Entity.getRoll(partialTick)));
poseStack.mulPose(Axis.ZP.rotationDegrees(-ah6Entity.getViewXRot(partialTick)));
} else {
poseStack.mulPose(Axis.XP.rotationDegrees(-ah6Entity.getViewXRot(partialTick)));
poseStack.mulPose(Axis.ZP.rotationDegrees(-ah6Entity.getRoll(partialTick)));
}
} else { } else {
float a = Mth.wrapDegrees(Mth.lerp(partialTick, entity.yBodyRotO, entity.yBodyRot) - Mth.lerp(partialTick, vehicle.yRotO, vehicle.getYRot())); float a = Mth.wrapDegrees(Mth.lerp(partialTick, entity.yBodyRotO, entity.yBodyRot) - Mth.lerp(partialTick, vehicle.yRotO, vehicle.getYRot()));
float r = (Mth.abs(a) - 90f) / 90f; float r = (Mth.abs(a) - 90f) / 90f;
float r2; float r2;
if (Mth.abs(a) <= 90f) { if (Mth.abs(a) <= 90f) {
r2 = a / 90f; r2 = a / 90f;
} else { } else {