From 4998f3d06642e414b1adff1f906c01dc01d2a02b Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 29 Nov 2019 11:31:09 +0200 Subject: [PATCH] Fixed the final issues with skulls --- .../mixin/MixinSkullBlockEntityRenderer.java | 44 +++++++++++++++++++ .../client/model/ModelPonyHead.java | 15 ++++++- .../blockentity/skull/PonySkullRenderer.java | 43 +++++++----------- .../assets/minelittlepony/models/skull.json | 10 ++++- src/main/resources/minelp.mixin.json | 1 + 5 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java b/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java new file mode 100644 index 00000000..577c88e1 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java @@ -0,0 +1,44 @@ +package com.minelittlepony.client.mixin; + +import net.minecraft.block.SkullBlock; +import net.minecraft.block.entity.SkullBlockEntity; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.block.entity.BlockEntityRenderer; +import net.minecraft.client.render.block.entity.SkullBlockEntityRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.Direction; + +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 com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer; +import com.mojang.authlib.GameProfile; + +import javax.annotation.Nullable; + +@Mixin(SkullBlockEntityRenderer.class) +abstract class MixinSkullBlockEntityRenderer extends BlockEntityRenderer { + + MixinSkullBlockEntityRenderer() { super(null); } + + @Inject(method = "render(" + + "Lnet/minecraft/util/math/Direction;" + + "F" + + "Lnet/minecraft/block/SkullBlock$SkullType;" + + "Lcom/mojang/authlib/GameProfile;" + + "F" + + "Lnet/minecraft/client/util/math/MatrixStack;" + + "Lnet/minecraft/client/render/VertexConsumerProvider;" + + "I" + + ")V", at = @At("HEAD"), cancellable = true) + private static void onRender(@Nullable Direction direction, float angle, + SkullBlock.SkullType skullType, @Nullable GameProfile profile, float poweredTicks, + MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, + CallbackInfo info) { + if (!info.isCancelled() && PonySkullRenderer.renderPonySkull(direction, angle, skullType, profile, poweredTicks, stack, renderContext, lightUv)) { + info.cancel(); + } + } +} diff --git a/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java b/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java index 7e6cc605..98a45941 100644 --- a/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java +++ b/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java @@ -21,11 +21,14 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel, private PonyEars ears; + private ModelPart hair; + public IPonyData metadata = new PonyData(); @Override public void init(ModelContext context) { - context.findByName("head", skull); + context.findByName("skull", skull); + hair = context.findByName("hair"); snout = context.findByName("snout"); horn = context.findByName("horn"); ears = context.findByName("ears"); @@ -41,6 +44,13 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel, return false; } + @Override + public void render(float poweredTicks, float yaw, float pitch) { + super.render(poweredTicks, yaw, pitch); + hair.yaw = skull.yaw; + hair.pitch = skull.pitch; + } + @Override public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) { snout.setVisible(!metadata.getRace().isHuman()); @@ -48,7 +58,8 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel, snout.setGender(metadata.getGender()); - super.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha); + hair.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha); + skull.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha); if (metadata.hasHorn()) { getHead().rotate(stack); diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java index ba48a5ed..b5120568 100644 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java @@ -10,12 +10,8 @@ import com.minelittlepony.pony.IPony; import com.minelittlepony.settings.PonyConfig; import com.mojang.authlib.GameProfile; -import net.minecraft.block.AbstractSkullBlock; -import net.minecraft.block.BlockState; import net.minecraft.block.SkullBlock; -import net.minecraft.block.WallSkullBlock; import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.entity.SkullBlockEntity; import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; @@ -35,10 +31,8 @@ import javax.annotation.Nullable; */ public class PonySkullRenderer extends SkullBlockEntityRenderer { - /** - * Resolves the games skull renderer to either a special pony skull renderer - * or some other skull renderer depending on the ponyskull's state. - */ + private static PonySkullRenderer INSTANCE; + public static void resolve(boolean ponySkulls) { Mson.getInstance().getEntityRendererRegistry().registerBlockRenderer(BlockEntityType.SKULL, ponySkulls ? PonySkullRenderer::new : SkullBlockEntityRenderer::new @@ -54,36 +48,27 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { public PonySkullRenderer(BlockEntityRenderDispatcher dispatcher) { super(dispatcher); + + INSTANCE = this; } - @Override - public void render(SkullBlockEntity skullBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) { - float poweredTicks = skullBlockEntity.getTicksPowered(f); - BlockState state = skullBlockEntity.getCachedState(); - - boolean onWalll = state.getBlock() instanceof WallSkullBlock; - - Direction direction = onWalll ? (Direction)state.get(WallSkullBlock.FACING) : null; - - float angle = 22.5F * (float)(direction != null ? (2 + direction.getHorizontal()) * 4F : state.get(SkullBlock.ROTATION)); - - renderSkull(direction, - angle, - ((AbstractSkullBlock)state.getBlock()).getSkullType(), - skullBlockEntity.getOwner(), poweredTicks, - matrixStack, vertexConsumerProvider, i); + public static boolean renderPonySkull(@Nullable Direction direction, float angle, + SkullBlock.SkullType skullType, @Nullable GameProfile profile, float poweredTicks, + MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { + if (INSTANCE != null) { + return INSTANCE.renderSkull(direction, angle, skullType, profile, poweredTicks, stack, renderContext, lightUv); + } + return false; } - public void renderSkull(@Nullable Direction direction, float angle, + boolean renderSkull(@Nullable Direction direction, float angle, SkullBlock.SkullType skullType, @Nullable GameProfile profile, float poweredTicks, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { ISkull skull = skullMap.get(skullType); if (skull == null || !skull.canRender(MineLittlePony.getInstance().getConfig())) { - SkullBlockEntityRenderer.render(direction, angle, skullType, profile, poweredTicks, stack, renderContext, lightUv); - - return; + return false; } Identifier skin = skull.getSkinResource(profile); @@ -102,6 +87,8 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { skull.render(stack, vertices, lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); stack.pop(); + + return true; } static void handleRotation(MatrixStack stack, @Nullable Direction direction) { diff --git a/src/main/resources/assets/minelittlepony/models/skull.json b/src/main/resources/assets/minelittlepony/models/skull.json index 4a5d851c..a98965ed 100644 --- a/src/main/resources/assets/minelittlepony/models/skull.json +++ b/src/main/resources/assets/minelittlepony/models/skull.json @@ -6,9 +6,9 @@ "horn_x": -1, "horn_z": 4 }, - "head": { + "skull": { "cubes": [ - {"from": [-4, -8, -4], "size": [8, 8, 8], "stretch": 0.25} + {"from": [-4, -8, -4], "size": [8, 8, 8]} ], "children": [ { @@ -45,5 +45,11 @@ "content": "minelittlepony:components/horn" } ] + }, + "hair": { + "texture": {"u": 32}, + "cubes": [ + {"from": [-4, -8, -4], "size": [8, 8, 8], "stretch": 0.25} + ] } } diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index a03d4df0..592a9fea 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -9,6 +9,7 @@ "MixinCamera", "MixinDefaultPlayerSkin", "MixinEntityRenderDispatcher", + "MixinSkullBlockEntityRenderer", "MixinFirstPersonRenderer", "MixinItemRenderer", "MixinClientPlayerEntity",