Skip to content

Commit

Permalink
Changed the way to construct BindingTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
xTracr committed May 6, 2024
1 parent 29f634b commit 923e52d
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void setCameraPos(Vec3d vec3d) {
cameraPos = vec3d;
}

public static void init(MinecraftClient client) {
public static void initialize(MinecraftClient client) {
Entity entity = client.getCameraEntity();
active = ConfigFile.config().enabled() && client.options.getPerspective().isFirstPerson() && client.gameRenderer.getCamera() != null && entity != null && !DisableHelper.isDisabled("mainFeature", entity);
rendering = active && ConfigFile.config().renderModel() && !DisableHelper.isDisabled("renderModel", entity);
Expand Down Expand Up @@ -124,9 +124,9 @@ public static void computeCamera() {
if (readyToSendMessage && player != null) player.sendMessage(LocUtil.MESSAGE("bindingFailed", LocUtil.MOD_NAME(), LocUtil.MODEL_VIEW_TITLE()));
active = readyToSendMessage = false;
} else readyToSendMessage = true;
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);
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();
Expand Down
158 changes: 121 additions & 37 deletions common/src/main/java/com/xtracr/realcamera/config/BindingTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,189 @@

import net.minecraft.util.math.MathHelper;

import java.util.ArrayList;
import java.util.List;

public class BindingTarget {
protected static final List<BindingTarget> defaultTargets = List.of(createDefaultTarget("minecraft_head", "minecraft:textures/entity/player/", 5, false),
createDefaultTarget("skin_head", "minecraft:skins/", 5, false),
createDefaultTarget("minecraft_head_2", "minecraft:textures/entity/player/", 0, true),
createDefaultTarget("skin_head_2", "minecraft:skins/", 0, true));
public List<String> disabledTextureIds = new ArrayList<>();
public final String name, textureId;
public final int priority;
public final float forwardU, forwardV, upwardU, upwardV, posU, posV, disablingDepth;
public final boolean bindX, bindY, bindZ, bindRotation;
public double scale, offsetX, offsetY, offsetZ;
public float pitch, yaw, roll;
public int priority = 0;
public float forwardU = 0, forwardV = 0, upwardU = 0, upwardV = 0, posU = 0, posV = 0, disablingDepth = 0.2f;
public boolean bindX = false, bindY = true, bindZ = false, bindRotation = false;
public double scale = 1, offsetX = 0, offsetY = 0, offsetZ = 0;
public float pitch = 0, yaw = 0, roll = 0;
public List<String> disabledTextureIds = List.of();

public BindingTarget() {
this(null, null, 0, 0, 0, 0, 0, 0, 0, 0.2f, false, true, false, false, 1, 0, 0, 0, 0, 0, 0);
this(null, null);
}

public BindingTarget(String name, String textureId, int priority, float forwardU, float forwardV, float upwardU, float upwardV, float posU, float posV, float disablingDepth, boolean bindX, boolean bindY, boolean bindZ, boolean bindRotation, double scale, double offsetX, double offsetY, double offsetZ, float pitch, float yaw, float roll) {
public BindingTarget(String name, String textureId) {
this.name = name;
this.textureId = textureId;
this.priority = priority;
this.forwardU = forwardU;
this.forwardV = forwardV;
this.upwardU = upwardU;
this.upwardV = upwardV;
this.posU = posU;
this.posV = posV;
this.disablingDepth = disablingDepth;
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;
}

private static BindingTarget createDefaultTarget(String name, String textureId, int priority, boolean shouldBind) {
BindingTarget target = new BindingTarget(name, textureId, priority, 0.1875f, 0.2f, 0.1875f, 0.075f, 0.1875f, 0.2f, 0.2f, shouldBind, true, shouldBind, shouldBind, 1, -0.12, 0, 0, 0, 0, 0);
target.disabledTextureIds.add("minecraft:textures/entity/enderdragon/dragon.png");
return target;
return new BindingTarget(name, textureId).priority(priority)
.forwardU(0.1875f).forwardV(0.2f)
.upwardU(0.1875f).upwardV(0.075f)
.posU(0.1875f).posV(0.2f)
.bindX(shouldBind).bindZ(shouldBind).bindRotation(shouldBind)
.offsetX(-0.12)
.disabledTextureIds(List.of("minecraft:textures/entity/enderdragon/dragon.png"));
}

public boolean isEmpty() {
return name == null;
}

public double offsetX() {
public double getOffsetX() {
return offsetX * scale;
}

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

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

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

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

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

public float pitch() {
public float getPitch() {
return pitch;
}

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

public float yaw() {
public float getYaw() {
return yaw;
}

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

public float roll() {
public float getRoll() {
return roll;
}

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

public BindingTarget priority(int priority) {
this.priority = priority;
return this;
}

public BindingTarget forwardU(float forwardU) {
this.forwardU = forwardU;
return this;
}

public BindingTarget forwardV(float forwardV) {
this.forwardV = forwardV;
return this;
}

public BindingTarget upwardU(float upwardU) {
this.upwardU = upwardU;
return this;
}

public BindingTarget upwardV(float upwardV) {
this.upwardV = upwardV;
return this;
}

public BindingTarget posU(float posU) {
this.posU = posU;
return this;
}

public BindingTarget posV(float posV) {
this.posV = posV;
return this;
}

public BindingTarget disablingDepth(float disablingDepth) {
this.disablingDepth = disablingDepth;
return this;
}

public BindingTarget bindX(boolean bindX) {
this.bindX = bindX;
return this;
}

public BindingTarget bindY(boolean bindY) {
this.bindY = bindY;
return this;
}

public BindingTarget bindZ(boolean bindZ) {
this.bindZ = bindZ;
return this;
}

public BindingTarget bindRotation(boolean bindRotation) {
this.bindRotation = bindRotation;
return this;
}

public BindingTarget scale(double scale) {
this.scale = scale;
return this;
}

public BindingTarget offsetX(double offsetX) {
this.offsetX = offsetX;
return this;
}

public BindingTarget offsetY(double offsetY) {
this.offsetY = offsetY;
return this;
}

public BindingTarget offsetZ(double offsetZ) {
this.offsetZ = offsetZ;
return this;
}

public BindingTarget pitch(float pitch) {
this.pitch = pitch;
return this;
}

public BindingTarget yaw(float yaw) {
this.yaw = yaw;
return this;
}

public BindingTarget roll(float roll) {
this.roll = roll;
return this;
}

public BindingTarget disabledTextureIds(List<String> disabledTextureIds) {
this.disabledTextureIds = disabledTextureIds;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ConfigFile {
private static final Path PATH;

static {
final File configDir = new File(MinecraftClient.getInstance().runDirectory, "config");
File configDir = new File(MinecraftClient.getInstance().runDirectory, "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 @@ -11,12 +11,8 @@
public class ConfigScreen {
public static Screen create(Screen parent) {
ConfigFile.load();
final ModConfig config = ConfigFile.config();
final ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.transparentBackground()
.setSavingRunnable(ConfigFile::save)
.setTitle(LocUtil.MOD_NAME());
ModConfig config = ConfigFile.config();
ConfigBuilder builder = ConfigBuilder.create().setParentScreen(parent).transparentBackground().setSavingRunnable(ConfigFile::save).setTitle(LocUtil.MOD_NAME());
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
ConfigCategory general = builder.getOrCreateCategory(LocUtil.CONFIG_CATEGORY("general"));
ConfigCategory classic = builder.getOrCreateCategory(LocUtil.CONFIG_CATEGORY("classic"));
Expand Down
25 changes: 14 additions & 11 deletions common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public ModelAnalyser(BindingTarget target) {

private static boolean intersects(Vertex[] quad, List<Vertex[]> quads) {
final float precision = 1.0E-05f;
for (Vertex[] q : quads)
for (Vertex v1 : quad)
for (Vertex v2 : q) if (v1.pos().squaredDistanceTo(v2.pos()) < precision) return true;
for (Vertex[] q : quads) for (Vertex v1 : quad) for (Vertex v2 : q) if (v1.pos().squaredDistanceTo(v2.pos()) < precision) return true;
return false;
}

Expand All @@ -55,8 +53,13 @@ private static void drawNormal(DrawContext context, Vec3d start, Vec3d normal, i
context.draw();
}

public void initialize(int entitySize, int mouseX, int mouseY, int layers) {
public void initialize(int entitySize, int mouseX, int mouseY, int layers, boolean hideDisabled, String idInField) {
buildLastRecord();
List<BuiltRecord> removedRecords = records.stream().filter(record -> {
boolean isIdInField = !idInField.isBlank() && record.renderLayer().toString().contains(idInField);
return (hideDisabled && isIdInField) || (!isIdInField && target.disabledTextureIds.stream().anyMatch(record.renderLayer().toString()::contains));
}).toList();
records.removeAll(removedRecords);
List<Triple> sortByDepth = new ArrayList<>();
records.forEach(record -> {
Vertex[][] vertices = record.vertices();
Expand All @@ -79,10 +82,12 @@ public void initialize(int entitySize, int mouseX, int mouseY, int layers) {
focusedIndex = result.index;
}
target.scale *= entitySize;
records.addAll(removedRecords);
currentRecord = getTargetPosAndRot(target, normal, position);
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);
records.removeAll(removedRecords);
normal.rotateLocal((float) Math.toRadians(target.getYaw()), normal.m10, normal.m11, normal.m12);
normal.rotateLocal((float) Math.toRadians(target.getPitch()), normal.m00, normal.m01, normal.m02);
normal.rotateLocal((float) Math.toRadians(target.getRoll()), normal.m20, normal.m21, normal.m22);
}

public String focusedTextureId() {
Expand All @@ -101,10 +106,8 @@ public Vec2f getFocusedUV() {
return new Vec2f(u / quad.length, v / quad.length);
}

public void previewEffect(DrawContext context, int entitySize, boolean canSelect, boolean hideDisabled, String disabledTextureId) {
drawByAnother(context.getVertexConsumers(),
renderLayer -> !canSelect || hideDisabled || disabledTextureId.isEmpty() || !renderLayer.toString().contains(disabledTextureId),
(renderLayer, vertices) -> vertices);
public void previewEffect(DrawContext context, int entitySize, boolean canSelect) {
drawByAnother(context.getVertexConsumers(), renderLayer -> true, (renderLayer, vertices) -> vertices);
context.draw();
if (canSelect) drawFocused(context);
if (normal.m00() == 0 && normal.m11() == 0 && normal.m22() == 0) return;
Expand Down
Loading

0 comments on commit 923e52d

Please sign in to comment.