From 8dd927e8511da6a1fcd211aa21ad9ca0c2944d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 14:57:07 -0700 Subject: [PATCH 1/7] more cleanup --- .../create/trainperspective/CreateTrainPerspectiveMod.java | 6 ------ 1 file changed, 6 deletions(-) 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 759d396..63c38fd 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 @@ -1,23 +1,17 @@ package net.derfruhling.minecraft.create.trainperspective; -import com.mojang.logging.LogUtils; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import dev.architectury.event.events.common.TickEvent; import net.minecraft.client.Minecraft; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import org.slf4j.Logger; import java.util.*; -// The value here should match an entry in the META-INF/mods.toml file public class CreateTrainPerspectiveMod { - // Define mod id in a common place for everything to reference public static final String MODID = "create_train_perspective"; public static CreateTrainPerspectiveMod INSTANCE; - // Directly reference a slf4j logger - private static final Logger LOGGER = LogUtils.getLogger(); public CreateTrainPerspectiveMod() { TickEvent.PLAYER_POST.register(this::onTickPlayer); From 0f1e0788b97ca254365d393ea532e6a0bf0a897c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 16:12:58 -0700 Subject: [PATCH 2/7] correctly apply roll in CameraMixin --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 025b314..e850164 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 @@ -33,7 +33,7 @@ public abstract class CameraMixin { @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; + return original + (ctp$zRot * Mth.DEG_TO_RAD); } @Inject(method = "setRotation", at = @At(value = "INVOKE", target = "Lorg/joml/Quaternionf;rotationYXZ(FFF)Lorg/joml/Quaternionf;", shift = At.Shift.AFTER)) From ea7347a025ed5add69872a435b7cafa4ffdf3067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 16:13:56 -0700 Subject: [PATCH 3/7] this fixes #39 but idk if i'm happy about it --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e850164..5809c13 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 @@ -38,7 +38,7 @@ private float modifyRoll(float original) { @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); + //this.rotation.rotateY(ctp$extraYRot * Mth.DEG_TO_RAD); } @Unique From bfb6bf641c61d9cd1225608954264a302dc4b281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 17:18:45 -0700 Subject: [PATCH 4/7] i did something --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 5809c13..18f3fd2 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 @@ -59,7 +59,9 @@ public void modifyRotationsPrimary(Camera instance, @Local(argsOnly = true) float f) { if(entity instanceof AbstractClientPlayer player && !isThirdPerson) { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); - ctp$zRot = persp.getLean(f) * Mth.cos((persp.getYaw(f) - y) * Mth.DEG_TO_RAD); + ctp$zRot = persp.getLean(f) + * Mth.cos((persp.getYaw(f) - y) * Mth.DEG_TO_RAD) + * Mth.sin((x * Mth.DEG_TO_RAD + Mth.PI) / 2.0f); ctp$extraYRot = MixinUtil.getExtraYRot(persp, x, y, f); setRotation( y, From 73a0f4cbe312e8cc2bf8b62c3faf6ac561fe0888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 17:28:02 -0700 Subject: [PATCH 5/7] Update changelog and version --- changelog.md | 32 +++++--------------------------- changelog.txt | 12 ++++-------- gradle.properties | 2 +- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/changelog.md b/changelog.md index b126835..8272e15 100644 --- a/changelog.md +++ b/changelog.md @@ -1,36 +1,14 @@ -Major update to fix major problems. The mod is in a pretty good state now. +Smaller update to fix some issues. -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. +Changelog: +- Cleaned up some code. +- Mod applies to other players now. (probably) +- Sound system & fog fix. [View issue.](https://github.com/der-fruhling/create-train-perspective/issues/39) [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) - ---- - Issues? Feature Requests? [View the issue tracker!](https://github.com/der-fruhling-entertainment/create-train-perspective/issues) diff --git a/changelog.txt b/changelog.txt index 0f44573..95a23e9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,13 +1,9 @@ -Major update to fix major problems. The mod is in a pretty good state now. +Smaller update to fix some issues. [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. +- Cleaned up some code. +- Mod applies to other players now. (probably) +- Sound system & fog fix. https://github.com/der-fruhling/create-train-perspective/issues/39 Commits: https://github.com/der-fruhling/create-train-perspective/compare/v0.2.3...v0.3.0 diff --git a/gradle.properties b/gradle.properties index 0ea34bc..fc5b11e 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.3.0 +mod_version=0.3.1 maven_group=net.derfruhling.minecraft archives_base_name=create-train-perspective From 57f96115b7fefac0e8c0f30be648dee16c1330bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 17:28:43 -0700 Subject: [PATCH 6/7] [squeaky clean] remove function consisting of only commented code --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 5 ----- 1 file changed, 5 deletions(-) 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 18f3fd2..44871ab 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 @@ -36,11 +36,6 @@ private float modifyRoll(float original) { return original + (ctp$zRot * Mth.DEG_TO_RAD); } - @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 * Mth.DEG_TO_RAD); - } - @Unique public float c3d$getZRot() { return this.ctp$zRot; From e972bba39c497e0a5cb36da826f32e7a52ffdd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Sun, 19 May 2024 17:57:09 -0700 Subject: [PATCH 7/7] [squeaky clean] it's squeaky clean now --- .../CreateTrainPerspectiveMod.java | 68 ++++++++++--------- .../create/trainperspective/Perspective.java | 2 +- .../trainperspective/RotationState.java | 36 +++++----- .../trainperspective/RotationStateKeeper.java | 2 +- .../mixin/AbstractContraptionEntityMixin.java | 9 ++- .../trainperspective/mixin/CameraMixin.java | 12 ++-- .../mixin/CreateRaycastHelperMixin.java | 12 ++-- .../trainperspective/mixin/EntityMixin.java | 24 +++---- .../mixin/GameRendererMixin.java | 2 +- 9 files changed, 86 insertions(+), 81 deletions(-) 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 63c38fd..ae59a25 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 @@ -3,9 +3,7 @@ import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import dev.architectury.event.events.common.TickEvent; import net.minecraft.client.Minecraft; -import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import java.util.*; @@ -14,46 +12,53 @@ public class CreateTrainPerspectiveMod { public static CreateTrainPerspectiveMod INSTANCE; public CreateTrainPerspectiveMod() { - TickEvent.PLAYER_POST.register(this::onTickPlayer); + TickEvent.PLAYER_POST.register(this::tickEntity); INSTANCE = this; } - public void onEntityMount(boolean isMounting, Entity entityMounting, Entity entityBeingMounted) { + public void onEntityMountEvent(boolean isMounting, Entity entityMounting, Entity entityBeingMounted) { if( - entityMounting instanceof AbstractClientPlayer player && + Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(entityMounting) instanceof Perspective persp && entityBeingMounted instanceof CarriageContraptionEntity contraption ) { - var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); if(isMounting) { - if(persp.getRotationState() == null) { - var state = new RotationState(contraption, false, true); - persp.setRotationState(state); - var carriage = state.getCarriageEntity(); - assert carriage != null; - persp.enable(carriage.pitch, carriage.yaw); - } else { - var state = persp.getRotationState(); - state.onMounted(); - } + onEntityMount(persp, contraption); } else { - if(persp.getRotationState() != null) { - persp.setRotationState(null); - persp.disable(); - } + onEntityDismount(persp); } } } - public void tickStandingPlayer(final CarriageContraptionEntity contraption, final Player player) { - if(player.getVehicle() != null) return; + public void onEntityMount(Perspective persp, CarriageContraptionEntity contraption) { + if(persp.getRotationState() == null) { + var state = new RotationState(contraption, false, true); + persp.setRotationState(state); + var carriage = state.getContraption(); + assert carriage != null; + persp.enable(carriage.pitch, carriage.yaw); + } else { + var state = persp.getRotationState(); + state.onMounted(); + } + } + + private void onEntityDismount(Perspective persp) { + if(persp.getRotationState() != null) { + persp.setRotationState(null); + persp.disable(); + } + } + + public void tickStandingEntity(final CarriageContraptionEntity contraption, final Entity entity) { + if(entity.getVehicle() != null) return; - var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(entity); var state = persp.getRotationState(); - if (state == null || !Objects.equals(state.getCarriageEntity(), contraption)) { + if (state == null || !Objects.equals(state.getContraption(), contraption)) { state = new RotationState(contraption, true, false); persp.setRotationState(state); - var carriage = state.getCarriageEntity(); + var carriage = state.getContraption(); assert carriage != null; persp.enable(carriage.pitch, carriage.yaw); } else { @@ -61,8 +66,8 @@ public void tickStandingPlayer(final CarriageContraptionEntity contraption, fina } } - private void tickState(Player player, Perspective persp, RotationState state) { - var carriage = state.getCarriageEntity(); + private void tickPerspectiveState(Entity player, Perspective persp, RotationState state) { + var carriage = state.getContraption(); if(carriage == null) return; persp.setLean(carriage.pitch); persp.setYaw(carriage.yaw); @@ -78,19 +83,18 @@ private void tickState(Player player, Perspective persp, RotationState state) { } } - public void onTickPlayer(final Player player) { - if(!(player instanceof AbstractClientPlayer)) return; - if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp + public void tickEntity(final Entity entity) { + if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(entity) instanceof Perspective persp && persp.getRotationState() != null) { var state = persp.getRotationState(); assert state != null; if(state.shouldTickState()) { - tickState(player, persp, state); + tickPerspectiveState(entity, persp, state); } else { persp.diminish(); - if(persp.diminished()) { + if(persp.isDiminished()) { persp.setRotationState(null); persp.disable(); } 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 b9b2d3f..005ffcb 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 @@ -18,7 +18,7 @@ default void diminish() { setLean(getLean(1.0f) * 0.9f); } - default boolean diminished() { + default boolean isDiminished() { return Mth.abs(getLean(1.0f)) < 0.01f; } } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationState.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationState.java index a91a102..523e1b0 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationState.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationState.java @@ -4,48 +4,48 @@ import org.jetbrains.annotations.Nullable; public class RotationState implements RotationStateKeeper { - private CarriageContraptionEntity entity; - private float lastYaw; - private final boolean standingState; + private CarriageContraptionEntity contraption; + private float lastRecordedYaw; + private final boolean isStandingState; private boolean isMounted; private boolean shouldTickState = true; private int ticksSinceLastUpdate = 0; - public RotationState(CarriageContraptionEntity entity, boolean standingState, boolean isMounted) { - this.entity = entity; - lastYaw = entity.yaw; - this.standingState = standingState; + public RotationState(CarriageContraptionEntity contraption, boolean isStandingState, boolean isMounted) { + this.contraption = contraption; + lastRecordedYaw = contraption.yaw; + this.isStandingState = isStandingState; this.isMounted = isMounted; } @Override public float getYawDelta() { - while (entity.yaw - lastYaw < -180.0f) { - lastYaw -= 360.0f; + while (contraption.yaw - lastRecordedYaw < -180.0f) { + lastRecordedYaw -= 360.0f; } - while (entity.yaw - lastYaw >= 180.0f) { - lastYaw += 360.0f; + while (contraption.yaw - lastRecordedYaw >= 180.0f) { + lastRecordedYaw += 360.0f; } - var rotation = entity.yaw - lastYaw; - lastYaw = entity.yaw; + var rotation = contraption.yaw - lastRecordedYaw; + lastRecordedYaw = contraption.yaw; return rotation; } @Override - public @Nullable CarriageContraptionEntity getCarriageEntity() { - return entity; + public @Nullable CarriageContraptionEntity getContraption() { + return contraption; } @Override - public void setCarriageEntity(@Nullable CarriageContraptionEntity entity) { - this.entity = entity; + public void setCarriageEntity(@Nullable CarriageContraptionEntity contraption) { + this.contraption = contraption; } @Override public boolean isStanding() { - return standingState; + return isStandingState; } @Override diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationStateKeeper.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationStateKeeper.java index 8be5110..655ab77 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationStateKeeper.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/RotationStateKeeper.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.Nullable; public interface RotationStateKeeper { - @Nullable CarriageContraptionEntity getCarriageEntity(); + @Nullable CarriageContraptionEntity getContraption(); void setCarriageEntity(@Nullable CarriageContraptionEntity entity); boolean isStanding(); boolean isMounted(); diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java index c072623..2ae1f8a 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/AbstractContraptionEntityMixin.java @@ -3,10 +3,11 @@ import com.simibubi.create.content.contraptions.AbstractContraptionEntity; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; 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.Minecraft; 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; @@ -21,8 +22,10 @@ private void onRegisterColliding( Entity entity, CallbackInfo ci ) { - if((Object) this instanceof CarriageContraptionEntity carriage && entity instanceof Player player) { - CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayer(carriage, player); + if(!entity.level().isClientSide) return; + if((Object) this instanceof CarriageContraptionEntity carriage && + Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(entity) instanceof Perspective) { + CreateTrainPerspectiveMod.INSTANCE.tickStandingEntity(carriage, entity); } } } 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 44871ab..592a57e 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 @@ -14,10 +14,8 @@ 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$")}) @@ -47,11 +45,11 @@ private float modifyRoll(float original) { } @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 = 0) boolean isThirdPerson, - @Local(argsOnly = true) float f) { + public void modifyRotations(Camera instance, + float y, + float x, + @Local(argsOnly = true, ordinal = 0) boolean isThirdPerson, + @Local(argsOnly = true) float f) { if(entity instanceof AbstractClientPlayer player && !isThirdPerson) { var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); ctp$zRot = persp.getLean(f) 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 index 86defd0..2ccce5a 100644 --- 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 @@ -12,16 +12,16 @@ @Mixin(RaycastHelper.class) public class CreateRaycastHelperMixin { @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 4) - private static float modifyXRot(float value, Player player) { + private static float modifyPitch(float pitch, Player player) { if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { - return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot(), 1.0f); - } else return value; + return MixinUtil.applyDirectionXRotChange(persp, pitch, player.getYRot(), 1.0f); + } else return pitch; } @ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 5) - private static float modifyYRot(float value, Player player) { + private static float modifyYaw(float yaw, Player player) { if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { - return value + MixinUtil.getExtraYRot(persp, player.getXRot(), value, 1.0f); - } else return value; + return yaw + MixinUtil.getExtraYRot(persp, player.getXRot(), yaw, 1.0f); + } else return yaw; } } 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 c067f41..fef438c 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 @@ -23,34 +23,34 @@ public abstract class EntityMixin { @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) { - CreateTrainPerspectiveMod.INSTANCE.onEntityMount(true, (Entity)(Object)this, entity); + public void onMount(Entity entity, boolean bl, CallbackInfoReturnable cir) { + CreateTrainPerspectiveMod.INSTANCE.onEntityMountEvent(true, (Entity)(Object)this, entity); } @Inject(method = "removeVehicle", at = @At("HEAD")) - public void onRemoveVehicle(CallbackInfo ci) { + public void onDismount(CallbackInfo ci) { if(vehicle != null) { - CreateTrainPerspectiveMod.INSTANCE.onEntityMount(false, (Entity)(Object)this, vehicle); + CreateTrainPerspectiveMod.INSTANCE.onEntityMountEvent(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) { + public float modifyPitch(float pitch, @Local(argsOnly = true, index = 2) float yaw) { 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; + return MixinUtil.applyDirectionXRotChange(persp, pitch, yaw, 1.0f); + } else return pitch; + } else return pitch; } @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) { + public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch) { 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; + return yaw + MixinUtil.getExtraYRot(persp, pitch, yaw, 1.0f); + } else return yaw; + } else return yaw; } } 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 18e6ff9..59035c7 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 @@ -20,7 +20,7 @@ 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) { + public void applyLevelRotations(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())); }