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); } 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..0835a8602 --- /dev/null +++ b/src/main/java/hunternif/mc/impl/atlas/mixin/HeldItemFeatureRendererMixin.java @@ -0,0 +1,103 @@ +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.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(); + 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) { + 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 || !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); + + 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, -3.6, 0.0); + } else { + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(160.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(210.0f)); + matrices.scale(0.38f/3, 0.38f/3, 0.38f/3); + + matrices.translate(-4.0, -5.0, 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