Skip to content

Commit

Permalink
Upstream mod to Minecraft 1.19.3
Browse files Browse the repository at this point in the history
Update `worldToScreen` function in monkey way

Optimize imports
  • Loading branch information
qualterz committed Dec 12, 2022
1 parent 115f878 commit 47992e5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 40 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.8
loader_version=0.14.9
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.3
loader_version=0.14.11

#Fabric api
fabric_version=0.60.0+1.19.2
fabric_version=0.69.1+1.19.3


# Mod Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
package me.qualterz.minecraft.lookaround;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.util.math.*;
import net.minecraft.util.math.Vec3d;

public class ProjectionUtils {
public static Vec3f worldToScreen(Vec3d destination)
public static Vec3d worldToScreen(Vec3d destination)
{
var client = MinecraftClient.getInstance();
var renderer = client.gameRenderer;
var camera = renderer.getCamera();
var position = camera.getPos();
var rotation = camera.getRotation().copy();
var rotation = camera.getRotation();

rotation.conjugate();

var calculation = new Vec3f(
(float) (position.x - destination.getX()),
(float) (position.y - destination.getY()),
(float) (position.z - destination.getZ())
);

calculation.transform(new Matrix3f(rotation));
var calculation = rotation.conjugate().transform(position.subtract(destination).toVector3f());

// TODO: use dynamic fov value
var fov = client.options.getFov().getValue();

var half = client.getWindow().getScaledHeight() / 2;
var scale = half / (calculation.getZ() * Math.tan(Math.toRadians(fov / 2)));
var scale = half / (calculation.z() * Math.tan(Math.toRadians(fov / 2)));

return new Vec3f((float) (calculation.getX() * scale), (float) (calculation.getY() * scale), calculation.getZ());
return new Vec3d((calculation.x() * scale), (calculation.y() * scale), calculation.z());
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package me.qualterz.minecraft.lookaround.mixin;

import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import me.qualterz.minecraft.lookaround.LookaroundMod;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.BlockView;
import net.minecraft.client.render.Camera;
import me.qualterz.minecraft.lookaround.LookaroundMod;

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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(Camera.class)
public abstract class CameraMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import me.qualterz.minecraft.lookaround.CameraState;
import me.qualterz.minecraft.lookaround.LookaroundMod;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package me.qualterz.minecraft.lookaround.mixin;

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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import me.qualterz.minecraft.lookaround.CameraState;
import me.qualterz.minecraft.lookaround.LookaroundMod;
import me.qualterz.minecraft.lookaround.ProjectionUtils;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Vec3d;

import me.qualterz.minecraft.lookaround.CameraState;
import me.qualterz.minecraft.lookaround.LookaroundMod;
import me.qualterz.minecraft.lookaround.ProjectionUtils;
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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(InGameHud.class)
public class InGameHudMixin {
private CameraState camera;

private float offsetCrosshairX;
private float offsetCrosshairY;
private double offsetCrosshairX;
private double offsetCrosshairY;

@Inject(method = "renderCrosshair", at = @At("HEAD"), cancellable = true)
private void onRenderCrosshairBegin(MatrixStack matrices, CallbackInfo ci)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"depends": {
"fabricloader": ">=0.14.7",
"fabric": ">=0.55.1",
"minecraft": ">=1.19",
"minecraft": ">=1.19.3",
"java": ">=17"
}
}

0 comments on commit 47992e5

Please sign in to comment.