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/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..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 @@ -1,65 +1,64 @@ 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); + 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 { @@ -67,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); @@ -84,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 025b314..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$")}) @@ -33,12 +31,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; - } - - @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); + return original + (ctp$zRot * Mth.DEG_TO_RAD); } @Unique @@ -52,14 +45,16 @@ private void modifyQuaternion(float f, float g, CallbackInfo ci) { } @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) * 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, 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())); } 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