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