development on renderers and ponies

This commit is contained in:
Matthew Messinger 2016-08-22 17:32:03 -04:00
parent 6b3cd62549
commit 79ab9d51ee
8 changed files with 313 additions and 50 deletions

View file

@ -6,6 +6,7 @@ import com.brohoof.minelittlepony.gui.PonySettingPanel;
import com.brohoof.minelittlepony.hdskins.gui.EntityPonyModel;
import com.brohoof.minelittlepony.hdskins.gui.GuiSkinsMineLP;
import com.brohoof.minelittlepony.hdskins.gui.RenderPonyModel;
import com.brohoof.minelittlepony.renderer.RenderPonyPigman;
import com.brohoof.minelittlepony.renderer.RenderPonySkeleton;
import com.brohoof.minelittlepony.renderer.RenderPonyVillager;
import com.brohoof.minelittlepony.renderer.RenderPonyZombie;
@ -18,6 +19,7 @@ import com.voxelmodpack.hdskins.gui.GuiSkins;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
@ -59,6 +61,9 @@ public class MineLittlePony {
this.proxy = new ProxyContainer();
LiteLoader.getInstance().registerExposable(config, null);
IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
irrm.registerReloadListener(this.ponyManager);
}
void postInit(Minecraft minecraft) {
@ -78,12 +83,12 @@ public class MineLittlePony {
}
if (this.config.zombies) {
ModUtilities.addRenderer(EntityZombie.class, new RenderPonyZombie<EntityZombie>(rm));
ModUtilities.addRenderer(EntityZombie.class, new RenderPonyZombie(rm));
MineLPLogger.info("Zombies are now ponies.");
}
if (this.config.pigzombies) {
ModUtilities.addRenderer(EntityPigZombie.class, new RenderPonyZombie<EntityPigZombie>(rm));
ModUtilities.addRenderer(EntityPigZombie.class, new RenderPonyPigman(rm));
MineLPLogger.info("Zombie pigmen are now ponies.");
}

View file

@ -1,35 +1,50 @@
package com.brohoof.minelittlepony;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.compress.utils.IOUtils;
import com.brohoof.minelittlepony.model.PMAPI;
import com.brohoof.minelittlepony.util.MineLPLogger;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.entity.monster.SkeletonType;
import net.minecraft.entity.monster.ZombieType;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.util.ResourceLocation;
public class PonyManager {
public class PonyManager implements IResourceManagerReloadListener {
private static final String NAMESPACE = "minelittlepony";
public static final String NAMESPACE = "minelittlepony";
public static final ResourceLocation ZOMBIE = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_pony.png");
public static final ResourceLocation ZOMBIE_VILLAGER = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_villager_pony.png");
public static final ResourceLocation PIGMAN = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_pigman_pony.png");
public static final ResourceLocation SKELETON = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/skeleton_pony.png");
public static final ResourceLocation WITHER_SKELETON = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/skeleton_wither_pony.png");
public static final ResourceLocation STRAY_SKELETON = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/stray_pony.png");
public static final ResourceLocation STRAY_SKELETON_OVERLAY = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/stray_pony_overlay.png");
public static final ResourceLocation STEVE = new ResourceLocation(NAMESPACE, "textures/entity/steve_pony.png");
public static final ResourceLocation ALEX = new ResourceLocation(NAMESPACE, "textures/entity/alex_pony.png");
public static final ResourceLocation ZOMBIE_VILLAGER = new ResourceLocation(NAMESPACE, "textures/entity/zombie_villager/zombie_villager_pony.png");
private static final int MAX_BGPONY_COUNT = 141;
public static final Map<ZombieType, ResourceLocation> ZOMBIES = Maps.immutableEnumMap(ImmutableMap.<ZombieType, ResourceLocation> builder()
.put(ZombieType.NORMAL, ZOMBIE)
.put(ZombieType.HUSK, new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_husk_pony.png"))
.put(ZombieType.VILLAGER_FARMER, new ResourceLocation(NAMESPACE, "textures/entity/zombie_villager/zombie_farmer_pony.png"))
.put(ZombieType.VILLAGER_LIBRARIAN, new ResourceLocation(NAMESPACE, "textures/entity/zombie_villager/zombie_librarian_pony.png"))
.put(ZombieType.VILLAGER_PRIEST, new ResourceLocation(NAMESPACE, "textures/entity/zombie_villager/zombie_priest_pony.png"))
.put(ZombieType.VILLAGER_SMITH, new ResourceLocation(NAMESPACE, "textures/entity/zombie_villager/zombie_smith_pony.png"))
.put(ZombieType.VILLAGER_BUTCHER, new ResourceLocation(NAMESPACE, "textures/entity/zombie_villager/zombie_butcher_pony.png"))
.build());
private final List<ResourceLocation> backgroundPonyList = makeBkgndPonies();
private final List<ResourceLocation> villagerList = ImmutableList.<ResourceLocation> builder()
public static final List<ResourceLocation> VILLAGER_LIST = ImmutableList.<ResourceLocation> builder()
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/farmer_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/librarian_pony.png"))
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/priest_pony.png"))
@ -38,23 +53,28 @@ public class PonyManager {
.add(new ResourceLocation(NAMESPACE, "textures/entity/villager/villager_pony.png"))
.build();
private static List<ResourceLocation> makeBkgndPonies() {
ImmutableList.Builder<ResourceLocation> list = ImmutableList.builder();
for (int check = 0; check < MAX_BGPONY_COUNT; ++check) {
list.add(new ResourceLocation(NAMESPACE, "textures/entity/pony/bpony_" + check + ".png"));
}
return list.build();
}
public static final ResourceLocation PIGMAN = new ResourceLocation(NAMESPACE, "textures/entity/zombie/zombie_pigman_pony.png");
public static final ResourceLocation SKELETON = new ResourceLocation(NAMESPACE, "textures/entity/skeleton/skeleton_pony.png");
public static final Map<SkeletonType, ResourceLocation> SKELETONS = Maps.immutableEnumMap(ImmutableMap.<SkeletonType, ResourceLocation> builder()
.put(SkeletonType.NORMAL, SKELETON)
.put(SkeletonType.WITHER, new ResourceLocation(NAMESPACE, "textures/entity/skeleton/skeleton_wither_pony.png"))
.put(SkeletonType.STRAY, new ResourceLocation(NAMESPACE, "testures/entity/skeleton/stray_pony.png"))
.build());
public static final ResourceLocation STEVE = new ResourceLocation(NAMESPACE, "textures/entity/steve_pony.png");
public static final ResourceLocation ALEX = new ResourceLocation(NAMESPACE, "textures/entity/alex_pony.png");
private static final ResourceLocation BGPONIES_JSON = new ResourceLocation(NAMESPACE, "textures/entity/pony/bgponies.json");
private List<ResourceLocation> backgroundPonyList = Lists.newArrayList();
private PonyConfig config;
private Map<ResourceLocation, Pony> ponies = Maps.newHashMap();
private Map<ResourceLocation, Pony> backgroudPonies = Maps.newHashMap();
private Map<ResourceLocation, Pony> poniesCache = Maps.newHashMap();
private Map<ResourceLocation, Pony> backgroudPoniesCache = Maps.newHashMap();
public PonyManager(PonyConfig config) {
this.config = config;
initmodels();
MineLPLogger.info("Detected %d of %d background ponies installed.", getNumberOfPonies(), MAX_BGPONY_COUNT);
}
public void initmodels() {
@ -65,16 +85,16 @@ public class PonyManager {
private Pony getPonyFromResourceRegistry(ResourceLocation skinResourceLocation, AbstractClientPlayer player) {
Pony myLittlePony;
if (!this.ponies.containsKey(skinResourceLocation)) {
if (!this.poniesCache.containsKey(skinResourceLocation)) {
if (player != null) {
myLittlePony = new Pony(player);
} else {
myLittlePony = new Pony(skinResourceLocation);
}
this.ponies.put(skinResourceLocation, myLittlePony);
this.poniesCache.put(skinResourceLocation, myLittlePony);
} else {
myLittlePony = this.ponies.get(skinResourceLocation);
myLittlePony = this.poniesCache.get(skinResourceLocation);
}
return myLittlePony;
@ -98,9 +118,9 @@ public class PonyManager {
ResourceLocation villagerResourceLocation;
try {
villagerResourceLocation = villagerList.get(profession);
villagerResourceLocation = VILLAGER_LIST.get(profession);
} catch (IndexOutOfBoundsException var5) {
villagerResourceLocation = villagerList.get(5);
villagerResourceLocation = VILLAGER_LIST.get(5);
}
Pony myLittlePony = this.getPonyFromResourceRegistry(villagerResourceLocation);
@ -129,16 +149,47 @@ public class PonyManager {
}
Pony myLittlePony;
if (!this.backgroudPonies.containsKey(textureResourceLocation)) {
if (!this.backgroudPoniesCache.containsKey(textureResourceLocation)) {
myLittlePony = new Pony(textureResourceLocation);
this.backgroudPonies.put(textureResourceLocation, myLittlePony);
this.backgroudPoniesCache.put(textureResourceLocation, myLittlePony);
} else {
myLittlePony = this.backgroudPonies.get(textureResourceLocation);
myLittlePony = this.backgroudPoniesCache.get(textureResourceLocation);
}
return myLittlePony;
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
// TODO Auto-generated method stub
this.backgroudPoniesCache.clear();
this.backgroundPonyList.clear();
try {
for (IResource res : resourceManager.getAllResources(BGPONIES_JSON)) {
try {
BackgroundPonies ponies = getBackgroundPonies(res.getInputStream());
if (ponies.override) {
this.backgroundPonyList.clear();
}
this.backgroundPonyList.addAll(ponies.getPonies());
} catch (JsonParseException e) {
MineLPLogger.error(e, "Invalid bgponies.json in {}", res.getResourcePackName());
}
}
} catch (IOException e) {
// this isn't the exception you're looking for.
}
MineLPLogger.info("Detected %d background ponies installed.", getNumberOfPonies());
}
private BackgroundPonies getBackgroundPonies(InputStream stream) {
try {
return new Gson().fromJson(new InputStreamReader(stream), BackgroundPonies.class);
} finally {
IOUtils.closeQuietly(stream);
}
}
public static ResourceLocation getDefaultSkin(UUID uuid) {
return (uuid.hashCode() & 1) == 0 ? STEVE : ALEX;
}
@ -146,4 +197,19 @@ public class PonyManager {
public int getNumberOfPonies() {
return backgroundPonyList.size();
}
private static class BackgroundPonies implements Function<String, ResourceLocation> {
public boolean override;
private List<String> ponies;
@Override
public ResourceLocation apply(String input) {
return new ResourceLocation(NAMESPACE, String.format("textures/entity/pony/%s.png", input));
}
public List<ResourceLocation> getPonies() {
return Lists.transform(ponies, this);
}
}
}

View file

@ -0,0 +1,21 @@
package com.brohoof.minelittlepony.renderer;
import com.brohoof.minelittlepony.PonyManager;
import com.brohoof.minelittlepony.model.PMAPI;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.util.ResourceLocation;
public class RenderPonyPigman extends RenderPonyMob<EntityPigZombie> {
public RenderPonyPigman(RenderManager renderManager) {
super(renderManager, PMAPI.pony);
}
@Override
protected ResourceLocation getEntityTexture(EntityPigZombie entity) {
return PonyManager.PIGMAN;
}
}

View file

@ -60,11 +60,9 @@ public class RenderPonySkeleton extends RenderPonyMob<EntitySkeleton> {
@Override
protected ResourceLocation getEntityTexture(EntitySkeleton skeleton) {
SkeletonType type = skeleton.getSkeletonType();
if (type == SkeletonType.WITHER)
return PonyManager.WITHER_SKELETON;
else if (type == SkeletonType.STRAY)
return PonyManager.STRAY_SKELETON;
else
return PonyManager.SKELETON;
ResourceLocation loc = PonyManager.SKELETONS.get(type);
if (loc == null)
loc = PonyManager.SKELETON;
return loc;
}
}

View file

@ -10,25 +10,25 @@ import com.brohoof.minelittlepony.TailLengths;
import com.brohoof.minelittlepony.model.PMAPI;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.util.ResourceLocation;
public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob<Zombie> {
public class RenderPonyZombie extends RenderPonyMob<EntityZombie> {
public RenderPonyZombie(RenderManager rendermanager) {
super(rendermanager, PMAPI.zombie);
}
@Override
protected void preRenderCallback(Zombie entity, float partick) {
protected void preRenderCallback(EntityZombie entity, float partick) {
super.preRenderCallback(entity, partick);
Random rand = new Random(entity.getUniqueID().hashCode());
// 50-50 chance for gender
this.playerModel.getModel().metadata.setGender(rand.nextBoolean() ? PonyGender.MARE : PonyGender.STALLION);
// races
switch (entity instanceof EntityPigZombie ? 0 : rand.nextInt(4)) {
switch (rand.nextInt(2)+2) {
case 0:
case 1:
this.playerModel.getModel().metadata.setRace(PonyRace.EARTH);
@ -64,7 +64,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
}
@Override
protected void rotateCorpse(Zombie zombie, float xPosition, float yPosition, float zPosition) {
protected void rotateCorpse(EntityZombie zombie, float xPosition, float yPosition, float zPosition) {
super.rotateCorpse(zombie, xPosition, yPosition, zPosition);
if (zombie.isConverting()) {
yPosition += (float) (Math.cos(zombie.ticksExisted * 3.25D) * Math.PI * 0.25D);
@ -72,10 +72,12 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
}
@Override
protected ResourceLocation getEntityTexture(Zombie zombie) {
return zombie instanceof EntityPigZombie ? PonyManager.PIGMAN
: (zombie.isVillager() ? PonyManager.ZOMBIE_VILLAGER
: PonyManager.ZOMBIE);
protected ResourceLocation getEntityTexture(EntityZombie zombie) {
ResourceLocation loc = PonyManager.ZOMBIES.get(zombie.getZombieType());
if (loc == null) {
loc = zombie.isVillager() ? PonyManager.ZOMBIE_VILLAGER : PonyManager.ZOMBIE;
}
return loc;
}
}

View file

@ -11,6 +11,8 @@ import net.minecraft.util.ResourceLocation;
public class LayerPonySkeletonOverlay extends LayerOverlayBase<EntitySkeleton> {
public static final ResourceLocation STRAY_SKELETON_OVERLAY = new ResourceLocation(PonyManager.NAMESPACE, "textures/entity/skeleton/stray_pony_overlay.png");
private final ModelSkeletonPony overlayModel;
public LayerPonySkeletonOverlay(RenderLivingBase<?> render) {
@ -33,6 +35,6 @@ public class LayerPonySkeletonOverlay extends LayerOverlayBase<EntitySkeleton> {
@Override
protected ResourceLocation getOverlayTexture() {
return PonyManager.STRAY_SKELETON_OVERLAY;
return STRAY_SKELETON_OVERLAY;
}
}

View file

@ -0,0 +1,149 @@
{
// Removes all of the previous resourcepack's ponies
"override": false,
// A list of all the pony names without the extension
// e.g. textures/entity/pony/bpony_12.png
"ponies": [
"bpony_0",
"bpony_1",
"bpony_2",
"bpony_3",
"bpony_4",
"bpony_5",
"bpony_6",
"bpony_7",
"bpony_8",
"bpony_9",
"bpony_10",
"bpony_11",
"bpony_12",
"bpony_13",
"bpony_14",
"bpony_15",
"bpony_16",
"bpony_17",
"bpony_18",
"bpony_19",
"bpony_20",
"bpony_21",
"bpony_22",
"bpony_23",
"bpony_24",
"bpony_25",
"bpony_26",
"bpony_27",
"bpony_28",
"bpony_29",
"bpony_30",
"bpony_31",
"bpony_32",
"bpony_33",
"bpony_34",
"bpony_35",
"bpony_36",
"bpony_37",
"bpony_38",
"bpony_39",
"bpony_40",
"bpony_41",
"bpony_42",
"bpony_43",
"bpony_44",
"bpony_45",
"bpony_46",
"bpony_47",
"bpony_48",
"bpony_49",
"bpony_50",
"bpony_51",
"bpony_52",
"bpony_53",
"bpony_54",
"bpony_55",
"bpony_56",
"bpony_57",
"bpony_58",
"bpony_59",
"bpony_60",
"bpony_61",
"bpony_62",
"bpony_63",
"bpony_64",
"bpony_65",
"bpony_66",
"bpony_67",
"bpony_68",
"bpony_69",
"bpony_70",
"bpony_71",
"bpony_72",
"bpony_73",
"bpony_74",
"bpony_75",
"bpony_76",
"bpony_77",
"bpony_78",
"bpony_79",
"bpony_80",
"bpony_81",
"bpony_82",
"bpony_83",
"bpony_84",
"bpony_85",
"bpony_86",
"bpony_87",
"bpony_88",
"bpony_89",
"bpony_90",
"bpony_91",
"bpony_92",
"bpony_93",
"bpony_94",
"bpony_95",
"bpony_96",
"bpony_97",
"bpony_98",
"bpony_99",
"bpony_100",
"bpony_101",
"bpony_102",
"bpony_103",
"bpony_104",
"bpony_105",
"bpony_106",
"bpony_107",
"bpony_108",
"bpony_109",
"bpony_110",
"bpony_111",
"bpony_112",
"bpony_113",
"bpony_114",
"bpony_115",
"bpony_116",
"bpony_117",
"bpony_118",
"bpony_119",
"bpony_120",
"bpony_121",
"bpony_122",
"bpony_123",
"bpony_124",
"bpony_125",
"bpony_126",
"bpony_127",
"bpony_128",
"bpony_129",
"bpony_130",
"bpony_131",
"bpony_132",
"bpony_133",
"bpony_134",
"bpony_135",
"bpony_136",
"bpony_137",
"bpony_138",
"bpony_139",
"bpony_140"
]
}

View file

@ -0,0 +1,20 @@
package com.brohoof.minelittlepony.test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.brohoof.minelittlepony.PonyManager;
import net.minecraft.entity.monster.ZombieType;
public class TestEnumMap {
@Test
public void testMapCompletion() {
int size = PonyManager.ZOMBIES.size();
assertEquals(size, ZombieType.values().length);
}
}