Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.3.1 #46

Merged
merged 9 commits into from
May 20, 2024
32 changes: 5 additions & 27 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 4 additions & 8 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,73 @@
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 {
state.update();
}
}

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);
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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$")})
Expand All @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading
Loading