-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Players now look at their perceived down (e.g. the seat they're sitting in) rather than the real ground. #32 - Fixed jittery leaning. #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. #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.
- Loading branch information
Showing
16 changed files
with
252 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
public interface Camera3D { | ||
float getZRot(); | ||
float getExtraYRot(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixinUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
package net.derfruhling.minecraft.create.trainperspective; | ||
|
||
import net.minecraft.client.Camera; | ||
import net.minecraft.util.Mth; | ||
|
||
public class MixinUtil { | ||
private MixinUtil() {} | ||
|
||
public static Camera3D asCamera3D(Camera camera) { | ||
return (Camera3D) camera; | ||
} | ||
|
||
private static float invCos(float x) { | ||
return Mth.cos(x + Mth.PI); | ||
} | ||
|
||
public static float applyDirectionXRotChange(Perspective persp, float xRot, float yRot, float f) { | ||
return xRot - persp.getLean(f) * Mth.sin((persp.getYaw(f) - yRot) * Mth.DEG_TO_RAD); | ||
} | ||
|
||
public static float getExtraYRot(Perspective persp, float xRot, float yRot, float f) { | ||
return persp.getLean(f) * (xRot / 90.0f) * invCos((persp.getYaw(f) - yRot) * Mth.DEG_TO_RAD); | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Perspective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
package net.derfruhling.minecraft.create.trainperspective; | ||
|
||
import net.minecraft.util.Mth; | ||
|
||
public interface Perspective { | ||
void enable(float initialLean, float initialYaw); | ||
void disable(); | ||
boolean isEnabled(); | ||
void setLean(float lean); | ||
void setYaw(float yaw); | ||
float getLean(); | ||
float getYaw(); | ||
float getLean(float f); | ||
float getYaw(float f); | ||
|
||
default void diminish() { | ||
setLean(getLean() * 0.97f); | ||
setYaw(getYaw() * 0.97f); | ||
setLean(getLean(1.0f) * 0.9f); | ||
} | ||
|
||
default boolean diminished() { | ||
return Mth.abs(getLean(1.0f)) < 0.01f; | ||
} | ||
} |
21 changes: 13 additions & 8 deletions
21
...ctive/mixin/ContraptionColliderMixin.java → ...mixin/AbstractContraptionEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
package net.derfruhling.minecraft.create.trainperspective.mixin; | ||
|
||
import com.simibubi.create.content.contraptions.AbstractContraptionEntity; | ||
import com.simibubi.create.content.contraptions.ContraptionCollider; | ||
import com.simibubi.create.content.trains.entity.CarriageContraptionEntity; | ||
import net.derfruhling.minecraft.create.trainperspective.CreateTrainPerspectiveMod; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
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; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ContraptionCollider.class) | ||
public class ContraptionColliderMixin { | ||
@Inject(method = "collideEntities", at = @At("HEAD"), remap = false) | ||
private static void saveClientPlayerFromClipping( | ||
AbstractContraptionEntity contraptionEntity, | ||
@Mixin(AbstractContraptionEntity.class) | ||
@Environment(EnvType.CLIENT) | ||
public class AbstractContraptionEntityMixin { | ||
@SuppressWarnings({"ConstantValue", "UnreachableCode"}) | ||
@Inject(method = "registerColliding", at = @At("TAIL"), remap = false) | ||
private void onRegisterColliding( | ||
Entity entity, | ||
CallbackInfo ci | ||
) { | ||
if(contraptionEntity instanceof CarriageContraptionEntity carriage) { | ||
CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayers(carriage); | ||
if((Object) this instanceof CarriageContraptionEntity carriage && entity instanceof Player player) { | ||
CreateTrainPerspectiveMod.INSTANCE.tickStandingPlayer(carriage, player); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ava/net/derfruhling/minecraft/create/trainperspective/mixin/CreateRaycastHelperMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.derfruhling.minecraft.create.trainperspective.mixin; | ||
|
||
import com.simibubi.create.foundation.utility.RaycastHelper; | ||
import net.derfruhling.minecraft.create.trainperspective.MixinUtil; | ||
import net.derfruhling.minecraft.create.trainperspective.Perspective; | ||
import net.minecraft.client.Minecraft; | ||
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.ModifyVariable; | ||
|
||
@Mixin(RaycastHelper.class) | ||
public class CreateRaycastHelperMixin { | ||
@ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 4) | ||
private static float modifyXRot(float value, Player player) { | ||
if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { | ||
return MixinUtil.applyDirectionXRotChange(persp, value, player.getYRot(), 1.0f); | ||
} else return value; | ||
} | ||
|
||
@ModifyVariable(method = "getTraceTarget", at = @At("STORE"), index = 5) | ||
private static float modifyYRot(float value, Player player) { | ||
if(Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player) instanceof Perspective persp) { | ||
return value + MixinUtil.getExtraYRot(persp, player.getXRot(), value, 1.0f); | ||
} else return value; | ||
} | ||
} |
Oops, something went wrong.