diff --git a/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java b/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java index 5478cd77..7e6cc605 100644 --- a/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java +++ b/src/main/java/com/minelittlepony/client/model/ModelPonyHead.java @@ -5,13 +5,15 @@ import com.minelittlepony.client.model.part.PonySnout; import com.minelittlepony.client.model.part.UnicornHorn; import com.minelittlepony.client.pony.PonyData; import com.minelittlepony.model.ICapitated; +import com.minelittlepony.mson.api.ModelContext; +import com.minelittlepony.mson.api.MsonModel; import com.minelittlepony.pony.IPonyData; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.entity.model.SkullOverlayEntityModel; import net.minecraft.client.util.math.MatrixStack; -public class ModelPonyHead extends SkullOverlayEntityModel implements ICapitated { +public class ModelPonyHead extends SkullOverlayEntityModel implements MsonModel, ICapitated { private PonySnout snout; @@ -21,6 +23,14 @@ public class ModelPonyHead extends SkullOverlayEntityModel implements ICapitated 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 public ModelPart getHead() { return skull; diff --git a/src/main/java/com/minelittlepony/client/model/ModelType.java b/src/main/java/com/minelittlepony/client/model/ModelType.java index d566ff80..6771588c 100644 --- a/src/main/java/com/minelittlepony/client/model/ModelType.java +++ b/src/main/java/com/minelittlepony/client/model/ModelType.java @@ -61,6 +61,7 @@ public final class ModelType { public static final ModelKey> BREEZIE = register("breezie", ModelBreezie::new); public static final ModelKey> ELYTRA = register("elytra", PonyElytra::new); + public static final ModelKey SKULL = register("skull", ModelPonyHead::new); public static final ModelKey> ARMOUR_INNER = register("armour_inner", ModelPonyArmour::new); public static final ModelKey> ARMOUR_OUTER = register("armour_outer", ModelPonyArmour::new); diff --git a/src/main/java/com/minelittlepony/client/model/part/UnicornHorn.java b/src/main/java/com/minelittlepony/client/model/part/UnicornHorn.java index 089dca3c..46a7f72b 100644 --- a/src/main/java/com/minelittlepony/client/model/part/UnicornHorn.java +++ b/src/main/java/com/minelittlepony/client/model/part/UnicornHorn.java @@ -3,15 +3,10 @@ package com.minelittlepony.client.model.part; import net.minecraft.client.MinecraftClient; import net.minecraft.client.model.ModelPart; 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.VertexFormats; import net.minecraft.client.render.VertexConsumerProvider.Immediate; import net.minecraft.client.util.math.MatrixStack; -import org.lwjgl.opengl.GL11; - import com.minelittlepony.client.render.MagicGlow; import com.minelittlepony.model.IPart; import com.minelittlepony.mson.api.ModelContext; diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/AbstractPonySkull.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/AbstractPonySkull.java new file mode 100644 index 00000000..39594ce5 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/AbstractPonySkull.java @@ -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); + } +} diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/ZombieSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java similarity index 60% rename from src/main/java/com/minelittlepony/client/render/blockentity/skull/ZombieSkullRenderer.java rename to src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java index abe2b826..08e211ea 100644 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/ZombieSkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java @@ -1,22 +1,29 @@ package com.minelittlepony.client.render.blockentity.skull; import com.minelittlepony.client.render.entity.MobRenderers; -import com.minelittlepony.client.render.entity.RenderPonyZombie; import com.minelittlepony.settings.PonyConfig; import com.mojang.authlib.GameProfile; import net.minecraft.util.Identifier; 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 public boolean canRender(PonyConfig config) { - return MobRenderers.ZOMBIES.get(); + return type.get(); } @Override public Identifier getSkinResource(@Nullable GameProfile profile) { - return RenderPonyZombie.ZOMBIE; + return texture; } } diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerSkullRenderer.java deleted file mode 100644 index ad3e065d..00000000 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerSkullRenderer.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkull.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkull.java index 36e78335..b5a5028e 100644 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkull.java +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkull.java @@ -1,28 +1,48 @@ 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 com.minelittlepony.client.model.ModelPonyHead; -import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull; -import com.minelittlepony.pony.IPony; +import javax.annotation.Nullable; -public abstract class PonySkull implements ISkull { +public class PonySkull extends AbstractPonySkull { - private static ModelPonyHead ponyHead = new ModelPonyHead(); + private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears(); @Override - public void preRender(boolean transparency) { - + public boolean canRender(PonyConfig config) { + return config.ponyLevel.get() != PonyLevel.HUMANS; } @Override - public void bindPony(IPony pony) { - ponyHead.metadata = pony.getMetadata(); + 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 lightUv, int overlayUv, float red, float green, float blue, float alpha) { - ponyHead.render(stack, vertices, lightUv, overlayUv, red, green, blue, alpha); + 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); } -} \ No newline at end of file +} 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 6ce24f97..ba48a5ed 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 @@ -2,12 +2,14 @@ package com.minelittlepony.client.render.blockentity.skull; import com.google.common.collect.Maps; 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.settings.PonyConfig; import com.mojang.authlib.GameProfile; -import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry; import net.minecraft.block.AbstractSkullBlock; import net.minecraft.block.BlockState; import net.minecraft.block.SkullBlock; @@ -33,25 +35,23 @@ import javax.annotation.Nullable; */ public class PonySkullRenderer extends SkullBlockEntityRenderer { - private static final Map 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 * or some other skull renderer depending on the ponyskull's state. */ public static void resolve(boolean ponySkulls) { - if (ponySkulls) { - BlockEntityRendererRegistry.INSTANCE.register(BlockEntityType.SKULL, new PonySkullRenderer(BlockEntityRenderDispatcher.INSTANCE)); - } else { - BlockEntityRendererRegistry.INSTANCE.register(BlockEntityType.SKULL, new SkullBlockEntityRenderer(BlockEntityRenderDispatcher.INSTANCE)); - } + Mson.getInstance().getEntityRendererRegistry().registerBlockRenderer(BlockEntityType.SKULL, + ponySkulls ? PonySkullRenderer::new : SkullBlockEntityRenderer::new + ); } + private final Map 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) { super(dispatcher); } @@ -65,16 +65,16 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { 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, ((AbstractSkullBlock)state.getBlock()).getSkullType(), skullBlockEntity.getOwner(), poweredTicks, 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, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { @@ -95,11 +95,10 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { handleRotation(stack, direction); stack.scale(-1, -1, 1); - skull.preRender(LevitatingItemRenderer.usesTransparency()); - VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getEntityTranslucent(skin)); + skull.setAngles(angle, poweredTicks); skull.render(stack, vertices, lightUv, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); stack.pop(); @@ -135,7 +134,7 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { */ 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); diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/SkeletonSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/SkeletonSkullRenderer.java deleted file mode 100644 index 73aaca44..00000000 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/SkeletonSkullRenderer.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/WitherSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/WitherSkullRenderer.java deleted file mode 100644 index d1cf9a2b..00000000 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/WitherSkullRenderer.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/resources/assets/minelittlepony/models/components/ears.json b/src/main/resources/assets/minelittlepony/models/components/ears.json index 8f9e8718..8bd7a1ff 100644 --- a/src/main/resources/assets/minelittlepony/models/components/ears.json +++ b/src/main/resources/assets/minelittlepony/models/components/ears.json @@ -1,13 +1,20 @@ { "texture": {"w": 64, "h": 64}, + "locals": { + "x": 0, + "y": 0, + "z": 0 + }, "right": { "texture": {"u": 12, "v": 16}, + "offset": ["#x", "#y", "#z"], "cubes": [ { "from": [-4, -6, -1], "size": [2, 2, 2] } ] }, "left": { "texture": {"u": 12, "v": 16}, + "offset": ["#x", "#y", "#z"], "cubes": [ { "from": [2, -6, -1], "size": [2, 2, 2] } ] diff --git a/src/main/resources/assets/minelittlepony/models/components/horn.json b/src/main/resources/assets/minelittlepony/models/components/horn.json index ff6f9993..be388ad2 100644 --- a/src/main/resources/assets/minelittlepony/models/components/horn.json +++ b/src/main/resources/assets/minelittlepony/models/components/horn.json @@ -1,30 +1,32 @@ { "texture": {"w": 64, "h": 64, "u": 0, "v": 3}, "locals": { - "horn_x": -0.5, - "horn_y": -11, - "horn_z": -3.5 + "x": 0, + "y": 0, + "z": 0 }, "bone": { - "offset": ["#horn_x", "#horn_y", "#horn_z"], + "offset": ["#x", "#y", "#z"], "rotate": [29, 0, 0], "cubes": [ - { "size": [1, 4, 1] } + { "from": [-0.5, -11, -3.5], "size": [1, 4, 1] } ] }, "corona": { - "offset": ["#horn_x", "#horn_y", "#horn_z"], + "offset": ["#x", "#y", "#z"], "rotate": [29, 0, 0], "cubes": [ { "type": "mson:cone", "size": [1, 4, 1], + "from": [-0.5, -11, -3.5], "stretch": 0.5, "taper": 0.4 }, { "type": "mson:cone", "size": [1, 3, 1], + "from": [-0.5, -11, -3.5], "stretch": 0.8, "taper": 0.4 } diff --git a/src/main/resources/assets/minelittlepony/models/components/snout.json b/src/main/resources/assets/minelittlepony/models/components/snout.json index 1f528274..cc8e95ba 100644 --- a/src/main/resources/assets/minelittlepony/models/components/snout.json +++ b/src/main/resources/assets/minelittlepony/models/components/snout.json @@ -1,8 +1,13 @@ { "texture": {"w": 64, "h": 64, "u": 16, "v": 8}, + "locals": { + "x": 0, + "y": 0, + "z": 0 + }, "stallion": { "type": "mson:planar", - "offset": [0, -1, -2], + "offset": ["#x", "#y", "#z"], "south": [-2, 1, -5, 4, 3, 10, 13], "up": [-2, 1, -5, 4, 1, 10, 13], "down": [-2, 4, -5, 4, 1, 18, 7], @@ -11,7 +16,7 @@ }, "mare": { "type": "mson:planar", - "offset": [0, -1, -1.75], + "offset": ["#x", "#y", "#z"], "south": [ [-2, 2, -5, 4, 2, 10, 14], [-1, 1, -5, 2, 1, 11, 13] diff --git a/src/main/resources/assets/minelittlepony/models/head.json b/src/main/resources/assets/minelittlepony/models/skull.json similarity index 76% rename from src/main/resources/assets/minelittlepony/models/head.json rename to src/main/resources/assets/minelittlepony/models/skull.json index 13510dff..4a5d851c 100644 --- a/src/main/resources/assets/minelittlepony/models/head.json +++ b/src/main/resources/assets/minelittlepony/models/skull.json @@ -1,5 +1,5 @@ { - "texture": {"u": 32, "w": 64, "h": 64}, + "texture": {"w": 64, "h": 64}, "locals": { "snout_x": -3, "snout_z": 2, @@ -14,18 +14,33 @@ { "type": "mson:slot", "name": "snout", + "locals": { + "x": 0, + "y": -4, + "z": 0 + }, "implementation": "com.minelittlepony.client.model.part.PonySnout", "content": "minelittlepony:components/snout" }, { "type": "mson:slot", "name": "ears", + "locals": { + "x": 0, + "y": -4, + "z": 2 + }, "implementation": "com.minelittlepony.client.model.part.PonyEars", "content": "minelittlepony:components/ears" }, { "type": "mson:slot", "name": "horn", + "locals": { + "x": 0, + "y": -1, + "z": 3 + }, "implementation": "com.minelittlepony.client.model.part.UnicornHorn", "content": "minelittlepony:components/horn" }