From c55a36cb77bf49f2e45decaf6ba56ea54a34b539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Tue, 21 May 2024 17:43:31 -0700 Subject: [PATCH 1/3] #53 Mostly add perspective translations --- .../create/trainperspective/ModConfig.java | 20 +++++++++-- .../trainperspective/mixin/CameraMixin.java | 36 +++++++++++++++++++ .../assets/minecraft/lang/en_us.json | 6 +++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/ModConfig.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/ModConfig.java index ad35238..b944260 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/ModConfig.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/ModConfig.java @@ -2,9 +2,8 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.simibubi.create.foundation.config.ui.entries.BooleanEntry; import me.shedaniel.clothconfig2.api.ConfigBuilder; -import me.shedaniel.clothconfig2.api.ConfigScreen; +import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -21,6 +20,7 @@ private ModConfig() {} public boolean rollEnabled = true; public float rollMagnitude = 1.0f; public boolean applyToOthers = true; + public boolean dbgShowStandingTransforms = false; private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); private static final WatchService WATCH_SERVICE; @@ -157,6 +157,22 @@ public static Screen createConfigScreen(Screen parent) { .setDefaultValue(1.0f) .build()); + var debug = entryBuilder.startSubCategory(Component.translatable("category.create_train_perspective.debug")); + + debug.add(entryBuilder + .startTextDescription(Component.translatable("category.create_train_perspective.debug.description").withStyle(ChatFormatting.BOLD)) + .build()); + + debug.add(entryBuilder + .startBooleanToggle( + Component.translatable("option.create_train_perspective.debug.standing_transforms"), + INSTANCE.dbgShowStandingTransforms) + .setSaveConsumer(value -> INSTANCE.dbgShowStandingTransforms = value) + .setTooltip(Component.translatable("option.create_train_perspective.debug.standing_transforms.tooltip")) + .setDefaultValue(false) + .build()); + + advanced.add(debug.build()); general.addEntry(advanced.build()); return builder.build(); 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 0393462..28f612d 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 @@ -7,6 +7,7 @@ import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import org.joml.Quaternionf; @@ -27,6 +28,8 @@ public abstract class CameraMixin { @Shadow @Final private Quaternionf rotation; + @Shadow protected abstract void setPosition(double d, double e, double f); + @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 * Mth.DEG_TO_RAD); @@ -72,4 +75,37 @@ public void modifyRotations(Camera instance, setRotation(y, x); } } + + @Redirect(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setPosition(DDD)V")) + public void modifyPosition(Camera instance, + double x, + double y, + double z, + @Local(argsOnly = true, ordinal = 0) boolean isThirdPerson, + @Local(argsOnly = true) float f) { + if(entity instanceof AbstractClientPlayer player + && Conditional.shouldApplyPerspectiveTo(entity) + && Conditional.shouldApplyLeaning() + && player.getVehicle() == null + && !isThirdPerson) { + var persp = (Perspective) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); + var lean = persp.getLean(f); + var yaw = persp.getYaw(f); + + var height = player.getEyeHeight(); + // var leanFactor = (1.0f - Mth.cos(2.0f * lean * Mth.DEG_TO_RAD)) / 2.0f; + var leanFactor = (lean / 90.0f); + var newY = y - (height * leanFactor); + var newX = x - Mth.abs(height * height * (Mth.cos(yaw * Mth.DEG_TO_RAD)) * leanFactor); + var newZ = z - Mth.abs(height * height * (Mth.sin(yaw * Mth.DEG_TO_RAD)) * leanFactor); + + if(ModConfig.INSTANCE.dbgShowStandingTransforms) { + player.displayClientMessage(Component.literal(String.format("%f, %f, %f", newX - x, newY - y, newZ - z)), true); + } + + setPosition(newX, newY, newZ); + } else { + setPosition(x, y, z); + } + } } diff --git a/common/src/main/resources/assets/minecraft/lang/en_us.json b/common/src/main/resources/assets/minecraft/lang/en_us.json index fe73d39..c238e8b 100644 --- a/common/src/main/resources/assets/minecraft/lang/en_us.json +++ b/common/src/main/resources/assets/minecraft/lang/en_us.json @@ -5,6 +5,8 @@ "category.create_train_perspective.leaning": "Leaning", "category.create_train_perspective.multiplayer": "Multiplayer", "category.create_train_perspective.advanced": "Advanced", + "category.create_train_perspective.debug": "Debug Features", + "category.create_train_perspective.debug.description": "These are debugging features used for development. You probably don't want to touch these unless you're working on the mod itself.", "option.create_train_perspective.enabled": "Enabled", "option.create_train_perspective.enabled.tooltip": "Enables the mod. If False, the mod is disabled.", @@ -17,5 +19,7 @@ "option.create_train_perspective.advanced.lean_magnitude": "Leaning Magnitude", "option.create_train_perspective.advanced.lean_magnitude.tooltip": "The magnitude to which the player will lean. Higher = more intense.", "option.create_train_perspective.advanced.roll_magnitude": "Rolling Magnitude", - "option.create_train_perspective.advanced.roll_magnitude.tooltip": "The magnitude to which the player will roll. Higher = more intense." + "option.create_train_perspective.advanced.roll_magnitude.tooltip": "The magnitude to which the player will roll. Higher = more intense.", + "option.create_train_perspective.debug.standing_transforms": "Show Standing Translations", + "option.create_train_perspective.debug.standing_transforms.tooltip": "Shows translations used to transform the player while standing on a train. (X, Y, Z)" } \ No newline at end of file From d66f816bff144c68baac7ac1530e915b08f43042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Tue, 21 May 2024 17:44:08 -0700 Subject: [PATCH 2/3] #53 Bonus: magic number fix --- .../create/trainperspective/mixin/PlayerRendererMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c8012a6..aa752e3 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 @@ -97,7 +97,7 @@ protected void setupRotations(AbstractClientPlayer p_117802_, PoseStack p_117803 float height = 0; if(p_117802_.getVehicle() != null) { - height = 1.4f; + height = p_117802_.getEyeHeight(); } p_117803_.rotateAround(Axis.ZP.rotationDegrees(Mth.cos(Mth.DEG_TO_RAD * ctp$yaw) * ctp$lean), 0, height, 0); From 6ceccd0742d83c7f2964d635327c58e4e587872f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Tue, 21 May 2024 17:44:29 -0700 Subject: [PATCH 3/3] #53 Bonus: add mixin agent to fabric client --- build.gradle | 5 +++++ fabric/build.gradle | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/build.gradle b/build.gradle index 3761ae0..cd3af5e 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,10 @@ subprojects { apply plugin: "dev.architectury.loom" apply plugin: "maven-publish" + configurations { + mixinDependency + } + loom { silentMojangMappingsLicense() } @@ -24,6 +28,7 @@ subprojects { dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" mappings loom.officialMojangMappings() + mixinDependency("net.fabricmc:sponge-mixin:0.12.5+mixin.0.8.5") { transitive = false } } publishing { diff --git a/fabric/build.gradle b/fabric/build.gradle index 3978cde..b2e317c 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -8,6 +8,21 @@ architectury { fabric() } +loom { + runs { + client { + client() + ideConfigGenerated = true + + configurations.mixinDependency.files.each { + vmArg "-javaagent:$it.absolutePath".toString() + } + + source sourceSets.main + } + } +} + configurations { common shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.