mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Fixed the final issues with skulls
This commit is contained in:
parent
dcd2442442
commit
4998f3d066
5 changed files with 81 additions and 32 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"MixinCamera",
|
||||
"MixinDefaultPlayerSkin",
|
||||
"MixinEntityRenderDispatcher",
|
||||
"MixinSkullBlockEntityRenderer",
|
||||
"MixinFirstPersonRenderer",
|
||||
"MixinItemRenderer",
|
||||
"MixinClientPlayerEntity",
|
||||
|
|
Loading…
Reference in a new issue