-
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.
Merge pull request #18 from der-fruhling-entertainment/feat/camera-ro…
…lling Implement vertical camera roll & improve vertical camera movement
- Loading branch information
Showing
5 changed files
with
82 additions
and
16 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
common/src/main/java/net/derfruhling/minecraft/create/trainperspective/Camera3D.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,6 @@ | ||
package net.derfruhling.minecraft.create.trainperspective; | ||
|
||
public interface Camera3D { | ||
float getZRot(); | ||
void setRotation3D(float y, float x, float z); | ||
} |
12 changes: 12 additions & 0 deletions
12
common/src/main/java/net/derfruhling/minecraft/create/trainperspective/MixUtil.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,12 @@ | ||
package net.derfruhling.minecraft.create.trainperspective; | ||
|
||
import net.derfruhling.minecraft.create.trainperspective.mixin.CameraMixin; | ||
import net.minecraft.client.Camera; | ||
|
||
public class MixUtil { | ||
private MixUtil() {} | ||
|
||
public static Camera3D asCamera3D(Camera camera) { | ||
return (Camera3D) camera; | ||
} | ||
} |
52 changes: 38 additions & 14 deletions
52
...on/src/main/java/net/derfruhling/minecraft/create/trainperspective/mixin/CameraMixin.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,33 +1,57 @@ | ||
package net.derfruhling.minecraft.create.trainperspective.mixin; | ||
|
||
import net.derfruhling.minecraft.create.trainperspective.Camera3D; | ||
import net.derfruhling.minecraft.create.trainperspective.PlayerPerspectiveBehavior; | ||
import net.minecraft.client.Camera; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.player.AbstractClientPlayer; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.entity.Entity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.joml.Quaternionf; | ||
import org.joml.Vector3f; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(Camera.class) | ||
public class CameraMixin { | ||
@Implements({@Interface(iface = Camera3D.class, prefix = "ctp$")}) | ||
public abstract class CameraMixin { | ||
@Shadow private Entity entity; | ||
@Shadow private float xRot; | ||
@Shadow private float yRot; | ||
@Unique private float ctp$zRot; | ||
|
||
@ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 0), index = 1) | ||
public float modifyXRotPrimary(float xRot) { | ||
if(entity instanceof LocalPlayer player) { | ||
var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); | ||
return xRot - persp.getLean(); | ||
} else return xRot; | ||
@Shadow @Final private Quaternionf rotation; | ||
@Shadow @Final private Vector3f forwards; | ||
@Shadow @Final private Vector3f up; | ||
@Shadow @Final private Vector3f left; | ||
|
||
@Shadow protected abstract void setRotation(float f, float g); | ||
|
||
@Unique | ||
public void ctp$setRotation3D(float y, float x, float z) { | ||
this.xRot = x; | ||
this.yRot = y; | ||
this.ctp$zRot = z; | ||
this.rotation.rotationYXZ(-y * 0.017453292F, x * 0.017453292F, z * 0.017453292F); | ||
this.forwards.set(0.0F, 0.0F, 1.0F).rotate(this.rotation); | ||
this.up.set(0.0F, 1.0F, 0.0F).rotate(this.rotation); | ||
this.left.set(1.0F, 0.0F, 0.0F).rotate(this.rotation); | ||
} | ||
|
||
@Unique | ||
public float ctp$getZRot() { | ||
return this.ctp$zRot; | ||
} | ||
|
||
@ModifyArg(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V", ordinal = 1), index = 1) | ||
public float modifyXRotThirdPersonMirrored(float invertedXRot) { | ||
@Redirect(method = "setup", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V")) | ||
public void modifyRotationsPrimary(Camera instance, float y, float x) { | ||
if(entity instanceof LocalPlayer player) { | ||
var persp = (PlayerPerspectiveBehavior) Minecraft.getInstance().getEntityRenderDispatcher().getRenderer(player); | ||
return invertedXRot + persp.getLean(); | ||
} else return invertedXRot; | ||
ctp$setRotation3D(y, | ||
x + persp.getLean() * Mth.cos(y * Mth.DEG_TO_RAD), | ||
360.0f - (persp.getLean() * Mth.sin(y * Mth.DEG_TO_RAD))); | ||
} else setRotation(y, x); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/net/derfruhling/minecraft/create/trainperspective/mixin/GameRendererMixin.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,23 @@ | ||
package net.derfruhling.minecraft.create.trainperspective.mixin; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.math.Axis; | ||
import net.derfruhling.minecraft.create.trainperspective.MixUtil; | ||
import net.minecraft.client.Camera; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
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(GameRenderer.class) | ||
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 = 3, shift = At.Shift.AFTER)) | ||
public void applyZRotation(float f, long l, PoseStack poseStack, CallbackInfo ci) { | ||
poseStack.mulPose(Axis.ZP.rotationDegrees(MixUtil.asCamera3D(mainCamera).getZRot())); | ||
} | ||
} |
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