Skip to content

Commit

Permalink
Migrated to official mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Jul 11, 2024
1 parent 80e0e1c commit 5e2c204
Show file tree
Hide file tree
Showing 43 changed files with 922 additions and 918 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ subprojects {

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
//mappings loom.officialMojangMappings()
mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
//mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
}
}

Expand Down
18 changes: 9 additions & 9 deletions common/src/main/java/com/xtracr/realcamera/KeyBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.gui.ModelViewScreen;
import com.xtracr.realcamera.util.LocUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import org.lwjgl.glfw.GLFW;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public final class KeyBindings {
private static final Map<KeyBinding, Consumer<MinecraftClient>> KEY_BINDINGS = new HashMap<>();
private static final Map<KeyMapping, Consumer<Minecraft>> KEY_BINDINGS = new HashMap<>();

static {
createKeyBinding("modelViewScreen", client -> client.setScreen(new ModelViewScreen()));
Expand All @@ -32,22 +32,22 @@ public final class KeyBindings {
createKeyBinding("adjustRIGHT", client -> ConfigFile.config().adjustOffsetZ(-1));
}

private static void createKeyBinding(String id, Consumer<MinecraftClient> whenPressed) {
private static void createKeyBinding(String id, Consumer<Minecraft> whenPressed) {
createKeyBinding(id, GLFW.GLFW_KEY_UNKNOWN, whenPressed);
}

private static void createKeyBinding(String id, int code, Consumer<MinecraftClient> whenPressed) {
KEY_BINDINGS.put(new KeyBinding("key." + RealCamera.FULL_ID + "." + id, code, LocUtil.KEY_MOD_NAME), whenPressed);
private static void createKeyBinding(String id, int code, Consumer<Minecraft> whenPressed) {
KEY_BINDINGS.put(new KeyMapping("key." + RealCamera.FULL_ID + "." + id, code, LocUtil.KEY_MOD_NAME), whenPressed);
}

public static void register(Consumer<KeyBinding> registerer) {
public static void register(Consumer<KeyMapping> registerer) {
KEY_BINDINGS.keySet().forEach(registerer);
}

public static void handle(MinecraftClient client) {
public static void handle(Minecraft client) {
if (client.player == null) return;
KEY_BINDINGS.forEach((keyBinding, whenPressed) -> {
while (keyBinding.wasPressed()) {
while (keyBinding.consumeClick()) {
whenPressed.accept(client);
ConfigFile.save();
}
Expand Down
95 changes: 49 additions & 46 deletions common/src/main/java/com/xtracr/realcamera/RealCameraCore.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
package com.xtracr.realcamera;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.xtracr.realcamera.compat.DisableHelper;
import com.xtracr.realcamera.config.BindingTarget;
import com.xtracr.realcamera.config.ConfigFile;
import com.xtracr.realcamera.util.LocUtil;
import com.xtracr.realcamera.util.MathUtil;
import com.xtracr.realcamera.util.VertexRecorder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector3f;

import java.util.Arrays;
import java.util.Objects;

public class RealCameraCore {
private static final VertexRecorder recorder = new VertexRecorder();
public static BindingTarget currentTarget = new BindingTarget();
private static Vec3d pos = Vec3d.ZERO, cameraPos = Vec3d.ZERO, offset = Vec3d.ZERO;
private static Vec3 pos = Vec3.ZERO, cameraPos = Vec3.ZERO, offset = Vec3.ZERO;
private static boolean active = false, rendering = false, readyToSendMessage = true;
private static float pitch, yaw, roll;

Expand All @@ -44,21 +41,21 @@ public static float getRoll(float f) {
return f;
}

public static Vec3d getPos(Vec3d vec3d) {
return new Vec3d(currentTarget.bindX ? pos.getX() : vec3d.getX(), currentTarget.bindY ? pos.getY() : vec3d.getY(), currentTarget.bindZ ? pos.getZ() : vec3d.getZ());
public static Vec3 getPos(Vec3 vec) {
return new Vec3(currentTarget.bindX ? pos.x() : vec.x(), currentTarget.bindY ? pos.y() : vec.y(), currentTarget.bindZ ? pos.z() : vec.z());
}

public static Vec3d getCameraPos(Vec3d vec3d) {
return new Vec3d(currentTarget.bindX ? cameraPos.getX() : vec3d.getX(), currentTarget.bindY ? cameraPos.getY() : vec3d.getY(), currentTarget.bindZ ? cameraPos.getZ() : vec3d.getZ());
public static Vec3 getCameraPos(Vec3 vec) {
return new Vec3(currentTarget.bindX ? cameraPos.x() : vec.x(), currentTarget.bindY ? cameraPos.y() : vec.y(), currentTarget.bindZ ? cameraPos.z() : vec.z());
}

public static void setCameraPos(Vec3d vec3d) {
cameraPos = vec3d;
public static void setCameraPos(Vec3 vec) {
cameraPos = vec;
}

public static void initialize(MinecraftClient client) {
public static void initialize(Minecraft client) {
Entity entity = client.getCameraEntity();
active = ConfigFile.config().enabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null && entity != null && !DisableHelper.isDisabled("mainFeature", entity);
active = ConfigFile.config().enabled() && client.options.getCameraType().isFirstPerson() && entity != null && !DisableHelper.isDisabled("mainFeature", entity);
rendering = active && ConfigFile.config().renderModel() && !DisableHelper.isDisabled("renderModel", entity);
}

Expand All @@ -74,38 +71,44 @@ public static boolean isRendering() {
return active && rendering;
}

public static void updateModel(MinecraftClient client, float tickDelta) {
public static void updateModel(Minecraft client, float tickDelta) {
recorder.clear();
// WorldRenderer.render
Entity entity = client.getCameraEntity();
EntityRenderDispatcher dispatcher = client.getEntityRenderDispatcher();
dispatcher.configure(client.world, client.gameRenderer.getCamera(), client.targetedEntity);
if (entity.age == 0) {
entity.lastRenderX = entity.getX();
entity.lastRenderY = entity.getY();
entity.lastRenderZ = entity.getZ();
dispatcher.prepare(client.level, client.gameRenderer.getMainCamera(), client.crosshairPickEntity);
if (entity.tickCount == 0) {
entity.xOld = entity.getX();
entity.yOld = entity.getY();
entity.zOld = entity.getZ();
}
// WorldRenderer.renderEntity
offset = new Vec3d(MathHelper.lerp(tickDelta, entity.lastRenderX, entity.getX()), MathHelper.lerp(tickDelta, entity.lastRenderY, entity.getY()), MathHelper.lerp(tickDelta, entity.lastRenderZ, entity.getZ()));
dispatcher.render(entity, 0, 0, 0, MathHelper.lerp(tickDelta, entity.prevYaw, entity.getYaw()), tickDelta, new MatrixStack(), recorder, dispatcher.getLight(entity, tickDelta));
offset = new Vec3(Mth.lerp(tickDelta, entity.xOld, entity.getX()), Mth.lerp(tickDelta, entity.yOld, entity.getY()), Mth.lerp(tickDelta, entity.zOld, entity.getZ()));
dispatcher.render(entity, 0, 0, 0, Mth.lerp(tickDelta, entity.yRotO, entity.getYRot()), tickDelta, new PoseStack(), recorder, dispatcher.getPackedLightCoords(entity, tickDelta));
recorder.buildRecords();
}

public static void renderCameraEntity(VertexConsumerProvider vertexConsumers) {
Matrix3f normalMatrix = new Matrix3f().rotate(RotationAxis.POSITIVE_Z.rotationDegrees(roll))
.rotate(RotationAxis.POSITIVE_X.rotationDegrees(pitch))
.rotate(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f))
.transpose().invert();
public static void renderCameraEntity(MultiBufferSource bufferSource) {
Matrix3f normalMatrix = new Matrix3f().rotateZ((float) Math.toRadians(roll)).rotateX((float) Math.toRadians(pitch)).rotateY((float) Math.toRadians(yaw + 180.0f)).transpose().invert();
Matrix4f positionMatrix = new Matrix4f(normalMatrix).translate(offset.subtract(pos).toVector3f());
recorder.drawByAnother(vertexConsumers, record -> currentTarget.disabledTextureIds.stream().noneMatch(record.textureId()::contains), record -> {
recorder.forEachRecord(record -> {
if (currentTarget.disabledTextureIds.stream().anyMatch(record.textureId()::contains)) return;
VertexConsumer buffer = bufferSource.getBuffer(record.renderType());
if (!record.renderType().canConsolidateConsecutiveGeometry()) {
VertexRecorder.renderVertices(record.vertices(), buffer);
return;
}
final double depth = currentTarget.disablingDepth;
final int primitiveLength = record.primitiveLength();
return Arrays.stream(record.primitives()).map(primitive -> {
final int primitiveLength = record.renderType().mode().primitiveLength;
for (VertexRecorder.Vertex[] primitive : record.primitives()) {
VertexRecorder.Vertex[] newPrimitive = new VertexRecorder.Vertex[primitiveLength];
for (int j = 0; j < primitiveLength ; j++) newPrimitive[j] = primitive[j].transform(positionMatrix, normalMatrix);
for (VertexRecorder.Vertex vertex : newPrimitive) if (vertex.z() < -depth) return newPrimitive;
return null;
}).filter(Objects::nonNull).toArray(VertexRecorder.Vertex[][]::new);
for (VertexRecorder.Vertex vertex : newPrimitive) {
if (vertex.z() > -depth) continue;
VertexRecorder.renderVertices(newPrimitive, buffer);
break;
}
}
});
}

Expand All @@ -115,21 +118,21 @@ public static void computeCamera() {
for (BindingTarget target : ConfigFile.config().getTargetList()) {
Vector3f position = new Vector3f();
if (recorder.getTargetPosAndRot(target, normal, position) == null || !(Math.abs(normal.determinant() - 1) <= 0.01f) || !Float.isFinite(position.lengthSquared())) continue;
pos = new Vec3d(position).add(offset);
pos = new Vec3(position).add(offset);
currentTarget = target;
break;
}
if (currentTarget.isEmpty()) {
Entity player = MinecraftClient.getInstance().player;
if (readyToSendMessage && player != null) player.sendMessage(LocUtil.MESSAGE("bindingFailed", LocUtil.MOD_NAME(), LocUtil.MODEL_VIEW_TITLE()));
Entity player = Minecraft.getInstance().player;
if (readyToSendMessage && player != null) player.sendSystemMessage(LocUtil.MESSAGE("bindingFailed", LocUtil.MOD_NAME(), LocUtil.MODEL_VIEW_TITLE()));
active = readyToSendMessage = false;
} else readyToSendMessage = true;
normal.rotateLocal((float) Math.toRadians(currentTarget.getYaw()), normal.m10, normal.m11, normal.m12);
normal.rotateLocal((float) Math.toRadians(currentTarget.getPitch()), normal.m00, normal.m01, normal.m02);
normal.rotateLocal((float) Math.toRadians(currentTarget.getRoll()), normal.m20, normal.m21, normal.m22);
Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(Math.toDegrees(1));
pitch = (float) eulerAngle.getX();
yaw = (float) -eulerAngle.getY();
roll = (float) eulerAngle.getZ();
Vec3 eulerAngle = MathUtil.getEulerAngleYXZ(normal).scale(Math.toDegrees(1));
pitch = (float) eulerAngle.x();
yaw = (float) -eulerAngle.y();
roll = (float) eulerAngle.z();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.xtracr.realcamera.compat;

import com.xtracr.realcamera.config.ConfigFile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.Registries;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -15,9 +15,9 @@ public class DisableHelper {

public static void initialize() {
registerOr("mainFeature", LivingEntity::isSleeping);
registerOr("renderModel", entity -> entity instanceof PlayerEntity player && player.isUsingSpyglass());
registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getMainHandStack().getItem()).toString()));
registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(Registries.ITEM.getId(entity.getOffHandStack().getItem()).toString()));
registerOr("renderModel", entity -> entity instanceof Player player && player.isScoping());
registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(BuiltInRegistries.ITEM.getKey(entity.getMainHandItem().getItem()).toString()));
registerOr("renderModel", entity -> ConfigFile.config().getDisableRenderItems().contains(BuiltInRegistries.ITEM.getKey(entity.getOffhandItem().getItem()).toString()));
}

public static void registerOr(String type, Predicate<LivingEntity> predicate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xtracr.realcamera.config;

import net.minecraft.util.math.MathHelper;
import net.minecraft.util.Mth;

import java.util.List;

Expand Down Expand Up @@ -45,47 +45,47 @@ public double getOffsetX() {
}

public void setOffsetX(double offsetX) {
this.offsetX = MathHelper.clamp(offsetX, ModConfig.MIN_DOUBLE, ModConfig.MAX_DOUBLE);
this.offsetX = Mth.clamp(offsetX, ModConfig.MIN_DOUBLE, ModConfig.MAX_DOUBLE);
}

public double getOffsetY() {
return offsetY * scale;
}

public void setOffsetY(double offsetY) {
this.offsetY = MathHelper.clamp(offsetY, ModConfig.MIN_DOUBLE, ModConfig.MAX_DOUBLE);
this.offsetY = Mth.clamp(offsetY, ModConfig.MIN_DOUBLE, ModConfig.MAX_DOUBLE);
}

public double getOffsetZ() {
return offsetZ * scale;
}

public void setOffsetZ(double offsetZ) {
this.offsetZ = MathHelper.clamp(offsetZ, ModConfig.MIN_DOUBLE, ModConfig.MAX_DOUBLE);
this.offsetZ = Mth.clamp(offsetZ, ModConfig.MIN_DOUBLE, ModConfig.MAX_DOUBLE);
}

public float getPitch() {
return pitch;
}

public void setPitch(float pitch) {
this.pitch = MathHelper.wrapDegrees(pitch);
this.pitch = Mth.wrapDegrees(pitch);
}

public float getYaw() {
return yaw;
}

public void setYaw(float yaw) {
this.yaw = MathHelper.wrapDegrees(yaw);
this.yaw = Mth.wrapDegrees(yaw);
}

public float getRoll() {
return roll;
}

public void setRoll(float roll) {
this.roll = MathHelper.wrapDegrees(roll);
this.roll = Mth.wrapDegrees(roll);
}

public BindingTarget priority(int priority) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.xtracr.realcamera.RealCamera;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Minecraft;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand All @@ -18,7 +18,7 @@ public class ConfigFile {
private static final Path PATH;

static {
File configDir = new File(MinecraftClient.getInstance().runDirectory, "config");
File configDir = new File(Minecraft.getInstance().gameDirectory, "config");
if (!configDir.exists()) configDir.mkdirs();
PATH = configDir.toPath().resolve(FILE_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Formatting;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;

public class ConfigScreen {
public static Screen create(Screen parent) {
Expand Down Expand Up @@ -120,7 +120,7 @@ public static Screen create(Screen parent) {
classic.addEntry(classicCameraRotation.build());

binding.addEntry(entryBuilder.startTextDescription(LocUtil.CONFIG_OPTION("toModelViewScreen",
LocUtil.MODEL_VIEW_TITLE().styled(s -> s.withColor(Formatting.BLUE))))
LocUtil.MODEL_VIEW_TITLE().withStyle(s -> s.withColor(ChatFormatting.BLUE))))
.build());
binding.addEntry(entryBuilder.startBooleanToggle(LocUtil.CONFIG_OPTION("adjustOffset"), config.binding.adjustOffset)
.setDefaultValue(true)
Expand Down
Loading

0 comments on commit 5e2c204

Please sign in to comment.