diff --git a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java index a2c9d6e..78acdb6 100644 --- a/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java +++ b/common/src/main/java/com/xtracr/realcamera/RealCameraCore.java @@ -7,8 +7,8 @@ import com.xtracr.realcamera.config.ModConfig; import com.xtracr.realcamera.mixin.PlayerEntityRendererAccessor; import com.xtracr.realcamera.util.MathUtil; -import com.xtracr.realcamera.util.VertexDataCatcher; -import com.xtracr.realcamera.util.VertexDataCatcherProvider; +import com.xtracr.realcamera.util.VertexRecorder; +import com.xtracr.realcamera.util.VertexRecorderProvider; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; @@ -30,9 +30,8 @@ public class RealCameraCore { private static final ModConfig config = ConfigFile.modConfig; - private static VertexDataCatcherProvider catcherProvider = new VertexDataCatcherProvider(); + private static VertexRecorderProvider recorderProvider = new VertexRecorderProvider(); private static String status = "Successful"; - private static boolean renderingPlayer = false; private static boolean active = false; private static float pitch, yaw, roll; @@ -69,6 +68,10 @@ public static Vec3d getPos() { return pos; } + public static Vec3d getModelOffset() { + return modelOffset; + } + public static void setModelOffset(Vec3d vec3d) { modelOffset = vec3d; } @@ -82,14 +85,13 @@ public static boolean isActive() { return active; } - public static void renderPlayer(Vec3d cameraPos, MatrixStack matrices, VertexConsumerProvider vertexConsumers) { + public static void renderPlayer(Vec3d offset, MatrixStack matrices, VertexConsumerProvider vertexConsumers) { matrices.push(); - cameraPos = cameraPos.subtract(modelOffset); matrices.peek().getPositionMatrix().transpose().invertAffine() - .translate((float) -cameraPos.getX(), (float) -cameraPos.getY(), (float) -cameraPos.getZ()); + .translate((float) -offset.getX(), (float) -offset.getY(), (float) -offset.getZ()); matrices.peek().getNormalMatrix().transpose().invert(); // TODO - catcherProvider.drawByAnother(matrices, vertexConsumers, null, null); + recorderProvider.drawByAnother(matrices, vertexConsumers, null, null); matrices.pop(); } @@ -100,9 +102,9 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { // GameRenderer.renderWorld MatrixStack matrixStack = new MatrixStack(); - catcherProvider = new VertexDataCatcherProvider(); - virtualRender(client, tickDelta, matrixStack, catcherProvider); - VertexDataCatcher catcher = catcherProvider.getUnion(new VertexDataCatcher()); + recorderProvider = new VertexRecorderProvider(); + virtualRender(client, tickDelta, matrixStack, recorderProvider); + VertexRecorder unionRecorder = recorderProvider.getUnion(new VertexRecorder()); // ModelPart$Cuboid.renderCuboid Vector4f offset = matrixStack.peek().getPositionMatrix().transform(new Vector4f((float) (config.getBindingZ() * config.getScale()), @@ -111,12 +113,12 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { 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) try { - if (catcher.vertexCount() <= 0) throw new NullPointerException("Vertices not found"); + if (unionRecorder.vertexCount() <= 0) throw new NullPointerException("Vertices not found"); List indexList = config.binding.indexListMap.get(config.binding.nameOfList); - Vec3d front = catcher.getNormal(indexList.get(0)); - Vec3d up = catcher.getNormal(indexList.get(1)); + Vec3d front = unionRecorder.getNormal(indexList.get(0)); + Vec3d up = unionRecorder.getNormal(indexList.get(1)); Vec3d center = Vec3d.ZERO; - for (int i : indexList.subList(2, indexList.size())) center = center.add(catcher.getPos(i)); + for (int i : indexList.subList(2, indexList.size())) center = center.add(unionRecorder.getPos(i)); 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()), @@ -135,7 +137,7 @@ public static void computeCamera(MinecraftClient client, float tickDelta) { roll = config.isRollingBound() ? (float) eulerAngle.getZ() : config.getBindingRoll(); } - private static void virtualRender(MinecraftClient client, float tickDelta, MatrixStack matrixStack, VertexDataCatcherProvider provider) { + private static void virtualRender(MinecraftClient client, float tickDelta, MatrixStack matrixStack, VertexRecorderProvider provider) { ClientPlayerEntity player = client.player; // WorldRenderer.render if (player.age == 0) { 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 73e0c9b..c3e73fc 100644 --- a/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java +++ b/common/src/main/java/com/xtracr/realcamera/config/ModConfig.java @@ -295,7 +295,7 @@ private void clamp() { public static class Binding { public static final Map> defaultIndexListMap = Map.of( - "minecraft_head", Arrays.asList(12, 0, -9, 12, 13, 14, 15)); + "minecraft_head", Arrays.asList(12, 0, 12, 12, 13, 14, 15)); public VanillaModelPart vanillaModelPart = VanillaModelPart.head; public boolean experimental = false; public boolean adjustOffset = true; 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 2589666..f2dddf2 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,7 @@ package com.xtracr.realcamera.gui; -import com.xtracr.realcamera.util.VertexDataCatcher; -import com.xtracr.realcamera.util.VertexDataCatcherProvider; +import com.xtracr.realcamera.util.VertexRecorder; +import com.xtracr.realcamera.util.VertexRecorderProvider; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; @@ -14,9 +14,9 @@ import java.util.Comparator; import java.util.List; -public class ModelAnalyser extends VertexDataCatcherProvider { +public class ModelAnalyser extends VertexRecorderProvider { private final float precision = 0.00001f; - private final VertexDataCatcher catcher = new VertexDataCatcher(); + private final VertexRecorder unionRecorder = new VertexRecorder(); private final List> quads = new ArrayList<>(); public List getQuad(int index) { @@ -30,11 +30,11 @@ public List getQuad(int index) { } public void analyse() { - getUnion(catcher); - int size = catcher.vertexCount(); + getUnion(unionRecorder); + int size = unionRecorder.vertexCount(); quads.add(new ArrayList<>(List.of(0))); for (int i = 1; i < size; i++) { - double dotProduct = catcher.getNormal(i - 1).dotProduct(catcher.getNormal(i)); + double dotProduct = unionRecorder.getNormal(i - 1).dotProduct(unionRecorder.getNormal(i)); if (dotProduct >= 1 - precision) quads.get(quads.size() - 1).add(i); else quads.add(new ArrayList<>(List.of(i))); } @@ -44,9 +44,9 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) { List> sortByDepth = new ArrayList<>(); for (List vertices : quads) { Polygon quad = new Polygon(); - vertices.forEach(i -> quad.addPoint((int) catcher.getPos(i).getX(), (int) catcher.getPos(i).getY())); - Vector3f normal = catcher.getNormal(vertices.get(0)).toVector3f(); - Vector3f point = catcher.getPos(vertices.get(0)).toVector3f(); + vertices.forEach(i -> quad.addPoint((int) unionRecorder.getPos(i).getX(), (int) unionRecorder.getPos(i).getY())); + Vector3f normal = unionRecorder.getNormal(vertices.get(0)).toVector3f(); + Vector3f point = unionRecorder.getPos(vertices.get(0)).toVector3f(); float deltaZ = 0; if (normal.z() != 0) deltaZ = (normal.x() * (mouseX - point.x()) + normal.y() * (mouseY - point.y())) / normal.z(); if (quad.contains(mouseX, mouseY)) sortByDepth.add(new Pair<>(vertices.get(0), point.z() + deltaZ)); @@ -57,12 +57,12 @@ public int getFocusedIndex(int mouseX, int mouseY, int layers) { } public void drawQuad(DrawContext context, int vertex, int argb) { - if (vertex >= catcher.vertexCount()) return; + if (vertex >= unionRecorder.vertexCount()) return; drawQuad(context, getQuad(vertex), argb, 1000); } public void drawPolyhedron(DrawContext context, int vertex, int argb) { - if (vertex >= catcher.vertexCount()) return; + if (vertex >= unionRecorder.vertexCount()) return; List highlight = getQuad(vertex); List> polyhedron = new ArrayList<>(List.of(highlight)); boolean added; @@ -92,12 +92,12 @@ public void drawPolyhedron(DrawContext context, int vertex, int argb) { } public void drawNormal(DrawContext context, int vertex, int length, int argb) { - if (vertex >= catcher.vertexCount()) return; + if (vertex >= unionRecorder.vertexCount()) return; VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getLineStrip()); - Vector3f normal = catcher.getNormal(vertex).toVector3f(); + Vector3f normal = unionRecorder.getNormal(vertex).toVector3f(); Vector3f start = new Vector3f(); List quad = getQuad(vertex); - quad.forEach(i -> start.add(catcher.getPos(i).toVector3f())); + quad.forEach(i -> start.add(unionRecorder.getPos(i).toVector3f())); start.mul(1 / (float) quad.size()); Vector3f end = new Vector3f(normal).mul(length).add(start); vertexConsumer.vertex(start.x(), start.y(), start.z() + 1200f).color(argb).normal(normal.x(), normal.y(), normal.z()).next(); @@ -108,7 +108,7 @@ public void drawNormal(DrawContext context, int vertex, int length, int argb) { private boolean intersects(List quad, List> quads) { boolean ret = false; for (List p : quads) for (int v1 : quad) for (int v2 : p) { - if (catcher.getPos(v1).squaredDistanceTo(catcher.getPos(v2)) < precision) { + if (unionRecorder.getPos(v1).squaredDistanceTo(unionRecorder.getPos(v2)) < precision) { ret = true; break; } @@ -118,7 +118,7 @@ private boolean intersects(List quad, List> quads) { private void drawQuad(DrawContext context, List quad, int argb, int offset) { VertexConsumer vertexConsumer = context.getVertexConsumers().getBuffer(RenderLayer.getGui()); - quad.stream().map(catcher::getPos).forEach(pos -> vertexConsumer.vertex(pos.getX(), pos.getY(), pos.getZ() + offset).color(argb).next()); + quad.stream().map(unionRecorder::getPos).forEach(pos -> vertexConsumer.vertex(pos.getX(), pos.getY(), pos.getZ() + offset).color(argb).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 4703942..95de3a7 100644 --- a/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java +++ b/common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java @@ -30,7 +30,7 @@ public class ModelViewScreen extends Screen { private static final String KEY_TOOLTIP = "screen.tooltip.xtracr_" + RealCamera.MODID + "_modelView_"; protected int xSize = 400, ySize = 220; protected int x, y; - protected boolean shouldPause = false; + protected boolean shouldPause = false, showCube = false; private int entitySize = 80; private double entityX, entityY; private float yaw, pitch, xRot, yRot; @@ -49,6 +49,8 @@ public class ModelViewScreen extends Screen { private final DoubleValueSlider pitchWidget = new DoubleValueSlider((xSize - ySize)/2 - 15, 18, 0.5D, -90.0D, 90.0D, d -> Text.translatable(KEY_WIDGET + "pitch", MathUtil.round(d, 2)), d -> pitch = (float) d); private final ButtonWidget resetWidget = ButtonWidget.builder(Text.translatable(KEY_WIDGET + "reset"), button -> reset()).size((xSize - ySize)/2 - 15, 18).build(); + private final ButtonWidget pauseWidget = ButtonWidget.builder(Text.translatable(KEY_WIDGET + "pause"), button -> shouldPause = !shouldPause).size((xSize - ySize)/2 - 15, 18).build(); + private final ButtonWidget showCubeWidget = ButtonWidget.builder(Text.translatable(KEY_WIDGET + "showCube"), button -> showCube = !showCube).size((xSize - ySize)/2 - 15, 18).build(); public ModelViewScreen() { super(Text.translatable(KEY_SCREEN + "title")); @@ -67,6 +69,8 @@ protected void init() { selectFrontButton.setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "selectFront"))); selectUpButton.setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "selectUp"))); selectPosButton.setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "selectPos"))); + pauseWidget.setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "pause"))); + showCubeWidget.setTooltip(Tooltip.of(Text.translatable(KEY_TOOLTIP + "showCube"))); addDrawableChild(resetWidget).setPosition(x + 5, y + 4); addDrawableChild(yawWidget).setPosition(x + 5, y + 26); addDrawableChild(pitchWidget).setPosition(x + 5, y + 48); @@ -79,15 +83,23 @@ protected void init() { addDrawableChild(saveButton).setPosition(x + 5, y + 136); addDrawableChild(loadButton).setPosition(x + (xSize - ySize)/4, y + 136); addDrawableChild(nameWidget).setTooltip(Tooltip.of(Text.translatable(KEY_WIDGET + "listName"))); + addDrawableChild(pauseWidget).setPosition(x + (xSize + ySize) / 2 + 10, y + 4); + addDrawableChild(showCubeWidget).setPosition(x + (xSize + ySize) / 2 + 10, y + 26); } @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { + renderBackground(context);// 1.20.1 only + super.render(context, mouseX, mouseY, delta); + drawEntity(context, x + (xSize - ySize) / 2, y, x + (xSize + ySize) / 2, y + ySize, mouseX, mouseY, this.client.player); + } + + @Override + public void renderBackground(DrawContext context) { + super.renderBackground(context); context.fill(x, y, x + (xSize - ySize) / 2 - 5, y + ySize, 0xFF555555); context.fill(x + (xSize - ySize) / 2, y, x + (xSize + ySize) / 2, y + ySize, 0xFF222222); context.fill(x + (xSize + ySize) / 2 + 5, y, x + xSize, y + ySize, 0xFF555555); - super.render(context, mouseX, mouseY, delta); - drawEntity(context, x + (xSize - ySize) / 2, y, x + (xSize + ySize) / 2, y + ySize, mouseX, mouseY, this.client.player); } protected void drawEntity(DrawContext context, int x1, int y1, int x2, int y2, int mouseX, int mouseY, LivingEntity entity) { @@ -131,7 +143,10 @@ protected void drawEntity(DrawContext context, float x, float y, int mouseX, int analyser.analyse(); focusedIndex = analyser.getFocusedIndex(mouseX, mouseY, layers); analyser.drawQuad(context, posIndex, 0x6F3333CC); - if (focusedIndex > -1) analyser.drawPolyhedron(context, focusedIndex, 0x5FFFFFFF); + if (focusedIndex > -1) { + if (showCube) analyser.drawPolyhedron(context, focusedIndex, 0x5FFFFFFF); + else analyser.drawQuad(context, focusedIndex, 0x7FFFFFFF); + } analyser.drawNormal(context, frontIndex, entitySize / 2, 0xFF00CC00); analyser.drawNormal(context, upIndex, entitySize / 2, 0xFFCC0000); posPolygon = analyser.getQuad(posIndex); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java index 4d9ca01..b9a54b7 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinGameRenderer.java @@ -5,8 +5,6 @@ import com.xtracr.realcamera.util.CrosshairUtil; import com.xtracr.realcamera.util.RaycastUtil; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.Perspective; -import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; @@ -17,7 +15,6 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -25,9 +22,6 @@ @Mixin(GameRenderer.class) public abstract class MixinGameRenderer { - @Unique - private static boolean realCamera$toggled = false; - @Shadow @Final MinecraftClient client; @@ -47,25 +41,6 @@ public abstract class MixinGameRenderer { return CrosshairUtil.capturedEntityHitResult; } - @Inject(method = "renderHand", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/util/math/MatrixStack;push()V")) - private void realCamera$setThirdPerson(MatrixStack matrices, Camera camera, float tickDelta, CallbackInfo cInfo) { - if (ConfigFile.modConfig.isRendering() && !ConfigFile.modConfig.shouldDisableRendering(client) && RealCameraCore.isActive() && - !ConfigFile.modConfig.allowRenderingHand(client)) { - client.options.setPerspective(Perspective.THIRD_PERSON_BACK); - realCamera$toggled = true; - } - } - - @Inject(method = "renderHand", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V")) - private void realCamera$setFirstPerson(CallbackInfo cInfo) { - if (realCamera$toggled) { - client.options.setPerspective(Perspective.FIRST_PERSON); - realCamera$toggled = false; - } - } - @Inject(method = "renderWorld", at = @At("HEAD")) private void realCamera$onRenderWorldHEAD(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo cInfo) { RealCameraCore.init(client); diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java new file mode 100644 index 0000000..255a299 --- /dev/null +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinHeldItemRenderer.java @@ -0,0 +1,35 @@ +package com.xtracr.realcamera.mixin; + +import com.xtracr.realcamera.RealCameraCore; +import com.xtracr.realcamera.config.ConfigFile; +import com.xtracr.realcamera.config.ModConfig; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.item.HeldItemRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(HeldItemRenderer.class) +public abstract class MixinHeldItemRenderer { + @Shadow + @Final private MinecraftClient client; + + @Inject(method = "renderFirstPersonItem", at = @At("HEAD"), cancellable = true) + private void realcamera$cancelRendering(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, + ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo cInfo) { + ModConfig config = ConfigFile.modConfig; + if (player instanceof ClientPlayerEntity && RealCameraCore.isActive() && config.isRendering() && + !config.shouldDisableRendering(client) && !config.allowRenderingHand(client)) { + cInfo.cancel(); + } + } +} diff --git a/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java b/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java index 1df166e..774fa48 100644 --- a/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java +++ b/common/src/main/java/com/xtracr/realcamera/mixin/MixinWorldRenderer.java @@ -31,10 +31,10 @@ public abstract class MixinWorldRenderer { ModConfig config = ConfigFile.modConfig; if (camera.isThirdPerson() || !RealCameraCore.isActive() || !config.isRendering() || config.shouldDisableRendering(this.client)) return; VertexConsumerProvider.Immediate immediate = this.bufferBuilders.getEntityVertexConsumers(); - Vec3d cameraPos = camera.getPos(); + Vec3d offset = camera.getPos().subtract(RealCameraCore.getModelOffset()); RealCameraCore.setRenderingPlayer(true); - if (config.binding.experimental && !config.isClassic()) RealCameraCore.renderPlayer(cameraPos, matrices, immediate); - else renderEntity(camera.getFocusedEntity(), cameraPos.getX(), cameraPos.getY(), cameraPos.getZ(), tickDelta, matrices, immediate); + if (config.binding.experimental && !config.isClassic()) RealCameraCore.renderPlayer(offset, matrices, immediate); + else renderEntity(camera.getFocusedEntity(), offset.getX(), offset.getY(), offset.getZ(), tickDelta, matrices, immediate); RealCameraCore.setRenderingPlayer(false); } diff --git a/common/src/main/java/com/xtracr/realcamera/util/VertexDataCatcher.java b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java similarity index 95% rename from common/src/main/java/com/xtracr/realcamera/util/VertexDataCatcher.java rename to common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java index b8ce57e..d0f2814 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexDataCatcher.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorder.java @@ -6,13 +6,13 @@ import java.util.ArrayList; import java.util.List; -public class VertexDataCatcher implements VertexConsumer { +public class VertexRecorder implements VertexConsumer { protected final List vertices = new ArrayList<>(); private Vec3d pos = Vec3d.ZERO, normal = Vec3d.ZERO; private int argb, overlay, light; private float u, v; - public VertexDataCatcher() {} + public VertexRecorder() {} public int vertexCount() { return vertices.size(); diff --git a/common/src/main/java/com/xtracr/realcamera/util/VertexDataCatcherProvider.java b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorderProvider.java similarity index 64% rename from common/src/main/java/com/xtracr/realcamera/util/VertexDataCatcherProvider.java rename to common/src/main/java/com/xtracr/realcamera/util/VertexRecorderProvider.java index fcf327e..b385872 100644 --- a/common/src/main/java/com/xtracr/realcamera/util/VertexDataCatcherProvider.java +++ b/common/src/main/java/com/xtracr/realcamera/util/VertexRecorderProvider.java @@ -4,31 +4,32 @@ import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Pair; import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; import org.joml.Vector4f; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.function.Consumer; import java.util.function.Predicate; -public class VertexDataCatcherProvider implements VertexConsumerProvider { - protected final Map> catchers = new LinkedHashMap<>(); +public class VertexRecorderProvider implements VertexConsumerProvider { + protected final List> recorders = new ArrayList<>(); - public VertexDataCatcher getUnion(VertexDataCatcher union) { - catchers.values().forEach(catcherList -> catcherList.forEach(catcher -> union.vertices.addAll(catcher.vertices))); + public VertexRecorder getUnion(VertexRecorder union) { + recorders.forEach(pair -> union.vertices.addAll(pair.getRight().vertices)); return union; } public void drawByAnother(MatrixStack matrixStack, VertexConsumerProvider anotherProvider, @Nullable Predicate layerPredicate, @Nullable VertexPredicate vertexPredicate) { - catchers.forEach(((renderLayer, catcherList) -> catcherList.forEach(catcher -> { + recorders.forEach(pair -> { + RenderLayer renderLayer = pair.getLeft(); + VertexRecorder recorder = pair.getRight(); if (layerPredicate != null && !layerPredicate.test(renderLayer)) return; VertexConsumer buffer = anotherProvider.getBuffer(renderLayer); - Consumer vertexConsumer = vertex -> { + Consumer vertexConsumer = vertex -> { Vector4f pos = new Vector4f(vertex.pos().toVector3f(), 1.0f).mul(matrixStack.peek().getPositionMatrix()); Vector3f normal = vertex.normal().toVector3f().mul(matrixStack.peek().getNormalMatrix()); int argb = vertex.argb(); @@ -36,45 +37,45 @@ public void drawByAnother(MatrixStack matrixStack, VertexConsumerProvider anothe (float) (argb >> 16 & 0xFF) / 255, (float) (argb >> 8 & 0xFF) / 255, (float) (argb & 0xFF) / 255, (float) (argb >> 24) / 255, vertex.u(), vertex.v(), vertex.overlay(), vertex.light(), normal.x(), normal.y(), normal.z()); }; - int size = catcher.vertexCount(); - if (vertexPredicate == null) catcher.vertices.forEach(vertexConsumer); + int size = recorder.vertexCount(); + if (vertexPredicate == null) recorder.vertices.forEach(vertexConsumer); else for (int i = 0; i < size; i++) { - VertexDataCatcher.Vertex vertex = catcher.vertices.get(i); + VertexRecorder.Vertex vertex = recorder.vertices.get(i); if (vertexPredicate.test(renderLayer, vertex, i)) vertexConsumer.accept(vertex); } - }))); + }); } public void drawByAnother(VertexConsumerProvider anotherProvider, @Nullable Predicate layerPredicate, @Nullable VertexPredicate vertexPredicate) { - catchers.forEach(((renderLayer, catcherList) -> catcherList.forEach(catcher -> { + recorders.forEach(pair -> { + RenderLayer renderLayer = pair.getLeft(); + VertexRecorder recorder = pair.getRight(); if (layerPredicate != null && !layerPredicate.test(renderLayer)) return; VertexConsumer buffer = anotherProvider.getBuffer(renderLayer); - Consumer vertexConsumer = vertex -> { + Consumer vertexConsumer = vertex -> { Vec3d pos = vertex.pos(), normal = vertex.normal(); int argb = vertex.argb(); buffer.vertex((float) pos.getX(), (float) pos.getY(), (float) pos.getZ(), (float) (argb >> 16 & 0xFF) / 255, (float) (argb >> 8 & 0xFF) / 255, (float) (argb & 0xFF) / 255, (float) (argb >> 24) / 255, vertex.u(), vertex.v(), vertex.overlay(), vertex.light(), (float) normal.getX(), (float) normal.getY(), (float) normal.getZ()); }; - int size = catcher.vertexCount(); - if (vertexPredicate == null) catcher.vertices.forEach(vertexConsumer); + int size = recorder.vertexCount(); + if (vertexPredicate == null) recorder.vertices.forEach(vertexConsumer); else for (int i = 0; i < size; i++) { - VertexDataCatcher.Vertex vertex = catcher.vertices.get(i); + VertexRecorder.Vertex vertex = recorder.vertices.get(i); if (vertexPredicate.test(renderLayer, vertex, i)) vertexConsumer.accept(vertex); } - }))); + }); } @Override public VertexConsumer getBuffer(RenderLayer layer) { - VertexDataCatcher catcher = new VertexDataCatcher(); - List catcherList = catchers.getOrDefault(layer, new ArrayList<>()); - catcherList.add(catcher); - catchers.putIfAbsent(layer, catcherList); - return catcher; + VertexRecorder recorder = new VertexRecorder(); + recorders.add(new Pair<>(layer, recorder)); + return recorder; } public interface VertexPredicate { - boolean test(RenderLayer renderLayer, VertexDataCatcher.Vertex vertex, int index); + boolean test(RenderLayer renderLayer, VertexRecorder.Vertex vertex, int index); } } 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 ca22849..0f32901 100644 --- a/common/src/main/resources/assets/realcamera/lang/en_us.json +++ b/common/src/main/resources/assets/realcamera/lang/en_us.json @@ -110,6 +110,8 @@ "screen.widget.xtracr_realcamera_modelView_listName": "Name of the list of the indexes, can be selected and bound in the 'Experimental' screen of config screen if saved", "screen.widget.xtracr_realcamera_modelView_save": "Save", "screen.widget.xtracr_realcamera_modelView_load": "Load", + "screen.widget.xtracr_realcamera_modelView_pause": "Start/End Pause", + "screen.widget.xtracr_realcamera_modelView_showCube": "Show/Hide Cube", "screen.tooltip.xtracr_realcamera_modelView_selectFront": "When turned on, hold Alt and left click to select forward vector", "screen.tooltip.xtracr_realcamera_modelView_selectUp": "When turned on, hold Alt and left click to select upward vector", 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 bc4daaf..71b9dcc 100644 --- a/common/src/main/resources/assets/realcamera/lang/zh_cn.json +++ b/common/src/main/resources/assets/realcamera/lang/zh_cn.json @@ -110,6 +110,8 @@ "screen.widget.xtracr_realcamera_modelView_listName": "索引组的名称,保存后可在配置屏幕的'Experimental'界面选择并绑定", "screen.widget.xtracr_realcamera_modelView_save": "保存", "screen.widget.xtracr_realcamera_modelView_load": "加载", + "screen.widget.xtracr_realcamera_modelView_pause": "开始/结束 暂停", + "screen.widget.xtracr_realcamera_modelView_showCube": "显示/隐藏 立方体", "screen.tooltip.xtracr_realcamera_modelView_selectFront": "打开后,按住Alt并左键可选择向前矢量", "screen.tooltip.xtracr_realcamera_modelView_selectUp": "打开后,按住Alt并左键可选择向上矢量", diff --git a/common/src/main/resources/realcamera-common.mixins.json b/common/src/main/resources/realcamera-common.mixins.json index 5fbf488..deca10d 100644 --- a/common/src/main/resources/realcamera-common.mixins.json +++ b/common/src/main/resources/realcamera-common.mixins.json @@ -10,6 +10,7 @@ "MixinClientPlayerEntity", "MixinEntityRenderer", "MixinGameRenderer", + "MixinHeldItemRenderer", "MixinInGameHud", "MixinItem", "MixinPlayerEntity",