Got pony skulls working

This commit is contained in:
Sollace 2019-11-29 01:13:15 +02:00
parent 867f14dd0c
commit 3255325655
14 changed files with 141 additions and 143 deletions

View file

@ -5,13 +5,15 @@ import com.minelittlepony.client.model.part.PonySnout;
import com.minelittlepony.client.model.part.UnicornHorn; import com.minelittlepony.client.model.part.UnicornHorn;
import com.minelittlepony.client.pony.PonyData; import com.minelittlepony.client.pony.PonyData;
import com.minelittlepony.model.ICapitated; import com.minelittlepony.model.ICapitated;
import com.minelittlepony.mson.api.ModelContext;
import com.minelittlepony.mson.api.MsonModel;
import com.minelittlepony.pony.IPonyData; import com.minelittlepony.pony.IPonyData;
import net.minecraft.client.model.ModelPart; import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.entity.model.SkullOverlayEntityModel; import net.minecraft.client.render.entity.model.SkullOverlayEntityModel;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
public class ModelPonyHead extends SkullOverlayEntityModel implements ICapitated<ModelPart> { public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel, ICapitated<ModelPart> {
private PonySnout snout; private PonySnout snout;
@ -21,6 +23,14 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements ICapitated
public IPonyData metadata = new PonyData(); public IPonyData metadata = new PonyData();
@Override
public void init(ModelContext context) {
context.findByName("head", skull);
snout = context.findByName("snout");
horn = context.findByName("horn");
ears = context.findByName("ears");
}
@Override @Override
public ModelPart getHead() { public ModelPart getHead() {
return skull; return skull;

View file

@ -61,6 +61,7 @@ public final class ModelType {
public static final ModelKey<ModelBreezie<VexEntity>> BREEZIE = register("breezie", ModelBreezie::new); public static final ModelKey<ModelBreezie<VexEntity>> BREEZIE = register("breezie", ModelBreezie::new);
public static final ModelKey<PonyElytra<?>> ELYTRA = register("elytra", PonyElytra::new); public static final ModelKey<PonyElytra<?>> ELYTRA = register("elytra", PonyElytra::new);
public static final ModelKey<ModelPonyHead> SKULL = register("skull", ModelPonyHead::new);
public static final ModelKey<ModelPonyArmour<?>> ARMOUR_INNER = register("armour_inner", ModelPonyArmour::new); public static final ModelKey<ModelPonyArmour<?>> ARMOUR_INNER = register("armour_inner", ModelPonyArmour::new);
public static final ModelKey<ModelPonyArmour<?>> ARMOUR_OUTER = register("armour_outer", ModelPonyArmour::new); public static final ModelKey<ModelPonyArmour<?>> ARMOUR_OUTER = register("armour_outer", ModelPonyArmour::new);

View file

@ -3,15 +3,10 @@ package com.minelittlepony.client.model.part;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.model.ModelPart; import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.VertexConsumerProvider.Immediate; import net.minecraft.client.render.VertexConsumerProvider.Immediate;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import org.lwjgl.opengl.GL11;
import com.minelittlepony.client.render.MagicGlow; import com.minelittlepony.client.render.MagicGlow;
import com.minelittlepony.model.IPart; import com.minelittlepony.model.IPart;
import com.minelittlepony.mson.api.ModelContext; import com.minelittlepony.mson.api.ModelContext;

View file

@ -0,0 +1,29 @@
package com.minelittlepony.client.render.blockentity.skull;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import com.minelittlepony.client.model.ModelPonyHead;
import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull;
import com.minelittlepony.pony.IPony;
public abstract class AbstractPonySkull implements ISkull {
private ModelPonyHead ponyHead = ModelType.SKULL.createModel();
@Override
public void setAngles(float angle, float poweredTicks) {
ponyHead.render(poweredTicks, angle, 0);
}
@Override
public void bindPony(IPony pony) {
ponyHead.metadata = pony.getMetadata();
}
@Override
public void render(MatrixStack stack, VertexConsumer vertices, int lightUv, int overlayUv, float red, float green, float blue, float alpha) {
ponyHead.render(stack, vertices, lightUv, overlayUv, red, green, blue, alpha);
}
}

View file

@ -1,22 +1,29 @@
package com.minelittlepony.client.render.blockentity.skull; package com.minelittlepony.client.render.blockentity.skull;
import com.minelittlepony.client.render.entity.MobRenderers; import com.minelittlepony.client.render.entity.MobRenderers;
import com.minelittlepony.client.render.entity.RenderPonyZombie;
import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ZombieSkullRenderer extends PonySkull { public class MobSkull extends AbstractPonySkull {
private final Identifier texture;
private final MobRenderers type;
MobSkull(Identifier texture, MobRenderers type) {
this.texture = texture;
this.type = type;
}
@Override @Override
public boolean canRender(PonyConfig config) { public boolean canRender(PonyConfig config) {
return MobRenderers.ZOMBIES.get(); return type.get();
} }
@Override @Override
public Identifier getSkinResource(@Nullable GameProfile profile) { public Identifier getSkinResource(@Nullable GameProfile profile) {
return RenderPonyZombie.ZOMBIE; return texture;
} }
} }

View file

@ -1,48 +0,0 @@
package com.minelittlepony.client.render.blockentity.skull;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.model.ModelDeadMau5Ears;
import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import javax.annotation.Nullable;
public class PlayerSkullRenderer extends PonySkull {
private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears();
@Override
public boolean canRender(PonyConfig config) {
return config.ponyLevel.get() != PonyLevel.HUMANS;
}
@Override
public Identifier getSkinResource(@Nullable GameProfile profile) {
deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName()));
if (profile != null) {
Identifier skin = SkinsProxy.instance.getSkinTexture(profile);
if (skin != null) {
return skin;
}
return DefaultSkinHelper.getTexture(PlayerEntity.getUuidFromProfile(profile));
}
return DefaultSkinHelper.getTexture();
}
@Override
public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) {
super.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
deadMau5.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
}
}

View file

@ -1,28 +1,48 @@
package com.minelittlepony.client.render.blockentity.skull; package com.minelittlepony.client.render.blockentity.skull;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.model.ModelDeadMau5Ears;
import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import com.minelittlepony.client.model.ModelPonyHead; import javax.annotation.Nullable;
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull;
import com.minelittlepony.pony.IPony;
public abstract class PonySkull implements ISkull { public class PonySkull extends AbstractPonySkull {
private static ModelPonyHead ponyHead = new ModelPonyHead(); private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears();
@Override @Override
public void preRender(boolean transparency) { public boolean canRender(PonyConfig config) {
return config.ponyLevel.get() != PonyLevel.HUMANS;
} }
@Override @Override
public void bindPony(IPony pony) { public Identifier getSkinResource(@Nullable GameProfile profile) {
ponyHead.metadata = pony.getMetadata(); deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName()));
if (profile != null) {
Identifier skin = SkinsProxy.instance.getSkinTexture(profile);
if (skin != null) {
return skin;
}
return DefaultSkinHelper.getTexture(PlayerEntity.getUuidFromProfile(profile));
}
return DefaultSkinHelper.getTexture();
} }
@Override @Override
public void render(MatrixStack stack, VertexConsumer vertices, int lightUv, int overlayUv, 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) {
ponyHead.render(stack, vertices, lightUv, overlayUv, red, green, blue, alpha); super.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
deadMau5.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
} }
} }

View file

@ -2,12 +2,14 @@ package com.minelittlepony.client.render.blockentity.skull;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.LevitatingItemRenderer; import com.minelittlepony.client.render.entity.MobRenderers;
import com.minelittlepony.client.render.entity.RenderPonySkeleton;
import com.minelittlepony.client.render.entity.RenderPonyZombie;
import com.minelittlepony.mson.api.Mson;
import com.minelittlepony.pony.IPony; 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.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
import net.minecraft.block.AbstractSkullBlock; import net.minecraft.block.AbstractSkullBlock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SkullBlock; import net.minecraft.block.SkullBlock;
@ -33,25 +35,23 @@ import javax.annotation.Nullable;
*/ */
public class PonySkullRenderer extends SkullBlockEntityRenderer { public class PonySkullRenderer extends SkullBlockEntityRenderer {
private static final Map<SkullBlock.SkullType, ISkull> skullMap = Util.create(Maps.newHashMap(), (skullMap) -> {
skullMap.put(SkullBlock.Type.SKELETON, new SkeletonSkullRenderer());
skullMap.put(SkullBlock.Type.WITHER_SKELETON, new WitherSkullRenderer());
skullMap.put(SkullBlock.Type.ZOMBIE, new ZombieSkullRenderer());
skullMap.put(SkullBlock.Type.PLAYER, new PlayerSkullRenderer());
});
/** /**
* Resolves the games skull renderer to either a special pony skull renderer * Resolves the games skull renderer to either a special pony skull renderer
* or some other skull renderer depending on the ponyskull's state. * or some other skull renderer depending on the ponyskull's state.
*/ */
public static void resolve(boolean ponySkulls) { public static void resolve(boolean ponySkulls) {
if (ponySkulls) { Mson.getInstance().getEntityRendererRegistry().registerBlockRenderer(BlockEntityType.SKULL,
BlockEntityRendererRegistry.INSTANCE.register(BlockEntityType.SKULL, new PonySkullRenderer(BlockEntityRenderDispatcher.INSTANCE)); ponySkulls ? PonySkullRenderer::new : SkullBlockEntityRenderer::new
} else { );
BlockEntityRendererRegistry.INSTANCE.register(BlockEntityType.SKULL, new SkullBlockEntityRenderer(BlockEntityRenderDispatcher.INSTANCE));
}
} }
private final Map<SkullBlock.SkullType, ISkull> skullMap = Util.create(Maps.newHashMap(), (skullMap) -> {
skullMap.put(SkullBlock.Type.SKELETON, new MobSkull(RenderPonySkeleton.SKELETON, MobRenderers.SKELETONS));
skullMap.put(SkullBlock.Type.WITHER_SKELETON, new MobSkull(RenderPonySkeleton.WITHER, MobRenderers.SKELETONS));
skullMap.put(SkullBlock.Type.ZOMBIE, new MobSkull(RenderPonyZombie.ZOMBIE, MobRenderers.ZOMBIES));
skullMap.put(SkullBlock.Type.PLAYER, new PonySkull());
});
public PonySkullRenderer(BlockEntityRenderDispatcher dispatcher) { public PonySkullRenderer(BlockEntityRenderDispatcher dispatcher) {
super(dispatcher); super(dispatcher);
} }
@ -65,16 +65,16 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer {
Direction direction = onWalll ? (Direction)state.get(WallSkullBlock.FACING) : null; Direction direction = onWalll ? (Direction)state.get(WallSkullBlock.FACING) : null;
float angle = 22.5F * (direction != null ? (2 + direction.getHorizontal()) * 4F : (Integer)state.get(SkullBlock.ROTATION)); float angle = 22.5F * (float)(direction != null ? (2 + direction.getHorizontal()) * 4F : state.get(SkullBlock.ROTATION));
render(direction, renderSkull(direction,
angle, angle,
((AbstractSkullBlock)state.getBlock()).getSkullType(), ((AbstractSkullBlock)state.getBlock()).getSkullType(),
skullBlockEntity.getOwner(), poweredTicks, skullBlockEntity.getOwner(), poweredTicks,
matrixStack, vertexConsumerProvider, i); matrixStack, vertexConsumerProvider, i);
} }
public static void render(@Nullable Direction direction, float angle, public void 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) {
@ -95,11 +95,10 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer {
handleRotation(stack, direction); handleRotation(stack, direction);
stack.scale(-1, -1, 1); stack.scale(-1, -1, 1);
skull.preRender(LevitatingItemRenderer.usesTransparency());
VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getEntityTranslucent(skin)); VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getEntityTranslucent(skin));
skull.setAngles(angle, poweredTicks);
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();
@ -135,7 +134,7 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer {
*/ */
public interface ISkull { public interface ISkull {
void preRender(boolean transparency); void setAngles(float angle, float poweredTicks);
void render(MatrixStack stack, VertexConsumer vertices, int lightUv, int overlayUv, float red, float green, float blue, float alpha); void render(MatrixStack stack, VertexConsumer vertices, int lightUv, int overlayUv, float red, float green, float blue, float alpha);

View file

@ -1,22 +0,0 @@
package com.minelittlepony.client.render.blockentity.skull;
import com.minelittlepony.client.render.entity.MobRenderers;
import com.minelittlepony.client.render.entity.RenderPonySkeleton;
import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile;
import net.minecraft.util.Identifier;
import javax.annotation.Nullable;
public class SkeletonSkullRenderer extends PonySkull {
@Override
public boolean canRender(PonyConfig config) {
return MobRenderers.SKELETONS.get();
}
@Override
public Identifier getSkinResource(@Nullable GameProfile profile) {
return RenderPonySkeleton.SKELETON;
}
}

View file

@ -1,22 +0,0 @@
package com.minelittlepony.client.render.blockentity.skull;
import com.minelittlepony.client.render.entity.MobRenderers;
import com.minelittlepony.client.render.entity.RenderPonySkeleton;
import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile;
import net.minecraft.util.Identifier;
import javax.annotation.Nullable;
public class WitherSkullRenderer extends PonySkull {
@Override
public boolean canRender(PonyConfig config) {
return MobRenderers.SKELETONS.get();
}
@Override
public Identifier getSkinResource(@Nullable GameProfile profile) {
return RenderPonySkeleton.WITHER;
}
}

View file

@ -1,13 +1,20 @@
{ {
"texture": {"w": 64, "h": 64}, "texture": {"w": 64, "h": 64},
"locals": {
"x": 0,
"y": 0,
"z": 0
},
"right": { "right": {
"texture": {"u": 12, "v": 16}, "texture": {"u": 12, "v": 16},
"offset": ["#x", "#y", "#z"],
"cubes": [ "cubes": [
{ "from": [-4, -6, -1], "size": [2, 2, 2] } { "from": [-4, -6, -1], "size": [2, 2, 2] }
] ]
}, },
"left": { "left": {
"texture": {"u": 12, "v": 16}, "texture": {"u": 12, "v": 16},
"offset": ["#x", "#y", "#z"],
"cubes": [ "cubes": [
{ "from": [2, -6, -1], "size": [2, 2, 2] } { "from": [2, -6, -1], "size": [2, 2, 2] }
] ]

View file

@ -1,30 +1,32 @@
{ {
"texture": {"w": 64, "h": 64, "u": 0, "v": 3}, "texture": {"w": 64, "h": 64, "u": 0, "v": 3},
"locals": { "locals": {
"horn_x": -0.5, "x": 0,
"horn_y": -11, "y": 0,
"horn_z": -3.5 "z": 0
}, },
"bone": { "bone": {
"offset": ["#horn_x", "#horn_y", "#horn_z"], "offset": ["#x", "#y", "#z"],
"rotate": [29, 0, 0], "rotate": [29, 0, 0],
"cubes": [ "cubes": [
{ "size": [1, 4, 1] } { "from": [-0.5, -11, -3.5], "size": [1, 4, 1] }
] ]
}, },
"corona": { "corona": {
"offset": ["#horn_x", "#horn_y", "#horn_z"], "offset": ["#x", "#y", "#z"],
"rotate": [29, 0, 0], "rotate": [29, 0, 0],
"cubes": [ "cubes": [
{ {
"type": "mson:cone", "type": "mson:cone",
"size": [1, 4, 1], "size": [1, 4, 1],
"from": [-0.5, -11, -3.5],
"stretch": 0.5, "stretch": 0.5,
"taper": 0.4 "taper": 0.4
}, },
{ {
"type": "mson:cone", "type": "mson:cone",
"size": [1, 3, 1], "size": [1, 3, 1],
"from": [-0.5, -11, -3.5],
"stretch": 0.8, "stretch": 0.8,
"taper": 0.4 "taper": 0.4
} }

View file

@ -1,8 +1,13 @@
{ {
"texture": {"w": 64, "h": 64, "u": 16, "v": 8}, "texture": {"w": 64, "h": 64, "u": 16, "v": 8},
"locals": {
"x": 0,
"y": 0,
"z": 0
},
"stallion": { "stallion": {
"type": "mson:planar", "type": "mson:planar",
"offset": [0, -1, -2], "offset": ["#x", "#y", "#z"],
"south": [-2, 1, -5, 4, 3, 10, 13], "south": [-2, 1, -5, 4, 3, 10, 13],
"up": [-2, 1, -5, 4, 1, 10, 13], "up": [-2, 1, -5, 4, 1, 10, 13],
"down": [-2, 4, -5, 4, 1, 18, 7], "down": [-2, 4, -5, 4, 1, 18, 7],
@ -11,7 +16,7 @@
}, },
"mare": { "mare": {
"type": "mson:planar", "type": "mson:planar",
"offset": [0, -1, -1.75], "offset": ["#x", "#y", "#z"],
"south": [ "south": [
[-2, 2, -5, 4, 2, 10, 14], [-2, 2, -5, 4, 2, 10, 14],
[-1, 1, -5, 2, 1, 11, 13] [-1, 1, -5, 2, 1, 11, 13]

View file

@ -1,5 +1,5 @@
{ {
"texture": {"u": 32, "w": 64, "h": 64}, "texture": {"w": 64, "h": 64},
"locals": { "locals": {
"snout_x": -3, "snout_x": -3,
"snout_z": 2, "snout_z": 2,
@ -14,18 +14,33 @@
{ {
"type": "mson:slot", "type": "mson:slot",
"name": "snout", "name": "snout",
"locals": {
"x": 0,
"y": -4,
"z": 0
},
"implementation": "com.minelittlepony.client.model.part.PonySnout", "implementation": "com.minelittlepony.client.model.part.PonySnout",
"content": "minelittlepony:components/snout" "content": "minelittlepony:components/snout"
}, },
{ {
"type": "mson:slot", "type": "mson:slot",
"name": "ears", "name": "ears",
"locals": {
"x": 0,
"y": -4,
"z": 2
},
"implementation": "com.minelittlepony.client.model.part.PonyEars", "implementation": "com.minelittlepony.client.model.part.PonyEars",
"content": "minelittlepony:components/ears" "content": "minelittlepony:components/ears"
}, },
{ {
"type": "mson:slot", "type": "mson:slot",
"name": "horn", "name": "horn",
"locals": {
"x": 0,
"y": -1,
"z": 3
},
"implementation": "com.minelittlepony.client.model.part.UnicornHorn", "implementation": "com.minelittlepony.client.model.part.UnicornHorn",
"content": "minelittlepony:components/horn" "content": "minelittlepony:components/horn"
} }