Skip to content

Commit

Permalink
Push whatever was here before
Browse files Browse the repository at this point in the history
  • Loading branch information
landon-wills committed Oct 7, 2024
1 parent eb313e8 commit 9d42068
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 67 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ loom {

var clientConfig = runConfigs.getByName("client")
clientConfig.runDir = "runClient"
clientConfig.programArg("--username=landonjw")
// clientConfig.programArg("--username=landonjw")
clientConfig.vmArgs("-Dmixin.debug.export=true")
clientConfig.programArg("--8c9349fe-8e50-448c-a6e2-12d7a3a32991")
var serverConfig = runConfigs.getByName("server")
serverConfig.runDir = "runServer"

Expand Down
6 changes: 2 additions & 4 deletions src/client/java/ca/landonjw/OpenCameraClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

public class OpenCameraClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
}
}
public void onInitializeClient() {}
}
13 changes: 13 additions & 0 deletions src/client/java/ca/landonjw/math/AngleHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ca.landonjw.math;

public class AngleHelper {

public static float degrees(float radians) {
return (float) (radians * (180 / Math.PI));
}

public static float radians(float degrees) {
return (float) (degrees / (180 / Math.PI));
}

}
26 changes: 15 additions & 11 deletions src/client/java/ca/landonjw/mixin/client/CameraMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
import ca.landonjw.Rollable;
import net.minecraft.client.Camera;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.Supplier;

@Mixin(Camera.class)
public class CameraMixin implements Rollable {

@Shadow private Entity entity;
@Shadow @Final private Quaternionf rotation;
@Shadow @Final private Vector3f forwards;
@Shadow @Final private Vector3f up;
@Shadow @Final private Vector3f left;
@Unique Quaternionf orientation = new Quaternionf();

@Override
Expand All @@ -24,22 +31,19 @@ public Quaternionf getOrientation() {
}

@Override
public void setOrientation(Quaternionf orientation) {
this.orientation = orientation;
public void updateOrientation(Supplier<Quaternionf> update) {
this.orientation = update.get();
}

@Inject(method = "setRotation", at = @At("HEAD"))
@Inject(method = "setRotation", at = @At("HEAD"), cancellable = true)
public void open_camera$setRotation(float f, float g, CallbackInfo ci) {
if (this.entity instanceof Rollable rollable) {
this.orientation = rollable.getOrientation();
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);
ci.cancel();
}
}

@Inject(method = "setup", at = @At("TAIL"))
public void open_camera$setup(BlockGetter blockGetter, Entity entity, boolean bl, boolean bl2, float f, CallbackInfo ci) {
// if (bl && bl2) {
// this.roll = -roll;
// }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import ca.landonjw.Rollable;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -37,9 +34,7 @@ public class GameRendererMixin {
method = "renderLevel",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/math/Axis;rotationDegrees(F)Lorg/joml/Quaternionf;",
ordinal = 3,
shift = At.Shift.AFTER
target = "Lorg/joml/Matrix3f;<init>(Lorg/joml/Matrix3fc;)V"
)
)
public void open_camera$applyCameraRotations(float f, long l, PoseStack poseStack, CallbackInfo ci) {
Expand Down
13 changes: 8 additions & 5 deletions src/client/java/ca/landonjw/mixin/client/MouseHandlerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ public class MouseHandlerMixin {
public boolean open_camera$modifyRotation(LocalPlayer player, double cursorDeltaX, double cursorDeltaY) {
if (!(player instanceof Rollable rollable)) return true;

var pitch = cursorDeltaY * 0.15f;
var roll = cursorDeltaX * 0.15f;
rollable.updateOrientation(() -> {
var pitch = cursorDeltaY * 0.15f;
var roll = cursorDeltaX * 0.15f;

var pitchQ = Axis.XP.rotationDegrees((float)pitch);
var rollQ = Axis.ZP.rotationDegrees((float)roll);
var pitchQ = Axis.XP.rotationDegrees((float)pitch);
var rollQ = Axis.ZP.rotationDegrees((float)roll);

pitchQ.mul(rollQ).mul(rollable.getOrientation(), rollable.getOrientation());
var rotation = pitchQ.mul(rollQ);
return rotation.mul(rollable.getOrientation(), rollable.getOrientation());
});
return false;
}

Expand Down
30 changes: 18 additions & 12 deletions src/client/java/ca/landonjw/mixin/client/PlayerMixin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package ca.landonjw.mixin.client;

import ca.landonjw.Rollable;
import com.mojang.math.Axis;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import org.joml.Quaternionf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.Supplier;

@Mixin(Player.class)
public abstract class PlayerMixin extends LivingEntity implements Rollable {
Expand All @@ -18,16 +25,14 @@ protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level level
super(entityType, level);
}

@Override
public void turn(double deltaY, double deltaX) {
float adjustedDeltaX = (float)deltaX * 0.15f;
float adjustedDeltaY = (float)deltaY * 0.15f;
this.setXRot(this.getXRot() + adjustedDeltaX);
this.setYRot(this.getYRot() + adjustedDeltaY);
this.xRotO += adjustedDeltaX;
this.yRotO += adjustedDeltaY;
if (this.getVehicle() != null) {
this.getVehicle().onPassengerTurned(this);
@Inject(method = "tick", at = @At("HEAD"))
public void tick(CallbackInfo ci) {
// Proof of concept for yaw movement
if (this.getMainHandItem().is(Items.STICK)) {
Axis.YP.rotationDegrees((float)2).mul(this.orientation, this.orientation);
}
else if (this.getMainHandItem().is(Items.BLAZE_ROD)) {
Axis.YP.rotationDegrees((float)-2).mul(this.orientation, this.orientation);
}
}

Expand All @@ -46,7 +51,8 @@ public Quaternionf getOrientation() {
}

@Override
public void setOrientation(Quaternionf orientation) {
this.orientation = orientation;
public void updateOrientation(Supplier<Quaternionf> update) {
this.orientation = update.get();
}

}
9 changes: 1 addition & 8 deletions src/main/java/ca/landonjw/OpenCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@
import org.slf4j.LoggerFactory;

public class OpenCamera implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LoggerFactory.getLogger("open-camera");

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.

LOGGER.info("Hello Fabric world!");
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/ca/landonjw/Rollable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.joml.Quaternionf;

import java.util.function.Supplier;

public interface Rollable {

Quaternionf getOrientation();

void setOrientation(Quaternionf orientation);
void updateOrientation(Supplier<Quaternionf> update);

}
}
15 changes: 0 additions & 15 deletions src/main/java/ca/landonjw/mixin/ExampleMixin.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/resources/open-camera.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"package": "ca.landonjw.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
}
}
}

0 comments on commit 9d42068

Please sign in to comment.