From a022d3758a70850b8edf5339d32033b1d044becb Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Sun, 26 Aug 2018 15:30:22 -0400 Subject: [PATCH] Refactor Skulls to separate them from their entity renderer. (Most mods would just create their own TESR class for custom skulls) --- .../render/PonySkullRenderer.java | 47 +++++++------ .../render/player/RenderPonyPlayer.java | 63 +----------------- .../render/ponies/RenderPonySkeleton.java | 29 -------- .../render/ponies/RenderPonyZombie.java | 17 ----- .../render/skull/PlayerSkullRenderer.java | 66 +++++++++++++++++++ .../render/skull/SkeletonSkullRenderer.java | 22 +++++++ .../render/skull/WitherSkullRenderer.java | 22 +++++++ .../render/skull/ZombieSkullRenderer.java | 22 +++++++ .../render/skull/package-info.java | 7 ++ 9 files changed, 166 insertions(+), 129 deletions(-) create mode 100644 src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java create mode 100644 src/main/java/com/minelittlepony/render/skull/SkeletonSkullRenderer.java create mode 100644 src/main/java/com/minelittlepony/render/skull/WitherSkullRenderer.java create mode 100644 src/main/java/com/minelittlepony/render/skull/ZombieSkullRenderer.java create mode 100644 src/main/java/com/minelittlepony/render/skull/package-info.java diff --git a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java index 3f5a8a26..b2e4f945 100644 --- a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java @@ -1,16 +1,13 @@ package com.minelittlepony.render; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.lwjgl.opengl.GL11; - import com.minelittlepony.MineLittlePony; import com.minelittlepony.PonyConfig; import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.pony.data.Pony; +import com.minelittlepony.render.skull.PlayerSkullRenderer; +import com.minelittlepony.render.skull.SkeletonSkullRenderer; +import com.minelittlepony.render.skull.WitherSkullRenderer; +import com.minelittlepony.render.skull.ZombieSkullRenderer; import com.mojang.authlib.GameProfile; import com.mumfrey.liteloader.util.ModUtilities; import net.minecraft.client.renderer.GlStateManager; @@ -18,16 +15,35 @@ import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer; import net.minecraft.tileentity.TileEntitySkull; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; /** * PonySkullRenderer! It renders ponies as skulls, or something... */ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRenderItem { + private static final int SKELETON = 0; + private static final int WITHER = 1; + private static final int ZOMBIE = 2; + private static final int PLAYER = 3; + private static final int CREEPER = 4; + private static final int DRAGON = 5; + public static PonySkullRenderer ponyInstance = new PonySkullRenderer(); private static TileEntitySkullRenderer backup = null; - private static final Map skullMap = new HashMap(); + private final Map skullMap = new HashMap<>(); + + private PonySkullRenderer() { + skullMap.put(SKELETON, new SkeletonSkullRenderer()); + skullMap.put(WITHER, new WitherSkullRenderer()); + skullMap.put(ZOMBIE, new ZombieSkullRenderer()); + skullMap.put(PLAYER, new PlayerSkullRenderer()); + } /** * Resolves the games skull renderer to either a specialised pony skull renderer @@ -44,7 +60,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende } } else { if ((instance instanceof PonySkullRenderer)) { - ponyInstance = (PonySkullRenderer)instance; + ponyInstance = (PonySkullRenderer) instance; if (backup == null) { backup = new TileEntitySkullRenderer(); } @@ -61,7 +77,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende @Override public void renderSkull(float x, float y, float z, EnumFacing facing, float rotation, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks) { - ISkull skull = skullMap.getOrDefault(skullType, null); + ISkull skull = skullMap.get(skullType); if (skull == null || !skull.canRender(MineLittlePony.getConfig())) { if (backup != null) { @@ -150,12 +166,6 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende */ public interface ISkull { - public static final int SKELETON = 0; - public static final int WITHER = 1; - public static final int ZOMBIE = 2; - public static final int PLAYER = 3; - public static final int CREEPER = 4; - public static final int DRAGON = 5; void preRender(boolean transparency); @@ -166,10 +176,5 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende ResourceLocation getSkinResource(@Nullable GameProfile profile); void bindPony(Pony pony); - - default ISkull register(int metadataId) { - PonySkullRenderer.skullMap.put(metadataId, this); - return this; - } } } diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index 5c317096..1b7aec84 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -1,14 +1,9 @@ package com.minelittlepony.render.player; import com.minelittlepony.MineLittlePony; -import com.minelittlepony.PonyConfig; import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.ModelWrapper; -import com.minelittlepony.model.components.ModelDeadMau5Ears; import com.minelittlepony.pony.data.Pony; -import com.minelittlepony.pony.data.PonyLevel; -import com.minelittlepony.render.PonySkull; -import com.minelittlepony.render.PonySkullRenderer.ISkull; import com.minelittlepony.render.RenderPony; import com.minelittlepony.render.layer.LayerDJPon3Head; import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder; @@ -17,74 +12,17 @@ import com.minelittlepony.render.layer.LayerPonyArmor; import com.minelittlepony.render.layer.LayerPonyCape; import com.minelittlepony.render.layer.LayerPonyCustomHead; import com.minelittlepony.render.layer.LayerPonyElytra; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; -import com.voxelmodpack.hdskins.HDSkinManager; -import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.client.renderer.entity.layers.LayerArrow; -import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumHandSide; import net.minecraft.util.ResourceLocation; -import java.util.Map; - public class RenderPonyPlayer extends RenderPlayer implements IRenderPony { - public static final ISkull SKULL = new PonySkull() { - - private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears(); - - @Override - public boolean canRender(PonyConfig config) { - return config.getPonyLevel() != PonyLevel.HUMANS; - } - - @Override - public void preRender(boolean transparency) { - GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN); - - if (!transparency) { - RenderPony.enableModelRenderProfile(); - } - } - - @Override - public ResourceLocation getSkinResource(GameProfile profile) { - if (profile != null) { - deadMau5.setVisible("deadmau5".equals(profile.getName())); - - ResourceLocation skin = HDSkinManager.INSTANCE.getTextures(profile).get(Type.SKIN); - if (skin != null) { - return skin; - } - - Minecraft minecraft = Minecraft.getMinecraft(); - Map map = minecraft.getSkinManager().loadSkinFromCache(profile); - - if (map.containsKey(Type.SKIN)) { - return minecraft.getSkinManager().loadSkin(map.get(Type.SKIN), Type.SKIN); - } else { - return DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(profile)); - } - } - - return DefaultPlayerSkin.getDefaultSkinLegacy(); - } - - @Override - public void render(float animateTicks, float rotation, float scale) { - super.render(animateTicks, rotation, scale); - deadMau5.render(null, animateTicks, 0, 0, rotation, 0, scale); - } - }.register(ISkull.PLAYER); - protected final RenderPony renderPony = new RenderPony<>(this); public RenderPonyPlayer(RenderManager manager, boolean useSmallArms, ModelWrapper model) { @@ -192,4 +130,5 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony extends Rende public static final ResourceLocation WITHER = new ResourceLocation("minelittlepony", "textures/entity/skeleton/skeleton_wither_pony.png"); public static final ResourceLocation STRAY = new ResourceLocation("minelittlepony", "textures/entity/skeleton/stray_pony.png"); - public static final ISkull SKULL = new PonySkull() { - @Override - public boolean canRender(PonyConfig config) { - return config.skeletons; - } - - @Override - public ResourceLocation getSkinResource(GameProfile profile) { - return RenderPonySkeleton.SKELETON; - } - }.register(ISkull.SKELETON); - public RenderPonySkeleton(RenderManager manager) { super(manager, PMAPI.skeleton); } @@ -57,18 +40,6 @@ public class RenderPonySkeleton extends Rende public static class Wither extends RenderPonySkeleton { - public static final ISkull SKULL = new PonySkull() { - @Override - public boolean canRender(PonyConfig config) { - return config.skeletons; - } - - @Override - public ResourceLocation getSkinResource(GameProfile profile) { - return RenderPonySkeleton.WITHER; - } - }.register(ISkull.WITHER); - public Wither(RenderManager rm) { super(rm); } diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java index 541d8092..b9364c7d 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java @@ -1,12 +1,7 @@ package com.minelittlepony.render.ponies; -import com.minelittlepony.PonyConfig; import com.minelittlepony.model.PMAPI; import com.minelittlepony.render.RenderPonyMob; -import com.minelittlepony.render.PonySkull; -import com.minelittlepony.render.PonySkullRenderer.ISkull; -import com.mojang.authlib.GameProfile; - import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.monster.EntityGiantZombie; @@ -19,18 +14,6 @@ public class RenderPonyZombie extends RenderPonyMob public static final ResourceLocation ZOMBIE = new ResourceLocation("minelittlepony", "textures/entity/zombie/zombie_pony.png"); public static final ResourceLocation HUSK = new ResourceLocation("minelittlepony", "textures/entity/zombie/husk_pony.png"); - public static final ISkull SKULL = new PonySkull() { - @Override - public boolean canRender(PonyConfig config) { - return config.zombies; - } - - @Override - public ResourceLocation getSkinResource(GameProfile profile) { - return RenderPonyZombie.ZOMBIE; - } - }.register(ISkull.ZOMBIE); - public RenderPonyZombie(RenderManager manager) { super(manager, PMAPI.zombie); } diff --git a/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java b/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java new file mode 100644 index 00000000..cae3bacc --- /dev/null +++ b/src/main/java/com/minelittlepony/render/skull/PlayerSkullRenderer.java @@ -0,0 +1,66 @@ +package com.minelittlepony.render.skull; + +import com.minelittlepony.PonyConfig; +import com.minelittlepony.model.components.ModelDeadMau5Ears; +import com.minelittlepony.pony.data.PonyLevel; +import com.minelittlepony.render.PonySkull; +import com.minelittlepony.render.RenderPony; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import com.voxelmodpack.hdskins.HDSkinManager; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; + +import java.util.Map; +import javax.annotation.Nullable; + +public class PlayerSkullRenderer extends PonySkull { + + private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears(); + + @Override + public boolean canRender(PonyConfig config) { + return config.getPonyLevel() != PonyLevel.HUMANS; + } + + @Override + public void preRender(boolean transparency) { + GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN); + + if (!transparency) { + RenderPony.enableModelRenderProfile(); + } + } + + @Override + public ResourceLocation getSkinResource(@Nullable GameProfile profile) { + if (profile != null) { + deadMau5.setVisible("deadmau5".equals(profile.getName())); + + ResourceLocation skin = HDSkinManager.INSTANCE.getTextures(profile).get(MinecraftProfileTexture.Type.SKIN); + if (skin != null) { + return skin; + } + + Minecraft minecraft = Minecraft.getMinecraft(); + Map map = minecraft.getSkinManager().loadSkinFromCache(profile); + + if (map.containsKey(MinecraftProfileTexture.Type.SKIN)) { + return minecraft.getSkinManager().loadSkin(map.get(MinecraftProfileTexture.Type.SKIN), MinecraftProfileTexture.Type.SKIN); + } else { + return DefaultPlayerSkin.getDefaultSkin(EntityPlayer.getUUID(profile)); + } + } + + return DefaultPlayerSkin.getDefaultSkinLegacy(); + } + + @Override + public void render(float animateTicks, float rotation, float scale) { + super.render(animateTicks, rotation, scale); + deadMau5.render(null, animateTicks, 0, 0, rotation, 0, scale); + } +} diff --git a/src/main/java/com/minelittlepony/render/skull/SkeletonSkullRenderer.java b/src/main/java/com/minelittlepony/render/skull/SkeletonSkullRenderer.java new file mode 100644 index 00000000..30e184b7 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/skull/SkeletonSkullRenderer.java @@ -0,0 +1,22 @@ +package com.minelittlepony.render.skull; + +import com.minelittlepony.PonyConfig; +import com.minelittlepony.render.PonySkull; +import com.minelittlepony.render.ponies.RenderPonySkeleton; +import com.mojang.authlib.GameProfile; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; + +public class SkeletonSkullRenderer extends PonySkull { + + @Override + public boolean canRender(PonyConfig config) { + return config.skeletons; + } + + @Override + public ResourceLocation getSkinResource(@Nullable GameProfile profile) { + return RenderPonySkeleton.SKELETON; + } +} diff --git a/src/main/java/com/minelittlepony/render/skull/WitherSkullRenderer.java b/src/main/java/com/minelittlepony/render/skull/WitherSkullRenderer.java new file mode 100644 index 00000000..54eb705c --- /dev/null +++ b/src/main/java/com/minelittlepony/render/skull/WitherSkullRenderer.java @@ -0,0 +1,22 @@ +package com.minelittlepony.render.skull; + +import com.minelittlepony.PonyConfig; +import com.minelittlepony.render.PonySkull; +import com.minelittlepony.render.ponies.RenderPonySkeleton; +import com.mojang.authlib.GameProfile; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; + +public class WitherSkullRenderer extends PonySkull { + + @Override + public boolean canRender(PonyConfig config) { + return config.skeletons; + } + + @Override + public ResourceLocation getSkinResource(@Nullable GameProfile profile) { + return RenderPonySkeleton.WITHER; + } +} diff --git a/src/main/java/com/minelittlepony/render/skull/ZombieSkullRenderer.java b/src/main/java/com/minelittlepony/render/skull/ZombieSkullRenderer.java new file mode 100644 index 00000000..3b5b22f3 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/skull/ZombieSkullRenderer.java @@ -0,0 +1,22 @@ +package com.minelittlepony.render.skull; + +import com.minelittlepony.PonyConfig; +import com.minelittlepony.render.PonySkull; +import com.minelittlepony.render.ponies.RenderPonyZombie; +import com.mojang.authlib.GameProfile; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; + +public class ZombieSkullRenderer extends PonySkull { + + @Override + public boolean canRender(PonyConfig config) { + return config.zombies; + } + + @Override + public ResourceLocation getSkinResource(@Nullable GameProfile profile) { + return RenderPonyZombie.ZOMBIE; + } +} diff --git a/src/main/java/com/minelittlepony/render/skull/package-info.java b/src/main/java/com/minelittlepony/render/skull/package-info.java new file mode 100644 index 00000000..0c4d7a0a --- /dev/null +++ b/src/main/java/com/minelittlepony/render/skull/package-info.java @@ -0,0 +1,7 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package com.minelittlepony.render.skull; + +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault;