From 39fc39e1ec9eb9a9f7015ff9e0a70c9fde1f2df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Wed, 7 Aug 2024 16:29:19 -0700 Subject: [PATCH 1/6] #67 workaround for figura to work --- .../minecraft/create/trainperspective/mixin/CameraMixin.java | 3 ++- 1 file changed, 2 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 f49be03..c5f48d3 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 @@ -15,7 +15,8 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(Camera.class) +// workaround for figura to work (this is terrible but works) +@Mixin(value = Camera.class, priority = 1100) @Implements({@Interface(iface = Camera3D.class, prefix = "c3d$")}) @Environment(EnvType.CLIENT) public abstract class CameraMixin { From 10bf53b39568418c9bbf7f3db9925b350e6535fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Wed, 7 Aug 2024 16:48:33 -0700 Subject: [PATCH 2/6] serious smoothness --- .../CreateTrainPerspectiveMod.java | 7 +-- .../create/trainperspective/Perspective.java | 31 +++++++--- .../trainperspective/mixin/EntityMixin.java | 57 ++++++++----------- 3 files changed, 50 insertions(+), 45 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 25c81f9..761a1a0 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 @@ -36,7 +36,7 @@ public void onEntityMount(Perspective persp, CarriageContraptionEntity contrapti persp.setRotationState(state); var carriage = state.getContraption(); assert carriage != null; - persp.enable(carriage.pitch, carriage.yaw); + persp.enable(carriage); } else { var state = persp.getRotationState(); state.onMounted(); @@ -60,7 +60,7 @@ public void tickStandingEntity(final CarriageContraptionEntity contraption, fina persp.setRotationState(state); var carriage = state.getContraption(); assert carriage != null; - persp.enable(carriage.pitch, carriage.yaw); + persp.enable(carriage); } else { state.update(); } @@ -69,8 +69,7 @@ public void tickStandingEntity(final CarriageContraptionEntity contraption, fina 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); + persp.setReference(carriage); player.setYRot(player.getYRot() + state.getYawDelta()); player.setYBodyRot(player.getYRot()); 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 5042d74..38a3cbd 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,31 +1,46 @@ package net.derfruhling.minecraft.create.trainperspective; +import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.Nullable; public interface Perspective { - void enable(float initialLean, float initialYaw); + void enable(CarriageContraptionEntity entity); void disable(); boolean isEnabled(); - void setLean(float lean); + void setReference(CarriageContraptionEntity entity); - void setYaw(float yaw); + @Nullable + CarriageContraptionEntity getReference(); - float getLean(float f); + default float getLean(float f) { + var ref = getReference(); + if (ref == null) return 0.0f; + if (f == 1.0f) return ref.pitch * getScale(); + return Mth.lerp(f, ref.prevPitch * getPrevScale(), ref.pitch * getScale()); + } - float getYaw(float f); + default float getYaw(float f) { + var ref = getReference(); + if (ref == null) return 0.0f; + if (f == 1.0f) return ref.yaw * getScale(); + return Mth.lerp(f, ref.prevYaw * getPrevScale(), ref.yaw * getScale()); + } @Nullable RotationState getRotationState(); void setRotationState(@Nullable RotationState state); - default void diminish() { - setLean(getLean(1.0f) * 0.9f); - } + void diminish(); + + float getPrevScale(); + + float getScale(); default boolean isDiminished() { return Mth.abs(getLean(1.0f)) < 0.01f; 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 bded9c6..f916823 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,6 +1,7 @@ package net.derfruhling.minecraft.create.trainperspective.mixin; import com.llamalad7.mixinextras.sugar.Local; +import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import net.derfruhling.minecraft.create.trainperspective.*; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -28,7 +29,9 @@ public abstract class EntityMixin { @Unique private boolean ctp$perspectiveActive = false; @Unique - private float ctp$lean = 0.0f, ctp$yaw = 0.0f, ctp$oldLean = 0.0f, ctp$oldYaw = 0.0f; + private @Nullable CarriageContraptionEntity ctp$reference = null; + @Unique + private float ctp$scale = 1.0f, ctp$prevScale = 1.0f; @Unique private @Nullable RotationState ctp$currentState = null; @@ -74,54 +77,42 @@ public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch } else return yaw; } - public void ctp$enable(float initialLean, float initialYaw) { + public void ctp$enable(CarriageContraptionEntity entity) { ctp$perspectiveActive = true; - ctp$lean = initialLean; - ctp$yaw = initialYaw; - ctp$oldLean = initialLean; - ctp$oldYaw = initialYaw; + ctp$reference = entity; } public void ctp$disable() { ctp$perspectiveActive = false; - ctp$lean = 0.0f; - ctp$yaw = 0.0f; - ctp$oldLean = 0.0f; - ctp$oldYaw = 0.0f; + ctp$reference = null; } - public boolean ctp$isEnabled() { - return ctp$perspectiveActive; + public void ctp$setReference(CarriageContraptionEntity entity) { + ctp$reference = entity; + ctp$prevScale = ctp$scale; + ctp$scale = 1.0f; } - public void ctp$setLean(float lean) { - ctp$oldLean = ctp$lean; - ctp$lean = lean; + public CarriageContraptionEntity ctp$getReference() { + return ctp$reference; } - 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; - } + public void ctp$diminish() { + if (ctp$scale <= 0.0f) return; + ctp$prevScale = ctp$scale; + ctp$scale -= 0.99f; + } - while (ctp$yaw - ctp$oldYaw >= 180.0f) { - ctp$oldYaw += 360.0f; - } + public float ctp$getScale() { + return ctp$scale; } - public float ctp$getLean(float f) { - if (f == 1.0f) return ctp$lean; - return Mth.lerp(f, ctp$oldLean, ctp$lean); + public float ctp$getPrevScale() { + return ctp$prevScale; } - public float ctp$getYaw(float f) { - if (f == 1.0f) return ctp$yaw; - return Mth.lerp(f, ctp$oldYaw, ctp$yaw); + public boolean ctp$isEnabled() { + return ctp$perspectiveActive; } public @Nullable RotationState ctp$getRotationState() { From ae32868c50b5b1169955a2d39928b5847e6e5f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 8 Aug 2024 13:49:33 -0700 Subject: [PATCH 3/6] fix the scale and add debug options --- .../create/trainperspective/ModConfig.java | 11 +++++++++ .../create/trainperspective/Perspective.java | 18 +++++++------- .../trainperspective/mixin/EntityMixin.java | 14 +++++++---- .../mixin/LocalPlayerMixin.java | 24 ++++++++++++++++++- .../assets/minecraft/lang/en_us.json | 6 +++-- 5 files changed, 58 insertions(+), 15 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 ad7dfe6..5e2bca4 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 @@ -40,6 +40,7 @@ public class ModConfig { public boolean applyToNonPlayerEntities = true; public List blockedEntities = new ArrayList<>(); public boolean dbgShowStandingTransforms = false; + public boolean dbgShowValueScales = false; private ModConfig() { } @@ -187,6 +188,16 @@ public static Screen createConfigScreen(Screen parent) { .setDefaultValue(false) .build()); + + debug.add(entryBuilder + .startBooleanToggle( + Component.translatable("option.create_train_perspective.debug.value_scales"), + INSTANCE.dbgShowValueScales) + .setSaveConsumer(value -> INSTANCE.dbgShowValueScales = value) + .setTooltip(Component.translatable("option.create_train_perspective.debug.value_scales.tooltip")) + .setDefaultValue(false) + .build()); + advanced.add(debug.build()); general.addEntry(advanced.build()); 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 38a3cbd..e12c62a 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 @@ -2,7 +2,6 @@ import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.Nullable; public interface Perspective { @@ -20,15 +19,15 @@ public interface Perspective { default float getLean(float f) { var ref = getReference(); if (ref == null) return 0.0f; - if (f == 1.0f) return ref.pitch * getScale(); - return Mth.lerp(f, ref.prevPitch * getPrevScale(), ref.pitch * getScale()); + if (f == 1.0f) return ref.pitch * getValueScale(); + return Mth.lerp(f, ref.prevPitch * getPrevValueScale(), ref.pitch * getValueScale()); } default float getYaw(float f) { var ref = getReference(); if (ref == null) return 0.0f; - if (f == 1.0f) return ref.yaw * getScale(); - return Mth.lerp(f, ref.prevYaw * getPrevScale(), ref.yaw * getScale()); + if (f == 1.0f) return ref.yaw * getValueScale(); + return Mth.lerp(f, ref.prevYaw * getPrevValueScale(), ref.yaw * getValueScale()); } @Nullable @@ -38,11 +37,14 @@ default float getYaw(float f) { void diminish(); - float getPrevScale(); + float getPrevValueScale(); - float getScale(); + // this must not be named getScale()!!!! + // Entity (or something) has a method also called getScale() that conflicts + // with this method in a fuckey way. + float getValueScale(); default boolean isDiminished() { - return Mth.abs(getLean(1.0f)) < 0.01f; + return getValueScale() < 0.00025f; } } 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 f916823..ed5d608 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 @@ -31,7 +31,9 @@ public abstract class EntityMixin { @Unique private @Nullable CarriageContraptionEntity ctp$reference = null; @Unique - private float ctp$scale = 1.0f, ctp$prevScale = 1.0f; + private float ctp$scale = 1.0f; + @Unique + private float ctp$prevScale = 1.0f; @Unique private @Nullable RotationState ctp$currentState = null; @@ -80,11 +82,15 @@ public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch public void ctp$enable(CarriageContraptionEntity entity) { ctp$perspectiveActive = true; ctp$reference = entity; + ctp$prevScale = 1.0f; + ctp$scale = 1.0f; } public void ctp$disable() { ctp$perspectiveActive = false; ctp$reference = null; + ctp$prevScale = 1.0f; + ctp$scale = 1.0f; } public void ctp$setReference(CarriageContraptionEntity entity) { @@ -100,14 +106,14 @@ public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch public void ctp$diminish() { if (ctp$scale <= 0.0f) return; ctp$prevScale = ctp$scale; - ctp$scale -= 0.99f; + ctp$scale = Mth.lerp(0.1f, ctp$scale, 0.0f); } - public float ctp$getScale() { + public float ctp$getValueScale() { return ctp$scale; } - public float ctp$getPrevScale() { + public float ctp$getPrevValueScale() { return ctp$prevScale; } diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java index 4209e9d..e2c4292 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java @@ -2,23 +2,45 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.mojang.authlib.GameProfile; +import net.derfruhling.minecraft.create.trainperspective.ModConfig; import net.derfruhling.minecraft.create.trainperspective.Perspective; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Final; 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.callback.CallbackInfo; @Mixin(value = LocalPlayer.class) -public class LocalPlayerMixin { +public abstract class LocalPlayerMixin extends AbstractClientPlayer { @Shadow @Final protected Minecraft minecraft; + @Shadow public abstract void displayClientMessage(Component arg, boolean bl); + + public LocalPlayerMixin(ClientLevel clientLevel, GameProfile gameProfile) { + super(clientLevel, gameProfile); + } + @WrapOperation(method = "getViewYRot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isPassenger()Z")) public boolean isPassenger(LocalPlayer localPlayer, Operation original) { var perspective = (Perspective) localPlayer; return original.call(localPlayer) || perspective.isEnabled(); } + + @Inject(method = "tick", at = @At(value = "TAIL")) + public void tickDebugFeatures(CallbackInfo ci) { + var persp = (Perspective) this; + + if(ModConfig.INSTANCE.dbgShowValueScales) { + this.displayClientMessage(Component.literal(persp.getValueScale() + ", " + persp.getPrevValueScale()), true); + } + } } 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 b494b15..224b254 100644 --- a/common/src/main/resources/assets/minecraft/lang/en_us.json +++ b/common/src/main/resources/assets/minecraft/lang/en_us.json @@ -5,7 +5,7 @@ "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.", + "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, and you should only enable one at a time if you want them to mean anything.", "option.create_train_perspective.enabled": "Enabled", "option.create_train_perspective.enabled.tooltip": "Enables the mod. If False, the mod is disabled.", "option.create_train_perspective.leaning.enabled": "Enable Leaning", @@ -23,5 +23,7 @@ "option.create_train_perspective.advanced.blocked_entities": "Blocked entities", "option.create_train_perspective.advanced.blocked_entities.tooltip": "Entities with an ID in this list will not be considered for this mod's functionality", "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)" + "option.create_train_perspective.debug.standing_transforms.tooltip": "Shows translations used to transform the player while standing on a train. (X, Y, Z)", + "option.create_train_perspective.debug.value_scales": "Show Value Scales", + "option.create_train_perspective.debug.value_scales.tooltip": "Shows scalars used to scale leaning and yaw after leaving a train. (CURRENT, LAST)" } \ No newline at end of file From 651ef45f3dc6664cc8e8474073a5714c2a5152e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 8 Aug 2024 13:59:55 -0700 Subject: [PATCH 4/6] calculate height based on camera y - foot y instead of relying on minecraft being correct --- .../minecraft/create/trainperspective/MixinUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e7a46b1..e40d948 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 @@ -27,7 +27,7 @@ public static float getExtraYRot(Perspective persp, float xRot, float yRot, floa public static Vector3d applyStandingCameraTranslation(Player player, double x, double y, double z, Perspective persp, float f) { var lean = persp.getLean(f) * Mth.DEG_TO_RAD; var yaw = persp.getYaw(f) * Mth.DEG_TO_RAD; - var height = player.getEyeHeight(); + var height = y - player.getY(); var newY = y + ((height * Mth.cos(lean)) - height); var leanSin = Mth.sin(lean); var newZ = z - (height * Mth.sin(yaw) * leanSin); From 0a68ce1d9a6df97342f3f42003cebc757cece3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 8 Aug 2024 14:49:45 -0700 Subject: [PATCH 5/6] refactor and document a bit --- .../create/trainperspective/Camera3D.java | 26 +++++ .../create/trainperspective/Conditional.java | 26 +++++ .../CreateTrainPerspectiveMod.java | 39 +++++-- .../create/trainperspective/MixinUtil.java | 26 +++++ .../create/trainperspective/ModConfig.java | 26 +++++ .../create/trainperspective/Perspective.java | 89 +++++++++++++- .../trainperspective/RotationState.java | 110 +++++++++++++++++- .../mixin/AbstractContraptionEntityMixin.java | 26 +++++ .../trainperspective/mixin/CameraMixin.java | 26 +++++ .../mixin/ClientLevelMixin.java | 26 +++++ .../mixin/CreateRaycastHelperMixin.java | 26 +++++ .../trainperspective/mixin/EntityMixin.java | 32 ++++- .../mixin/GameRendererMixin.java | 26 +++++ .../mixin/LivingEntityRendererMixin.java | 26 +++++ .../mixin/LocalPlayerMixin.java | 26 +++++ .../fabric/ConfigIntegration.java | 26 +++++ .../fabric/ModFabricEntrypoint.java | 26 +++++ .../forge/ModForgeEntrypoint.java | 26 +++++ 18 files changed, 619 insertions(+), 15 deletions(-) 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 6aed625..46f3115 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 @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; public interface Camera3D { diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Conditional.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Conditional.java index 7fead56..65f0109 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Conditional.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Conditional.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; import net.minecraft.client.player.LocalPlayer; 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 761a1a0..034e4ee 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,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; @@ -33,10 +59,7 @@ public void onEntityMountEvent(boolean isMounting, Entity entityMounting, Entity public void onEntityMount(Perspective persp, CarriageContraptionEntity contraption) { if (persp.getRotationState() == null) { var state = new RotationState(contraption, false); - persp.setRotationState(state); - var carriage = state.getContraption(); - assert carriage != null; - persp.enable(carriage); + persp.enable(contraption, state); } else { var state = persp.getRotationState(); state.onMounted(); @@ -57,10 +80,7 @@ public void tickStandingEntity(final CarriageContraptionEntity contraption, fina if (state == null || !Objects.equals(state.getContraption(), contraption)) { state = new RotationState(contraption, true); - persp.setRotationState(state); - var carriage = state.getContraption(); - assert carriage != null; - persp.enable(carriage); + persp.enable(contraption, state); } else { state.update(); } @@ -77,7 +97,7 @@ private void tickPerspectiveState(Entity player, Perspective persp, RotationStat state.tick(); if (state.getTicksSinceLastUpdate() > 5) { - state.setShouldTickState(false); + state.stopTickingState(); } } } @@ -93,7 +113,6 @@ public void tickEntity(Entity entity, Perspective persp) { persp.diminish(); if (persp.isDiminished()) { - persp.setRotationState(null); 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 e40d948..8303d6e 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,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; import net.minecraft.client.Camera; 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 5e2bca4..09051af 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 @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; import com.google.gson.Gson; 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 e12c62a..516c454 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,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; @@ -5,17 +31,45 @@ import org.jetbrains.annotations.Nullable; public interface Perspective { - void enable(CarriageContraptionEntity entity); + /** + * Enables this perspective and attaches it to the provided carriage + * contraption entity. + * + * @param entity The entity. + */ + void enable(CarriageContraptionEntity entity, RotationState state); + /** + * Disables this perspective and resets it to the default state. + */ void disable(); + /** + * @return {@code true} if enabled. + */ boolean isEnabled(); + /** + * Sets the new reference carriage contraption entity for this perspective. + * + * @throws IllegalStateException If {@link #isEnabled()} returns {@code false}. + * @param entity The new reference. + */ void setReference(CarriageContraptionEntity entity); + /** + * @return The reference carriage contraption entity, or {@code null} if + * {@link #isEnabled()} would return {@code false} + */ @Nullable CarriageContraptionEntity getReference(); + /** + * Calculates the amount of lean to apply to this perspective. + * + * @param f The delta between the last tick and the next tick. + * @return Lean value. + */ default float getLean(float f) { var ref = getReference(); if (ref == null) return 0.0f; @@ -23,6 +77,12 @@ default float getLean(float f) { return Mth.lerp(f, ref.prevPitch * getPrevValueScale(), ref.pitch * getValueScale()); } + /** + * Calculates the amount of yaw to apply to this perspective. + * + * @param f The delta between the last tick and the next tick. + * @return Yaw value. + */ default float getYaw(float f) { var ref = getReference(); if (ref == null) return 0.0f; @@ -30,20 +90,47 @@ default float getYaw(float f) { return Mth.lerp(f, ref.prevYaw * getPrevValueScale(), ref.yaw * getValueScale()); } + /** + * @return The current {@link RotationState} value. + */ @Nullable RotationState getRotationState(); + /** + * Sets the rotation state. + */ + @Deprecated(since = "0.6.0", forRemoval = true) void setRotationState(@Nullable RotationState state); + /** + * Applies a diminishing effect to this perspective, called every tick if + * {@link RotationState#shouldTickState()} returns {@code false}. + */ void diminish(); + /** + * @return The value scale calculated in the last tick. + * This will only be less than one if {@link #diminish()} was + * called last tick. + */ float getPrevValueScale(); // this must not be named getScale()!!!! // Entity (or something) has a method also called getScale() that conflicts // with this method in a fuckey way. + /** + * @return The value scale calculated in this tick. + * This will only be less than one if {@link #diminish()} was + * called this tick. + */ float getValueScale(); + /** + * @return {@code true} if {@link #diminish()} has been called enough to + * reduce the effect that the mod is having on the perspective that + * it looks close enough to vanilla to just {@link #disable()} + * this perspective and stop wasting time multiplying values forever. + */ default boolean isDiminished() { return getValueScale() < 0.00025f; } 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 cf117eb..fde0c03 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 @@ -1,8 +1,41 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; import org.jetbrains.annotations.Nullable; +/** + * Contains some state needed to support rotating the player based on a + * carriage contraption's value. + * This is here mostly for simplicity, otherwise there would be too many + * {@code @Nullable} fields in + * {@link net.derfruhling.minecraft.create.trainperspective.mixin.EntityMixin EntityMixin} + */ public class RotationState { private CarriageContraptionEntity contraption; private boolean isStandingState; @@ -10,12 +43,37 @@ public class RotationState { private boolean shouldTickState = true; private int ticksSinceLastUpdate = 0; + /** + * Constructs a new rotation state. + * This constructor is used when an entity is mounting a train. + * + * @param contraption The contraption to bind to. + * @param isStandingState If {@code true} then the entity is standing on + * the train and requires different logic to + * detect when the player leaves the train. + *

+ * Otherwise, the player is seated, and therefore + * it can be assumed that when the player leaves + * their seat they will probably continue to stand + * for at least a moment. + *

+ * As such, the state is updated to be a + * standing state, which correctly handles if the + * player dismounts into a position which is no + * longer on the train. + */ public RotationState(CarriageContraptionEntity contraption, boolean isStandingState) { this.contraption = contraption; lastRecordedYaw = contraption.yaw; this.isStandingState = isStandingState; } + /** + * @return The difference between the current yaw of the contraption and + * the last yaw recorded by this function. + * @implNote This method does not take into account mid-tick frames, and + * as such should not be used for rendering. + */ public float getYawDelta() { while (contraption.yaw - lastRecordedYaw < -180.0f) { lastRecordedYaw -= 360.0f; @@ -30,48 +88,94 @@ public float getYawDelta() { return rotation; } + /** + * @return The currently bound contraption. + */ public @Nullable CarriageContraptionEntity getContraption() { return contraption; } - public void setCarriageEntity(@Nullable CarriageContraptionEntity contraption) { + @Deprecated(since = "0.6.0", forRemoval = true) + public void setContraption(@Nullable CarriageContraptionEntity contraption) { this.contraption = contraption; } + /** + * @return {@code true} if this is a standing state, + * {@code false} otherwise. + */ public boolean isStanding() { return isStandingState; } + /** + * @return {@code true} if this is not a standing state, + * {@code false} otherwise. + */ public boolean isSeated() { return !isStandingState; } + /** + * If {@link #isStanding isStanding()} is true, then after the player is + * detected not to be on the contraption this method will start returning + * {@code false}. + * Otherwise, it will always return {@code true}. + * + * @return {@code true} if this standing state should continue being ticked. + */ public boolean shouldTickState() { return shouldTickState; } + /** + * Called when the player begins riding the contraption. + * Converts this state into a seated state. + */ public void onMounted() { this.isStandingState = false; + + // ensure correct behavior (this is ignored for seated states anyway) this.shouldTickState = true; } + /** + * Called when the player stops riding the contraption. + * Converts this state into a standing state. + */ public void onDismount() { this.isStandingState = true; } + @Deprecated(since = "0.6.0", forRemoval = true) public void setShouldTickState(boolean shouldTickState) { this.shouldTickState = shouldTickState; } + /** + * Calls for this state to stop ticking. + * + * @throws IllegalStateException Not {@link #isStanding()} + */ + public void stopTickingState() { + if(!isStandingState) throw new IllegalStateException("not a standing state"); + + this.shouldTickState = false; + } + + /** + * @return Returns the number of {@link #tick()} calls since the last + * {@link #update()} + */ public int getTicksSinceLastUpdate() { return ticksSinceLastUpdate; } - public void update() { + void update() { ticksSinceLastUpdate = 0; } - public void tick() { + void tick() { ticksSinceLastUpdate += 1; } } 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 8208892..7937b3e 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 @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.simibubi.create.content.contraptions.AbstractContraptionEntity; 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 c5f48d3..4d2283d 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 @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import net.derfruhling.minecraft.create.trainperspective.*; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ClientLevelMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ClientLevelMixin.java index 2e28eb2..ab89639 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ClientLevelMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/ClientLevelMixin.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; 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 dccd291..485c648 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 @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.llamalad7.mixinextras.injector.ModifyReturnValue; 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 ed5d608..628a148 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,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.llamalad7.mixinextras.sugar.Local; @@ -79,8 +105,9 @@ public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch } else return yaw; } - public void ctp$enable(CarriageContraptionEntity entity) { + public void ctp$enable(CarriageContraptionEntity entity, RotationState state) { ctp$perspectiveActive = true; + ctp$currentState = state; ctp$reference = entity; ctp$prevScale = 1.0f; ctp$scale = 1.0f; @@ -88,6 +115,7 @@ public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch public void ctp$disable() { ctp$perspectiveActive = false; + ctp$currentState = null; ctp$reference = null; ctp$prevScale = 1.0f; ctp$scale = 1.0f; @@ -125,6 +153,8 @@ public float modifyYaw(float yaw, @Local(argsOnly = true, index = 1) float pitch return ctp$currentState; } + @SuppressWarnings("removal") + @Deprecated(since = "0.6.0", forRemoval = true) public void ctp$setRotationState(@Nullable RotationState state) { ctp$currentState = state; } 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 6bcba19..22bfb38 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 @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.mojang.blaze3d.vertex.PoseStack; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LivingEntityRendererMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LivingEntityRendererMixin.java index 3a866be..2f1978b 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LivingEntityRendererMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LivingEntityRendererMixin.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.mojang.blaze3d.vertex.PoseStack; diff --git a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java index e2c4292..11272b6 100644 --- a/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java +++ b/common/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/LocalPlayerMixin.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.mixin; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; diff --git a/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ConfigIntegration.java b/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ConfigIntegration.java index 49658b1..d52c4d6 100644 --- a/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ConfigIntegration.java +++ b/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ConfigIntegration.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.fabric; import com.terraformersmc.modmenu.api.ConfigScreenFactory; diff --git a/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ModFabricEntrypoint.java b/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ModFabricEntrypoint.java index 5b9095c..40f37ad 100644 --- a/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ModFabricEntrypoint.java +++ b/fabric/src/main/java/net/derfruhling/minecraft/create/trainperspective/fabric/ModFabricEntrypoint.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.fabric; import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; diff --git a/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java b/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java index 10ed3d2..058e863 100644 --- a/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java +++ b/forge/src/main/java/net/derfruhling/minecraft/create/trainperspective/forge/ModForgeEntrypoint.java @@ -1,3 +1,29 @@ +/* + * Part of the Create: Train Perspective project. + * + * The MIT License (MIT) + * + * Copyright (c) 2024 der_frühling + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package net.derfruhling.minecraft.create.trainperspective.forge; import dev.architectury.platform.forge.EventBuses; From ffc9c5dd379f5f4b7b5c5da54b43d9b3a9666523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?der=5Ffr=C3=BChling?= Date: Thu, 8 Aug 2024 14:58:40 -0700 Subject: [PATCH 6/6] bump version + write changelog --- changelog.md | 12 +++++++----- gradle.properties | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 9fd9fa2..147a401 100644 --- a/changelog.md +++ b/changelog.md @@ -1,12 +1,14 @@ -Multiplayer and non-player entity compatibility, along with 1.18.2 support. +Extra smoothness and extra compatibility change. Changelog: -- **Fixed:** Player camera turns when an unrelated player is on a train. -- **Added:** Ability for non-player entities to be affected by this mod. -- **Technical:** Cleaned up the code a bit. +- **Fixed:** Delayed camera movement when train turns. +- **Added:** Debug option to display new value scales used to fix the aforementioned delayed camera movement. +- **Fixed:** Incompatibility with Figura combined with some mods. [#67](https://github.com/der-fruhling-entertainment/create-train-perspective/issues/67) + - (fixed via possibly temporary workaround. please report any other issues with this mod and mine! it likes to get breaky) +- **Technical:** Cleaned up the code a bit more. -[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.4.1...v0.5.0) +[View full change log.](https://github.com/der-fruhling/create-train-perspective/compare/v0.5.0...v0.6.0) --- diff --git a/gradle.properties b/gradle.properties index 2d7bb1b..73b38e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ quilt_loader_version=0.21.2-beta.2 quilt_fabric_api_version=7.4.0+0.90.0-1.20.1 # public info mod_id=create_train_perspective -mod_version=0.5.0 +mod_version=0.6.0 maven_group=net.derfruhling.minecraft archives_base_name=create-train-perspective # mod dependency versions