Fixed the final issues with skulls

This commit is contained in:
Sollace 2019-11-29 11:31:09 +02:00
parent dcd2442442
commit 4998f3d066
5 changed files with 81 additions and 32 deletions

View file

@ -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<SkullBlockEntity> {
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();
}
}
}

View file

@ -21,11 +21,14 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel,
private PonyEars ears; private PonyEars ears;
private ModelPart hair;
public IPonyData metadata = new PonyData(); public IPonyData metadata = new PonyData();
@Override @Override
public void init(ModelContext context) { public void init(ModelContext context) {
context.findByName("head", skull); context.findByName("skull", skull);
hair = context.findByName("hair");
snout = context.findByName("snout"); snout = context.findByName("snout");
horn = context.findByName("horn"); horn = context.findByName("horn");
ears = context.findByName("ears"); ears = context.findByName("ears");
@ -41,6 +44,13 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel,
return false; 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 @Override
public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) { public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) {
snout.setVisible(!metadata.getRace().isHuman()); snout.setVisible(!metadata.getRace().isHuman());
@ -48,7 +58,8 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel,
snout.setGender(metadata.getGender()); 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()) { if (metadata.hasHorn()) {
getHead().rotate(stack); getHead().rotate(stack);

View file

@ -10,12 +10,8 @@ import com.minelittlepony.pony.IPony;
import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.block.AbstractSkullBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.SkullBlock; import net.minecraft.block.SkullBlock;
import net.minecraft.block.WallSkullBlock;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.SkullBlockEntity;
import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
@ -35,10 +31,8 @@ import javax.annotation.Nullable;
*/ */
public class PonySkullRenderer extends SkullBlockEntityRenderer { public class PonySkullRenderer extends SkullBlockEntityRenderer {
/** private static PonySkullRenderer INSTANCE;
* Resolves the games skull renderer to either a special pony skull renderer
* or some other skull renderer depending on the ponyskull's state.
*/
public static void resolve(boolean ponySkulls) { public static void resolve(boolean ponySkulls) {
Mson.getInstance().getEntityRendererRegistry().registerBlockRenderer(BlockEntityType.SKULL, Mson.getInstance().getEntityRendererRegistry().registerBlockRenderer(BlockEntityType.SKULL,
ponySkulls ? PonySkullRenderer::new : SkullBlockEntityRenderer::new ponySkulls ? PonySkullRenderer::new : SkullBlockEntityRenderer::new
@ -54,36 +48,27 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer {
public PonySkullRenderer(BlockEntityRenderDispatcher dispatcher) { public PonySkullRenderer(BlockEntityRenderDispatcher dispatcher) {
super(dispatcher); super(dispatcher);
INSTANCE = this;
} }
@Override public static boolean renderPonySkull(@Nullable Direction direction, float angle,
public void render(SkullBlockEntity skullBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) { SkullBlock.SkullType skullType, @Nullable GameProfile profile, float poweredTicks,
float poweredTicks = skullBlockEntity.getTicksPowered(f); MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
BlockState state = skullBlockEntity.getCachedState(); if (INSTANCE != null) {
return INSTANCE.renderSkull(direction, angle, skullType, profile, poweredTicks, stack, renderContext, lightUv);
boolean onWalll = state.getBlock() instanceof WallSkullBlock; }
return false;
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 void renderSkull(@Nullable Direction direction, float angle, boolean renderSkull(@Nullable Direction direction, float angle,
SkullBlock.SkullType skullType, @Nullable GameProfile profile, float poweredTicks, SkullBlock.SkullType skullType, @Nullable GameProfile profile, float poweredTicks,
MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
ISkull skull = skullMap.get(skullType); ISkull skull = skullMap.get(skullType);
if (skull == null || !skull.canRender(MineLittlePony.getInstance().getConfig())) { if (skull == null || !skull.canRender(MineLittlePony.getInstance().getConfig())) {
SkullBlockEntityRenderer.render(direction, angle, skullType, profile, poweredTicks, stack, renderContext, lightUv); return false;
return;
} }
Identifier skin = skull.getSkinResource(profile); 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); skull.render(stack, vertices, lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1);
stack.pop(); stack.pop();
return true;
} }
static void handleRotation(MatrixStack stack, @Nullable Direction direction) { static void handleRotation(MatrixStack stack, @Nullable Direction direction) {

View file

@ -6,9 +6,9 @@
"horn_x": -1, "horn_x": -1,
"horn_z": 4 "horn_z": 4
}, },
"head": { "skull": {
"cubes": [ "cubes": [
{"from": [-4, -8, -4], "size": [8, 8, 8], "stretch": 0.25} {"from": [-4, -8, -4], "size": [8, 8, 8]}
], ],
"children": [ "children": [
{ {
@ -45,5 +45,11 @@
"content": "minelittlepony:components/horn" "content": "minelittlepony:components/horn"
} }
] ]
},
"hair": {
"texture": {"u": 32},
"cubes": [
{"from": [-4, -8, -4], "size": [8, 8, 8], "stretch": 0.25}
]
} }
} }

View file

@ -9,6 +9,7 @@
"MixinCamera", "MixinCamera",
"MixinDefaultPlayerSkin", "MixinDefaultPlayerSkin",
"MixinEntityRenderDispatcher", "MixinEntityRenderDispatcher",
"MixinSkullBlockEntityRenderer",
"MixinFirstPersonRenderer", "MixinFirstPersonRenderer",
"MixinItemRenderer", "MixinItemRenderer",
"MixinClientPlayerEntity", "MixinClientPlayerEntity",