diff --git a/src/main/java/com/minelittlepony/client/render/MobRenderers.java b/src/main/java/com/minelittlepony/client/render/MobRenderers.java index 4e96fa2d..ec7ded80 100644 --- a/src/main/java/com/minelittlepony/client/render/MobRenderers.java +++ b/src/main/java/com/minelittlepony/client/render/MobRenderers.java @@ -25,33 +25,33 @@ public final class MobRenderers { }); public static final MobRenderers ILLAGER = register("illagers", (state, pony) -> { pony.switchRenderer(state, EntityType.VEX, VexRenderer::new); - pony.switchRenderer(state, EntityType.EVOKER, IllagerPonyRenderer.Evoker::new); - pony.switchRenderer(state, EntityType.VINDICATOR, IllagerPonyRenderer.Vindicator::new); + pony.switchRenderer(state, EntityType.EVOKER, IllagerPonyRenderer::evoker); + pony.switchRenderer(state, EntityType.VINDICATOR, IllagerPonyRenderer::vindicator); pony.switchRenderer(state, EntityType.ILLUSIONER, IllagerPonyRenderer.Illusionist::new); pony.switchRenderer(state, EntityType.PILLAGER, PillagerRenderer::new); }); public static final MobRenderers ZOMBIE = register("zombies", (state, pony) -> { - pony.switchRenderer(state, EntityType.ZOMBIE, ZomponyRenderer::new); - pony.switchRenderer(state, EntityType.HUSK, ZomponyRenderer.Husk::new); - pony.switchRenderer(state, EntityType.GIANT, ZomponyRenderer.Giant::new); - pony.switchRenderer(state, EntityType.DROWNED, ZomponyRenderer.Drowned::new); + pony.switchRenderer(state, EntityType.ZOMBIE, ZomponyRenderer::zombie); + pony.switchRenderer(state, EntityType.HUSK, ZomponyRenderer::husk); + pony.switchRenderer(state, EntityType.GIANT, ZomponyRenderer::giant); + pony.switchRenderer(state, EntityType.DROWNED, ZomponyRenderer::drowned); }); public static final MobRenderers PIGLIN = register("pigzombies", (state, pony) -> { - pony.switchRenderer(state, EntityType.PIGLIN, PonyPiglinRenderer::new); - pony.switchRenderer(state, EntityType.PIGLIN_BRUTE, PonyPiglinRenderer::new); - pony.switchRenderer(state, EntityType.ZOMBIFIED_PIGLIN, PonyPiglinRenderer::new); + pony.switchRenderer(state, EntityType.PIGLIN, PonyPiglinRenderer::piglin); + pony.switchRenderer(state, EntityType.PIGLIN_BRUTE, PonyPiglinRenderer::brute); + pony.switchRenderer(state, EntityType.ZOMBIFIED_PIGLIN, PonyPiglinRenderer::zombified); if (!MineLittlePony.getInstance().getConfig().noFun.get()) { pony.switchRenderer(state, EntityType.PIG, PonyPigRenderer::new); } }); public static final MobRenderers SKELETON = register("skeletons", (state, pony) -> { - pony.switchRenderer(state, EntityType.SKELETON, SkeleponyRenderer::new); - pony.switchRenderer(state, EntityType.STRAY, SkeleponyRenderer.Stray::new); - pony.switchRenderer(state, EntityType.WITHER_SKELETON, SkeleponyRenderer.Wither::new); + pony.switchRenderer(state, EntityType.SKELETON, SkeleponyRenderer::skeleton); + pony.switchRenderer(state, EntityType.STRAY, SkeleponyRenderer::stray); + pony.switchRenderer(state, EntityType.WITHER_SKELETON, SkeleponyRenderer::wither); }); public static final MobRenderers GUARDIAN = register("guardians", (state, pony) -> { - pony.switchRenderer(state, EntityType.GUARDIAN, SeaponyRenderer::new); - pony.switchRenderer(state, EntityType.ELDER_GUARDIAN, SeaponyRenderer.Elder::new); + pony.switchRenderer(state, EntityType.GUARDIAN, SeaponyRenderer::guardian); + pony.switchRenderer(state, EntityType.ELDER_GUARDIAN, SeaponyRenderer::elder); }); public static final MobRenderers ENDERMAN = register("endermen", (state, pony) -> { pony.switchRenderer(state, EntityType.ENDERMAN, EnderStallionRenderer::new); diff --git a/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java new file mode 100644 index 00000000..2a73f14e --- /dev/null +++ b/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java @@ -0,0 +1,167 @@ +package com.minelittlepony.client.render.entity; + +import com.minelittlepony.api.pony.IPony; +import com.minelittlepony.api.pony.meta.Wearable; +import com.minelittlepony.client.model.*; +import com.minelittlepony.client.render.DebugBoundingBoxRenderer; +import com.minelittlepony.client.render.IPonyRenderContext; +import com.minelittlepony.client.render.EquineRenderManager; +import com.minelittlepony.client.render.entity.feature.*; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; +import com.minelittlepony.mson.api.ModelKey; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.Function; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.Frustum; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.MobEntityRenderer; +import net.minecraft.client.render.entity.feature.FeatureRenderer; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.render.entity.model.PlayerEntityModel; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public abstract class AbstractPonyRenderer & IPonyModel> extends MobEntityRenderer implements IPonyRenderContext { + + protected final EquineRenderManager manager = new EquineRenderManager<>(this); + + private final Map wearableTextures = new EnumMap<>(Wearable.class); + + private final TextureSupplier texture; + + private final float scale; + + public AbstractPonyRenderer(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture, float scale) { + super(context, null, 0.5F); + this.model = manager.setModel(key).body(); + this.texture = texture; + this.scale = scale; + addFeatures(context); + } + + protected void addFeatures(EntityRendererFactory.Context context) { + addFeature(new ArmourFeature<>(this, context.getModelManager())); + addFeature(createHeldItemFeature(context)); + addFeature(new SkullFeature<>(this, context.getModelLoader())); + addFeature(new ElytraFeature<>(this)); + addFeature(new GearFeature<>(this)); + } + + protected HeldItemFeature createHeldItemFeature(EntityRendererFactory.Context context) { + return new GlowingItemFeature<>(this); + } + + @Override + public final Identifier getTexture(T entity) { + return texture.apply(entity); + } + + @Override + public void render(T entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { + super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv); + DebugBoundingBoxRenderer.render(manager.getPony(entity), this, entity, stack, renderContext, tickDelta); + } + + @Override + protected void setupTransforms(T entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks) { + manager.preRenderCallback(entity, stack, partialTicks); + if (getModel() instanceof PlayerEntityModel) { + ((PlayerEntityModel)getModel()).setVisible(true); + } + + if (getModel().getAttributes().isSitting) { + stack.translate(0, 0.125D, 0); + } + + rotationYaw = manager.getRenderYaw(entity, rotationYaw, partialTicks); + super.setupTransforms(entity, stack, ageInTicks, rotationYaw, partialTicks); + + manager.applyPostureTransform(entity, stack, rotationYaw, partialTicks); + } + + @Override + public boolean shouldRender(T entity, Frustum visibleRegion, double camX, double camY, double camZ) { + return super.shouldRender(entity, manager.getFrustrum(entity, visibleRegion), camX, camY, camZ); + } + + @Override + public void scale(T entity, MatrixStack stack, float tickDelta) { + shadowRadius = manager.getShadowScale(); + + if (entity.isBaby()) { + shadowRadius *= 3; // undo vanilla shadow scaling + } + + if (!entity.hasVehicle()) { + stack.translate(0, 0, -entity.getWidth() / 2); // move us to the center of the shadow + } else { + stack.translate(0, entity.getHeightOffset(), 0); + } + + stack.scale(scale, scale, scale); + } + + @Override + public ModelWrapper getModelWrapper() { + return manager.playerModel; + } + + @Override + protected void renderLabelIfPresent(T entity, Text name, MatrixStack stack, VertexConsumerProvider renderContext, int maxDistance) { + stack.push(); + stack.translate(0, manager.getNamePlateYOffset(entity), 0); + super.renderLabelIfPresent(entity, name, stack, renderContext, maxDistance); + stack.pop(); + } + + @Override + public Identifier getDefaultTexture(T entity, Wearable wearable) { + return wearableTextures.computeIfAbsent(wearable, w -> { + Identifier texture = getTexture(entity); + texture = new Identifier(texture.getNamespace(), texture.getPath().split("\\.")[0] + "_" + wearable.name().toLowerCase(Locale.ROOT) + ".png"); + + if (MinecraftClient.getInstance().getResourceManager().getResource(texture).isPresent()) { + return texture; + } + return wearable.getDefaultTexture(); + }); + } + + @Override + public EquineRenderManager getInternalRenderer() { + return manager; + } + + @Override + public IPony getEntityPony(T entity) { + return IPony.getManager().getPony(getTexture(entity)); + } + + public static , T extends PonyRenderer, F extends FeatureRenderer> + T appendFeature(T renderer, Function featureFactory) { + renderer.addFeature(featureFactory.apply(renderer)); + return renderer; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static & IPonyModel> AbstractPonyRenderer proxy(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture, float scale, + List exportedLayers, Consumer modelConsumer) { + var renderer = new AbstractPonyRenderer(context, key, texture, scale) { + @Override + protected void addFeatures(EntityRendererFactory.Context context) { + features.clear(); + super.addFeatures(context); + } + }; + exportedLayers.clear(); + exportedLayers.addAll(renderer.features); + modelConsumer.accept(renderer.getModel()); + return renderer; + } +} diff --git a/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java index df0d4fd5..b830bd43 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java @@ -4,6 +4,7 @@ import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.EnderStallionModel; import com.minelittlepony.client.render.entity.feature.GlowingEyesFeature; import com.minelittlepony.client.render.entity.feature.HeldItemFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import com.minelittlepony.client.render.entity.feature.GlowingItemFeature; import com.minelittlepony.client.render.entity.feature.GlowingEyesFeature.IGlowingRenderer; @@ -26,18 +27,18 @@ public class EnderStallionRenderer extends PonyRenderer(context, this)); addFeature(new GlowingEyesFeature<>(this)); } @Override - protected HeldItemFeature createItemHoldingLayer() { + protected HeldItemFeature createHeldItemFeature(EntityRendererFactory.Context context) { return new GlowingItemFeature(this) { @Override protected ItemStack getRightItem(EndermanEntity entity) { @@ -51,17 +52,10 @@ public class EnderStallionRenderer extends PonyRenderer(this)); + addLayer(new ArmourFeature<>(this, context.getModelManager())); addLayer(new GlowingItemFeature<>(this)); addLayer(new DJPon3Feature<>(this)); addLayer(new CapeFeature<>(this)); diff --git a/src/main/java/com/minelittlepony/client/render/entity/PonyPiglinRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PonyPiglinRenderer.java index 7ba5bd34..cfce8abb 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PonyPiglinRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PonyPiglinRenderer.java @@ -1,42 +1,33 @@ package com.minelittlepony.client.render.entity; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.EntityType; import net.minecraft.entity.mob.AbstractPiglinEntity; import net.minecraft.entity.mob.HostileEntity; import net.minecraft.util.Identifier; -import net.minecraft.util.Util; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.PiglinPonyModel; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; -import java.util.HashMap; -import java.util.Map; +public class PonyPiglinRenderer extends PonyRenderer { + private static final Identifier PIGLIN = new Identifier("minelittlepony", "textures/entity/piglin/piglin_pony.png"); + private static final Identifier PIGLIN_BRUTE = new Identifier("minelittlepony", "textures/entity/piglin/piglin_brute_pony.png"); + private static final Identifier ZOMBIFIED_PIGLIN = new Identifier("minelittlepony", "textures/entity/piglin/zombified_piglin_pony.png"); -public class PonyPiglinRenderer extends PonyRenderer.Caster { - - private static final Map, Identifier> TEXTURES = Util.make(new HashMap<>(), map -> { - map.put(EntityType.PIGLIN, new Identifier("minelittlepony", "textures/entity/piglin/piglin_pony.png")); - map.put(EntityType.PIGLIN_BRUTE, new Identifier("minelittlepony", "textures/entity/piglin/piglin_brute_pony.png")); - map.put(EntityType.ZOMBIFIED_PIGLIN, new Identifier("minelittlepony", "textures/entity/piglin/zombified_piglin_pony.png")); - }); - - public PonyPiglinRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.PIGLIN); + public PonyPiglinRenderer(EntityRendererFactory.Context context, Identifier texture, float scale) { + super(context, ModelType.PIGLIN, TextureSupplier.of(texture), scale); } - @Override - public void scale(HostileEntity entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - if (entity.getType() == EntityType.PIGLIN_BRUTE) { - stack.scale(1.15F, 1.15F, 1.15F); - } + public static PonyPiglinRenderer piglin(EntityRendererFactory.Context context) { + return new PonyPiglinRenderer(context, PIGLIN, 1); } - @Override - public Identifier getTexture(HostileEntity entity) { - return TEXTURES.get(entity.getType()); + public static PonyPiglinRenderer brute(EntityRendererFactory.Context context) { + return new PonyPiglinRenderer(context, PIGLIN_BRUTE, 1.15F); + } + + public static PonyPiglinRenderer zombified(EntityRendererFactory.Context context) { + return new PonyPiglinRenderer(context, ZOMBIFIED_PIGLIN, 1); } @Override diff --git a/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java index add7c4e2..7398543d 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java @@ -1,162 +1,26 @@ package com.minelittlepony.client.render.entity; -import com.minelittlepony.api.pony.IPony; -import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.client.model.ClientPonyModel; -import com.minelittlepony.client.model.IPonyModel; -import com.minelittlepony.client.model.ModelWrapper; -import com.minelittlepony.client.render.DebugBoundingBoxRenderer; -import com.minelittlepony.client.render.IPonyRenderContext; -import com.minelittlepony.client.render.EquineRenderManager; -import com.minelittlepony.client.render.entity.feature.GearFeature; -import com.minelittlepony.client.render.entity.feature.HeldItemFeature; -import com.minelittlepony.client.render.entity.feature.GlowingItemFeature; -import com.minelittlepony.client.render.entity.feature.ArmourFeature; -import com.minelittlepony.client.render.entity.feature.SkullFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import com.minelittlepony.mson.api.ModelKey; -import com.minelittlepony.client.render.entity.feature.ElytraFeature; -import java.util.*; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.Frustum; -import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.entity.MobEntityRenderer; -import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.client.render.entity.model.PlayerEntityModel; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.render.entity.feature.StuckArrowsFeatureRenderer; import net.minecraft.entity.mob.MobEntity; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -public abstract class PonyRenderer & IPonyModel> extends MobEntityRenderer implements IPonyRenderContext { +public class PonyRenderer> extends AbstractPonyRenderer { - protected final EquineRenderManager manager = new EquineRenderManager<>(this); - - private final Map wearableTextures = new EnumMap<>(Wearable.class); - - public PonyRenderer(EntityRendererFactory.Context context, ModelKey key) { - super(context, null, 0.5F); - this.model = manager.setModel(key).body(); - addLayers(context); + public PonyRenderer(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture) { + this(context, key, texture, 1); } - protected void addLayers(EntityRendererFactory.Context context) { - addFeature(new ArmourFeature<>(this)); - addFeature(createItemHoldingLayer()); - //addFeature(new StuckArrowsFeatureRenderer<>(this)); - addFeature(new SkullFeature<>(this, context.getModelLoader())); - addFeature(new ElytraFeature<>(this)); - addFeature(new GearFeature<>(this)); - } - - protected abstract HeldItemFeature createItemHoldingLayer(); - - @Override - public void render(T entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { - super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv); - DebugBoundingBoxRenderer.render(manager.getPony(entity), this, entity, stack, renderContext, tickDelta); + public PonyRenderer(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture, float scale) { + super(context, key, texture, scale); } @Override - protected void setupTransforms(T entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks) { - manager.preRenderCallback(entity, stack, partialTicks); - if (getModel() instanceof PlayerEntityModel) { - ((PlayerEntityModel)getModel()).setVisible(true); - } - - if (getModel().getAttributes().isSitting) { - stack.translate(0, 0.125D, 0); - } - - rotationYaw = manager.getRenderYaw(entity, rotationYaw, partialTicks); - super.setupTransforms(entity, stack, ageInTicks, rotationYaw, partialTicks); - - manager.applyPostureTransform(entity, stack, rotationYaw, partialTicks); - } - - @Override - public boolean shouldRender(T entity, Frustum visibleRegion, double camX, double camY, double camZ) { - return super.shouldRender(entity, manager.getFrustrum(entity, visibleRegion), camX, camY, camZ); - } - - @Override - public void scale(T entity, MatrixStack stack, float tickDelta) { - shadowRadius = manager.getShadowScale(); - - if (entity.isBaby()) { - shadowRadius *= 3; // undo vanilla shadow scaling - } - - if (!entity.hasVehicle()) { - stack.translate(0, 0, -entity.getWidth() / 2); // move us to the center of the shadow - } else { - stack.translate(0, entity.getHeightOffset(), 0); - } - } - - @Override - public ModelWrapper getModelWrapper() { - return manager.playerModel; - } - - @Override - protected void renderLabelIfPresent(T entity, Text name, MatrixStack stack, VertexConsumerProvider renderContext, int maxDistance) { - stack.push(); - stack.translate(0, manager.getNamePlateYOffset(entity), 0); - super.renderLabelIfPresent(entity, name, stack, renderContext, maxDistance); - stack.pop(); - } - - @Override - public Identifier getDefaultTexture(T entity, Wearable wearable) { - return wearableTextures.computeIfAbsent(wearable, w -> { - Identifier texture = getTexture(entity); - texture = new Identifier(texture.getNamespace(), texture.getPath().split("\\.")[0] + "_" + wearable.name().toLowerCase(Locale.ROOT) + ".png"); - - if (MinecraftClient.getInstance().getResourceManager().getResource(texture).isPresent()) { - return texture; - } - return wearable.getDefaultTexture(); - }); - } - - @Override - public EquineRenderManager getInternalRenderer() { - return manager; - } - - @Override - public IPony getEntityPony(T entity) { - return IPony.getManager().getPony(getTexture(entity)); - } - - public abstract static class Caster> extends PonyRenderer { - - public Caster(EntityRendererFactory.Context context, ModelKey key) { - super(context, key); - } - - @Override - protected HeldItemFeature createItemHoldingLayer() { - return new GlowingItemFeature<>(this); - } - } - - public abstract static class Proxy & IPonyModel> extends PonyRenderer { - - @SuppressWarnings({"rawtypes", "unchecked"}) - public Proxy(List exportedLayers, EntityRendererFactory.Context context, ModelKey key) { - super(context, key); - - exportedLayers.addAll(features); - } - - @Override - protected void addLayers(EntityRendererFactory.Context context) { - features.clear(); - super.addLayers(context); - } + protected void addFeatures(EntityRendererFactory.Context context) { + super.addFeatures(context); + addFeature(new StuckArrowsFeatureRenderer<>(context, this)); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java index 574a02bc..49fe2888 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java @@ -5,9 +5,7 @@ import org.jetbrains.annotations.NotNull; import com.minelittlepony.client.mixin.IResizeable; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.GuardianPonyModel; -import com.minelittlepony.client.render.entity.PonyRenderer.Proxy; -import com.minelittlepony.client.render.entity.feature.HeldItemFeature; -import com.minelittlepony.client.render.entity.feature.GlowingItemFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRendererFactory; @@ -21,24 +19,19 @@ import net.minecraft.util.Identifier; public class SeaponyRenderer extends GuardianEntityRenderer { public static final Identifier TEXTURE = new Identifier("minelittlepony", "textures/entity/seapony.png"); - private final Proxy ponyRenderer; + private final AbstractPonyRenderer ponyRenderer; - public SeaponyRenderer(EntityRendererFactory.Context context) { + public SeaponyRenderer(EntityRendererFactory.Context context, float scale) { super(context); + ponyRenderer = AbstractPonyRenderer.proxy(context, ModelType.GUARDIAN, TextureSupplier.of(TEXTURE), scale, features, m -> model = m); + } - features.clear(); - ponyRenderer = new Proxy(features, context, ModelType.GUARDIAN) { - @Override - public Identifier getTexture(GuardianEntity entity) { - return TEXTURE; - } + public static SeaponyRenderer guardian(EntityRendererFactory.Context context) { + return new SeaponyRenderer(context, 1); + } - @Override - protected HeldItemFeature createItemHoldingLayer() { - return new GlowingItemFeature<>(this); - } - }; - model = ponyRenderer.getModel(); + public static SeaponyRenderer elder(EntityRendererFactory.Context context) { + return new SeaponyRenderer(context, 1); } @Override @@ -64,17 +57,4 @@ public class SeaponyRenderer extends GuardianEntityRenderer { resize.setCurrentSize(origin); } - - public static class Elder extends SeaponyRenderer { - - public Elder(EntityRendererFactory.Context context) { - super(context); - } - - @Override - protected void scale(GuardianEntity entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - stack.scale(2.35F, 2.35F, 2.35F); - } - } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/SkeleponyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/SkeleponyRenderer.java index a55f7bd2..6aab7ed7 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/SkeleponyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/SkeleponyRenderer.java @@ -2,15 +2,11 @@ package com.minelittlepony.client.render.entity; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.SkeleponyModel; -import com.minelittlepony.client.render.entity.feature.HeldItemFeature; -import com.minelittlepony.client.render.entity.feature.GlowingItemFeature; import com.minelittlepony.client.render.entity.feature.StrayClothingFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.mob.AbstractSkeletonEntity; -import net.minecraft.entity.mob.StrayEntity; -import net.minecraft.entity.mob.WitherSkeletonEntity; +import net.minecraft.entity.mob.*; import net.minecraft.util.Identifier; public class SkeleponyRenderer extends PonyRenderer> { @@ -19,50 +15,19 @@ public class SkeleponyRenderer extends public static final Identifier WITHER = new Identifier("minelittlepony", "textures/entity/skeleton/skeleton_wither_pony.png"); public static final Identifier STRAY = new Identifier("minelittlepony", "textures/entity/skeleton/stray_pony.png"); - public SkeleponyRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.SKELETON); + public SkeleponyRenderer(EntityRendererFactory.Context context, Identifier texture, float scale) { + super(context, ModelType.SKELETON, TextureSupplier.of(texture), scale); } - @Override - public Identifier getTexture(Skeleton entity) { - return SKELETON; + public static SkeleponyRenderer skeleton(EntityRendererFactory.Context context) { + return new SkeleponyRenderer<>(context, SKELETON, 1); } - @Override - protected HeldItemFeature> createItemHoldingLayer() { - return new GlowingItemFeature<>(this); + public static SkeleponyRenderer stray(EntityRendererFactory.Context context) { + return PonyRenderer.appendFeature(new SkeleponyRenderer<>(context, STRAY, 1), StrayClothingFeature::new); } - public static class Stray extends SkeleponyRenderer { - - public Stray(EntityRendererFactory.Context context) { - super(context); - addFeature(new StrayClothingFeature<>(this)); - } - - @Override - public Identifier getTexture(StrayEntity entity) { - return STRAY; - } + public static SkeleponyRenderer wither(EntityRendererFactory.Context context) { + return new SkeleponyRenderer<>(context, WITHER, 1.2F); } - - public static class Wither extends SkeleponyRenderer { - - public Wither(EntityRendererFactory.Context context) { - super(context); - } - - @Override - public Identifier getTexture(WitherSkeletonEntity entity) { - return WITHER; - } - - @Override - public void scale(WitherSkeletonEntity skeleton, MatrixStack stack, float ticks) { - super.scale(skeleton, stack, ticks); - stack.scale(1.2F, 1.2F, 1.2F); - } - - } - } diff --git a/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java index 379ca463..b6a390aa 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java @@ -3,6 +3,7 @@ package com.minelittlepony.client.render.entity; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.WitchPonyModel; import com.minelittlepony.client.render.entity.feature.HeldItemFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.model.json.ModelTransformationMode; @@ -18,11 +19,11 @@ public class WitchRenderer extends PonyRenderer { private static final Identifier WITCH_TEXTURES = new Identifier("minelittlepony", "textures/entity/witch_pony.png"); public WitchRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.WITCH); + super(context, ModelType.WITCH, TextureSupplier.of(WITCH_TEXTURES), BASE_MODEL_SCALE); } @Override - protected HeldItemFeature createItemHoldingLayer() { + protected HeldItemFeature createHeldItemFeature(EntityRendererFactory.Context context) { return new HeldItemFeature(this) { @Override protected void preItemRender(WitchEntity entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack) { @@ -31,15 +32,4 @@ public class WitchRenderer extends PonyRenderer { } }; } - - @Override - public void scale(WitchEntity entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - stack.scale(BASE_MODEL_SCALE, BASE_MODEL_SCALE, BASE_MODEL_SCALE); - } - - @Override - public Identifier getTexture(WitchEntity entity) { - return WITCH_TEXTURES; - } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/ZomponyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/ZomponyRenderer.java index 981f5774..52480380 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/ZomponyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/ZomponyRenderer.java @@ -1,77 +1,36 @@ package com.minelittlepony.client.render.entity; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.mob.DrownedEntity; -import net.minecraft.entity.mob.GiantEntity; -import net.minecraft.entity.mob.HuskEntity; -import net.minecraft.entity.mob.ZombieEntity; +import net.minecraft.entity.mob.*; import net.minecraft.util.Identifier; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.ZomponyModel; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; -public class ZomponyRenderer extends PonyRenderer.Caster> { +public class ZomponyRenderer extends PonyRenderer> { public static final Identifier ZOMBIE = new Identifier("minelittlepony", "textures/entity/zombie/zombie_pony.png"); public static final Identifier HUSK = new Identifier("minelittlepony", "textures/entity/zombie/husk_pony.png"); public static final Identifier DROWNED = new Identifier("minelittlepony", "textures/entity/zombie/drowned_pony.png"); - public ZomponyRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.ZOMBIE); + public ZomponyRenderer(EntityRendererFactory.Context context, Identifier texture, float scale) { + super(context, ModelType.ZOMBIE, TextureSupplier.of(texture), scale); } - @Override - public Identifier getTexture(Zombie entity) { - return ZOMBIE; + public static ZomponyRenderer zombie(EntityRendererFactory.Context context) { + return new ZomponyRenderer<>(context, ZOMBIE, 1); } - public static class Drowned extends ZomponyRenderer { - - public Drowned(EntityRendererFactory.Context context) { - super(context); - } - - @Override - public Identifier getTexture(DrownedEntity entity) { - return DROWNED; - } + public static ZomponyRenderer husk(EntityRendererFactory.Context context) { + return new ZomponyRenderer<>(context, HUSK, 1.0625F); } - public static class Husk extends ZomponyRenderer { - - public Husk(EntityRendererFactory.Context context) { - super(context); - } - - @Override - public void scale(HuskEntity entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - stack.scale(1.0625F, 1.0625F, 1.0625F); - } - - @Override - public Identifier getTexture(HuskEntity entity) { - return HUSK; - } - + public static ZomponyRenderer drowned(EntityRendererFactory.Context context) { + return new ZomponyRenderer<>(context, DROWNED, 1); } - public static class Giant extends PonyRenderer.Caster> { - - public Giant(EntityRendererFactory.Context context) { - super(context, ModelType.ZOMBIE); - } - - @Override - public void scale(GiantEntity entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - stack.scale(3, 3, 3); - } - - @Override - public Identifier getTexture(GiantEntity entity) { - return ZOMBIE; - } + public static ZomponyRenderer giant(EntityRendererFactory.Context context) { + return new ZomponyRenderer<>(context, ZOMBIE, 3); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/AbstractNpcRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/npc/AbstractNpcRenderer.java index 4bb0f797..3b787ea9 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/AbstractNpcRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/AbstractNpcRenderer.java @@ -18,9 +18,7 @@ import com.minelittlepony.client.render.entity.npc.textures.*; import java.util.*; -abstract class AbstractNpcRenderer extends PonyRenderer.Caster> { - - private final TextureSupplier baseTextures; +abstract class AbstractNpcRenderer extends PonyRenderer> { private final String entityType; @@ -29,16 +27,15 @@ abstract class AbstractNpcRenderer private final NpcClothingFeature, AbstractNpcRenderer> clothing; public AbstractNpcRenderer(EntityRendererFactory.Context context, String type, TextureSupplier textureSupplier, TextureSupplier formatter) { - super(context, ModelType.getPlayerModel(Race.EARTH).getKey(false)); + super(context, ModelType.getPlayerModel(Race.EARTH).getKey(false), new SillyPonyTextureSupplier<>(textureSupplier, formatter)); entityType = type; - baseTextures = new SillyPonyTextureSupplier<>(textureSupplier, formatter); clothing = new NpcClothingFeature<>(this, entityType); addFeature(clothing); } @Override - protected void addLayers(EntityRendererFactory.Context context) { - addFeature(createItemHoldingLayer()); + protected void addFeatures(EntityRendererFactory.Context context) { + addFeature(createHeldItemFeature(context)); addFeature(new GearFeature<>(this)); } @@ -89,9 +86,4 @@ abstract class AbstractNpcRenderer } return wearable.getDefaultTexture(); } - - @Override - public Identifier getTexture(T villager) { - return baseTextures.apply(villager); - } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/IllagerPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/npc/IllagerPonyRenderer.java index 9a51c1f3..8316260e 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/IllagerPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/IllagerPonyRenderer.java @@ -3,6 +3,7 @@ package com.minelittlepony.client.render.entity.npc; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.IllagerPonyModel; import com.minelittlepony.client.render.entity.feature.IllagerHeldItemFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import com.minelittlepony.client.render.entity.PonyRenderer; import com.minelittlepony.client.render.entity.feature.HeldItemFeature; @@ -17,61 +18,32 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -public abstract class IllagerPonyRenderer extends PonyRenderer> { - +public class IllagerPonyRenderer extends PonyRenderer> { public static final Identifier ILLUSIONIST = new Identifier("minelittlepony", "textures/entity/illager/illusionist_pony.png"); public static final Identifier EVOKER = new Identifier("minelittlepony", "textures/entity/illager/evoker_pony.png"); public static final Identifier VINDICATOR = new Identifier("minelittlepony", "textures/entity/illager/vindicator_pony.png"); - public IllagerPonyRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.ILLAGER); + public IllagerPonyRenderer(EntityRendererFactory.Context context, Identifier texture) { + super(context, ModelType.ILLAGER, TextureSupplier.of(texture), BASE_MODEL_SCALE); } @Override - protected HeldItemFeature> createItemHoldingLayer() { + protected HeldItemFeature> createHeldItemFeature(EntityRendererFactory.Context context) { return new IllagerHeldItemFeature<>(this); } - @Override - public void scale(T entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - stack.scale(BASE_MODEL_SCALE, BASE_MODEL_SCALE, BASE_MODEL_SCALE); + public static IllagerPonyRenderer vindicator(EntityRendererFactory.Context context) { + return new IllagerPonyRenderer<>(context, VINDICATOR); } - public static class Vindicator extends IllagerPonyRenderer { - - public Vindicator(EntityRendererFactory.Context context) { - super(context); - - } - - @Override - public Identifier getTexture(VindicatorEntity entity) { - return VINDICATOR; - } - } - - public static class Evoker extends IllagerPonyRenderer { - - public Evoker(EntityRendererFactory.Context context) { - super(context); - } - - @Override - public Identifier getTexture(EvokerEntity entity) { - return EVOKER; - } + public static IllagerPonyRenderer evoker(EntityRendererFactory.Context context) { + return new IllagerPonyRenderer<>(context, EVOKER); } public static class Illusionist extends IllagerPonyRenderer { public Illusionist(EntityRendererFactory.Context context) { - super(context); - } - - @Override - public Identifier getTexture(IllusionerEntity entity) { - return ILLUSIONIST; + super(context, ILLUSIONIST); } @Override diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java index 07d646c4..0116b8f6 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java @@ -7,24 +7,20 @@ import net.minecraft.util.Identifier; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.PillagerPonyModel; import com.minelittlepony.client.render.entity.feature.IllagerHeldItemFeature; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import com.minelittlepony.client.render.entity.PonyRenderer; import com.minelittlepony.client.render.entity.feature.HeldItemFeature; public class PillagerRenderer extends PonyRenderer> { - private static final Identifier TEXTURES = new Identifier("minelittlepony", "textures/entity/illager/pillager_pony.png"); + private static final Identifier TEXTURE = new Identifier("minelittlepony", "textures/entity/illager/pillager_pony.png"); public PillagerRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.PILLAGER); + super(context, ModelType.PILLAGER, TextureSupplier.of(TEXTURE)); } @Override - public Identifier getTexture(PillagerEntity entity) { - return TEXTURES; - } - - @Override - protected HeldItemFeature> createItemHoldingLayer() { + protected HeldItemFeature> createHeldItemFeature(EntityRendererFactory.Context context) { return new IllagerHeldItemFeature<>(this); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/TraderRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/npc/TraderRenderer.java index fb7115a6..3e37208a 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/TraderRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/TraderRenderer.java @@ -1,30 +1,19 @@ package com.minelittlepony.client.render.entity.npc; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.passive.WanderingTraderEntity; import net.minecraft.util.Identifier; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.race.AlicornModel; import com.minelittlepony.client.render.entity.PonyRenderer; +import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; -public class TraderRenderer extends PonyRenderer.Caster> { +public class TraderRenderer extends PonyRenderer> { public static final Identifier TEXTURE = new Identifier("minelittlepony", "textures/entity/wandering_trader_pony.png"); public TraderRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.ALICORN.getKey(false)); - } - - @Override - public Identifier getTexture(WanderingTraderEntity entity) { - return TEXTURE; - } - - @Override - public void scale(WanderingTraderEntity entity, MatrixStack stack, float ticks) { - super.scale(entity, stack, ticks); - stack.scale(BASE_MODEL_SCALE, BASE_MODEL_SCALE, BASE_MODEL_SCALE); + super(context, ModelType.ALICORN.getKey(false), TextureSupplier.of(TEXTURE), BASE_MODEL_SCALE); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/textures/TextureSupplier.java b/src/main/java/com/minelittlepony/client/render/entity/npc/textures/TextureSupplier.java index f13c9db1..cb329d6a 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/textures/TextureSupplier.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/textures/TextureSupplier.java @@ -41,6 +41,10 @@ public interface TextureSupplier extends Function { }; } + static TextureSupplier of(Identifier texture) { + return a -> texture; + } + static TextureSupplier memoize(Function func, Function keyFunc) { final Map cache = new ConcurrentHashMap<>(); return a -> cache.computeIfAbsent(keyFunc.apply(a), k -> func.apply(a));