diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index ba29205..10c32d8 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -29,7 +29,6 @@ import org.joml.Vector4f; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.function.BiFunction; @@ -137,16 +136,15 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { 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()))); + List targets = config().binding.targetList; + recorder.setCurrent(renderLayer -> targets.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()); + if (textureId != null) targetList.addAll(targets.stream().filter(t -> textureId.contains(t.textureId())).toList()); } - targetList.add(config().getTarget(config().binding.nameOfList)); + targetList.add(config().getTarget(config().binding.targetName)); for (BindingTarget target : targetList) { try { recorder.setCurrent(renderLayer -> renderLayer.toString().contains(target.textureId())); - if (recorder.quadCount() <= 0) throw new NullPointerException("Vertices not found"); pos = recorder.getTargetPosAndRot(target, normal); currentTarget = target; break; 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 7569465..6eb76eb 100644 --- a/common/src/main/java/com/xtracr/realcamera/compat/PehkuiCompat.java +++ b/common/src/main/java/com/xtracr/realcamera/compat/PehkuiCompat.java @@ -3,7 +3,6 @@ import com.xtracr.realcamera.util.ReflectUtil; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; -import net.minecraft.util.math.Vec3d; import java.lang.reflect.Method; import java.util.Optional; @@ -31,11 +30,4 @@ public static void scaleMatrices(MatrixStack matrixStack, Entity entity, float t 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); - 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 4eddaa4..b78f826 100644 --- a/common/src/main/java/com/xtracr/realcamera/compat/PhysicsModCompat.java +++ b/common/src/main/java/com/xtracr/realcamera/compat/PhysicsModCompat.java @@ -49,10 +49,13 @@ public class PhysicsModCompat { public static void renderStart(EntityRenderDispatcher dispatcher, E entity, double x, double y, double z, float yRot, float renderPercent, MatrixStack matrixStack) { if (!loaded) return; - 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); + try { + 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); + } + } catch (Exception ignored) { } } } 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 150e2c7..4d60110 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ConfigScreen.java @@ -314,7 +314,7 @@ public static Screen create(Screen parent) { disable.addEntry(disableModWhen.build()); experimental.addEntry(entryBuilder.startBooleanToggle(Text.literal("Enabled"), config.binding.experimental) - .setDefaultValue(false) + .setDefaultValue(true) .setSaveConsumer(b -> config.binding.experimental = b) .build()); experimental.addEntry(entryBuilder.startBooleanToggle(Text.literal("Auto Bind"), config.binding.autoBind) 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 522eb3e..599d706 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -6,6 +6,7 @@ import net.minecraft.util.math.MathHelper; import java.util.*; +import java.util.stream.IntStream; public class ModConfig { protected static final double MIN_DOUBLE = -64.0d; @@ -81,7 +82,7 @@ public boolean isAdjustingOffset() { } public BindingTarget getTarget(String name) { - return binding.targetMap.get(name); + return binding.targetList.stream().filter(target -> target.name().equals(name)).findAny().orElse(null); } public boolean isXBound() { @@ -129,7 +130,11 @@ public void setAdjustOffset(boolean value) { } public void putTarget(BindingTarget target) { - if (!target.isEmpty()) binding.targetMap.put(target.name(), target); + if (target.isEmpty()) return; + IntStream.range(0, binding.targetList.size()) + .filter(i -> binding.targetList.get(i).name().equals(target.name())) + .findAny() + .ifPresentOrElse(i -> binding.targetList.set(i, target), () -> binding.targetList.add(target)); } public void adjustBindingX(boolean add) { @@ -299,12 +304,12 @@ private void clamp() { } public static class Binding { + public List targetList = new ArrayList<>(BindingTarget.defaultTargets); public VanillaModelPart vanillaModelPart = VanillaModelPart.head; - public boolean experimental = false; + public boolean experimental = true; public boolean adjustOffset = true; public boolean autoBind = true; - public String nameOfList = "minecraft_head"; - public LinkedHashMap targetMap = new LinkedHashMap<>(); + public String targetName = "minecraft_head"; public boolean bindX = true; public boolean bindY = true; public boolean bindZ = true; @@ -318,10 +323,7 @@ public static class Binding { private void clamp() { if (vanillaModelPart == null) vanillaModelPart = VanillaModelPart.head; - if (targetMap == null || targetMap.isEmpty()) { - targetMap = new LinkedHashMap<>(); - BindingTarget.defaultTargets.forEach(target -> targetMap.put(target.name(), target)); - } + if (targetList == null || targetList.isEmpty()) targetList = new ArrayList<>(BindingTarget.defaultTargets); cameraX = MathHelper.clamp(cameraX, MIN_DOUBLE, MAX_DOUBLE); cameraY = MathHelper.clamp(cameraY, MIN_DOUBLE, MAX_DOUBLE); cameraZ = MathHelper.clamp(cameraZ, MIN_DOUBLE, MAX_DOUBLE); diff --git a/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java b/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java index d4b85fa..0e053ff 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/CyclingTexturedButton.java @@ -12,27 +12,27 @@ 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; + protected final int textureWidth, textureHeight, vOffset, size; + protected int u, v, value; - public CyclingTexturedButton(int u, int v, int maximum) { - this(0, 0, 16, 16, u, v, maximum); + public CyclingTexturedButton(int u, int v, int value, int size) { + this(0, 0, 16, 16, u, v, value, size); } - 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 value, int size) { + this(x, y, width, height, u, v, height, value, size, 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) { + public CyclingTexturedButton(int x, int y, int width, int height, int u, int v, int vOffset, int value, int size, 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.size = size; this.texture = texture; this.textureWidth = textureWidth; this.textureHeight = textureHeight; + setValue(value); } public int getValue() { @@ -40,17 +40,13 @@ public int getValue() { } public void setValue(int value) { - this.value = (value % maximum + maximum) % maximum; - } - - private void cycle(int amount) { - value = (value + amount % maximum + maximum) % maximum; + this.value = (value % size + size) % size; } @Override public void onPress() { - if (Screen.hasShiftDown()) cycle(-1); - else cycle(1); + if (Screen.hasShiftDown()) setValue(value - 1); + else setValue(value + 1); } @Override 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 b1156fc..ea668d3 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelAnalyser.java @@ -1,7 +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; import net.minecraft.client.render.RenderLayer; @@ -19,7 +18,7 @@ public class ModelAnalyser extends VertexRecorder { private BuiltRecord focusedRecord; private static boolean intersects(Vertex[] quad, List quads) { - final float precision = 0.00001f; + 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; @@ -28,8 +27,7 @@ private static boolean intersects(Vertex[] quad, List quads) { private static void drawQuad(DrawContext context, Vertex[] quad, int argb, int offset) { VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getGui()); - for (Vertex vertex : quad) - vertexConsumer.vertex(vertex.x(), vertex.y(), vertex.z() + offset).color(argb).next(); + for (Vertex vertex : quad) vertexConsumer.vertex(vertex.x(), vertex.y(), vertex.z() + offset).color(argb).next(); if (quad.length == 3) vertexConsumer.vertex(quad[2].x(), quad[2].y(), quad[2].z() + offset).color(argb).next(); context.draw(); } @@ -61,7 +59,7 @@ public Vec2f getCenterUV(int quadIndex) { } public int getFocusedIndex(int mouseX, int mouseY, int layers) { - List> sortByDepth = new ArrayList<>(); + List sortByDepth = new ArrayList<>(); records.forEach(record -> { Vertex[][] vertices = record.vertices(); for (int i = 0, size = vertices.length; i < size; i++) { @@ -71,34 +69,32 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) { Vertex point = quad[0]; double deltaZ = 0; if (point.normalZ() != 0) deltaZ = (point.normalX() * (mouseX - point.x()) + point.normalY() * (mouseY - point.y())) / point.normalZ(); - if (polygon.contains(mouseX, mouseY)) sortByDepth.add(new Triple<>(point.z() + deltaZ, record, i)); + if (polygon.contains(mouseX, mouseY)) sortByDepth.add(new Triple(point.z() + deltaZ, record, i)); } }); if (sortByDepth.isEmpty()) return -1; - sortByDepth.sort(Comparator.comparingDouble(triple -> -triple.getLeft())); - Triple result = sortByDepth.get(Math.min(sortByDepth.size() - 1, layers)); - focusedRecord = result.getMiddle(); - return result.getRight(); + sortByDepth.sort(Comparator.comparingDouble(triple -> -triple.depth)); + Triple result = sortByDepth.get(Math.min(sortByDepth.size() - 1, layers)); + focusedRecord = result.record; + return result.index; } public void preview(DrawContext context, BindingTarget target, int entitySize, int forwardArgb, int upwardArgb, int leftArgb) { - Matrix3f normal = new Matrix3f(); + drawByAnother(context.getVertexConsumers()); + context.draw(); target.setOffsetX(entitySize * target.offsetX()); target.setOffsetY(entitySize * target.offsetY()); target.setOffsetZ(entitySize * target.offsetZ()); + 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()), 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); @@ -151,4 +147,6 @@ public void drawNormal(DrawContext context, float u, float v, int length, int ar if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return; drawNormal(context, getPos(quad, u, v), quad[0].normal(), length, argb); } + + record Triple(double depth, BuiltRecord record, int index) {} } 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 43ec766..0219b2f 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -24,7 +24,7 @@ import org.joml.Vector3f; import org.lwjgl.glfw.GLFW; -import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; public class ModelViewScreen extends Screen { @@ -45,11 +45,11 @@ public class ModelViewScreen extends Screen { 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 CyclingTexturedButton pauseButton = new CyclingTexturedButton(0, 0, 0, 2); + private final CyclingTexturedButton bindXButton = new CyclingTexturedButton(16, 0, 1, 2); + private final CyclingTexturedButton bindYButton = new CyclingTexturedButton(16, 0, 0, 2); + private final CyclingTexturedButton bindZButton = new CyclingTexturedButton(16, 0, 1, 2); + private final CyclingTexturedButton bindRotButton = new CyclingTexturedButton(16, 0, 1, 2); private final DoubleSliderWidget entityPitchSlider = createSlider("pitch", widgetWidth * 2 + 4, -90.0d, 90.0d); private final DoubleSliderWidget entityYawSlider = createSlider("yaw", widgetWidth * 2 + 4, -60.0d, 60.0d); private final DoubleSliderWidget offsetXSlider = createSlider("offsetX", widgetWidth * 2 - 18, -1.0d, 1.0d); @@ -129,7 +129,15 @@ private void initLeftWidgets(final int category) { adder.add(bindRotButton, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "bindButtons"))); 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(new TexturedButton(32, 0, button -> { + offsetXSlider.setValue(0); + offsetYSlider.setValue(0); + offsetZSlider.setValue(0); + pitchSlider.setValue(0); + yawSlider.setValue(0); + rollSlider.setValue(0); + }), 1, smallPositioner); + adder.add(rollSlider, 1, sliderPositioner); adder.add(scaleField, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "scale"))); adder.add(depthField, 1, smallPositioner).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "depth"))); } @@ -139,7 +147,7 @@ private void initLeftWidgets(final int category) { initWidgets(category, page); })); adder.add(createButton(Text.translatable(KEY_WIDGET + "bind"), widgetWidth, button -> { - ConfigFile.modConfig.binding.nameOfList = nameField.getText(); + ConfigFile.modConfig.binding.targetName = nameField.getText(); ConfigFile.save(); initWidgets(category, page); })).setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "bind", "Auto Bind"))); @@ -152,8 +160,8 @@ private void initLeftWidgets(final int category) { } private void initRightWidgets(final int page) { - LinkedHashMap targetMap = ConfigFile.modConfig.binding.targetMap; - final int widgetsPerPage = 6, pages = (targetMap.size() - 1) / widgetsPerPage + 1; + List targetList = ConfigFile.modConfig.binding.targetList; + final int widgetsPerPage = 6, pages = (targetList.size() - 1) / widgetsPerPage + 1; GridWidget gridWidget = new GridWidget(); gridWidget.getMainPositioner().margin(4, 2, 0, 0); Positioner smallPositioner = gridWidget.copyPositioner().margin(5, 3, 1, 1); @@ -161,16 +169,15 @@ private void initRightWidgets(final int page) { addDrawableChild(new TexturedButton(x + (xSize + ySize) / 2 + 8, y + 4, 16, 16, 0, 32, button -> initWidgets(category, (page - 1 + pages) % pages))); addDrawableChild(new TextWidget(x + (xSize + ySize) / 2 + 30, y + 4, widgetWidth * 2 - 40, widgetHeight, Text.of((page + 1) + " / " + pages), textRenderer)); addDrawableChild(new TexturedButton(x + xSize - 21, y + 4, 16, 16, 16, 32, button -> initWidgets(category, (page + 1) % pages))); - String[] names = targetMap.keySet().toArray(String[]::new); - for (int i = page * widgetsPerPage; i < Math.min((page + 1) * widgetsPerPage, targetMap.size()); i++) { - String name = names[i]; - BindingTarget target = targetMap.get(name); - adder.add(createButton(Text.literal(name).styled(s -> name.equals(ConfigFile.modConfig.binding.nameOfList) ? s.withColor(Formatting.GREEN) : s), + for (int i = page * widgetsPerPage; i < Math.min((page + 1) * widgetsPerPage, targetList.size()); i++) { + BindingTarget target = targetList.get(i); + String name = target.name(); + adder.add(createButton(Text.literal(name).styled(s -> name.equals(ConfigFile.modConfig.binding.targetName) ? s.withColor(Formatting.GREEN) : s), widgetWidth * 2 - 18, button -> loadBindingTarget(target))); adder.add(new TexturedButton(32, 32, button -> { - targetMap.remove(name); + targetList.remove(target); ConfigFile.save(); - initWidgets(category, page * widgetsPerPage >= targetMap.size() && !targetMap.isEmpty() ? page - 1 : page); + initWidgets(category, page * widgetsPerPage >= targetList.size() && !targetList.isEmpty() ? page - 1 : page); }), 1, smallPositioner); } gridWidget.refreshPositions(); 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 e0ea53c..c5bda6c 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java @@ -10,10 +10,8 @@ import org.joml.Vector3f; import java.awt.*; -import java.util.ArrayList; -import java.util.Comparator; +import java.util.*; import java.util.List; -import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -26,12 +24,11 @@ public class VertexRecorder implements VertexConsumerProvider { protected static Vertex[] getQuad(BuiltRecord record, float u, float v) { final int resolution = 1000000; - for (Vertex[] quad : record.vertices) { + return Arrays.stream(record.vertices).filter(quad -> { 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 quad; - } - return null; + return polygon.contains(resolution * u, resolution * v); + }).findAny().orElse(null); } protected static Vec3d getPos(Vertex[] quad, float u, float v) { @@ -56,28 +53,11 @@ public void clear() { lastRecord = null; } - public int quadCount() { - if (currentRecord == null) return 0; - return currentRecord.quadCount; - } - public String currentTextureId() { if (currentRecord == null) return null; return getTextureId(currentRecord); } - public Vec3d getPos(float u, float v) { - 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) { - Vertex[] quad; - if (currentRecord == null || (quad = getQuad(currentRecord, u, v)) == null) return null; - return quad[0].normal(); - } - public void buildLastRecord() { if (lastRecord != null && !lastRecord.vertices.isEmpty()) records.add(lastRecord.build()); lastRecord = null; @@ -87,14 +67,14 @@ public void setCurrent(Predicate predicate) { currentRecord = records.stream().filter(record -> predicate.test(record.renderLayer)).max(Comparator.comparingInt(BuiltRecord::quadCount)).orElse(null); } - 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()); + public Vec3d getTargetPosAndRot(BindingTarget target, Matrix3f normal) throws NullPointerException, ArithmeticException { + Vec3d front = Objects.requireNonNull(getQuad(currentRecord, target.forwardU(), target.forwardV()))[0].normal(); + Vec3d up = Objects.requireNonNull(getQuad(currentRecord, target.upwardU(), target.upwardV()))[0].normal(); + Vec3d center = getPos(Objects.requireNonNull(getQuad(currentRecord, target.posU(), target.posV())), 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()); + Vector3f offset = new Vector3f((float) target.offsetZ(), (float) target.offsetY(), (float) target.offsetX()).mul(normal); + return center.add(offset.x(), offset.y(), offset.z()); } public void drawByAnother(VertexConsumerProvider anotherProvider) { @@ -132,7 +112,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 = net.minecraft.util.math.Vec3d.ZERO, normal = net.minecraft.util.math.Vec3d.ZERO; + private Vec3d pos = Vec3d.ZERO, normal = Vec3d.ZERO; private int argb, overlay, light; private float u, v; @@ -194,7 +174,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 = net.minecraft.util.math.Vec3d.ZERO; + pos = normal = Vec3d.ZERO; u = v = overlay = light = argb = 0; }