diff --git a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java index 71cd677..16de976 100644 --- a/common/src/main/java/com/xtracr/realcamera/KeyBindings.java +++ b/common/src/main/java/com/xtracr/realcamera/KeyBindings.java @@ -5,17 +5,16 @@ import com.xtracr.realcamera.gui.ModelViewScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; import org.lwjgl.glfw.GLFW; -import java.util.Collection; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; public final class KeyBindings { - private static final ModConfig config = ConfigFile.modConfig; private static final String KEY_CATEGORY = "key.category.xtracr_" + RealCamera.MODID; private static final String KEY_ID = "key.xtracr_" + RealCamera.MODID + "_"; - public static final Collection KEY_BINDINGS = new HashSet<>(); + private static final List KEY_BINDINGS = new ArrayList<>(); private static final KeyBinding MODEL_VIEW_GUI = createKeyBinding("modelViewGui"); private static final KeyBinding TOGGLE_PERSPECTIVE = createKeyBinding("togglePerspective", GLFW.GLFW_KEY_F6); private static final KeyBinding TOGGLE_ADJUST_MODE = createKeyBinding("toggleAdjustMode"); @@ -28,7 +27,7 @@ public final class KeyBindings { private static final KeyBinding ADJUST_RIGHT = createKeyBinding("adjustRIGHT"); public static KeyBinding createKeyBinding(String id) { - return createKeyBinding(id, InputUtil.UNKNOWN_KEY.getCode()); + return createKeyBinding(id, GLFW.GLFW_KEY_UNKNOWN); } public static KeyBinding createKeyBinding(String id, int code) { @@ -37,8 +36,13 @@ public static KeyBinding createKeyBinding(String id, int code) { return keyBinding; } + public static void register(Consumer registerer) { + KEY_BINDINGS.forEach(registerer); + } + public static void handle(MinecraftClient client) { if (client.player == null) return; + final ModConfig config = ConfigFile.modConfig; while (MODEL_VIEW_GUI.wasPressed()) { client.setScreen(new ModelViewScreen()); } @@ -58,32 +62,32 @@ public static void handle(MinecraftClient client) { ConfigFile.save(); } while (ADJUST_LEFT.wasPressed()) { - if (config.isClassic()) config.adjustClassicZ(true); + if (config.isClassic()) config.adjustClassicZ(1); else config.adjustBindingZ(true); ConfigFile.save(); } while (ADJUST_RIGHT.wasPressed()) { - if (config.isClassic()) config.adjustClassicZ(false); + if (config.isClassic()) config.adjustClassicZ(-1); else config.adjustBindingZ(false); ConfigFile.save(); } while (ADJUST_UP.wasPressed()) { - if (config.isClassic()) config.adjustClassicY(true); + if (config.isClassic()) config.adjustClassicY(1); else config.adjustBindingY(true); ConfigFile.save(); } while (ADJUST_DOWN.wasPressed()) { - if (config.isClassic()) config.adjustClassicY(false); + if (config.isClassic()) config.adjustClassicY(-1); else config.adjustBindingY(false); ConfigFile.save(); } while (ADJUST_FRONT.wasPressed()) { - if (config.isClassic()) config.adjustClassicX(true); + if (config.isClassic()) config.adjustClassicX(1); else config.adjustBindingX(true); ConfigFile.save(); } while (ADJUST_BACK.wasPressed()) { - if (config.isClassic()) config.adjustClassicX(false); + if (config.isClassic()) config.adjustClassicX(-1); else config.adjustBindingX(false); ConfigFile.save(); } diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index d31dc2c..bf814ea 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -3,6 +3,7 @@ import com.xtracr.realcamera.api.VirtualRenderer; import com.xtracr.realcamera.compat.PehkuiCompat; import com.xtracr.realcamera.compat.PhysicsModCompat; +import com.xtracr.realcamera.config.BindingTarget; import com.xtracr.realcamera.config.ConfigFile; import com.xtracr.realcamera.config.ModConfig; import com.xtracr.realcamera.mixin.PlayerEntityRendererAccessor; @@ -25,17 +26,16 @@ import net.minecraft.util.math.Vec3d; import org.joml.Matrix3f; import org.joml.Matrix4f; -import org.joml.Vector3f; import org.joml.Vector4f; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.function.BiPredicate; +import java.util.function.BiFunction; public class RealCameraCore { - private static final ModConfig config = ConfigFile.modConfig; private static VertexRecorder recorder = new VertexRecorder(); + private static BindingTarget currentTarget = new BindingTarget(); private static String status = "Successful"; private static boolean renderingPlayer = false; private static boolean active = false; @@ -55,31 +55,31 @@ public static void setRenderingPlayer(boolean value) { } public static float getPitch(float f) { - if (config.isRotationBound()) return pitch; - else return f + config.getBindingPitch(); + if (currentTarget.bindRotation()) return pitch; + else return f + currentTarget.pitch(); } public static float getYaw(float f) { - if (config.isRotationBound()) return yaw; - else return f - config.getBindingYaw(); + if (currentTarget.bindRotation()) return yaw; + else return f - currentTarget.yaw(); } public static float getRoll(float f) { - if (config.isClassic()) return f + config.getClassicRoll(); - else if (config.isRotationBound()) return roll; - else return f + config.getBindingRoll(); + if (config().isClassic()) return f + config().getClassicRoll(); + else if (currentTarget.bindRotation()) return roll; + else return f + currentTarget.roll(); } public static Vec3d getPos(Vec3d vec3d) { - return new Vec3d(config.isXBound() ? pos.getX() : vec3d.getX() + config.getBindingX(), - config.isYBound() ? pos.getY() : vec3d.getY() + config.getBindingY(), - config.isZBound() ? pos.getZ() : vec3d.getZ() + config.getBindingZ()); + return new Vec3d(currentTarget.bindX() ? pos.getX() : vec3d.getX() + currentTarget.offsetX(), + currentTarget.bindY() ? pos.getY() : vec3d.getY() + currentTarget.offsetY(), + currentTarget.bindZ() ? pos.getZ() : vec3d.getZ() + currentTarget.offsetZ()); } public static Vec3d getCameraPos(Vec3d vec3d) { - return new Vec3d(config.isXBound() ? cameraPos.getX() : vec3d.getX() + config.getBindingX(), - config.isYBound() ? cameraPos.getY() : vec3d.getY() + config.getBindingY(), - config.isZBound() ? cameraPos.getZ() : vec3d.getZ() + config.getBindingZ()); + return new Vec3d(currentTarget.bindX() ? cameraPos.getX() : vec3d.getX() + currentTarget.offsetX(), + currentTarget.bindY() ? cameraPos.getY() : vec3d.getY() + currentTarget.offsetY(), + currentTarget.bindZ() ? cameraPos.getZ() : vec3d.getZ() + currentTarget.offsetZ()); } public static void setCameraPos(Vec3d vec3d) { @@ -87,8 +87,8 @@ public static void setCameraPos(Vec3d vec3d) { } public static void init(MinecraftClient client) { - active = config.isEnabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null - && client.player != null && !config.shouldDisableMod(client); + active = config().isEnabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null + && client.player != null && !config().shouldDisableMod(client); } public static boolean isActive() { @@ -103,20 +103,24 @@ public static void renderPlayer(VertexConsumerProvider vertexConsumers) { Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix().transpose().invertAffine() .translate((float) -pos.getX(), (float) -pos.getY(), (float) -pos.getZ()); Matrix3f normalMatrix = matrixStack.peek().getNormalMatrix().transpose().invert(); - BiPredicate biPredicate = (renderLayer, vertices) -> { - double depth = config.disable.depth, centerZ = 0; - for (VertexRecorder.Vertex vertex : vertices) { - if (vertex.z() < -depth) return true; + BiFunction function = (renderLayer, vertices) -> { + double depth = currentTarget.disablingDepth(), centerZ = 0; + int size = vertices.length; + VertexRecorder.Vertex[] newQuad = new VertexRecorder.Vertex[size]; + for (int i = 0; i < size; i++) newQuad[i] = vertices[i].transform(positionMatrix, normalMatrix); + for (VertexRecorder.Vertex vertex : newQuad) { + if (vertex.z() < -depth) return newQuad; centerZ += vertex.z(); } - return centerZ < -depth * vertices.length; + return centerZ < -depth * vertices.length ? newQuad : null; }; - recorder.drawByAnother(vertex -> vertex.transform(positionMatrix, normalMatrix), vertexConsumers, renderLayer -> true, biPredicate); + recorder.drawByAnother(vertexConsumers, renderLayer -> true, function); } public static void computeCamera(MinecraftClient client, float tickDelta) { - roll = config.getClassicRoll(); - if (config.isClassic()) return; + roll = config().getClassicRoll(); + currentTarget = new BindingTarget(); + if (config().isClassic()) return; // GameRenderer.renderWorld MatrixStack matrixStack = new MatrixStack(); @@ -125,48 +129,45 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { recorder.buildLastRecord(); // ModelPart$Cuboid.renderCuboid - Vector4f offset = matrixStack.peek().getPositionMatrix().transform(new Vector4f((float) (config.getBindingZ() * config.getScale()), - -(float) (config.getBindingY() * config.getScale()) - 0.125f, - -(float) (config.getBindingX() * config.getScale()) - 0.225f, 1.0F)); + Vector4f offset = matrixStack.peek().getPositionMatrix().transform(new Vector4f((float) (config().getBindingZ() * config().getScale()), + -(float) (config().getBindingY() * config().getScale()) - 0.125f, + -(float) (config().getBindingX() * config().getScale()) - 0.225f, 1.0f)); pos = new Vec3d(offset.x(), offset.y(), offset.z()); - Matrix3f normal = matrixStack.peek().getNormalMatrix().scale(1.0F, -1.0F, -1.0F); - if (config.binding.experimental) { - List targetList = new ArrayList<>(); - if (config.binding.autoBind) { - Collection targetSet = config.binding.targetMap.values(); + Matrix3f normal = matrixStack.peek().getNormalMatrix().scale(1.0f, -1.0f, -1.0f); + if (config().binding.experimental) { + List targetList = new ArrayList<>(); + if (config().binding.autoBind) { + Collection targetSet = config().binding.targetMap.values(); recorder.setCurrent(renderLayer -> targetSet.stream().anyMatch(t -> renderLayer.toString().contains(t.textureId()))); String textureId = recorder.currentTextureId(); if (textureId != null) targetList.addAll(targetSet.stream().filter(t -> textureId.contains(t.textureId())).toList()); } - targetList.add(config.binding.targetMap.get(config.binding.nameOfList)); - for (ModConfig.Binding.Target target : targetList) { + targetList.add(config().binding.targetMap.get(config().binding.nameOfList)); + for (BindingTarget target : targetList) { try { recorder.setCurrent(renderLayer -> renderLayer.toString().contains(target.textureId())); if (recorder.quadCount() <= 0) throw new NullPointerException("Vertices not found"); - Vec3d front = recorder.getNormal(target.forwardU(), target.forwardV()); - Vec3d up = recorder.getNormal(target.upwardU(), target.upwardV()); - Vec3d center = recorder.getPos(target.posU(), target.posV()); - if (!MathUtil.isFinite(front) || !MathUtil.isFinite(up) || !MathUtil.isFinite(center)) throw new ArithmeticException(); - normal.set(up.crossProduct(front).toVector3f(), up.toVector3f(), front.toVector3f()); - Vector3f vec3f = normal.transform(new Vector3f((float) (config.getBindingZ() * config.getScale()), - (float) (config.getBindingY() * config.getScale()), - (float) (config.getBindingX() * config.getScale()))); - pos = center.add(vec3f.x(), vec3f.y(), vec3f.z()); + pos = recorder.getTargetPosAndRot(target, normal); + currentTarget = target; break; } catch (Exception ignored) { } } } - normal.rotateLocal((float) Math.toRadians(config.getBindingYaw()), normal.m10, normal.m11, normal.m12); - normal.rotateLocal((float) Math.toRadians(config.getBindingPitch()), normal.m00, normal.m01, normal.m02); - normal.rotateLocal((float) Math.toRadians(config.getBindingRoll()), normal.m20, normal.m21, normal.m22); - Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(180.0D / Math.PI); + normal.rotateLocal((float) Math.toRadians(currentTarget.yaw()), normal.m10, normal.m11, normal.m12); + normal.rotateLocal((float) Math.toRadians(currentTarget.pitch()), normal.m00, normal.m01, normal.m02); + normal.rotateLocal((float) Math.toRadians(currentTarget.roll()), normal.m20, normal.m21, normal.m22); + Vec3d eulerAngle = MathUtil.getEulerAngleYXZ(normal).multiply(180.0d / Math.PI); pitch = (float) eulerAngle.getX(); yaw = (float) -eulerAngle.getY(); roll = (float) eulerAngle.getZ(); } + private static ModConfig config() { + return ConfigFile.modConfig; + } + private static void virtualRender(MinecraftClient client, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider consumers) { ClientPlayerEntity player = client.player; // WorldRenderer.render @@ -182,11 +183,11 @@ private static void virtualRender(MinecraftClient client, float tickDelta, Matri matrixStack.push(); EntityRenderDispatcher dispatcher = client.getEntityRenderDispatcher(); dispatcher.configure(client.world, client.gameRenderer.getCamera(), player); - if (config.binding.experimental) dispatcher.render(player, renderOffset.getX(), renderOffset.getY(), renderOffset.getZ(), + if (config().binding.experimental) dispatcher.render(player, renderOffset.getX(), renderOffset.getY(), renderOffset.getZ(), MathHelper.lerp(tickDelta, player.prevYaw, player.getYaw()), tickDelta, matrixStack, consumers, dispatcher.getLight(player, tickDelta)); matrixStack.pop(); // EntityRenderDispatcher.render - if (config.compatPhysicsMod()) + if (config().compatPhysicsMod()) PhysicsModCompat.renderStart(client.getEntityRenderDispatcher(), player, renderOffset.getX(), renderOffset.getY(), renderOffset.getZ(), MathHelper.lerp(tickDelta, player.prevYaw, player.getYaw()), tickDelta, matrixStack); @@ -194,9 +195,9 @@ private static void virtualRender(MinecraftClient client, float tickDelta, Matri renderOffset = renderOffset.add(playerRenderer.getPositionOffset(player, tickDelta)); matrixStack.translate(renderOffset.getX(), renderOffset.getY(), renderOffset.getZ()); - if (config.compatPehkui()) PehkuiCompat.scaleMatrices(matrixStack, player, tickDelta); + if (config().compatPehkui()) PehkuiCompat.scaleMatrices(matrixStack, player, tickDelta); - if (config.isUsingModModel()) { + if (config().isUsingModModel()) { status = "Successful"; try { matrixStack.push(); @@ -257,6 +258,6 @@ private static void virtualRender(MinecraftClient client, float tickDelta, Matri playerModel.setAngles(player, o, n, l, k, m); // AnimalModel.render // ModelPart.render - config.getVanillaModelPart().get(playerRenderer.getModel()).rotate(matrixStack); + config().getVanillaModelPart().get(playerRenderer.getModel()).rotate(matrixStack); } } diff --git a/common/src/main/java/com/xtracr/realcamera/compat/PehkuiCompat.java b/common/src/main/java/com/xtracr/realcamera/compat/PehkuiCompat.java index 8f27b26..7569465 100644 --- a/common/src/main/java/com/xtracr/realcamera/compat/PehkuiCompat.java +++ b/common/src/main/java/com/xtracr/realcamera/compat/PehkuiCompat.java @@ -27,15 +27,15 @@ public class PehkuiCompat { public static void scaleMatrices(MatrixStack matrixStack, Entity entity, float tickDelta) { if (!loaded) return; - final float widthScale = (float) ReflectUtil.invokeMethod(getModelWidthScale, null, entity, tickDelta).orElse(1.0F); - final float heightScale = (float) ReflectUtil.invokeMethod(getModelHeightScale, null, entity, tickDelta).orElse(1.0F); + final float widthScale = (float) ReflectUtil.invokeMethod(getModelWidthScale, null, entity, tickDelta).orElse(1.0f); + final float heightScale = (float) ReflectUtil.invokeMethod(getModelHeightScale, null, entity, tickDelta).orElse(1.0f); matrixStack.peek().getPositionMatrix().scale(widthScale, heightScale, widthScale); } public static Vec3d scaleVec3d(Vec3d vec3d, Entity entity, float tickDelta) { if (!loaded) return vec3d; - final float widthScale = (float) ReflectUtil.invokeMethod(getModelWidthScale, null, entity, tickDelta).orElse(1.0F); - final float heightScale = (float) ReflectUtil.invokeMethod(getModelHeightScale, null, entity, tickDelta).orElse(1.0F); + final float widthScale = (float) ReflectUtil.invokeMethod(getModelWidthScale, null, entity, tickDelta).orElse(1.0f); + final float heightScale = (float) ReflectUtil.invokeMethod(getModelHeightScale, null, entity, tickDelta).orElse(1.0f); return vec3d.multiply(widthScale, heightScale, widthScale); } } diff --git a/common/src/main/java/com/xtracr/realcamera/compat/PhysicsModCompat.java b/common/src/main/java/com/xtracr/realcamera/compat/PhysicsModCompat.java index aac23bc..4eddaa4 100644 --- a/common/src/main/java/com/xtracr/realcamera/compat/PhysicsModCompat.java +++ b/common/src/main/java/com/xtracr/realcamera/compat/PhysicsModCompat.java @@ -52,7 +52,7 @@ public static void renderStart(EntityRenderDispatcher dispatc Object world = ReflectUtil.getFieldValue(EntityRenderDispatcher_worldField, dispatcher).get(); if ((boolean) ReflectUtil.invokeMethod(ConfigClient_areOceanPhysicsEnabled, null).orElse(false) && world instanceof ClientWorld clientWorld) { Object oceanWorld = ReflectUtil.invokeMethod(PhysicsWorld_getOceanWorld, ReflectUtil.invokeMethod(PhysicsMod_getPhysicsWorld, ReflectUtil.invokeMethod(PhysicsMod_getInstance, null, clientWorld).get()).get()).get(); - ReflectUtil.invokeMethod(OceanWorld_computeEntityOffset, oceanWorld, matrixStack.peek().getPositionMatrix(), matrixStack.peek().getNormalMatrix(), clientWorld, entity, x, y, z, 0.0D, 0.0D, 0.0D, yRot, renderPercent); + ReflectUtil.invokeMethod(OceanWorld_computeEntityOffset, oceanWorld, matrixStack.peek().getPositionMatrix(), matrixStack.peek().getNormalMatrix(), clientWorld, entity, x, y, z, 0.0d, 0.0d, 0.0d, yRot, renderPercent); } } } diff --git a/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java b/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java new file mode 100644 index 0000000..1eba724 --- /dev/null +++ b/common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java @@ -0,0 +1,196 @@ +package com.xtracr.realcamera.config; + +public class BindingTarget { + public static final BindingTarget MINECRAFT_HEAD = new BindingTarget("minecraft:textures/entity/player/", 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, true, true, true, true, 1, -0.15f, 0, 0, 0, 0, 0, 0.2f); + String textureId; + float forwardU, forwardV, upwardU, upwardV, posU, posV; + boolean bindX, bindY, bindZ, bindRotation; + double scale, offsetX, offsetY, offsetZ; + float pitch, yaw, roll, disablingDepth; + + public BindingTarget() { + this(null, 0, 0, 0, 0, 0, 0, true, true, true, true, 1, 0, 0, 0, 0, 0, 0, 0); + } + + public BindingTarget(String textureId, float forwardU, float forwardV, float upwardU, float upwardV, float posU, float posV, boolean bindX, boolean bindY, boolean bindZ, boolean bindRotation, double scale, double offsetX, double offsetY, double offsetZ, float pitch, float yaw, float roll, float disablingDepth) { + this.textureId = textureId; + this.forwardU = forwardU; + this.forwardV = forwardV; + this.upwardU = upwardU; + this.upwardV = upwardV; + this.posU = posU; + this.posV = posV; + this.bindX = bindX; + this.bindY = bindY; + this.bindZ = bindZ; + this.bindRotation = bindRotation; + this.scale = scale; + this.offsetX = offsetX; + this.offsetY = offsetY; + this.offsetZ = offsetZ; + this.pitch = pitch; + this.yaw = yaw; + this.roll = roll; + this.disablingDepth = disablingDepth; + } + + public String textureId() { + return textureId; + } + + public void setTextureId(String textureId) { + this.textureId = textureId; + } + + public float forwardU() { + return forwardU; + } + + public void setForwardU(float forwardU) { + this.forwardU = forwardU; + } + + public float forwardV() { + return forwardV; + } + + public void setForwardV(float forwardV) { + this.forwardV = forwardV; + } + + public float upwardU() { + return upwardU; + } + + public void setUpwardU(float upwardU) { + this.upwardU = upwardU; + } + + public float upwardV() { + return upwardV; + } + + public void setUpwardV(float upwardV) { + this.upwardV = upwardV; + } + + public float posU() { + return posU; + } + + public void setPosU(float posU) { + this.posU = posU; + } + + public float posV() { + return posV; + } + + public void setPosV(float posV) { + this.posV = posV; + } + + public boolean bindX() { + return isExperimental() ? bindX : config().isXBound(); + } + + public void setBindX(boolean bindX) { + this.bindX = bindX; + } + + public boolean bindY() { + return isExperimental() ? bindY : config().isYBound(); + } + + public void setBindY(boolean bindY) { + this.bindY = bindY; + } + + public boolean bindZ() { + return isExperimental() ? bindZ : config().isZBound(); + } + + public void setBindZ(boolean bindZ) { + this.bindZ = bindZ; + } + + public boolean bindRotation() { + return isExperimental() ? bindRotation : config().isRotationBound(); + } + + public void setBindRotation(boolean bindRotation) { + this.bindRotation = bindRotation; + } + + public double scale() { + return isExperimental() ? scale : config().getScale(); + } + + public void setScale(double scale) { + this.scale = scale; + } + + public double offsetX() { + return isExperimental() ? offsetX * scale : config().getBindingX() * config().getScale(); + } + + public void setOffsetX(double offsetX) { + this.offsetX = offsetX; + } + + public double offsetY() { + return isExperimental() ? offsetY * scale : config().getBindingY() * config().getScale(); + } + + public void setOffsetY(double offsetY) { + this.offsetY = offsetY; + } + + public double offsetZ() { + return isExperimental() ? offsetZ * scale : config().getBindingZ() * config().getScale(); + } + + public void setOffsetZ(double offsetZ) { + this.offsetZ = offsetZ; + } + + public float pitch() { + return isExperimental() ? pitch : config().getBindingPitch(); + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + + public float yaw() { + return isExperimental() ? yaw : config().getBindingYaw(); + } + + public void setYaw(float yaw) { + this.yaw = yaw; + } + + public float roll() { + return isExperimental() ? roll : config().getBindingRoll(); + } + + public void setRoll(float roll) { + this.roll = roll; + } + + public float disablingDepth() { + return disablingDepth; + } + + public void setDisablingDepth(float disablingDepth) { + this.disablingDepth = disablingDepth; + } + + private boolean isExperimental() { + return config().binding.experimental && textureId != null; + } + + private static ModConfig config() { + return ConfigFile.modConfig; + } +} diff --git a/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java b/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java index 295eb30..971e342 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigFile.java @@ -15,9 +15,7 @@ public class ConfigFile { public static final ModConfig modConfig = new ModConfig(); private static final String FILE_NAME = RealCamera.MODID + ".json"; private static final Path PATH; - private static final Gson GSON = new GsonBuilder() - .setPrettyPrinting() - .create(); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); static { final File configDir = new File(MinecraftClient.getInstance().runDirectory, "config"); diff --git a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java index 3242e59..955be2b 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java @@ -322,13 +322,6 @@ public static Screen create(Screen parent) { .setTooltip(Text.translatable(TOOLTIP + "autoBind")) .setSaveConsumer(b -> config.binding.autoBind = b) .build()); - experimental.addEntry(entryBuilder.startDoubleField(Text.literal("Disabling Depth"), config.disable.depth) - .setDefaultValue(0.2) - .setMin(0.01) - .setMax(ModConfig.MAX_DOUBLE) - .setTooltip(Text.translatable(TOOLTIP + "depth")) - .setSaveConsumer(d -> config.disable.depth = d) - .build()); return builder.build(); } diff --git a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java index 280869e..c9a233d 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -8,8 +8,8 @@ import java.util.*; public class ModConfig { - protected static final double MIN_DOUBLE = -64.0D; - protected static final double MAX_DOUBLE = 64.0D; + protected static final double MIN_DOUBLE = -64.0d; + protected static final double MAX_DOUBLE = 64.0d; public General general = new General(); public Binding binding = new Binding(); @@ -186,32 +186,29 @@ public void cycleClassicAdjustMode() { classic.adjustMode = classic.adjustMode.cycle(); } - public void adjustClassicX(boolean add) { - int s = add ? 1 : -1; + public void adjustClassicX(int count) { switch (classic.adjustMode) { - case CENTER -> classic.centerX += s * getAdjustStep(); - case ROTATION -> classic.roll += s * 4 * (float) getAdjustStep(); - default -> classic.cameraX += s * getAdjustStep(); + case CENTER -> classic.centerX += count * getAdjustStep(); + case ROTATION -> classic.roll += count * 4 * (float) getAdjustStep(); + default -> classic.cameraX += count * getAdjustStep(); } classic.clamp(); } - public void adjustClassicY(boolean add) { - int s = add ? 1 : -1; + public void adjustClassicY(int count) { switch (classic.adjustMode) { - case CENTER -> classic.centerY += s * getAdjustStep(); - case ROTATION -> classic.yaw += s * 4 * (float) getAdjustStep(); - default -> classic.cameraY += s * getAdjustStep(); + case CENTER -> classic.centerY += count * getAdjustStep(); + case ROTATION -> classic.yaw += count * 4 * (float) getAdjustStep(); + default -> classic.cameraY += count * getAdjustStep(); } classic.clamp(); } - public void adjustClassicZ(boolean add) { - int s = add ? 1 : -1; + public void adjustClassicZ(int count) { switch (classic.adjustMode) { - case CENTER -> classic.centerZ += s * getAdjustStep(); - case ROTATION -> classic.pitch += s * 4 * (float) getAdjustStep(); - default -> classic.cameraZ += s * getAdjustStep(); + case CENTER -> classic.centerZ += count * getAdjustStep(); + case ROTATION -> classic.pitch += count * 4 * (float) getAdjustStep(); + default -> classic.cameraZ += count * getAdjustStep(); } classic.clamp(); } @@ -285,34 +282,32 @@ public static class General { public boolean dynamicCrosshair = false; public boolean renderModel = true; public double adjustStep = 0.25D; - public double scale = 1.0D; + public double scale = 1.0d; private void clamp() { - adjustStep = MathHelper.clamp(adjustStep, 0.0D, MAX_DOUBLE); - scale = MathHelper.clamp(scale, 0.0D, MAX_DOUBLE); + adjustStep = MathHelper.clamp(adjustStep, 0.0d, MAX_DOUBLE); + scale = MathHelper.clamp(scale, 0.0d, MAX_DOUBLE); } } public static class Binding { - protected static final Map defaultTargetMap = Map.of("minecraft_head", - new Target("minecraft:textures/entity/player/", - 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f)); + protected static final Map defaultTargetMap = Map.of("minecraft_head", BindingTarget.MINECRAFT_HEAD); public VanillaModelPart vanillaModelPart = VanillaModelPart.head; public boolean experimental = false; public boolean adjustOffset = true; public boolean autoBind = true; public String nameOfList = "minecraft_head"; - public LinkedHashMap targetMap = new LinkedHashMap<>(defaultTargetMap); + public LinkedHashMap targetMap = new LinkedHashMap<>(defaultTargetMap); public boolean bindX = true; public boolean bindY = true; public boolean bindZ = true; - public double cameraX = 0.0D; - public double cameraY = 0.0D; - public double cameraZ = 0.0D; + public double cameraX = 0.0d; + public double cameraY = 0.0d; + public double cameraZ = 0.0d; public boolean bindRotation = true; - public float pitch = 0.0F; - public float yaw = 0.0F; - public float roll = 0.0F; + public float pitch = 0.0f; + public float yaw = 0.0f; + public float roll = 0.0f; private void clamp() { if (vanillaModelPart == null) vanillaModelPart = VanillaModelPart.head; @@ -324,21 +319,19 @@ private void clamp() { yaw = MathHelper.wrapDegrees(yaw); roll = MathHelper.wrapDegrees(roll); } - - public record Target(String textureId, float forwardU, float forwardV, float upwardU, float upwardV, float posU, float posV) {} } public static class Classic { public AdjustMode adjustMode = AdjustMode.CAMERA; - public double cameraX = -60.0D; - public double cameraY = 2.0D; - public double cameraZ = -16.0D; - public double centerX = 0.0D; + public double cameraX = -60.0d; + public double cameraY = 2.0d; + public double cameraZ = -16.0d; + public double centerX = 0.0d; public double centerY = -3.4D; - public double centerZ = 0.0D; - public float pitch = 0.0F; - public float yaw = 18.0F; - public float roll = 0.0F; + public double centerZ = 0.0d; + public float pitch = 0.0f; + public float yaw = 18.0f; + public float roll = 0.0f; private void clamp() { if (adjustMode == null) adjustMode = AdjustMode.CAMERA; @@ -393,7 +386,6 @@ public static class Disable { public boolean sneaking = false; public boolean sleeping = false; public boolean screenOpened = false; - public double depth = 0.2; private void clamp() { if (disabledModelParts == null) disabledModelParts = new ArrayList<>(defaultParts); diff --git a/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java b/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java new file mode 100644 index 0000000..b5ce393 --- /dev/null +++ b/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java @@ -0,0 +1,67 @@ +package com.xtracr.realcamera.gui; + +import com.xtracr.realcamera.RealCamera; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +import net.minecraft.client.gui.widget.PressableWidget; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + + +public class CyclingTexturedButton extends PressableWidget { + private static final Identifier ICON_TEXTURE = new Identifier(RealCamera.MODID, "textures/gui/icon.png"); + protected final Identifier texture; + protected final int textureWidth, textureHeight, vOffset, maximum; + protected int u, v; + private int value = 0; + + public CyclingTexturedButton(int u, int v, int maximum) { + this(0, 0, 16, 16, u, v, maximum); + } + + public CyclingTexturedButton(int x, int y, int width, int height, int u, int v, int maximum) { + this(x, y, width, height, u, v, height, maximum, ICON_TEXTURE, 256, 256, Text.empty()); + } + + public CyclingTexturedButton(int x, int y, int width, int height, int u, int v, int vOffset, int maximum, Identifier texture, int textureWidth, int textureHeight, Text message) { + super(x, y, width, height, message); + this.u = u; + this.v = v; + this.vOffset = vOffset; + this.maximum = maximum; + this.texture = texture; + this.textureWidth = textureWidth; + this.textureHeight = textureHeight; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = (value % maximum + maximum) % maximum; + } + + private void cycle(int amount) { + value = (value + amount % maximum + maximum) % maximum; + } + + @Override + public void onPress() { + if (Screen.hasShiftDown()) cycle(-1); + else cycle(1); + } + + @Override + public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { + context.fill(getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0xFF646464); + context.drawTexture(texture, getX(), getY(), u, v + value * vOffset, width, height, textureWidth, textureHeight); + if (hovered) context.drawBorder(getX(), getY(), getWidth(), getHeight(), 0xFFFFFFFF); + } + + @Override + protected void appendClickableNarrations(NarrationMessageBuilder builder) { + appendDefaultNarrations(builder); + } +} diff --git a/common/src/main/java/com/xtracr/realcamera/gui/FloatFieldWidget.java b/common/src/main/java/com/xtracr/realcamera/gui/FloatFieldWidget.java index 7d06fdf..aa4cf5c 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/FloatFieldWidget.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/FloatFieldWidget.java @@ -6,8 +6,7 @@ public class FloatFieldWidget extends NumberFieldWidget { - public FloatFieldWidget(TextRenderer textRenderer, int width, int height, - @Nullable NumberFieldWidget copyFrom, Text text) { + public FloatFieldWidget(TextRenderer textRenderer, int width, int height, @Nullable NumberFieldWidget copyFrom, Text text) { super(textRenderer, 0, 0, width, height, copyFrom, text, 0f, Float.MAX_VALUE, -Float.MAX_VALUE); setMaxLength(8); } diff --git a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java index b65369c..1317773 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java @@ -1,5 +1,6 @@ package com.xtracr.realcamera.gui; +import com.xtracr.realcamera.config.BindingTarget; import com.xtracr.realcamera.util.Triple; import com.xtracr.realcamera.util.VertexRecorder; import net.minecraft.client.gui.DrawContext; @@ -7,6 +8,7 @@ import net.minecraft.client.render.VertexConsumer; import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec3d; +import org.joml.Matrix3f; import java.awt.*; import java.util.ArrayList; @@ -14,7 +16,7 @@ import java.util.List; public class ModelAnalyser extends VertexRecorder { - BuiltRecord focusedRecord; + private BuiltRecord focusedRecord; public String focusedTextureId() { if (focusedRecord == null) return null; @@ -53,11 +55,31 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) { return result.getRight(); } - public void drawQuad(DrawContext context, float u, float v, int argb) { + public void preview(DrawContext context, BindingTarget target, int length, int forwardArgb, int upwardArgb, int leftArgb) { if (currentRecord == null) return; - int quadIndex = getQuadIndex(currentRecord, u, v); - if (quadIndex == -1) return; - drawQuad(context, currentRecord.vertices()[quadIndex], argb, 1000); + Matrix3f normal = new Matrix3f(); + Vec3d pos; + try { + pos = getTargetPosAndRot(target, normal); + } catch (Exception exception) { + drawByAnother(context.getVertexConsumers()); + context.draw(); + return; + } + normal.rotateLocal((float) Math.toRadians(target.yaw()), normal.m10, normal.m11, normal.m12); + normal.rotateLocal((float) Math.toRadians(target.pitch()), normal.m00, normal.m01, normal.m02); + normal.rotateLocal((float) Math.toRadians(target.roll()), normal.m20, normal.m21, normal.m22); + drawByAnother(context.getVertexConsumers()); + context.draw(); + drawNormal(context, pos, new Vec3d(normal.m20(), normal.m21(), normal.m22()), length, forwardArgb); + drawNormal(context, pos, new Vec3d(normal.m10(), normal.m11(), normal.m12()), length / 2, upwardArgb); + drawNormal(context, pos, new Vec3d(normal.m00(), normal.m01(), normal.m02()), length / 2, leftArgb); + } + + public void drawQuad(DrawContext context, float u, float v, int argb) { + Vertex[] quad; + if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return; + drawQuad(context, quad, argb, 1000); } public void drawPolyhedron(DrawContext context, int quadIndex, int argb1, int argb2) { @@ -97,18 +119,9 @@ public void drawPolyhedron(DrawContext context, int quadIndex, int argb1, int ar } public void drawNormal(DrawContext context, float u, float v, int length, int argb) { - if (currentRecord == null) return; - int quadIndex = getQuadIndex(currentRecord, u, v); - if (quadIndex == -1) return; - Vertex vertex = currentRecord.vertices()[quadIndex][0]; - Vec3d start = getPos(u, v); - Vec3d end = vertex.normal().multiply(length).add(start); - VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getLineStrip()); - vertexConsumer.vertex(start.getX(), start.getY(), start.getZ() + 1200f).color(argb) - .normal(vertex.normalX(), vertex.normalY(), vertex.normalZ()).next(); - vertexConsumer.vertex(end.getX(), end.getY(), end.getZ() + 1200f).color(argb) - .normal(vertex.normalX(), vertex.normalY(), vertex.normalZ()).next(); - context.draw(); + Vertex[] quad; + if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return; + drawNormal(context, getPos(quad, u, v), quad[0].normal(), length, argb); } private static boolean intersects(Vertex[] quad, List quads) { @@ -124,4 +137,14 @@ private static void drawQuad(DrawContext context, Vertex[] quad, int argb, int o if (quad.length == 3) vertexConsumer.vertex(quad[2].x(), quad[2].y(), quad[2].z() + offset).color(argb).next(); context.draw(); } + + private static void drawNormal(DrawContext context, Vec3d start, Vec3d normal, int length, int argb) { + Vec3d end = normal.multiply(length).add(start); + VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getLineStrip()); + vertexConsumer.vertex(start.getX(), start.getY(), start.getZ() + 1200f).color(argb) + .normal((float) normal.getX(), (float) normal.getY(), (float) normal.getZ()).next(); + vertexConsumer.vertex(end.getX(), end.getY(), end.getZ() + 1200f).color(argb) + .normal((float) normal.getX(), (float) normal.getY(), (float) normal.getZ()).next(); + context.draw(); + } } diff --git a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java index e30dec2..4d474b1 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -1,8 +1,8 @@ package com.xtracr.realcamera.gui; import com.xtracr.realcamera.RealCamera; +import com.xtracr.realcamera.config.BindingTarget; import com.xtracr.realcamera.config.ConfigFile; -import com.xtracr.realcamera.config.ModConfig; import com.xtracr.realcamera.util.MathUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; @@ -31,19 +31,31 @@ public class ModelViewScreen extends Screen { private static final String KEY_TOOLTIP = "screen.tooltip.xtracr_" + RealCamera.MODID + "_modelView_"; protected int xSize = 420, ySize = 220, widgetWidth = (xSize - ySize) / 4 - 8, widgetHeight = 18; protected int x, y; - private boolean shouldPause = false; - private int entitySize = 80, layers = 0, currentPage = 0; + private int entitySize = 80, layers = 0, category = 0, page = 0; private double entityX, entityY; private float xRot, yRot; private String focusedTextureId; private Vec2f focusedUV; - private CyclingButtonWidget selectingButton; - private NumberFieldWidget forwardUField, forwardVField, upwardUField, upwardVField, posUField, posVField; + private NumberFieldWidget forwardUField, forwardVField, upwardUField, upwardVField, posUField, posVField, scaleField, depthField; private TextFieldWidget textureIdField, nameField; - private final DoubleSliderWidget yawSlider = new DoubleSliderWidget(widgetWidth * 2 + 4, widgetHeight, 0, - -60.0D, 60.0D, d -> Text.translatable(KEY_WIDGET + "yaw", MathUtil.round(d, 2))); - private final DoubleSliderWidget pitchSlider = new DoubleSliderWidget(widgetWidth * 2 + 4, widgetHeight, 0, - -90.0D, 90.0D, d -> Text.translatable(KEY_WIDGET + "pitch", MathUtil.round(d, 2))); + private final CyclingButtonWidget selectingButton = createCyclingButton(Map.of( + 0, Text.translatable(KEY_WIDGET + "forwardMode").styled(s -> s.withColor(Formatting.GREEN)), + 1, Text.translatable(KEY_WIDGET + "upwardMode").styled(s -> s.withColor(Formatting.RED)), + 2, Text.translatable(KEY_WIDGET + "posMode").styled(s -> s.withColor(Formatting.BLUE))), + widgetWidth * 2 + 4, Text.translatable(KEY_WIDGET + "selectMode")); + private final CyclingTexturedButton pauseButton = new CyclingTexturedButton(0, 0, 2); + private final CyclingTexturedButton bindXButton = new CyclingTexturedButton(16, 0, 2); + private final CyclingTexturedButton bindYButton = new CyclingTexturedButton(16, 0, 2); + private final CyclingTexturedButton bindZButton = new CyclingTexturedButton(16, 0, 2); + private final CyclingTexturedButton bindRotButton = new CyclingTexturedButton(16, 0, 2); + private final DoubleSliderWidget localPitchSlider = createSlider("pitch", widgetWidth * 2 + 4, -90.0d, 90.0d); + private final DoubleSliderWidget localYawSlider = createSlider("yaw", widgetWidth * 2 + 4, -60.0d, 60.0d); + private final DoubleSliderWidget offsetXSlider = createSlider("offsetX", widgetWidth * 2 - 18, -1.0d, 1.0d); + private final DoubleSliderWidget offsetYSlider = createSlider("offsetY", widgetWidth * 2 - 18, -1.0d, 1.0d); + private final DoubleSliderWidget offsetZSlider = createSlider("offsetZ", widgetWidth * 2 - 18, -1.0d, 1.0d); + private final DoubleSliderWidget pitchSlider = createSlider("pitch", widgetWidth * 2 - 18, -180.0d, 180.0d); + private final DoubleSliderWidget yawSlider = createSlider("yaw", widgetWidth * 2 - 18, -180.0d, 180.0d); + private final DoubleSliderWidget rollSlider = createSlider("roll", widgetWidth * 2 - 18, -180.0d, 180.0d); public ModelViewScreen() { super(Text.translatable("screen.xtracr_" + RealCamera.MODID + "_modelView_title")); @@ -54,22 +66,19 @@ protected void init() { super.init(); x = (width - xSize) / 2; y = (height - ySize) / 2; - initWidgets(currentPage); + initWidgets(category, page); } - private void initWidgets(int page) { - this.currentPage = page; + private void initWidgets(int category, int page) { + this.category = category; + this.page = page; clearChildren(); - initLeftWidgets(); - addDrawableChild(new TexturedButton(x + (xSize - ySize) / 2 + 4, y + 4, 16, 16, 0, 0, button -> { - shouldPause = !shouldPause; - if (shouldPause) button.setUV(16, 0); - else button.setUV(0, 0); - })); + initLeftWidgets(category); + addDrawableChild(pauseButton).setPosition(x + (xSize - ySize) / 2 + 4, y + 4); addDrawableChild(new TexturedButton(x + (xSize - ySize) / 2 + 22, y + 4, 16, 16, 32, 0, button -> { entitySize = 80; - yawSlider.setValue(0); - pitchSlider.setValue(0); + localYawSlider.setValue(0); + localPitchSlider.setValue(0); entityX = entityY = 0; xRot = yRot = 0; layers = 0; @@ -77,40 +86,61 @@ private void initWidgets(int page) { initRightWidgets(page); } - private void initLeftWidgets() { + private void initLeftWidgets(final int category) { GridWidget gridWidget = new GridWidget(); gridWidget.getMainPositioner().margin(4, 2, 0, 0); - Positioner fieldPositioner = gridWidget.copyPositioner().margin(5, 3, 1, 1); + Positioner smallPositioner = gridWidget.copyPositioner().margin(5, 3, 1, 1); GridWidget.Adder adder = gridWidget.createAdder(2); - adder.add(yawSlider, 2); - adder.add(pitchSlider, 2); - adder.add(selectingButton = createCyclingButton(Map.of(0 ,Text.translatable(KEY_WIDGET + "forwardMode").styled(s -> s.withColor(Formatting.GREEN)), - 1, Text.translatable(KEY_WIDGET + "upwardMode").styled(s -> s.withColor(Formatting.RED)), - 2, Text.translatable(KEY_WIDGET + "posMode").styled(s -> s.withColor(Formatting.BLUE))), widgetWidth * 2 + 4, - Text.translatable(KEY_WIDGET + "selectMode")), 2).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "selectMode"))); - adder.add(forwardUField = createFloatField(widgetWidth, forwardUField), 1, fieldPositioner); - adder.add(forwardVField = createFloatField(widgetWidth, forwardVField), 1, fieldPositioner); - adder.add(upwardUField = createFloatField(widgetWidth, upwardUField), 1, fieldPositioner); - adder.add(upwardVField = createFloatField(widgetWidth, upwardVField), 1, fieldPositioner); - adder.add(posUField = createFloatField(widgetWidth, posUField), 1, fieldPositioner); - adder.add(posVField = createFloatField(widgetWidth, posVField), 1, fieldPositioner); - adder.add(textureIdField = createTextField(widgetWidth * 2 + 4, textureIdField),2, fieldPositioner) - .setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "textureId"))); + adder.add(createButton(Text.translatable(KEY_WIDGET + "settings"), widgetWidth, button -> initWidgets(0, page))); + adder.add(createButton(Text.translatable(KEY_WIDGET + "preview"), widgetWidth, button -> initWidgets(1, page))); + forwardUField = createFloatField(widgetWidth, forwardUField); + forwardVField = createFloatField(widgetWidth, forwardVField); + upwardUField = createFloatField(widgetWidth, upwardUField); + upwardVField = createFloatField(widgetWidth, upwardVField); + posUField = createFloatField(widgetWidth, posUField); + posVField = createFloatField(widgetWidth, posVField); + textureIdField = createTextField(widgetWidth * 2 + 4, textureIdField); textureIdField.setMaxLength(1024); + scaleField = createFloatField(widgetWidth, scaleField).setMax(64.0f); + depthField = createFloatField(widgetWidth, depthField).setMax(4.0f); + if (category == 0) { + adder.add(localPitchSlider, 2); + adder.add(localYawSlider, 2); + adder.add(selectingButton, 2).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "selectMode"))); + adder.add(forwardUField, 1, smallPositioner); + adder.add(forwardVField, 1, smallPositioner); + adder.add(upwardUField, 1, smallPositioner); + adder.add(upwardVField, 1, smallPositioner); + adder.add(posUField, 1, smallPositioner); + adder.add(posVField, 1, smallPositioner); + adder.add(textureIdField,2, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "textureId"))); + } else if (category == 1) { + Positioner sliderPositioner = gridWidget.copyPositioner().margin(-20, 2, 0, 0); + adder.add(bindXButton, 1, smallPositioner); + adder.add(offsetXSlider, 1, sliderPositioner); + adder.add(bindYButton, 1, smallPositioner); + adder.add(offsetYSlider, 1, sliderPositioner); + adder.add(bindZButton, 1, smallPositioner); + adder.add(offsetZSlider, 1, sliderPositioner); + adder.add(bindRotButton, 1, smallPositioner); + adder.add(pitchSlider, 1, sliderPositioner); + adder.add(yawSlider,2, gridWidget.copyPositioner().margin(26, 2, 0, 0)); + adder.add(rollSlider,2, gridWidget.copyPositioner().margin(26, 2, 0, 0)); + adder.add(scaleField, 1, smallPositioner); + adder.add(depthField, 1, smallPositioner); + } adder.add(createButton(Text.translatable(KEY_WIDGET + "save"), widgetWidth, button -> { String name = nameField.getText(); if (name == null) return; - ConfigFile.modConfig.binding.targetMap.put(name, new ModConfig.Binding.Target(textureIdField.getText(), - forwardUField.getValue(), forwardVField.getValue(), upwardUField.getValue(), upwardVField.getValue(), - posUField.getValue(), posVField.getValue())); + ConfigFile.modConfig.binding.targetMap.put(name, generateBindingTarget()); ConfigFile.save(); - initWidgets(currentPage); + initWidgets(category, page); })); adder.add(createButton(Text.translatable(KEY_WIDGET + "bind"), widgetWidth, button -> { ConfigFile.modConfig.binding.nameOfList = nameField.getText(); - initWidgets(currentPage); + initWidgets(category, page); })).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "bind", "Auto Bind"))); - adder.add(nameField = createTextField(widgetWidth * 2 + 4, nameField),2, fieldPositioner) + adder.add(nameField = createTextField(widgetWidth * 2 + 4, nameField),2, smallPositioner) .setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "listName"))); nameField.setMaxLength(20); gridWidget.refreshPositions(); @@ -119,19 +149,19 @@ private void initLeftWidgets() { } private void initRightWidgets(final int page) { - LinkedHashMap targetMap = ConfigFile.modConfig.binding.targetMap; + LinkedHashMap targetMap = ConfigFile.modConfig.binding.targetMap; int pageCount = (targetMap.size() - 1) / 6 + 1; GridWidget gridWidget = new GridWidget(); gridWidget.getMainPositioner().margin(4, 2, 0, 0); - Positioner texturedPositioner = gridWidget.copyPositioner().margin(5, 3, 1, 1); + Positioner smallPositioner = gridWidget.copyPositioner().margin(5, 3, 1, 1); GridWidget.Adder adder = gridWidget.createAdder(3); - adder.add(new TexturedButton(0, 16, button -> initWidgets((page - 1 + pageCount) % pageCount)), 1, texturedPositioner); + adder.add(new TexturedButton(0, 32, button -> initWidgets(category, (page - 1 + pageCount) % pageCount)), 1, smallPositioner); adder.add(new TextWidget(18, widgetHeight, Text.of((page + 1) + " / " + pageCount), textRenderer)); - adder.add(new TexturedButton(16, 16, button -> initWidgets((page + 1) % pageCount)), 1, texturedPositioner); + adder.add(new TexturedButton(16, 32, button -> initWidgets(category, (page + 1) % pageCount)), 1, smallPositioner); String[] names = targetMap.keySet().toArray(String[]::new); for (int i = page * 6; i < Math.min(page * 6 + 6, targetMap.size()); i++) { String name = names[i]; - ModConfig.Binding.Target target = targetMap.get(name); + BindingTarget target = targetMap.get(name); adder.add(createButton(Text.literal(name).styled(s -> name.equals(ConfigFile.modConfig.binding.nameOfList) ? s.withColor(Formatting.GREEN) : s), widgetWidth * 2 - 18, button -> { nameField.setText(name); @@ -142,11 +172,23 @@ private void initRightWidgets(final int page) { upwardVField.setValue(target.upwardV()); posUField.setValue(target.posU()); posVField.setValue(target.posV()); + scaleField.setValue((float) target.scale()); + bindXButton.setValue(target.bindX() ? 0 : 1); + offsetXSlider.setValue(target.offsetX()); + bindYButton.setValue(target.bindY() ? 0 : 1); + offsetYSlider.setValue(target.offsetY()); + bindZButton.setValue(target.bindZ() ? 0 : 1); + offsetZSlider.setValue(target.offsetZ()); + bindRotButton.setValue(target.bindRotation() ? 0 : 1); + pitchSlider.setValue(target.pitch()); + yawSlider.setValue(target.yaw()); + rollSlider.setValue(target.roll()); + depthField.setValue(target.disablingDepth()); }), 2); - adder.add(new TexturedButton(32, 16, button -> { + adder.add(new TexturedButton(32, 32, button -> { targetMap.remove(name); - initWidgets(page * 6 >= targetMap.size() ? page - 1 : page); - }), 1, texturedPositioner); + initWidgets(category, page * 6 >= targetMap.size() ? page - 1 : page); + }), 1, smallPositioner); } gridWidget.refreshPositions(); SimplePositioningWidget.setPos(gridWidget, x + (xSize + ySize) / 2 + 4, y + 2, x + xSize, y + ySize, 0, 0); @@ -179,8 +221,8 @@ protected void drawEntity(DrawContext context, int x1, int y1, int x2, int y2, i float entityPrevHeadYaw = entity.prevHeadYaw; float entityHeadYaw = entity.headYaw; entity.bodyYaw = 180.0f; - entity.setYaw(180.0f + (float) yawSlider.getValue()); - entity.setPitch((float) pitchSlider.getValue()); + entity.setYaw(180.0f + (float) localYawSlider.getValue()); + entity.setPitch((float) localPitchSlider.getValue()); entity.headYaw = entity.getYaw(); entity.prevHeadYaw = entity.getYaw(); Vector3f vector3f = new Vector3f((float) entityX, (float) entityY, -2.0f); @@ -203,22 +245,32 @@ protected void drawEntity(DrawContext context, float x, float y, int mouseX, int EntityRenderDispatcher entityRenderDispatcher = MinecraftClient.getInstance().getEntityRenderDispatcher(); entityRenderDispatcher.setRenderShadows(false); ModelAnalyser analyser = new ModelAnalyser(); - entityRenderDispatcher.render(entity, 0, -entity.getHeight() / 2.0f, 0, 0.0f, 1.0f, context.getMatrices(), analyser, 0xF000F0); + entityRenderDispatcher.render(entity, 0, -entity.getHeight() / 2.0f, 0, 0.0f, 1.0f, context.getMatrices(), analyser, 0xF000f0); analyser.buildLastRecord(); - analyser.drawByAnother(context.getVertexConsumers(), renderLayer -> true, (renderLayer, vertices) -> true); // TODO - context.draw(); analyser.setCurrent(renderLayer -> renderLayer.toString().contains(textureIdField.getText())); int focusedIndex = analyser.getFocusedIndex(mouseX, mouseY, layers); focusedUV = analyser.getCenterUV(focusedIndex); focusedTextureId = analyser.focusedTextureId(); - analyser.drawQuad(context, posUField.getValue(), posVField.getValue(), 0x6F3333CC); - if (focusedIndex != -1) analyser.drawPolyhedron(context, focusedIndex, 0x7FFFFFFF, 0x2FFFFFFF); - analyser.drawNormal(context, forwardUField.getValue(), forwardVField.getValue(), entitySize / 2, 0xFF00CC00); - analyser.drawNormal(context, upwardUField.getValue(), upwardVField.getValue(), entitySize / 2, 0xFFCC0000); + if (category == 0) { + analyser.drawByAnother(context.getVertexConsumers()); + context.draw(); + analyser.drawQuad(context, posUField.getValue(), posVField.getValue(), 0x6F3333CC); + if (focusedIndex != -1) analyser.drawPolyhedron(context, focusedIndex, 0x7FFFFFFF, 0x2FFFFFFF); + analyser.drawNormal(context, forwardUField.getValue(), forwardVField.getValue(), entitySize / 2, 0xFF00CC00); + analyser.drawNormal(context, upwardUField.getValue(), upwardVField.getValue(), entitySize / 2, 0xFFCC0000); + } else analyser.preview(context, generateBindingTarget(), entitySize / 3, 0xFF00CC00, 0xFFCC0000, 0xFF0000CC); entityRenderDispatcher.setRenderShadows(true); context.getMatrices().pop(); DiffuseLighting.enableGuiDepthLighting(); } + + protected BindingTarget generateBindingTarget() { + return new BindingTarget(textureIdField.getText(), forwardUField.getValue(), + forwardVField.getValue(), upwardUField.getValue(), upwardVField.getValue(), posUField.getValue(), posVField.getValue(), + bindXButton.getValue() == 0, bindYButton.getValue() == 0, bindZButton.getValue() == 0, bindRotButton.getValue() == 0, + scaleField.getValue(), offsetXSlider.getValue(), offsetYSlider.getValue(), offsetZSlider.getValue(), + (float) pitchSlider.getValue(), (float) yawSlider.getValue(), (float) rollSlider.getValue(), depthField.getValue()); + } private ButtonWidget createButton(Text message, int width, ButtonWidget.PressAction onPress) { return ButtonWidget.builder(message, onPress).size(width, widgetHeight).build(); @@ -228,6 +280,10 @@ private CyclingButtonWidget createCyclingButton(Map mess return new CyclingButtonWidget.Builder(messages::get).values(messages.keySet()).build(0, 0, width, widgetHeight, optionText); } + private DoubleSliderWidget createSlider(String key, int width, double min, double max) { + return new DoubleSliderWidget(width, widgetHeight, 0, min, max, d -> Text.translatable(KEY_WIDGET + key, MathUtil.round(d, 2))); + } + private NumberFieldWidget createFloatField(int width, @Nullable NumberFieldWidget copyFrom) { return new FloatFieldWidget(textRenderer, width - 2, widgetHeight - 2, copyFrom, Text.empty()).setMax(1.0f).setMin(0f); } @@ -291,6 +347,6 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) { @Override public boolean shouldPause() { - return shouldPause; + return pauseButton.getValue() == 1; } } diff --git a/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java b/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java index 713aab6..02ae9e3 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/NumberFieldWidget.java @@ -58,9 +58,10 @@ protected void checkText() { setRenderTextProvider((string, firstCharacterIndex) -> OrderedText.styledForwardsVisitedString(string, Style.EMPTY)); try { T value = getValueInternal(); - if (value.compareTo(minimum) < 0 || value.compareTo(maximum) > 0) setValue(value); + if (value.compareTo(minimum) < 0) throw new Exception("<" + minimum + " !"); + if (value.compareTo(maximum) > 0) throw new Exception(">" + maximum + " !"); } catch (Exception exception) { - setTooltip(Tooltip.of(Text.literal("Invalid number!").styled(s -> s.withColor(Formatting.RED)))); + setTooltip(Tooltip.of(Text.literal("Invalid number: " + exception.getMessage()).styled(s -> s.withColor(Formatting.RED)))); setRenderTextProvider((string, firstCharacterIndex) -> OrderedText.styledForwardsVisitedString(string, Style.EMPTY.withColor(Formatting.RED))); } } diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java index 2d1b932..ae00dca 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinCamera.java @@ -47,7 +47,7 @@ public abstract class MixinCamera { Vec3d center = new Vec3d(config.getCenterX(), config.getCenterY(), config.getCenterZ()).multiply(scale); float newPitch = pitch + config.getClassicPitch(); float newYaw = yaw - config.getClassicYaw(); - setRotation(yaw, 0.0F); + setRotation(yaw, 0.0f); moveBy(center.getX(), center.getY(), center.getZ()); setRotation(newYaw, newPitch); moveBy(offset.getX(), offset.getY(), offset.getZ()); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java index 9282bf8..6be6705 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinItem.java @@ -19,7 +19,7 @@ public abstract class MixinItem { private static void realCamera$coverRaycast(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling, CallbackInfoReturnable cInfo) { if (!ConfigFile.modConfig.isCrosshairDynamic() && RealCameraCore.isActive()) { - RaycastUtil.update(player, 25.0D, 1.0F); + RaycastUtil.update(player, 25.0d, 1.0f); cInfo.setReturnValue(world.raycast(RaycastUtil.getRaycastContext(RaycastContext.ShapeType.OUTLINE, fluidHandling, player))); } } diff --git a/common/src/main/java/com/xtracr/realcamera/util/CrosshairUtil.java b/common/src/main/java/com/xtracr/realcamera/util/CrosshairUtil.java index bc75c38..6d1b08d 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/CrosshairUtil.java +++ b/common/src/main/java/com/xtracr/realcamera/util/CrosshairUtil.java @@ -14,7 +14,7 @@ public class CrosshairUtil { private static Vec3d offset = Vec3d.ZERO; public static void translateMatrices(MatrixStack matrixStack) { - matrixStack.translate(offset.getX(), -offset.getY(), 0.0D); + matrixStack.translate(offset.getX(), -offset.getY(), 0.0d); } public static void update(MinecraftClient client, Camera camera, Matrix4f... projectionMatrices) { @@ -28,6 +28,6 @@ public static void update(MinecraftClient client, Camera camera, Matrix4f... pro } Window window = client.getWindow(); offset = MathUtil.projectToVec2d(hitResult.getPos().subtract(camera.getPos()), projectionMatrices) - .multiply(0.5 * window.getScaledWidth(), 0.5 * window.getScaledHeight(), 0.0D); + .multiply(0.5 * window.getScaledWidth(), 0.5 * window.getScaledHeight(), 0.0d); } } diff --git a/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java b/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java index c07d5db..6adf59d 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java +++ b/common/src/main/java/com/xtracr/realcamera/util/MathUtil.java @@ -15,10 +15,10 @@ public static boolean isFinite(Vec3d vec3d) { } public static Vec3d getEulerAngleYXZ(Matrix3f normal) { - if (normal.m21 <= -1.0D) { - return new Vec3d(Math.PI / 2, Math.atan2(normal.m10, normal.m00), 0.0D); - } else if (normal.m21 >= 1.0D) { - return new Vec3d(-Math.PI / 2, -Math.atan2(normal.m10, normal.m00), 0.0D); + if (normal.m21 <= -1.0d) { + return new Vec3d(Math.PI / 2, Math.atan2(normal.m10, normal.m00), 0.0d); + } else if (normal.m21 >= 1.0d) { + return new Vec3d(-Math.PI / 2, -Math.atan2(normal.m10, normal.m00), 0.0d); } double xRot = Math.asin(-normal.m21); double yRot = Math.atan2(normal.m20, normal.m22); @@ -32,9 +32,9 @@ public static Vec3d getIntersectionPoint(Vec3d planePoint, Vec3d planeNormal, Ve } public static Vec3d projectToVec2d(Vec3d vec3d, Matrix4f... projectionMatrices) { - Vector4f vector4f = new Vector4f((float) vec3d.getX(), (float) vec3d.getY(), (float) vec3d.getZ(), 1.0F); + Vector4f vector4f = new Vector4f((float) vec3d.getX(), (float) vec3d.getY(), (float) vec3d.getZ(), 1.0f); for (Matrix4f matrix4f : projectionMatrices) vector4f.mul(matrix4f); - if (vector4f.w() == 0.0D) return Vec3d.ZERO; + if (vector4f.w() == 0.0d) return Vec3d.ZERO; return new Vec3d(vector4f.x(), vector4f.y(), 0).multiply(1 / (double) vector4f.w()); } } diff --git a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java index 387bdc3..bb126e2 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java @@ -1,5 +1,6 @@ package com.xtracr.realcamera.util; +import com.xtracr.realcamera.config.BindingTarget; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; @@ -14,8 +15,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; -import java.util.function.BiPredicate; -import java.util.function.Function; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -36,24 +36,14 @@ public String currentTextureId() { } public Vec3d getPos(float u, float v) { - if (currentRecord == null) return null; - return getPos(getQuadIndex(currentRecord, u, v), u, v); - } - - public Vec3d getPos(int quadIndex, float u, float v) { - if (currentRecord == null || quadIndex >= currentRecord.quadCount) return null; - Vertex[] quad = currentRecord.vertices[quadIndex]; - if (quad.length < 3) return null; - float u0 = quad[0].u, v0 = quad[0].v, u1 = quad[1].u, v1 = quad[1].v, u2 = quad[2].u, v2 = quad[2].v; - float alpha = ((u - u1) * (v1 - v2) - (v - v1) * (u1 - u2)) / ((u0 - u1) * (v1 - v2) - (v0 - v1) * (u1 - u2)), - beta = ((u - u2) * (v2 - v0) - (v - v2) * (u2 - u0)) / ((u1 - u2) * (v2 - v0) - (v1 - v2) * (u2 - u0)); - return quad[0].pos().multiply(alpha).add(quad[1].pos().multiply(beta)).add(quad[2].pos().multiply(1 - alpha - beta)); + Vertex[] quad; + if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return null; + return getPos(quad, u, v); } public Vec3d getNormal(float u, float v) { - if (currentRecord == null) return null; - Vertex[] quad = getQuad(currentRecord, u, v); - if (quad == null || quad.length < 1) return null; + Vertex[] quad; + if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return null; return quad[0].normal(); } @@ -66,22 +56,30 @@ public void setCurrent(Predicate predicate) { currentRecord = records.stream().filter(record -> predicate.test(record.renderLayer)).max(Comparator.comparingInt(BuiltRecord::quadCount)).orElse(null); } - public void drawByAnother(VertexConsumerProvider anotherProvider, Predicate layerPredicate, BiPredicate biPredicate) { - drawByAnother(vertex -> vertex, anotherProvider, layerPredicate, biPredicate); + public Vec3d getTargetPosAndRot(BindingTarget target, Matrix3f normal) throws ArithmeticException { + Vec3d front = getNormal(target.forwardU(), target.forwardV()); + Vec3d up = getNormal(target.upwardU(), target.upwardV()); + Vec3d center = getPos(target.posU(), target.posV()); + if (!MathUtil.isFinite(front) || !MathUtil.isFinite(up) || !MathUtil.isFinite(center)) throw new ArithmeticException(); + normal.set(up.crossProduct(front).toVector3f(), up.toVector3f(), front.toVector3f()); + Vector3f vec3f = normal.transform(new Vector3f((float) target.offsetZ(), (float) target.offsetY(), (float) target.offsetX())); + return center.add(vec3f.x(), vec3f.y(), vec3f.z()); + } + + public void drawByAnother(VertexConsumerProvider anotherProvider) { + drawByAnother(anotherProvider, renderLayer -> true, (renderLayer, vertices) -> vertices); } - public void drawByAnother(Function function, VertexConsumerProvider anotherProvider, Predicate layerPredicate, BiPredicate biPredicate) { + public void drawByAnother(VertexConsumerProvider anotherProvider, Predicate layerPredicate, BiFunction function) { records.forEach(record -> { RenderLayer renderLayer = record.renderLayer; if (!layerPredicate.test(renderLayer)) return; - int argb, length; + int argb; Vertex[] newQuad; VertexConsumer buffer = anotherProvider.getBuffer(renderLayer); for (Vertex[] quad : record.vertices) { - length = quad.length; - newQuad = new Vertex[length]; - for (int i = 0; i < length; i++) newQuad[i] = function.apply(quad[i]); - if (biPredicate.test(renderLayer, newQuad)) for (Vertex vertex : newQuad) { + if ((newQuad = function.apply(renderLayer, quad)) == null) continue; + for (Vertex vertex : newQuad) { argb = vertex.argb; buffer.vertex((float) vertex.x, (float) vertex.y, (float) vertex.z, (float) (argb >> 16 & 0xFF) / 255, (float) (argb >> 8 & 0xFF) / 255, (float) (argb & 0xFF) / 255, (float) (argb >> 24) / 255, @@ -92,20 +90,21 @@ public void drawByAnother(Function function, VertexConsumerProvi } protected static Vertex[] getQuad(BuiltRecord record, float u, float v) { - int i = getQuadIndex(record, u, v); - if (i >= 0) return record.vertices[i]; - return null; - } - - protected static int getQuadIndex(BuiltRecord record, float u, float v) { final int resolution = 1000000; - for (int i = 0, size = record.vertices.length; i < size; i++) { - Vertex[] quad = record.vertices[i]; + for (Vertex[] quad : record.vertices) { Polygon polygon = new Polygon(); for (Vertex vertex : quad) polygon.addPoint((int) (resolution * vertex.u), (int) (resolution * vertex.v)); - if (polygon.contains(resolution * u, resolution * v)) return i; + if (polygon.contains(resolution * u, resolution * v)) return quad; } - return -1; + return null; + } + + protected static Vec3d getPos(Vertex[] quad, float u, float v) { + if (quad.length < 3) return quad[0].pos(); + float u0 = quad[0].u, v0 = quad[0].v, u1 = quad[1].u, v1 = quad[1].v, u2 = quad[2].u, v2 = quad[2].v; + float alpha = ((u - u1) * (v1 - v2) - (v - v1) * (u1 - u2)) / ((u0 - u1) * (v1 - v2) - (v0 - v1) * (u1 - u2)), + beta = ((u - u2) * (v2 - v0) - (v - v2) * (u2 - u0)) / ((u1 - u2) * (v2 - v0) - (v1 - v2) * (u2 - u0)); + return quad[0].pos().multiply(alpha).add(quad[1].pos().multiply(beta)).add(quad[2].pos().multiply(1 - alpha - beta)); } protected static String getTextureId(BuiltRecord record) { @@ -128,7 +127,7 @@ public VertexConsumer getBuffer(RenderLayer renderLayer) { private static class VertexRecord implements VertexConsumer { private final List vertices = new ArrayList<>(); private final RenderLayer renderLayer; - private Vec3d pos = Vec3d.ZERO, normal = Vec3d.ZERO; + private Vec3d pos = net.minecraft.util.math.Vec3d.ZERO, normal = net.minecraft.util.math.Vec3d.ZERO; private int argb, overlay, light; private float u, v; @@ -190,7 +189,7 @@ public VertexConsumer normal(float x, float y, float z) { public void next() { vertices.add(new Vertex(pos.getX(), pos.getY(), pos.getZ(), argb, u, v, overlay, light, (float) normal.getX(), (float) normal.getY(), (float) normal.getZ())); - pos = normal = Vec3d.ZERO; + pos = normal = net.minecraft.util.math.Vec3d.ZERO; u = v = overlay = light = argb = 0; } diff --git a/common/src/main/resources/assets/realcamera/lang/en_us.json b/common/src/main/resources/assets/realcamera/lang/en_us.json index 60ff727..dd4db97 100644 --- a/common/src/main/resources/assets/realcamera/lang/en_us.json +++ b/common/src/main/resources/assets/realcamera/lang/en_us.json @@ -101,14 +101,20 @@ "message.xtracr_realcamera_command_listAll": "Found %d results: %s", "screen.xtracr_realcamera_modelView_title": "Model View", - "screen.widget.xtracr_realcamera_modelView_yaw": "Yaw = %s", - "screen.widget.xtracr_realcamera_modelView_pitch": "Pitch = %s", "screen.widget.xtracr_realcamera_modelView_selectMode": "Selecting", "screen.widget.xtracr_realcamera_modelView_forwardMode": "Forward Vector", "screen.widget.xtracr_realcamera_modelView_upwardMode": "Upward Vector", "screen.widget.xtracr_realcamera_modelView_posMode": "Plane", "screen.widget.xtracr_realcamera_modelView_save": "Save", "screen.widget.xtracr_realcamera_modelView_bind": "Bind", + "screen.widget.xtracr_realcamera_modelView_settings": "Settings", + "screen.widget.xtracr_realcamera_modelView_preview": "Preview", + "screen.widget.xtracr_realcamera_modelView_offsetX": "X Offset = %s", + "screen.widget.xtracr_realcamera_modelView_offsetY": "Y Offset = %s", + "screen.widget.xtracr_realcamera_modelView_offsetZ": "Z Offset = %s", + "screen.widget.xtracr_realcamera_modelView_pitch": "Pitch = %s", + "screen.widget.xtracr_realcamera_modelView_yaw": "Yaw = %s", + "screen.widget.xtracr_realcamera_modelView_roll": "Roll = %s", "screen.tooltip.xtracr_realcamera_modelView_selectMode": "Hold left Alt and left click to get the UV coordinates at the mouse pointer\nThe three sets of UV coordinates below are, from top to bottom, the forward vector, the upward vector, and the UV coordinates of the plane's center\nNote: Scroll with left Alt held to switch between the different layers of model. Manually inputting UV coordinates allows you to bind more accurately to the target position", "screen.tooltip.xtracr_realcamera_modelView_textureId": "The texture id of the selected model (not necessary to be the full id), can be shortened when saving to make it easier to recognize.\nFor example, shorten minecraft:textures/entity/player/slim/alex.png to minecraft:textures/entity/player/.", diff --git a/common/src/main/resources/assets/realcamera/lang/zh_cn.json b/common/src/main/resources/assets/realcamera/lang/zh_cn.json index e070dd2..04b85df 100644 --- a/common/src/main/resources/assets/realcamera/lang/zh_cn.json +++ b/common/src/main/resources/assets/realcamera/lang/zh_cn.json @@ -101,14 +101,20 @@ "message.xtracr_realcamera_command_listAll": "找到了%d个结果: %s", "screen.xtracr_realcamera_modelView_title": "模型视图", - "screen.widget.xtracr_realcamera_modelView_yaw": "俯仰 = %s", - "screen.widget.xtracr_realcamera_modelView_pitch": "偏航 = %s", "screen.widget.xtracr_realcamera_modelView_selectMode": "选择", "screen.widget.xtracr_realcamera_modelView_forwardMode": "向前矢量", "screen.widget.xtracr_realcamera_modelView_upwardMode": "向上矢量", "screen.widget.xtracr_realcamera_modelView_posMode": "平面", "screen.widget.xtracr_realcamera_modelView_save": "保存", "screen.widget.xtracr_realcamera_modelView_bind": "绑定", + "screen.widget.xtracr_realcamera_modelView_settings": "设置", + "screen.widget.xtracr_realcamera_modelView_preview": "预览", + "screen.widget.xtracr_realcamera_modelView_offsetX": "X偏移量 = %s", + "screen.widget.xtracr_realcamera_modelView_offsetY": "Y偏移量 = %s", + "screen.widget.xtracr_realcamera_modelView_offsetZ": "Z偏移量 = %s", + "screen.widget.xtracr_realcamera_modelView_pitch": "俯仰角 = %s", + "screen.widget.xtracr_realcamera_modelView_yaw": "偏航角 = %s", + "screen.widget.xtracr_realcamera_modelView_roll": "翻滚角 = %s", "screen.tooltip.xtracr_realcamera_modelView_selectMode": "按住左Alt并左键可获取鼠标指针处的UV坐标\n下方三组UV坐标由上到下依次为向前矢量、向上矢量和平面中心的UV坐标\n注:按住左Alt键滚动可在模型的不同层间切换,手动输入UV坐标可以更加精确地绑定到目标位置", "screen.tooltip.xtracr_realcamera_modelView_textureId": "被选中的模型的纹理的id(不是完整的id也可以识别),保存时可以缩短一部分以便于程序识别\n比如将minecraft:textures/entity/player/slim/alex.png缩短为minecraft:textures/entity/player/", diff --git a/common/src/main/resources/assets/realcamera/textures/gui/icon.png b/common/src/main/resources/assets/realcamera/textures/gui/icon.png index 9293f73..c921b5a 100644 Binary files a/common/src/main/resources/assets/realcamera/textures/gui/icon.png and b/common/src/main/resources/assets/realcamera/textures/gui/icon.png differ diff --git a/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java b/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java index 46b3dac..90d267b 100644 --- a/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java +++ b/fabric/src/main/java/com/xtracr/realcamera/RealCameraFabric.java @@ -15,7 +15,7 @@ public class RealCameraFabric implements ClientModInitializer { @Override public void onInitializeClient() { RealCamera.setup(); - KeyBindings.KEY_BINDINGS.forEach(KeyBindingHelper::registerKeyBinding); + KeyBindings.register(KeyBindingHelper::registerKeyBinding); ClientTickEvents.END_CLIENT_TICK.register(KeyBindings::handle); WorldRenderEvents.START.register(EventHandler::onWorldRenderStart); diff --git a/forge/src/main/java/com/xtracr/realcamera/RealCameraForge.java b/forge/src/main/java/com/xtracr/realcamera/RealCameraForge.java index 78e516c..607bcf0 100644 --- a/forge/src/main/java/com/xtracr/realcamera/RealCameraForge.java +++ b/forge/src/main/java/com/xtracr/realcamera/RealCameraForge.java @@ -40,6 +40,6 @@ public void clientSetup(FMLClientSetupEvent event) { @SubscribeEvent public void onKeyRegister(RegisterKeyMappingsEvent event) { - KeyBindings.KEY_BINDINGS.forEach(event::register); + KeyBindings.register(event::register); } }