Skip to content

Commit

Permalink
Changed localization format
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed Mar 1, 2024
1 parent d204614 commit 8acc4e3
Show file tree
Hide file tree
Showing 15 changed files with 473 additions and 431 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/com/xtracr/realcamera/KeyBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.util.function.Consumer;

public final class KeyBindings {
private static final String KEY_CATEGORY = "key.category.xtracr_" + RealCamera.MODID;
private static final String KEY_ID = "key.xtracr_" + RealCamera.MODID + "_";
private static final String KEY_CATEGORY = "key.category." + RealCamera.FULL_ID;
private static final String KEY_ID = "key." + RealCamera.FULL_ID + ".";
private static final List<KeyBinding> 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);
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/com/xtracr/realcamera/RealCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public class RealCamera {
public static final String MODID = "realcamera";
public static final String FULL_ID = "xtracr_" + MODID;
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);

public static void setup() {
Expand Down
38 changes: 19 additions & 19 deletions common/src/main/java/com/xtracr/realcamera/RealCameraCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@

public class RealCameraCore {
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;
private static float pitch, yaw, roll;
private static Vec3d pos = Vec3d.ZERO, cameraPos = Vec3d.ZERO;
public static BindingTarget currentTarget = new BindingTarget();

public static String getStatus() {
return status;
Expand All @@ -56,30 +56,30 @@ public static void setRenderingPlayer(boolean value) {

public static float getPitch(float f) {
if (currentTarget.bindRotation()) return pitch;
else return f + currentTarget.pitch();
return f;
}

public static float getYaw(float f) {
if (currentTarget.bindRotation()) return yaw;
else return f - currentTarget.yaw();
return f;
}

public static float getRoll(float f) {
if (config().isClassic()) return f + config().getClassicRoll();
else if (currentTarget.bindRotation()) return roll;
else return f + currentTarget.roll();
if (currentTarget.bindRotation()) return roll;
return f;
}

public static Vec3d getPos(Vec3d vec3d) {
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());
return new Vec3d(currentTarget.bindX() ? pos.getX() : vec3d.getX(),
currentTarget.bindY() ? pos.getY() : vec3d.getY(),
currentTarget.bindZ() ? pos.getZ() : vec3d.getZ());
}

public static Vec3d getCameraPos(Vec3d vec3d) {
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());
return new Vec3d(currentTarget.bindX() ? cameraPos.getX() : vec3d.getX(),
currentTarget.bindY() ? cameraPos.getY() : vec3d.getY(),
currentTarget.bindZ() ? cameraPos.getZ() : vec3d.getZ());
}

public static void setCameraPos(Vec3d vec3d) {
Expand All @@ -100,19 +100,19 @@ public static void renderPlayer(VertexConsumerProvider vertexConsumers) {
matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(roll));
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(pitch));
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(yaw + 180.0f));
Matrix3f normalMatrix = matrixStack.peek().getNormalMatrix().transpose().invert();
Matrix4f positionMatrix = matrixStack.peek().getPositionMatrix().transpose().invertAffine()
.translate((float) -pos.getX(), (float) -pos.getY(), (float) -pos.getZ());
Matrix3f normalMatrix = matrixStack.peek().getNormalMatrix().transpose().invert();
BiFunction<RenderLayer, VertexRecorder.Vertex[], VertexRecorder.Vertex[]> 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;
int count = vertices.length;
VertexRecorder.Vertex[] quad = new VertexRecorder.Vertex[count];
for (int i = 0; i < count; i++) quad[i] = vertices[i].transform(positionMatrix, normalMatrix);
for (VertexRecorder.Vertex vertex : quad) {
if (vertex.z() < -depth) return quad;
centerZ += vertex.z();
}
return centerZ < -depth * vertices.length ? newQuad : null;
return centerZ < -depth * count ? quad : null;
};
recorder.drawByAnother(vertexConsumers, renderLayer -> true, function);
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public static void computeCamera(MinecraftClient client, float tickDelta) {
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));
targetList.add(config().getTarget(config().binding.nameOfList));
for (BindingTarget target : targetList) {
try {
recorder.setCurrent(renderLayer -> renderLayer.toString().contains(target.textureId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.text.Text;

public class ClientCommand<S extends CommandSource>{
private static final String KEY_COMMAND = "message.xtracr_" + RealCamera.MODID + "_command_";
private static final String KEY_COMMAND = "message." + RealCamera.FULL_ID + ".command_";
private static final ModConfig config = ConfigFile.modConfig;

public void register(CommandDispatcher<S> dispatcher, CommandRegistryAccess access) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
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;
public static final BindingTarget MINECRAFT_HEAD = new BindingTarget("minecraft_head", "minecraft:textures/entity/player/", 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, false, true, false, false, 1, -0.15f, 0, 0, 0, 0, 0, 0.2f);
public static final BindingTarget MINECRAFT_HEAD_2 = new BindingTarget("minecraft_head_2", "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 name, 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);
this(null, 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) {
public BindingTarget(String name, 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.name = name;
this.textureId = textureId;
this.forwardU = forwardU;
this.forwardV = forwardV;
Expand All @@ -34,6 +36,14 @@ public BindingTarget(String textureId, float forwardU, float forwardV, float upw
this.disablingDepth = disablingDepth;
}

public String name() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String textureId() {
return textureId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.Optional;

public class ConfigScreen {
private static final String CATEGORY = "config.category.xtracr_" + RealCamera.MODID + "_";
private static final String OPTION = "config.option.xtracr_" + RealCamera.MODID + "_";
private static final String TOOLTIP = "config.tooltip.xtracr_" + RealCamera.MODID + "_";
private static final String CATEGORY = "config.category." + RealCamera.FULL_ID + ".";
private static final String OPTION = "config.option." + RealCamera.FULL_ID + ".";
private static final String TOOLTIP = "config.tooltip." + RealCamera.FULL_ID + ".";

public static Screen create(Screen parent) {
ConfigFile.load();
Expand All @@ -34,7 +34,7 @@ public static Screen create(Screen parent) {
.setParentScreen(parent)
.transparentBackground()
.setSavingRunnable(ConfigFile::save)
.setTitle(Text.translatable("config.title.xtracr_" + RealCamera.MODID));
.setTitle(Text.translatable("config.title." + RealCamera.FULL_ID));
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
ConfigCategory general = builder.getOrCreateCategory(Text.translatable(CATEGORY + "general"));
ConfigCategory binding = builder.getOrCreateCategory(Text.translatable(CATEGORY + "binding"));
Expand Down
17 changes: 14 additions & 3 deletions common/src/main/java/com/xtracr/realcamera/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public boolean isAdjustingOffset() {
return binding.adjustOffset;
}

public BindingTarget getTarget(String name) {
return binding.targetMap.get(name);
}

public boolean isXBound() {
return binding.bindX;
}
Expand Down Expand Up @@ -124,6 +128,10 @@ public void setAdjustOffset(boolean value) {
binding.adjustOffset = value;
}

public void putTarget(BindingTarget target) {
if (target.name() != null) binding.targetMap.put(target.name(), target);
}

public void adjustBindingX(boolean add) {
int s = add ? 1 : -1;
if (isAdjustingOffset()) binding.cameraX += s * getAdjustStep();
Expand Down Expand Up @@ -291,13 +299,13 @@ private void clamp() {
}

public static class Binding {
protected static final Map<String, BindingTarget> defaultTargetMap = Map.of("minecraft_head", BindingTarget.MINECRAFT_HEAD);
protected static final List<BindingTarget> defaultTargets = List.of(BindingTarget.MINECRAFT_HEAD, BindingTarget.MINECRAFT_HEAD_2);
public VanillaModelPart vanillaModelPart = VanillaModelPart.head;
public boolean experimental = false;
public boolean adjustOffset = true;
public boolean autoBind = true;
public String nameOfList = "minecraft_head";
public LinkedHashMap<String, BindingTarget> targetMap = new LinkedHashMap<>(defaultTargetMap);
public LinkedHashMap<String, BindingTarget> targetMap = new LinkedHashMap<>();
public boolean bindX = true;
public boolean bindY = true;
public boolean bindZ = true;
Expand All @@ -311,7 +319,10 @@ public static class Binding {

private void clamp() {
if (vanillaModelPart == null) vanillaModelPart = VanillaModelPart.head;
if (targetMap == null) targetMap = new LinkedHashMap<>(defaultTargetMap);
if (targetMap == null || targetMap.isEmpty()) {
targetMap = new LinkedHashMap<>();
defaultTargets.forEach(target -> targetMap.put(target.name(), target));
}
cameraX = MathHelper.clamp(cameraX, MIN_DOUBLE, MAX_DOUBLE);
cameraY = MathHelper.clamp(cameraY, MIN_DOUBLE, MAX_DOUBLE);
cameraZ = MathHelper.clamp(cameraZ, MIN_DOUBLE, MAX_DOUBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


public class FloatFieldWidget extends NumberFieldWidget<Float> {
public FloatFieldWidget(TextRenderer textRenderer, int width, int height, @Nullable NumberFieldWidget<Float> copyFrom, Text text) {
super(textRenderer, 0, 0, width, height, copyFrom, text, 0f, Float.MAX_VALUE, -Float.MAX_VALUE);
public FloatFieldWidget(TextRenderer textRenderer, int width, int height, float defaultValue, @Nullable NumberFieldWidget<Float> copyFrom, Text text) {
super(textRenderer, 0, 0, width, height, defaultValue, Float.MAX_VALUE, -Float.MAX_VALUE, copyFrom, text);
setMaxLength(8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) {
return result.getRight();
}

public void preview(DrawContext context, BindingTarget target, int length, int forwardArgb, int upwardArgb, int leftArgb) {
if (currentRecord == null) return;
public void preview(DrawContext context, BindingTarget target, int entitySize, int forwardArgb, int upwardArgb, int leftArgb) {
Matrix3f normal = new Matrix3f();
target.setOffsetX(entitySize * target.offsetX());
target.setOffsetY(entitySize * target.offsetY());
target.setOffsetZ(entitySize * target.offsetZ());
Vec3d pos;
try {
pos = getTargetPosAndRot(target, normal);
Expand All @@ -71,9 +73,9 @@ public void preview(DrawContext context, BindingTarget target, int length, int f
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);
drawNormal(context, pos, new Vec3d(normal.m20(), normal.m21(), -normal.m22()), entitySize / 3, forwardArgb);
drawNormal(context, pos, new Vec3d(normal.m10(), normal.m11(), -normal.m12()), entitySize / 6, upwardArgb);
drawNormal(context, pos, new Vec3d(normal.m00(), normal.m01(), -normal.m02()), entitySize / 6, leftArgb);
}

public void drawQuad(DrawContext context, float u, float v, int argb) {
Expand Down
Loading

0 comments on commit 8acc4e3

Please sign in to comment.