From 9d9fc5bd433a9a17001c74c6fa7f4e28bbad2640 Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sat, 4 Sep 2021 19:30:15 +0200 Subject: [PATCH 1/4] WIP rendering maps in 3rd person --- .../mixin/HeldItemFeatureRendererMixin.java | 93 +++++++++++++++++++ src/main/resources/antiqueatlas.mixins.json | 3 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java diff --git a/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java new file mode 100644 index 000000000..37e91bcc6 --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java @@ -0,0 +1,93 @@ +package hunternif.mc.impl.atlas.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import hunternif.mc.impl.atlas.AntiqueAtlasMod; +import hunternif.mc.impl.atlas.RegistrarAntiqueAtlas; +import hunternif.mc.impl.atlas.client.OverlayRenderer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.FeatureRenderer; +import net.minecraft.client.render.entity.feature.FeatureRendererContext; +import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.render.entity.model.ModelWithArms; +import net.minecraft.client.render.model.json.ModelTransformation; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Arm; +import net.minecraft.util.math.Vec3f; + + +@Mixin(HeldItemFeatureRenderer.class) +public abstract class HeldItemFeatureRendererMixin> + extends FeatureRenderer { + + public HeldItemFeatureRendererMixin(FeatureRendererContext context) { + super(context); + } + + private OverlayRenderer atlasOverlayRenderer = new OverlayRenderer(); + + @Inject(at = @At("HEAD"), method = "renderItem", cancellable = true) + private void renderItem(LivingEntity entity, ItemStack stack, ModelTransformation.Mode transformationMode, Arm arm, + MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) { + if (arm == entity.getMainArm() && entity.getMainHandStack().getItem().equals(RegistrarAntiqueAtlas.ATLAS)) { // Mainhand with or without the offhand + matrices.push(); + ((ModelWithArms) getContextModel()).setArmAngle(arm, matrices); + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0f)); + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(200.0f)); + boolean bl = arm.equals(Arm.LEFT); + matrices.translate((double) ((float) (bl ? -1 : 1) / 16.0f), 0.125, -0.625); + renderThirdPersonAtlas(matrices, vertexConsumers, light, stack, !entity.getOffHandStack().isEmpty(), bl); + matrices.pop(); + info.cancel(); + return; + } + if (arm != entity.getMainArm() && entity.getOffHandStack().getItem().equals(RegistrarAntiqueAtlas.ATLAS)) { // Only offhand + matrices.push(); + ((ModelWithArms) getContextModel()).setArmAngle(arm, matrices); + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0f)); + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(200.0f)); + boolean bl = arm.equals(Arm.LEFT); + matrices.translate((double) ((float) (bl ? -1 : 1) / 16.0f), 0.125, -0.625); + renderThirdPersonAtlas(matrices, vertexConsumers, light, stack, true, bl); + matrices.pop(); + info.cancel(); + return; + } + } + + private void renderThirdPersonAtlas(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, ItemStack item, boolean smallMap, boolean leftHanded) { + if (smallMap) { + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0f)); + matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); + + matrices.translate(-0.8, -3.2, 0.0); + matrices.scale(0.0098125f, 0.0098125f, 0.0098125f); + } else { +// if(leftHanded) { +// matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); +// matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(150.0f)); +// matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); +// +// matrices.translate(+0.5, -1.3, 0.0); +// } else { + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0f)); + matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); + + matrices.translate(-4.5, -4.2, 0.0); +// } + + matrices.scale(0.0138125f, 0.0138125f, 0.0138125f); + } + + atlasOverlayRenderer.drawOverlay(matrices, vertexConsumers, light, item); + } + +} \ No newline at end of file diff --git a/src/main/resources/antiqueatlas.mixins.json b/src/main/resources/antiqueatlas.mixins.json index 592f320aa..97fac922f 100644 --- a/src/main/resources/antiqueatlas.mixins.json +++ b/src/main/resources/antiqueatlas.mixins.json @@ -20,7 +20,8 @@ "MixinClientPlayNetworkHandler", "MixinInGameHud", "MixinMinecraftClient", - "HeldItemRendererMixin" + "HeldItemRendererMixin", + "HeldItemFeatureRendererMixin" ], "injectors": { "defaultRequire": 1 From 72be15e0a34a29631ff4014bbb79086693431241 Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sat, 4 Sep 2021 19:56:42 +0200 Subject: [PATCH 2/4] Render a backside to the atlas --- .../mc/impl/atlas/client/OverlayRenderer.java | 2 ++ .../impl/atlas/client/texture/ATexture.java | 19 +++++++++++++++++++ .../impl/atlas/client/texture/ITexture.java | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/hunternif/mc/impl/atlas/client/OverlayRenderer.java b/src/main/java/hunternif/mc/impl/atlas/client/OverlayRenderer.java index 74a6c4539..a9cee1d88 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/OverlayRenderer.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/OverlayRenderer.java @@ -67,6 +67,8 @@ private void drawMinimap(MatrixStack matrices, int atlasID, VertexConsumerProvid matrices.push(); matrices.translate(0, 0, 0.01); Textures.BOOK.drawWithLight(buffer, matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light); + // Book backside + Textures.BOOK.drawWithLightFlipped(buffer, matrices, 0, 0, (int) (GuiAtlas.WIDTH * 1.5), (int) (GuiAtlas.HEIGHT * 1.5), light); matrices.pop(); matrices.push(); diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java index 1982df2e9..9e5894dea 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/ATexture.java @@ -64,6 +64,17 @@ public void draw(MatrixStack matrices, int x, int y, int width, int height, int public void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light) { drawWithLight(consumer, matrices, x, y, width, height, 0, 0, this.width(), this.height(), light); } + + public void drawWithLightFlipped(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light) { + drawWithLightFlipped(consumer, matrices, x, y, width, height, 0, 0, this.width(), this.height(), light); + } + + public void drawWithLightFlipped(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int light) { + if (autobind) { + bind(); + } + drawTexturedQuadWithLightFlipped(consumer, matrices.peek().getModel(), x, x + width, y, y + height, (u + 0.0F) / (float) this.width(), (u + (float) regionWidth) / (float) this.width(), (v + 0.0F) / (float) this.height(), (v + (float) regionHeight) / (float) this.height(), light); + } public void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int light) { if (autobind) { @@ -79,4 +90,12 @@ private void drawTexturedQuadWithLight(VertexConsumerProvider vertexConsumer, Ma consumer.vertex(matrices, (float) x1, (float) y0, 0f).color(255, 255, 255, 255).texture(u1, v0).light(light).next(); consumer.vertex(matrices, (float) x0, (float) y0, 0f).color(255, 255, 255, 255).texture(u0, v0).light(light).next(); } + + private void drawTexturedQuadWithLightFlipped(VertexConsumerProvider vertexConsumer, Matrix4f matrices, int x0, int x1, int y0, int y1, float u0, float u1, float v0, float v1, int light) { + VertexConsumer consumer = vertexConsumer.getBuffer(this.LAYER); + consumer.vertex(matrices, (float) x0, (float) y0, 0f).color(255, 255, 255, 255).texture(u0, v0).light(light).next(); + consumer.vertex(matrices, (float) x1, (float) y0, 0f).color(255, 255, 255, 255).texture(u1, v0).light(light).next(); + consumer.vertex(matrices, (float) x1, (float) y1, 0f).color(255, 255, 255, 255).texture(u1, v1).light(light).next(); + consumer.vertex(matrices, (float) x0, (float) y1, 0f).color(255, 255, 255, 255).texture(u0, v1).light(light).next(); + } } diff --git a/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java b/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java index c3d475992..2d64caf5d 100644 --- a/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java +++ b/src/main/java/hunternif/mc/impl/atlas/client/texture/ITexture.java @@ -35,6 +35,8 @@ public interface ITexture { void draw(MatrixStack matrices, int x, int y, int u, int v, int regionWidth, int regionHeight); void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light); + + void drawWithLightFlipped(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int light); void drawWithLight(VertexConsumerProvider consumer, MatrixStack matrices, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, int light); } From 22568c7fb127b58b6a4de78309d05b9600519d1e Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sat, 4 Sep 2021 20:43:12 +0200 Subject: [PATCH 3/4] Check for Not Enough Animations to decide rather big maps should be enabled --- .../mixin/HeldItemFeatureRendererMixin.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java index 37e91bcc6..70abffdea 100644 --- a/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java +++ b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java @@ -5,7 +5,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import hunternif.mc.impl.atlas.AntiqueAtlasMod; import hunternif.mc.impl.atlas.RegistrarAntiqueAtlas; import hunternif.mc.impl.atlas.client.OverlayRenderer; import net.minecraft.client.render.VertexConsumerProvider; @@ -31,7 +30,18 @@ public HeldItemFeatureRendererMixin(FeatureRendererContext context) { } private OverlayRenderer atlasOverlayRenderer = new OverlayRenderer(); + private boolean enableBigMaps = false; + @Inject(method = "*", at = @At("RETURN")) + public void constructor(CallbackInfo info) { + try { + Class.forName("dev.tr7zw.notenoughanimations.NEAnimationsLoader"); + enableBigMaps = true; + }catch(Exception ex) { + // No "Not Enough Animations" loaded + } + } + @Inject(at = @At("HEAD"), method = "renderItem", cancellable = true) private void renderItem(LivingEntity entity, ItemStack stack, ModelTransformation.Mode transformationMode, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo info) { @@ -62,7 +72,7 @@ private void renderItem(LivingEntity entity, ItemStack stack, ModelTransformatio } private void renderThirdPersonAtlas(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, ItemStack item, boolean smallMap, boolean leftHanded) { - if (smallMap) { + if (smallMap || !enableBigMaps) { matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0f)); matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); @@ -70,19 +80,19 @@ private void renderThirdPersonAtlas(MatrixStack matrices, VertexConsumerProvider matrices.translate(-0.8, -3.2, 0.0); matrices.scale(0.0098125f, 0.0098125f, 0.0098125f); } else { -// if(leftHanded) { -// matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); -// matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(150.0f)); -// matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); -// -// matrices.translate(+0.5, -1.3, 0.0); -// } else { + if(leftHanded) { + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(150.0f)); + matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); + + matrices.translate(+4.5, -4.2, 0.0); + } else { matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); - matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(180.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(220.0f)); matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); - matrices.translate(-4.5, -4.2, 0.0); -// } + matrices.translate(-4.5, -4.6, 0.0); + } matrices.scale(0.0138125f, 0.0138125f, 0.0138125f); } From d355d08fdb528ce57f8ec63587c293c97567493d Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sat, 4 Sep 2021 21:08:26 +0200 Subject: [PATCH 4/4] Main hand map offsets --- .../mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java index 70abffdea..0835a8602 100644 --- a/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java +++ b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java @@ -85,13 +85,13 @@ private void renderThirdPersonAtlas(MatrixStack matrices, VertexConsumerProvider matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(150.0f)); matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); - matrices.translate(+4.5, -4.2, 0.0); + matrices.translate(0, -3.6, 0.0); } else { matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); - matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(220.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(210.0f)); matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); - matrices.translate(-4.5, -4.6, 0.0); + matrices.translate(-4.0, -5.0, 0.0); } matrices.scale(0.0138125f, 0.0138125f, 0.0138125f);