Move all HDSkins references to one place

This commit is contained in:
Sollace 2019-06-30 12:05:38 +02:00
parent b3be7a0b18
commit e960aad9d5
12 changed files with 95 additions and 56 deletions

View file

@ -8,17 +8,26 @@ import com.minelittlepony.client.settings.ClientPonyConfig;
import com.minelittlepony.common.client.IModUtilities; import com.minelittlepony.common.client.IModUtilities;
import com.minelittlepony.settings.JsonConfig; import com.minelittlepony.settings.JsonConfig;
import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.stream.Collectors;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen; import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.options.KeyBinding; import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.texture.PlayerSkinProvider;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
import net.minecraft.resource.ReloadableResourceManager; import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Style; import net.minecraft.text.Style;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.SystemUtil; import net.minecraft.util.SystemUtil;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@ -47,11 +56,15 @@ public class MineLPClient extends MineLittlePony {
public MineLPClient(IModUtilities utils) { public MineLPClient(IModUtilities utils) {
utilities = utils; utilities = utils;
config = JsonConfig.of(utils.getConfigDirectory().resolve("minelp.json"), ClientPonyConfig::new); config = JsonConfig.of(utils.getConfigDirectory().resolve("minelp.json"), this::createConfig);
ponyManager = new PonyManager(config); ponyManager = new PonyManager(config);
keyBinding = utilities.registerKeybind("key.categories.misc", "minelittlepony:settings", GLFW.GLFW_KEY_F9); keyBinding = utilities.registerKeybind("key.categories.misc", "minelittlepony:settings", GLFW.GLFW_KEY_F9);
} }
protected ClientPonyConfig createConfig() {
return new ClientPonyConfig();
}
/** /**
* Called when the game is ready. * Called when the game is ready.
*/ */
@ -100,6 +113,15 @@ public class MineLPClient extends MineLittlePony {
PonySkullRenderer.resolve(); PonySkullRenderer.resolve();
} }
public Map<MinecraftProfileTexture.Type, Identifier> getProfileTextures(@Nullable GameProfile profile) {
PlayerSkinProvider provider = MinecraftClient.getInstance().getSkinProvider();
return provider.getTextures(profile)
.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> {
return provider.loadSkin(entry.getValue(), entry.getKey());
}));
}
@Override @Override
public PonyManager getManager() { public PonyManager getManager() {
return ponyManager; return ponyManager;

View file

@ -4,8 +4,6 @@ import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.minelittlepony.client.gui.hdskins.DummyPony;
import com.minelittlepony.client.gui.hdskins.RenderDummyPony;
import com.minelittlepony.client.model.IPonyModel; import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.model.races.PlayerModels; import com.minelittlepony.client.model.races.PlayerModels;
import com.minelittlepony.client.render.LevitatingItemRenderer; import com.minelittlepony.client.render.LevitatingItemRenderer;
@ -47,9 +45,6 @@ public class PonyRenderManager {
* Registers all new player skin types. (currently only pony and slimpony). * Registers all new player skin types. (currently only pony and slimpony).
*/ */
public void initialiseRenderers(EntityRenderDispatcher manager) { public void initialiseRenderers(EntityRenderDispatcher manager) {
// Preview on the select skin gui
MineLPClient.getInstance().getModUtilities().addRenderer(DummyPony.class, RenderDummyPony::new);
PlayerModels[] models = PlayerModels.values(); PlayerModels[] models = PlayerModels.values();
for (int i = 1; i < models.length; i++) { for (int i = 1; i < models.length; i++) {

View file

@ -6,21 +6,15 @@ public class PonySkinModifier implements ISkinModifier {
@Override @Override
public void convertSkin(ISkinModifier.IDrawer drawer) { public void convertSkin(ISkinModifier.IDrawer drawer) {
// int scale = drawer.getImage().getWidth() / 64; int scale = drawer.getImage().getWidth() / 64;
// TODO: What are these numbers!? // TODO: What are these numbers!?
//top, mirror drawer.draw(scale, 60, 32, 58, 34, 58, 16, 60, 18, false, false); // top, mirror
// drawer.draw(scale, 60, 32, 58, 34, 58, 16, 60, 18, false, false); drawer.draw(scale, 62, 32, 60, 34, 60, 16, 62, 18, false, false); // bottom, mirror
//bottom, mirror drawer.draw(scale, 58, 34, 56, 48, 60, 18, 62, 32, false, false); // inside
// drawer.draw(scale, 62, 32, 60, 34, 60, 16, 62, 18, false, false); drawer.draw(scale, 60, 34, 58, 48, 58, 18, 60, 32, false, false); // back
//inside drawer.draw(scale, 62, 34, 60, 48, 56, 18, 58, 32, false, false); // outside
// drawer.draw(scale, 58, 34, 56, 48, 60, 18, 62, 32, false, false); drawer.draw(scale, 64, 34, 62, 48, 62, 18, 64, 32, false, false); // back
//back
// drawer.draw(scale, 60, 34, 58, 48, 58, 18, 60, 32, false, false);
//outside
// drawer.draw(scale, 62, 34, 60, 48, 56, 18, 58, 32, false, false);
//back
// drawer.draw(scale, 64, 34, 62, 48, 62, 18, 64, 32, false, false);
} }
} }

View file

@ -0,0 +1,19 @@
package com.minelittlepony.client.gui.hdskins;
import com.minelittlepony.client.settings.ClientPonyConfig;
import com.minelittlepony.hdskins.HDSkins;
import com.minelittlepony.settings.PonyLevel;
public class ClientPonyConfigHDSkins extends ClientPonyConfig {
@Override
public void setPonyLevel(PonyLevel ponylevel) {
// only trigger reloads when the value actually changes
if (ponylevel != getPonyLevel()) {
HDSkins.getInstance().parseSkins();
}
super.setPonyLevel(ponylevel);
}
}

View file

@ -1,21 +1,28 @@
package com.minelittlepony.client.gui.hdskins; package com.minelittlepony.client.gui.hdskins;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;
import com.minelittlepony.common.client.IModUtilities; import com.minelittlepony.common.client.IModUtilities;
import com.minelittlepony.client.MineLPClient; import com.minelittlepony.client.MineLPClient;
import com.minelittlepony.client.PonySkinModifier; import com.minelittlepony.client.PonySkinModifier;
import com.minelittlepony.client.PonySkinParser; import com.minelittlepony.client.settings.ClientPonyConfig;
import com.minelittlepony.hdskins.HDSkins; import com.minelittlepony.hdskins.HDSkins;
import com.minelittlepony.hdskins.ISkinCacheClearListener;
import com.minelittlepony.hdskins.net.LegacySkinServer; import com.minelittlepony.hdskins.net.LegacySkinServer;
import com.minelittlepony.hdskins.net.SkinServer; import com.minelittlepony.hdskins.net.SkinServer;
import com.minelittlepony.hdskins.net.ValhallaSkinServer; import com.minelittlepony.hdskins.net.ValhallaSkinServer;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import javax.annotation.Nullable;
import java.util.Map;
/** /**
* All the interactions with HD Skins. * All the interactions with HD Skins.
*/ */
public class MineLPHDSkins extends MineLPClient { public class MineLPHDSkins extends MineLPClient implements ISkinCacheClearListener {
private static final String MINELP_VALHALLA_SERVER = "http://skins.minelittlepony-mod.com"; private static final String MINELP_VALHALLA_SERVER = "http://skins.minelittlepony-mod.com";
private static final String MINELP_LEGACY_SERVER = "http://minelpskins.voxelmodpack.com"; private static final String MINELP_LEGACY_SERVER = "http://minelpskins.voxelmodpack.com";
@ -35,6 +42,12 @@ public class MineLPHDSkins extends MineLPClient {
SkinServer.defaultServers.add(0, valhalla); SkinServer.defaultServers.add(0, valhalla);
} }
@Override
public boolean onSkinCacheCleared() {
getManager().clearCache();
return true;
}
/** /**
* Called when the game is ready. * Called when the game is ready.
*/ */
@ -42,6 +55,9 @@ public class MineLPHDSkins extends MineLPClient {
public void postInit(MinecraftClient minecraft) { public void postInit(MinecraftClient minecraft) {
super.postInit(minecraft); super.postInit(minecraft);
// Preview on the select skin gui
getModUtilities().addRenderer(DummyPony.class, RenderDummyPony::new);
HDSkins manager = HDSkins.getInstance(); HDSkins manager = HDSkins.getInstance();
// Convert legacy pony skins // Convert legacy pony skins
@ -49,8 +65,18 @@ public class MineLPHDSkins extends MineLPClient {
// Parse trigger pixel data // Parse trigger pixel data
manager.addSkinParser(new PonySkinParser()); manager.addSkinParser(new PonySkinParser());
// Clear ponies when skins are cleared // Clear ponies when skins are cleared
manager.addClearListener(getManager()); manager.addClearListener(this);
// Ponify the skins GUI. // Ponify the skins GUI.
manager.setSkinsGui(GuiSkinsMineLP::new); manager.setSkinsGui(GuiSkinsMineLP::new);
} }
@Override
protected ClientPonyConfig createConfig() {
return new ClientPonyConfigHDSkins();
}
@Override
public Map<MinecraftProfileTexture.Type, Identifier> getProfileTextures(@Nullable GameProfile profile) {
return HDSkins.getInstance().getTextures(profile);
}
} }

View file

@ -1,4 +1,4 @@
package com.minelittlepony.client; package com.minelittlepony.client.gui.hdskins;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.model.races.PlayerModels; import com.minelittlepony.client.model.races.PlayerModels;

View file

@ -5,7 +5,6 @@ import com.minelittlepony.client.model.ModelWrapper;
import com.minelittlepony.client.model.entities.ModelSeapony; import com.minelittlepony.client.model.entities.ModelSeapony;
import com.minelittlepony.client.render.entities.player.RenderPonyPlayer; import com.minelittlepony.client.render.entities.player.RenderPonyPlayer;
import com.minelittlepony.client.render.entities.player.RenderSeaponyPlayer; import com.minelittlepony.client.render.entities.player.RenderSeaponyPlayer;
import com.minelittlepony.hdskins.VanillaModels;
import com.minelittlepony.model.IModel; import com.minelittlepony.model.IModel;
import com.minelittlepony.pony.meta.Race; import com.minelittlepony.pony.meta.Race;
@ -21,7 +20,7 @@ public enum PlayerModels {
/** /**
* The default non-pony model. This is typically handled my the vanilla renderer. * The default non-pony model. This is typically handled my the vanilla renderer.
*/ */
DEFAULT(VanillaModels.DEFAULT, VanillaModels.SLIM, Race.HUMAN, ModelEarthPony::new), DEFAULT("default", "slim", Race.HUMAN, ModelEarthPony::new),
EARTHPONY(Race.EARTH, ModelEarthPony::new), EARTHPONY(Race.EARTH, ModelEarthPony::new),
PEGASUS(Race.PEGASUS, ModelPegasus::new), PEGASUS(Race.PEGASUS, ModelPegasus::new),
BATPONY(Race.BATPONY, ModelBatpony::new), BATPONY(Race.BATPONY, ModelBatpony::new),
@ -53,7 +52,7 @@ public enum PlayerModels {
PlayerModels(Race race, Function<Boolean, IModel> resolver) { PlayerModels(Race race, Function<Boolean, IModel> resolver) {
normal = new PendingModel(name().toLowerCase()); normal = new PendingModel(name().toLowerCase());
slim = new PendingModel(VanillaModels.SLIM + normal.key); slim = new PendingModel("slim" + normal.key);
this.resolver = resolver; this.resolver = resolver;

View file

@ -6,7 +6,6 @@ import com.minelittlepony.client.PonyRenderManager;
import com.minelittlepony.client.ducks.IBufferedTexture; import com.minelittlepony.client.ducks.IBufferedTexture;
import com.minelittlepony.client.render.IPonyRender; import com.minelittlepony.client.render.IPonyRender;
import com.minelittlepony.client.transform.PonyTransformation; import com.minelittlepony.client.transform.PonyTransformation;
import com.minelittlepony.hdskins.util.ProfileTextureUtil;
import com.minelittlepony.pony.IPony; import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.IPonyData; import com.minelittlepony.pony.IPonyData;
import com.minelittlepony.pony.meta.Race; import com.minelittlepony.pony.meta.Race;
@ -62,7 +61,8 @@ public class Pony implements IPony {
NativeImage ponyTexture = getBufferedImage(resource); NativeImage ponyTexture = getBufferedImage(resource);
if (ponyTexture == null) { if (ponyTexture == null) {
ponyTexture = ProfileTextureUtil.getDynamicBufferedImage(16, 16, MissingSprite.getMissingSpriteTexture()); ponyTexture = new NativeImage(16, 16, true);
ponyTexture.copyFrom(MissingSprite.getMissingSpriteTexture().getImage());
MinecraftClient.getInstance().getTextureManager().registerTexture(resource, new NativeImageBackedTexture(ponyTexture)); MinecraftClient.getInstance().getTextureManager().registerTexture(resource, new NativeImageBackedTexture(ponyTexture));
} }

View file

@ -8,7 +8,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.common.util.MoreStreams; import com.minelittlepony.common.util.MoreStreams;
import com.minelittlepony.hdskins.ISkinCacheClearListener;
import com.minelittlepony.pony.IPony; import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.IPonyManager; import com.minelittlepony.pony.IPonyManager;
import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyConfig;
@ -44,7 +43,7 @@ import java.util.concurrent.TimeUnit;
* The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin. * The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin.
* *
*/ */
public class PonyManager implements IPonyManager, ResourceReloadListener, ISkinCacheClearListener { public class PonyManager implements IPonyManager, ResourceReloadListener {
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
@ -159,6 +158,11 @@ public class PonyManager implements IPonyManager, ResourceReloadListener, ISkinC
}, clientExecutor); }, clientExecutor);
} }
public void clearCache() {
MineLittlePony.logger.info("Flushed {} cached ponies.", poniesCache.size());
poniesCache.invalidateAll();
}
public void reloadAll(ResourceManager resourceManager) { public void reloadAll(ResourceManager resourceManager) {
poniesCache.invalidateAll(); poniesCache.invalidateAll();
backgroundPonyList.clear(); backgroundPonyList.clear();
@ -253,11 +257,4 @@ public class PonyManager implements IPonyManager, ResourceReloadListener, ISkinC
return MoreStreams.map(imports, this::makeImport); return MoreStreams.map(imports, this::makeImport);
} }
} }
@Override
public boolean onSkinCacheCleared() {
MineLittlePony.logger.info("Flushed {} cached ponies.", poniesCache.size());
poniesCache.invalidateAll();
return true;
}
} }

View file

@ -14,7 +14,6 @@ import com.minelittlepony.client.render.layer.LayerPonyArmor;
import com.minelittlepony.client.render.layer.LayerPonyCustomHead; import com.minelittlepony.client.render.layer.LayerPonyCustomHead;
import com.minelittlepony.client.render.layer.LayerPonyElytra; import com.minelittlepony.client.render.layer.LayerPonyElytra;
import com.minelittlepony.client.util.render.PonyRenderer; import com.minelittlepony.client.util.render.PonyRenderer;
import com.minelittlepony.hdskins.HDSkins;
import com.minelittlepony.model.IUnicorn; import com.minelittlepony.model.IUnicorn;
import com.minelittlepony.pony.IPony; import com.minelittlepony.pony.IPony;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
@ -106,7 +105,7 @@ public abstract class RenderPonyMob<T extends MobEntity, M extends EntityModel<T
@Override @Override
@Nonnull @Nonnull
public final Identifier getTexture(T entity) { public final Identifier getTexture(T entity) {
return HDSkins.getInstance().getConvertedSkin(findTexture(entity)); return findTexture(entity);
} }
@Override @Override
@ -134,7 +133,7 @@ public abstract class RenderPonyMob<T extends MobEntity, M extends EntityModel<T
public abstract static class Proxy<T extends MobEntity, M extends EntityModel<T> & IPonyModel<T>> extends RenderPonyMob<T, M> { public abstract static class Proxy<T extends MobEntity, M extends EntityModel<T> & IPonyModel<T>> extends RenderPonyMob<T, M> {
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public Proxy(List exportedLayers, EntityRenderDispatcher manager, M model) { public Proxy(List exportedLayers, EntityRenderDispatcher manager, M model) {
super(manager, model); super(manager, model);
exportedLayers.addAll(features); exportedLayers.addAll(features);

View file

@ -1,9 +1,9 @@
package com.minelittlepony.client.render.tileentities.skull; package com.minelittlepony.client.render.tileentities.skull;
import com.minelittlepony.client.MineLPClient;
import com.minelittlepony.client.model.components.ModelDeadMau5Ears; import com.minelittlepony.client.model.components.ModelDeadMau5Ears;
import com.minelittlepony.client.pony.Pony; import com.minelittlepony.client.pony.Pony;
import com.minelittlepony.client.render.RenderPony; import com.minelittlepony.client.render.RenderPony;
import com.minelittlepony.hdskins.HDSkins;
import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel; import com.minelittlepony.settings.PonyLevel;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
@ -43,7 +43,7 @@ public class PlayerSkullRenderer extends PonySkull {
deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName())); deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName()));
if (profile != null) { if (profile != null) {
Identifier skin = HDSkins.getInstance().getTextures(profile).get(Type.SKIN); Identifier skin = MineLPClient.getInstance().getProfileTextures(profile).get(Type.SKIN);
if (skin != null && Pony.getBufferedImage(skin) != null) { if (skin != null && Pony.getBufferedImage(skin) != null) {
return skin; return skin;
} }

View file

@ -4,9 +4,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import com.minelittlepony.client.render.entities.MobRenderers; import com.minelittlepony.client.render.entities.MobRenderers;
import com.minelittlepony.hdskins.HDSkins;
import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
public class ClientPonyConfig extends PonyConfig { public class ClientPonyConfig extends PonyConfig {
@ -14,16 +12,6 @@ public class ClientPonyConfig extends PonyConfig {
initWith(MobRenderers.values()); initWith(MobRenderers.values());
} }
@Override
public void setPonyLevel(PonyLevel ponylevel) {
// only trigger reloads when the value actually changes
if (ponylevel != getPonyLevel()) {
HDSkins.getInstance().parseSkins();
}
super.setPonyLevel(ponylevel);
}
@Override @Override
public void save() { public void save() {
super.save(); super.save();