diff --git a/changelog.md b/changelog.md index 6be8101..b126835 100644 --- a/changelog.md +++ b/changelog.md @@ -1,14 +1,33 @@ -- Fixed incorrect rolling when looking certain directions -- Now compatible with [do a barrel roll](https://modrinth.com/mod/do-a-barrel-roll) and hopefully other camera roll kinds of mods. -- The third-person camera while seated on a train is now improved. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/24) +Major update to fix major problems. The mod is in a pretty good state now. -Known issues: -- The mod's leaning is a bit jittery. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22) - - This is probably more of a limitation of Minecraft itself. It might be fixable with a config option to emulate pitch, but that wouldn't make the player appear correctly to other players. - - Update: it's most definitely possible to fix this up. -- The easing back to normal posture after jumping off a train on a slope could use some work. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/23) +The scoops: +- Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/32) +- Fixed jittery leaning. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22) +- When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35) + - This is probably incompatible with anti-cheat mods/plugins. + - The feature is also still _ever so slightly_ janky, but for most purposes it should be very usable. +- Fixed jittering of hand when traveling along the negative X axis. +- Fabric only: added a contact email. -[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.2...v0.2.3) +[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0) + +--- + +In 0.1.2, I decided that the mod was basically ready and marked it as a Release version. + +On second thought, I have realized the state of the mod and decided that Beta better describes its current state. +I have marked versions 0.2.2+ as Beta and all versions before that as Alpha to better represent this. + +Of course, this does not mean that the mod is unusable or is going to break _everything_. +It just doesn't hold all the qualities I want it to. +In my opinion, A full Release version should be highly functional and configurable, +while retaining good compatibility with popular mods. + +On that note, this version is _quality_ enough to be a release candidate, +and would be if it weren't for the missing things below: +- Configuration. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/36) +- More accurate perspective. For a mod called "Create: _Train Perspective_", this is an important issue. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/38) +- Some sound system and fog issues. Nothing major, but slightly annoying. [View issue.](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/39) --- diff --git a/changelog.txt b/changelog.txt index 37dffd7..0f44573 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,16 +1,15 @@ -Minor update to fix some issues. +Major update to fix major problems. The mod is in a pretty good state now. -- Fixed incorrect rolling when looking certain directions -- Now compatible with [do a barrel roll] and hopefully other camera roll kinds of mods. -- The third-person camera while seated on a train is now improved. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/24 +[Changelog] +- Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/32 +- Fixed jittery leaning. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22 +- When targetting a block with the crosshair, the mod now makes some adjustments to target the block you should be looking at instead of the block the game thinks you're looking at. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/35 + - This is probably incompatible with anti-cheat mods/plugins. + - The feature is also still *ever so slightly* janky, but for most purposes it should be very usable. +- Fixed jittering of hand when traveling along the negative X axis. +- Fabric only: added a contact email. -Known issues: -- The mod's leaning is a bit jittery. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/22 - - This is probably more of a limitation of Minecraft itself. It might be fixable with a config option to emulate pitch, but that wouldn't make the player appear correctly to other players. - - Update: it's most definitely possible to fix this up. -- The easing back to normal posture after jumping off a train on a slope could use some work. https://github.com/der-fruhling-entertainment/create-train-perspective/issues/23 - -https://github.com/der-fruhling/create-train-perspective/compare/v0.2.2...v0.2.3 +Commits: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0 --- diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java index 394a6bc..7675707 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.java @@ -2,4 +2,5 @@ public interface Camera3D { float getZRot(); + float getExtraYRot(); } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java index 61bae09..ac9aaef 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/CreateTrainPerspectiveMod.java @@ -10,9 +10,7 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.slf4j.Logger; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; // The value here should match an entry in the META-INF/mods.toml file public class CreateTrainPerspectiveMod { @@ -30,7 +28,10 @@ public CreateTrainPerspectiveMod() { private static class RotationState { public final CarriageContraptionEntity entity; private float lastYaw; - public boolean standingState, isMounted, shouldTickState = true; + public boolean standingState; + public boolean isMounted; + public boolean shouldTickState = true; + public int ticksSinceLastUpdate = 0; public RotationState(CarriageContraptionEntity entity, boolean standingState, boolean isMounted) { this.entity = entity; @@ -40,6 +41,14 @@ public RotationState(CarriageContraptionEntity entity, boolean standingState, bo } public float getYawDelta() { + while (entity.yaw - lastYaw < -180.0f) { + lastYaw -= 360.0f; + } + + while (entity.yaw - lastYaw >= 180.0f) { + lastYaw += 360.0f; + } + var rotation = entity.yaw - lastYaw; lastYaw = entity.yaw; return rotation; @@ -60,40 +69,31 @@ public void onEntityMount(boolean isMounting, Entity entityMounting, Entity enti states.put(entityMounting.getUUID(), state); persp.enable(state.entity.pitch, state.entity.yaw); } else { - states.get(entityMounting.getUUID()).isMounted = true; + var state = states.get(entityMounting.getUUID()); + state.isMounted = true; + state.shouldTickState = true; } } else { if(states.containsKey(entityMounting.getUUID())) { - if(states.get(entityMounting.getUUID()).standingState) { - states.get(entityMounting.getUUID()).isMounted = false; - } else { - states.remove(entityMounting.getUUID()); - persp.disable(); - } + states.remove(entityMounting.getUUID()); + persp.disable(); } } } } - public void tickStandingPlayers(final CarriageContraptionEntity contraption) { - for(Map.Entry entry : contraption.collidingEntities.entrySet()) { - var entity = entry.getKey(); - var ticks = entry.getValue(); - if(entity instanceof LocalPlayer player) { - if(player.getVehicle() != null) continue; - - var state = states.get(player.getUUID()); - if (state == null) { - var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - state = new RotationState(contraption, true, false); - states.put(player.getUUID(), state); - persp.enable(state.entity.pitch, state.entity.yaw); - } else if(ticks.getValue() >= 2) { - state.shouldTickState = false; - } else if(!state.shouldTickState) { - state.shouldTickState = true; - } - } + public void tickStandingPlayer(final CarriageContraptionEntity contraption, final Player player) { + if(player.getVehicle() != null) return; + + var state = states.get(player.getUUID()); + + if (state == null || !Objects.equals(state.entity, contraption)) { + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + state = new RotationState(contraption, true, false); + states.put(player.getUUID(), state); + persp.enable(state.entity.pitch, state.entity.yaw); + } else { + state.ticksSinceLastUpdate = 0; } } @@ -104,6 +104,14 @@ private void tickState(LocalPlayer player) { persp.setYaw(state.entity.yaw); player.setYRot(player.getYRot() + state.getYawDelta()); player.setYBodyRot(player.getYRot()); + + if(state.standingState && !state.isMounted) { + state.ticksSinceLastUpdate += 1; + + if(state.ticksSinceLastUpdate > 5) { + state.shouldTickState = false; + } + } } public void onTickPlayer(final Player player) { @@ -115,12 +123,11 @@ public void onTickPlayer(final Player player) { } else { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); persp.diminish(); - } - if(localPlayer.onGround() && state.standingState) { - var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - states.remove(player.getUUID()); - persp.disable(); + if(persp.diminished()) { + states.remove(player.getUUID()); + persp.disable(); + } } } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java index 79f8b09..e55be63 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java @@ -1,6 +1,7 @@ package net.derfruhling.minecraft.create.trainperspective; import net.minecraft.client.Camera; +import net.minecraft.util.Mth; public class MixinUtil { private MixinUtil() {} @@ -8,4 +9,16 @@ private MixinUtil() {} public static Camera3D asCamera3D(Camera camera) { return (Camera3D) camera; } + + private static float invCos(float x) { + return Mth.cos(x + Mth.PI); + } + + public static float applyDirectionXRotChange(Perspective persp, float xRot, float yRot, float f) { + return xRot - persp.getLean(f) * Mth.sin((persp.getYaw(f) - yRot) * Mth.DEG_TO_RAD); + } + + public static float getExtraYRot(Perspective persp, float xRot, float yRot, float f) { + return persp.getLean(f) * (xRot / 90.0f) * invCos((persp.getYaw(f) - yRot) * Mth.DEG_TO_RAD); + } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java index cb64c9b..4636714 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java @@ -1,15 +1,21 @@ package net.derfruhling.minecraft.create.trainperspective; +import net.minecraft.util.Mth; + public interface Perspective { void enable(float initialLean, float initialYaw); void disable(); + boolean isEnabled(); void setLean(float lean); void setYaw(float yaw); - float getLean(); - float getYaw(); + float getLean(float f); + float getYaw(float f); default void diminish() { - setLean(getLean() * 0.97f); - setYaw(getYaw() * 0.97f); + setLean(getLean(1.0f) * 0.9f); + } + + default boolean diminished() { + return Mth.abs(getLean(1.0f)) < 0.01f; } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java similarity index 51% rename from common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java rename to common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java index 9fa6864..c072623 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ContraptionColliderMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java @@ -1,23 +1,28 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; import com.simibubi.create.content.contraptions.AbstractContraptionEntity; -import com.simibubi.create.content.contraptions.ContraptionCollider; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ContraptionCollider.class) -public class ContraptionColliderMixin { - @Inject(method = "collideEntities", at = @At("HEAD"), remap = false) - private static void saveClientPlayerFromClipping( - AbstractContraptionEntity contraptionEntity, +@Mixin(AbstractContraptionEntity.class) +@Environment(EnvType.CLIENT) +public class AbstractContraptionEntityMixin { + @SuppressWarnings({"ConstantValue", "UnreachableCode"}) + @Inject(method = "registerColliding", at = @At("TAIL"), remap = false) + private void onRegisterColliding( + Entity entity, CallbackInfo ci ) { - if(contraptionEntity instanceof CarriageContraptionEntity carriage) { - CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayers(carriage); + if((Object) this instanceof CarriageContraptionEntity carriage && entity instanceof Player player) { + CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayer(carriage, player); } } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java index 0143203..6bb219e 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.java @@ -2,43 +2,72 @@ import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.Camera3D; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; +import org.joml.Quaternionf; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Camera.class) @Implements({@Interface(iface = Camera3D.class, prefix = "c3d$")}) +@Environment(EnvType.CLIENT) public abstract class CameraMixin { @Shadow private Entity entity; @Unique private float ctp$zRot; + @Unique private float ctp$extraYRot; @Shadow protected abstract void setRotation(float f, float g); + @Shadow @Final private Quaternionf rotation; + @ModifyArg(method = "setRotation", at = @At(value = "INVOKE", target = "Lorg/joml/Quaternionf;rotationYXZ(FFF)Lorg/joml/Quaternionf;"), index = 2) private float modifyRoll(float original) { return original + ctp$zRot; } + @Inject(method = "setRotation", at = @At(value = "INVOKE", target = "Lorg/joml/Quaternionf;rotationYXZ(FFF)Lorg/joml/Quaternionf;", shift = At.Shift.AFTER)) + private void modifyQuaternion(float f, float g, CallbackInfo ci) { + this.rotation.rotateY(ctp$extraYRot); + } + @Unique public float c3d$getZRot() { return this.ctp$zRot; } + @Unique + public float c3d$getExtraYRot() { + return this.ctp$extraYRot; + } + @Redirect(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V")) - public void modifyRotationsPrimary(Camera instance, float y, float x, @Local(argsOnly = true, ordinal = 1) boolean isThirdPerson) { + public void modifyRotationsPrimary(Camera instance, + float y, + float x, + @Local(argsOnly = true, ordinal = 0) boolean isThirdPerson, + @Local(argsOnly = true) float f) { if(entity instanceof LocalPlayer player && !isThirdPerson) { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - ctp$zRot = persp.getLean() * Mth.cos((persp.getYaw() - y) * Mth.DEG_TO_RAD); - setRotation(y, x - persp.getLean() * Mth.sin((persp.getYaw() - y) * Mth.DEG_TO_RAD)); + ctp$zRot = persp.getLean(f) * Mth.cos((persp.getYaw(f) - y) * Mth.DEG_TO_RAD); + ctp$extraYRot = MixinUtil.getExtraYRot(persp, x, y, f); + setRotation( + y, + MixinUtil.applyDirectionXRotChange(persp, x, y, f) + ); } else { ctp$zRot = 0; + ctp$extraYRot = 0; setRotation(y, x); } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java new file mode 100644 index 0000000..86defd0 --- /dev/null +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java @@ -0,0 +1,27 @@ +package net.derfruhling.minecraft.create.trainperspective.mixin; + +import com.simibubi.create.foundation.utility.RaycastHelper; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; +import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.minecraft.client.Minecraft; +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.ModifyVariable; + +@Mixin(RaycastHelper.class) +public class CreateRaycastHelperMixin { + @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 4) + private static float modifyXRot(float value, Player player) { + if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { + return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot(), 1.0f); + } else return value; + } + + @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 5) + private static float modifyYRot(float value, Player player) { + if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { + return value + MixinUtil.getExtraYRot(persp, player.getXRot(), value, 1.0f); + } else return value; + } +} diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java index d29c011..c067f41 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/EntityMixin.java @@ -1,18 +1,26 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; +import com.llamalad7.mixinextras.sugar.Local; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; +import net.derfruhling.minecraft.create.trainperspective.MixinUtil; +import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Entity.class) -public class EntityMixin { +@Environment(EnvType.CLIENT) +public abstract class EntityMixin { @Shadow @Nullable private Entity vehicle; + @Shadow private Level level; @Inject(method = "startRiding(Lnet/minecraft/world/entity/Entity;Z)Z", at = @At(value = "RETURN", ordinal = 4)) public void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable cir) { @@ -25,4 +33,24 @@ public void onRemoveVehicle(CallbackInfo ci) { CreateTrainPerspectiveMod.INSTANCE.onEntityMount(false, (Entity)(Object)this, vehicle); } } + + @SuppressWarnings("UnreachableCode") + @ModifyVariable(method = "calculateViewVector", at = @At(value = "LOAD"), index = 1, argsOnly = true) + public float adjustXRot(float xRot, @Local(argsOnly = true, index = 2) float yRot) { + if (this.level.isClientSide) { + if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { + return MixinUtil.applyDirectionXRotChange(persp, xRot, yRot, 1.0f); + } else return xRot; + } else return xRot; + } + + @SuppressWarnings("UnreachableCode") + @ModifyVariable(method = "calculateViewVector", at = @At(value = "LOAD"), index = 2, argsOnly = true) + public float adjustYRot(float yRot, @Local(argsOnly = true, index = 1) float xRot) { + if (this.level.isClientSide) { + if (Minecraft.getInstance().getEntityRenderDispatcher().getRenderer((Entity)(Object)this) instanceof Perspective persp && persp.isEnabled()) { + return yRot + MixinUtil.getExtraYRot(persp, xRot, yRot, 1.0f); + } else return yRot; + } else return yRot; + } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java index 8263453..18e6ff9 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.java @@ -3,6 +3,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import net.derfruhling.minecraft.create.trainperspective.MixinUtil; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.Camera; import net.minecraft.client.renderer.GameRenderer; import org.spongepowered.asm.mixin.Final; @@ -13,11 +15,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GameRenderer.class) +@Environment(EnvType.CLIENT) public class GameRendererMixin { @Shadow @Final private Camera mainCamera; @Inject(method = "renderLevel", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;mulPose(Lorg/joml/Quaternionf;)V", ordinal = 2, shift = At.Shift.BEFORE)) public void applyZRotation(float f, long l, PoseStack poseStack, CallbackInfo ci) { poseStack.mulPose(Axis.ZP.rotationDegrees(MixinUtil.asCamera3D(mainCamera).getZRot())); + poseStack.mulPose(Axis.YP.rotationDegrees(MixinUtil.asCamera3D(mainCamera).getExtraYRot())); } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java index 8faae07..9cb1351 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/PlayerRendererMixin.java @@ -2,7 +2,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; +import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; import net.derfruhling.minecraft.create.trainperspective.Perspective; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.util.Mth; @@ -16,35 +19,59 @@ @Mixin(PlayerRenderer.class) @Implements({@Interface(iface = Perspective.class, prefix = "ctp$")}) +@Environment(EnvType.CLIENT) public class PlayerRendererMixin { @Unique private boolean ctp$perspectiveActive = false; - @Unique private float ctp$lean = 0.0f, ctp$yaw = 0.0f; + @Unique private float ctp$lean = 0.0f, ctp$yaw = 0.0f, ctp$oldLean = 0.0f, ctp$oldYaw = 0.0f; public void ctp$enable(float initialLean, float initialYaw) { ctp$perspectiveActive = true; ctp$lean = initialLean; ctp$yaw = initialYaw; + ctp$oldLean = initialLean; + ctp$oldYaw = initialYaw; } public void ctp$disable() { ctp$perspectiveActive = false; ctp$lean = 0.0f; + ctp$yaw = 0.0f; + ctp$oldLean = 0.0f; + ctp$oldYaw = 0.0f; + } + + public boolean ctp$isEnabled() { + return ctp$perspectiveActive; } public void ctp$setLean(float lean) { + ctp$oldLean = ctp$lean; ctp$lean = lean; } public void ctp$setYaw(float yaw) { + // some configurations flip between 0 and 360 constantly + // adjust accordingly + ctp$oldYaw = ctp$yaw; ctp$yaw = yaw; + + while (ctp$yaw - ctp$oldYaw < -180.0f) { + ctp$oldYaw -= 360.0f; + } + + while (ctp$yaw - ctp$oldYaw >= 180.0f) { + ctp$oldYaw += 360.0f; + } } - public float ctp$getLean() { - return ctp$lean; + public float ctp$getLean(float f) { + if(f == 1.0f) return ctp$lean; + return Mth.lerp(f, ctp$oldLean, ctp$lean); } - public float ctp$getYaw() { - return ctp$yaw; + public float ctp$getYaw(float f) { + if(f == 1.0f) return ctp$yaw; + return Mth.lerp(f, ctp$oldYaw, ctp$yaw); } @Inject( diff --git a/common/src/main/resources/create_train_perspective.mixins.json b/common/src/main/resources/create_train_perspective.mixins.json index 4c8eb29..56fb265 100644 --- a/common/src/main/resources/create_train_perspective.mixins.json +++ b/common/src/main/resources/create_train_perspective.mixins.json @@ -5,10 +5,11 @@ "compatibilityLevel": "JAVA_8", "client": [ "CameraMixin", - "ContraptionColliderMixin", + "AbstractContraptionEntityMixin", + "EntityMixin", "GameRendererMixin", "PlayerRendererMixin", - "EntityMixin" + "CreateRaycastHelperMixin" ], "injectors": { "defaultRequire": 1 diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 14206af..75c385b 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -3,11 +3,12 @@ "id": "${mod_id}", "name": "Create: Train Perspective", "description": "Moves your camera (and body!) with the Create Mod train you're riding to increase immersion!", - "version": "${version}+fabric", + "version": "${version}", "contact": { "homepage": "https://github.com/der-fruhling-entertainment/create-train-perspective", "issues": "https://github.com/der-fruhling-entertainment/create-train-perspective/issues", - "sources": "https://github.com/der-fruhling-entertainment/create-train-perspective" + "sources": "https://github.com/der-fruhling-entertainment/create-train-perspective", + "email": "works-on-my-machine@der-fruhling.mozmail.com" }, "license": "MIT", "environment": "client", diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index d2ca209..3af6a5b 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -17,7 +17,7 @@ issueTrackerURL="https://github.com/der-fruhling-entertainment/create-train-pers # The modid of the mod modId="${mod_id}" #mandatory # The version number of the mod -version="${mod_version}+forge" #mandatory +version="${mod_version}" #mandatory # A display name for the mod displayName="Create: Train Perspective" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/ diff --git a/gradle.properties b/gradle.properties index 5d0c324..0ea34bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ quilt_loader_version=0.21.2-beta.2 quilt_fabric_api_version=7.4.0+0.90.0-1.20.1 mod_id=create_train_perspective -mod_version=0.2.3 +mod_version=0.3.0 maven_group=net.derfruhling.minecraft archives_base_name=create-train-perspective @@ -25,5 +25,5 @@ flywheel_minecraft_version=1.20.1 registrate_version=MC1.20-1.3.11 modrinth_project_id=create-train-perspective -modrinth_version_type=release +modrinth_version_type=beta modrinth_game_versions=1.20.1