Refactor Skulls to separate them from their entity renderer.

(Most mods would just create their own TESR class for custom skulls)
This commit is contained in:
Matthew Messinger 2018-08-26 15:30:22 -04:00
parent 8b779f57b2
commit a022d3758a
9 changed files with 166 additions and 129 deletions

View file

@ -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<Integer, ISkull> skullMap = new HashMap<Integer, ISkull>();
private final Map<Integer, ISkull> 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
@ -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;
}
}
}

View file

@ -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<AbstractClientPlayer> {
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<Type, MinecraftProfileTexture> 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<AbstractClientPlayer> renderPony = new RenderPony<>(this);
public RenderPonyPlayer(RenderManager manager, boolean useSmallArms, ModelWrapper model) {
@ -192,4 +130,5 @@ public class RenderPonyPlayer extends RenderPlayer implements IRenderPony<Abstra
public Pony getEntityPony(AbstractClientPlayer player) {
return MineLittlePony.getInstance().getManager().getPony(player);
}
}

View file

@ -1,13 +1,8 @@
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.minelittlepony.render.layer.LayerPonyStrayOverlay;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.monster.AbstractSkeleton;
@ -21,18 +16,6 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> 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<Skeleton extends AbstractSkeleton> extends Rende
public static class Wither extends RenderPonySkeleton<EntityWitherSkeleton> {
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);
}

View file

@ -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<Zombie extends EntityZombie> 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);
}

View file

@ -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<MinecraftProfileTexture.Type, MinecraftProfileTexture> 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);
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.minelittlepony.render.skull;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;