From edc70b302e814fc2f785bf7005e60e08d5dbf2c9 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 23 Mar 2019 20:17:46 +0200 Subject: [PATCH] Further decouple client/common code --- .../minelittlepony/LiteModMineLittlePony.java | 10 ++- ...{MineLittlePony.java => MineLPClient.java} | 41 +++------- .../com/minelittlepony/PonyRenderManager.java | 9 +++ .../minelittlepony/gui/GuiPonySettings.java | 2 +- .../hdskins/gui/GuiSkinsMineLP.java | 4 +- .../mixin/MixinDefaultPlayerSkin.java | 16 ++-- .../mixin/MixinItemRenderer.java | 4 +- .../minelittlepony/model/ModelWrapper.java | 2 +- .../model/components/PonySnout.java | 2 +- .../com/minelittlepony/pony/data/Pony.java | 5 +- .../minelittlepony/pony/data/PonyManager.java | 78 ++++++------------- .../minelittlepony/pony/data/PonyRace.java | 5 +- .../render/LevitatingItemRenderer.java | 2 +- .../com/minelittlepony/render/RenderPony.java | 5 +- .../layer/LayerHeldPonyItemMagical.java | 4 +- .../render/ponies/MobRenderers.java | 2 +- .../render/skull/PonySkullRenderer.java | 4 +- .../com/minelittlepony/MineLittlePony.java | 43 ++++++++++ .../pony/data/IPonyManager.java | 77 ++++++++++++++++++ .../minelittlepony/pony/data/PonySize.java | 6 +- 20 files changed, 200 insertions(+), 121 deletions(-) rename src/client/java/com/minelittlepony/{MineLittlePony.java => MineLPClient.java} (82%) create mode 100644 src/common/java/com/minelittlepony/MineLittlePony.java create mode 100644 src/common/java/com/minelittlepony/pony/data/IPonyManager.java diff --git a/src/client/java/com/minelittlepony/LiteModMineLittlePony.java b/src/client/java/com/minelittlepony/LiteModMineLittlePony.java index 06f1b250..e1e7b9c8 100644 --- a/src/client/java/com/minelittlepony/LiteModMineLittlePony.java +++ b/src/client/java/com/minelittlepony/LiteModMineLittlePony.java @@ -16,6 +16,8 @@ import java.io.File; public class LiteModMineLittlePony implements InitCompleteListener, Tickable, Configurable { + private final MineLPClient mlp = new MineLPClient(); + @Override public String getName() { return MineLittlePony.MOD_NAME; @@ -34,20 +36,20 @@ public class LiteModMineLittlePony implements InitCompleteListener, Tickable, Co public void init(File configPath) { Config config = new Config(); - MineLittlePony.getInstance().init(config); + mlp.init(config); - LiteLoader.getInput().registerKeyBinding(MineLittlePony.SETTINGS_GUI); + LiteLoader.getInput().registerKeyBinding(MineLPClient.SETTINGS_GUI); LiteLoader.getInstance().registerExposable(config, null); } @Override public void onInitCompleted(Minecraft minecraft, LiteLoader loader) { - MineLittlePony.getInstance().postInit(minecraft); + mlp.postInit(minecraft); } @Override public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock) { - MineLittlePony.getInstance().onTick(minecraft, inGame); + mlp.onTick(minecraft, inGame); } @Override diff --git a/src/client/java/com/minelittlepony/MineLittlePony.java b/src/client/java/com/minelittlepony/MineLPClient.java similarity index 82% rename from src/client/java/com/minelittlepony/MineLittlePony.java rename to src/client/java/com/minelittlepony/MineLPClient.java index 092713bd..c6bac6d7 100644 --- a/src/client/java/com/minelittlepony/MineLittlePony.java +++ b/src/client/java/com/minelittlepony/MineLPClient.java @@ -21,19 +21,12 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextFormatting; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; /** * Static MineLittlePony singleton class. Everything's controlled from up here. */ -public class MineLittlePony { - - public static final Logger logger = LogManager.getLogger("MineLittlePony"); - - public static final String MOD_NAME = "Mine Little Pony"; - public static final String MOD_VERSION = "@VERSION@"; +public class MineLPClient extends MineLittlePony { private static final String MINELP_VALHALLA_SERVER = "http://skins.minelittlepony-mod.com"; private static final String MINELP_LEGACY_SERVER = "http://minelpskins.voxelmodpack.com"; @@ -41,15 +34,13 @@ public class MineLittlePony { static final KeyBinding SETTINGS_GUI = new KeyBinding("Settings", Keyboard.KEY_F9, "Mine Little Pony"); - private static final MineLittlePony instance = new MineLittlePony(); - private static int modelUpdateCounter = 0; private static boolean reloadingModels = false; private PonyConfig config; private PonyManager ponyManager; - private final PonyRenderManager renderManager = new PonyRenderManager(); + private final PonyRenderManager renderManager = PonyRenderManager.getInstance(); void init(PonyConfig newConfig) { config = newConfig; @@ -82,6 +73,7 @@ public class MineLittlePony { manager.setSkinsGui(GuiSkinsMineLP::new); RenderManager rm = minecraft.getRenderManager(); + renderManager.initialisePlayerRenderers(rm); renderManager.initializeMobRenderers(rm, config); } @@ -115,36 +107,21 @@ public class MineLittlePony { PonySkullRenderer.resolve(); } - - /** - * Gets the global MineLP instance. - */ - public static MineLittlePony getInstance() { - return MineLittlePony.instance; - } - - /** - * Gets the static pony manager instance. - */ + @Override public PonyManager getManager() { return ponyManager; } - /** - * Gets the static pony render manager responsible for all entity renderers. - */ - public PonyRenderManager getRenderManager() { - return renderManager; - } - - public static int getModelRevisionNumber() { + @Override + public int getModelRevisionNumber() { return modelUpdateCounter; } /** * Gets the global MineLP client configuration. */ - public static PonyConfig getConfig() { - return getInstance().config; + @Override + public PonyConfig getConfig() { + return config; } } diff --git a/src/client/java/com/minelittlepony/PonyRenderManager.java b/src/client/java/com/minelittlepony/PonyRenderManager.java index 318cc2dd..5340753b 100644 --- a/src/client/java/com/minelittlepony/PonyRenderManager.java +++ b/src/client/java/com/minelittlepony/PonyRenderManager.java @@ -28,6 +28,15 @@ import net.minecraft.entity.EntityLivingBase; */ public class PonyRenderManager { + private static final PonyRenderManager renderManager = new PonyRenderManager(); + + /** + * Gets the static pony render manager responsible for all entity renderers. + */ + public static PonyRenderManager getInstance() { + return renderManager; + } + private LevitatingItemRenderer magicRenderer = new LevitatingItemRenderer(); diff --git a/src/client/java/com/minelittlepony/gui/GuiPonySettings.java b/src/client/java/com/minelittlepony/gui/GuiPonySettings.java index 3edf3346..271889d7 100644 --- a/src/client/java/com/minelittlepony/gui/GuiPonySettings.java +++ b/src/client/java/com/minelittlepony/gui/GuiPonySettings.java @@ -21,7 +21,7 @@ public class GuiPonySettings extends SettingsPanel { private PonyConfig config; public GuiPonySettings() { - config = MineLittlePony.getConfig(); + config = MineLittlePony.getInstance().getConfig(); } @Override diff --git a/src/client/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java b/src/client/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java index f36ef107..40b9e259 100644 --- a/src/client/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java +++ b/src/client/java/com/minelittlepony/hdskins/gui/GuiSkinsMineLP.java @@ -3,7 +3,7 @@ package com.minelittlepony.hdskins.gui; import com.minelittlepony.MineLittlePony; import com.minelittlepony.gui.IconicToggle; import com.minelittlepony.gui.Style; -import com.minelittlepony.pony.data.PonyManager; +import com.minelittlepony.pony.data.IPonyManager; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; @@ -23,7 +23,7 @@ import java.util.List; */ public class GuiSkinsMineLP extends GuiSkins { - private PonyManager ponyManager = MineLittlePony.getInstance().getManager(); + private IPonyManager ponyManager = MineLittlePony.getInstance().getManager(); private boolean isWet = false; diff --git a/src/client/java/com/minelittlepony/mixin/MixinDefaultPlayerSkin.java b/src/client/java/com/minelittlepony/mixin/MixinDefaultPlayerSkin.java index bc5af1ac..62414a7e 100644 --- a/src/client/java/com/minelittlepony/mixin/MixinDefaultPlayerSkin.java +++ b/src/client/java/com/minelittlepony/mixin/MixinDefaultPlayerSkin.java @@ -1,8 +1,8 @@ package com.minelittlepony.mixin; import com.minelittlepony.MineLittlePony; +import com.minelittlepony.pony.data.IPonyManager; import com.minelittlepony.pony.data.PonyLevel; -import com.minelittlepony.pony.data.PonyManager; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.util.ResourceLocation; @@ -18,27 +18,27 @@ public abstract class MixinDefaultPlayerSkin { @Inject(method = "getDefaultSkinLegacy", at = @At("HEAD"), cancellable = true) private static void legacySkin(CallbackInfoReturnable cir) { - if (MineLittlePony.getConfig().getPonyLevel() == PonyLevel.PONIES) { - cir.setReturnValue(PonyManager.STEVE); + if (MineLittlePony.getInstance().getConfig().getPonyLevel() == PonyLevel.PONIES) { + cir.setReturnValue(IPonyManager.STEVE); } } @Inject(method = "getDefaultSkin", at = @At("HEAD"), cancellable = true) private static void defaultSkin(UUID uuid, CallbackInfoReturnable cir) { - if (MineLittlePony.getConfig().getPonyLevel() == PonyLevel.PONIES) { - cir.setReturnValue(PonyManager.getDefaultSkin(uuid)); + if (MineLittlePony.getInstance().getConfig().getPonyLevel() == PonyLevel.PONIES) { + cir.setReturnValue(IPonyManager.getDefaultSkin(uuid)); } } @Inject(method = "getSkinType", at = @At("HEAD"), cancellable = true) private static void skinType(UUID uuid, CallbackInfoReturnable cir) { - if (MineLittlePony.getConfig().getPonyLevel() == PonyLevel.PONIES) { + if (MineLittlePony.getInstance().getConfig().getPonyLevel() == PonyLevel.PONIES) { cir.setReturnValue(MineLittlePony.getInstance().getManager() - .getPony(PonyManager.getDefaultSkin(uuid), uuid) + .getPony(IPonyManager.getDefaultSkin(uuid), uuid) .getRace(false) .getModel() - .getId(PonyManager.isSlimSkin(uuid))); + .getId(IPonyManager.isSlimSkin(uuid))); } } diff --git a/src/client/java/com/minelittlepony/mixin/MixinItemRenderer.java b/src/client/java/com/minelittlepony/mixin/MixinItemRenderer.java index 72f53464..cd82d98d 100644 --- a/src/client/java/com/minelittlepony/mixin/MixinItemRenderer.java +++ b/src/client/java/com/minelittlepony/mixin/MixinItemRenderer.java @@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import com.minelittlepony.MineLittlePony; +import com.minelittlepony.PonyRenderManager; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.ItemRenderer; @@ -27,6 +27,6 @@ public class MixinItemRenderer { at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ItemRenderer;renderItemSide(" + EntityLivingBase + ItemStack + TransformType + "Z)V")) private void redirectRenderItemSide(ItemRenderer self, EntityLivingBase entity, ItemStack stack, TransformType transform, boolean left) { - MineLittlePony.getInstance().getRenderManager().getMagicRenderer().renderItemInFirstPerson(self, (AbstractClientPlayer)entity, stack, transform, left); + PonyRenderManager.getInstance().getMagicRenderer().renderItemInFirstPerson(self, (AbstractClientPlayer)entity, stack, transform, left); } } diff --git a/src/client/java/com/minelittlepony/model/ModelWrapper.java b/src/client/java/com/minelittlepony/model/ModelWrapper.java index 5d7e3241..ea91436a 100644 --- a/src/client/java/com/minelittlepony/model/ModelWrapper.java +++ b/src/client/java/com/minelittlepony/model/ModelWrapper.java @@ -44,7 +44,7 @@ public class ModelWrapper implements IModelWrapper { @Override public void apply(IPonyData meta) { - int modelRevision = MineLittlePony.getModelRevisionNumber(); + int modelRevision = MineLittlePony.getInstance().getModelRevisionNumber(); if (modelRevision != lastModelUpdate) { lastModelUpdate = modelRevision; diff --git a/src/client/java/com/minelittlepony/model/components/PonySnout.java b/src/client/java/com/minelittlepony/model/components/PonySnout.java index d6f9d009..bf5602fd 100644 --- a/src/client/java/com/minelittlepony/model/components/PonySnout.java +++ b/src/client/java/com/minelittlepony/model/components/PonySnout.java @@ -59,7 +59,7 @@ public class PonySnout { } public void setGender(PonyGender gender) { - boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getConfig().snuzzles; + boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getInstance().getConfig().snuzzles; mare.isHidden = !(show && gender.isMare()); stallion.isHidden = !(show && gender.isStallion()); diff --git a/src/client/java/com/minelittlepony/pony/data/Pony.java b/src/client/java/com/minelittlepony/pony/data/Pony.java index bd4edd36..f3d54d22 100644 --- a/src/client/java/com/minelittlepony/pony/data/Pony.java +++ b/src/client/java/com/minelittlepony/pony/data/Pony.java @@ -2,6 +2,7 @@ package com.minelittlepony.pony.data; import com.google.common.base.MoreObjects; import com.minelittlepony.MineLittlePony; +import com.minelittlepony.PonyRenderManager; import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.util.chron.Touchable; import com.voxelmodpack.hdskins.resources.texture.DynamicTextureImage; @@ -190,14 +191,14 @@ public class Pony extends Touchable implements IPony { @Override public boolean isRidingInteractive(EntityLivingBase entity) { - return MineLittlePony.getInstance().getRenderManager().getPonyRenderer(entity.getRidingEntity()) != null; + return PonyRenderManager.getInstance().getPonyRenderer(entity.getRidingEntity()) != null; } @Override public IPony getMountedPony(EntityLivingBase entity) { Entity mount = entity.getRidingEntity(); - IRenderPony render = MineLittlePony.getInstance().getRenderManager().getPonyRenderer(mount); + IRenderPony render = PonyRenderManager.getInstance().getPonyRenderer(mount); return render == null ? null : render.getEntityPony((EntityLivingBase)mount); } diff --git a/src/client/java/com/minelittlepony/pony/data/PonyManager.java b/src/client/java/com/minelittlepony/pony/data/PonyManager.java index 139d44bf..5bcc3ab3 100644 --- a/src/client/java/com/minelittlepony/pony/data/PonyManager.java +++ b/src/client/java/com/minelittlepony/pony/data/PonyManager.java @@ -10,6 +10,8 @@ import com.minelittlepony.util.math.MathUtil; import com.voxelmodpack.hdskins.ISkinCacheClearListener; import com.voxelmodpack.hdskins.util.MoreStreams; +import javax.annotation.Nullable; + import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.network.NetworkPlayerInfo; @@ -17,6 +19,7 @@ import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import java.io.IOException; @@ -32,12 +35,7 @@ import java.util.UUID; * The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin. * */ -public class PonyManager implements IResourceManagerReloadListener, ISkinCacheClearListener { - - public static final ResourceLocation STEVE = new ResourceLocation("minelittlepony", "textures/entity/steve_pony.png"); - public static final ResourceLocation ALEX = new ResourceLocation("minelittlepony", "textures/entity/alex_pony.png"); - - public static final String BGPONIES_JSON = "textures/entity/pony/bgponies.json"; +public class PonyManager implements IPonyManager, IResourceManagerReloadListener, ISkinCacheClearListener { private static final Gson GSON = new Gson(); @@ -54,23 +52,14 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl this.config = config; } - /** - * Gets or creates a pony for the given skin resource and vanilla model type. - * - * @param resource A texture resource - */ + @Override public IPony getPony(ResourceLocation resource) { return poniesCache.retrieve(resource, Pony::new); } - /** - * Gets or creates a pony for the given player. - * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. - * - * @param player the player - */ - public IPony getPony(AbstractClientPlayer player) { - ResourceLocation skin = player.getLocationSkin(); + @Override + public IPony getPony(EntityPlayer player) { + ResourceLocation skin = getSkin(player); UUID uuid = player.getGameProfile().getId(); if (Pony.getBufferedImage(skin) == null) { @@ -80,6 +69,15 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return getPony(skin, uuid); } + @Nullable + ResourceLocation getSkin(EntityPlayer player) { + if (player instanceof AbstractClientPlayer) { + return ((AbstractClientPlayer)player).getLocationSkin(); + } + + return null; + } + public IPony getPony(NetworkPlayerInfo playerInfo) { ResourceLocation skin = playerInfo.getLocationSkin(); UUID uuid = playerInfo.getGameProfile().getId(); @@ -91,16 +89,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return getPony(skin, uuid); } - /** - * Gets or creates a pony for the given skin resource and entity id. - * - * Whether is has slim arms is determined by the id. - * - * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. - * - * @param resource A texture resource - * @param uuid id of a player or entity - */ + @Override public IPony getPony(ResourceLocation resource, UUID uuid) { IPony pony = getPony(resource); @@ -111,11 +100,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return pony; } - /** - * Gets the default pony. Either STEVE/ALEX, or a background pony based on client settings. - * - * @param uuid id of a player or entity - */ + @Override public IPony getDefaultPony(UUID uuid) { if (config.getPonyLevel() != PonyLevel.PONIES) { return getPony(DefaultPlayerSkin.getDefaultSkin(uuid)); @@ -124,16 +109,10 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return getBackgroundPony(uuid); } - /** - * Gets a random background pony determined by the given uuid. - * - * Useful for mods that offer customisation, especially ones that have a whole lot of NPCs. - * - * @param uuid A UUID. Either a user or an entity. - */ + @Override public IPony getBackgroundPony(UUID uuid) { if (getNumberOfPonies() == 0 || isUser(uuid)) { - return getPony(getDefaultSkin(uuid)); + return getPony(IPonyManager.getDefaultSkin(uuid)); } int bgi = MathUtil.mod(uuid.hashCode(), getNumberOfPonies()); @@ -145,9 +124,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return Minecraft.getMinecraft().player != null && Minecraft.getMinecraft().player.getUniqueID().equals(uuid); } - /** - * De-registers a pony from the cache. - */ + @Override public IPony removePony(ResourceLocation resource) { return poniesCache.remove(resource); } @@ -216,17 +193,6 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl return collectedPonies; } - public static ResourceLocation getDefaultSkin(UUID uuid) { - return isSlimSkin(uuid) ? ALEX : STEVE; - } - - /** - * Returns true if the given uuid is of a player would would use the ALEX skin type. - */ - public static boolean isSlimSkin(UUID uuid) { - return (uuid.hashCode() & 1) == 1; - } - private int getNumberOfPonies() { return backgroundPonyList.size(); } diff --git a/src/client/java/com/minelittlepony/pony/data/PonyRace.java b/src/client/java/com/minelittlepony/pony/data/PonyRace.java index b820c199..dd1cb966 100644 --- a/src/client/java/com/minelittlepony/pony/data/PonyRace.java +++ b/src/client/java/com/minelittlepony/pony/data/PonyRace.java @@ -69,7 +69,10 @@ public enum PonyRace implements ITriggerPixelMapped { * PonyLevel.PONIES (should) return a pony if this is a human. Don't be fooled, though. It doesn't. */ public PonyRace getEffectiveRace(boolean ignorePony) { - if (MineLittlePony.getConfig().getEffectivePonyLevel(ignorePony) == PonyLevel.HUMANS) return HUMAN; + if (MineLittlePony.getInstance().getConfig().getEffectivePonyLevel(ignorePony) == PonyLevel.HUMANS) { + return HUMAN; + } + return this; } diff --git a/src/client/java/com/minelittlepony/render/LevitatingItemRenderer.java b/src/client/java/com/minelittlepony/render/LevitatingItemRenderer.java index 4cd291f4..b943d4b8 100644 --- a/src/client/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/client/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -75,7 +75,7 @@ public class LevitatingItemRenderer { pushMatrix(); - boolean doMagic = MineLittlePony.getConfig().fpsmagic && pony.getMetadata().hasMagic(); + boolean doMagic = MineLittlePony.getInstance().getConfig().fpsmagic && pony.getMetadata().hasMagic(); if (doMagic) { setupPerspective(entity, stack, left); diff --git a/src/client/java/com/minelittlepony/render/RenderPony.java b/src/client/java/com/minelittlepony/render/RenderPony.java index 319eca1a..3256cda4 100644 --- a/src/client/java/com/minelittlepony/render/RenderPony.java +++ b/src/client/java/com/minelittlepony/render/RenderPony.java @@ -1,6 +1,7 @@ package com.minelittlepony.render; import com.minelittlepony.MineLittlePony; +import com.minelittlepony.PonyRenderManager; import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.ModelWrapper; @@ -40,7 +41,7 @@ public class RenderPony { } public ICamera getFrustrum(T entity, ICamera vanilla) { - if (entity.isPlayerSleeping() || !MineLittlePony.getConfig().frustrum) { + if (entity.isPlayerSleeping() || !MineLittlePony.getInstance().getConfig().frustrum) { return vanilla; } return frustrum.withCamera(entity, vanilla); @@ -74,7 +75,7 @@ public class RenderPony { Entity ridingEntity = entity.getRidingEntity(); if (ridingEntity instanceof EntityLivingBase) { - IRenderPony renderer = MineLittlePony.getInstance().getRenderManager().getPonyRenderer((EntityLivingBase)ridingEntity); + IRenderPony renderer = PonyRenderManager.getInstance().getPonyRenderer((EntityLivingBase)ridingEntity); if (renderer != null) { // negate vanilla translations so the rider begins at the ridees feet. diff --git a/src/client/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java b/src/client/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java index dddc71c1..78fc5537 100644 --- a/src/client/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java +++ b/src/client/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java @@ -1,6 +1,6 @@ package com.minelittlepony.render.layer; -import com.minelittlepony.MineLittlePony; +import com.minelittlepony.PonyRenderManager; import com.minelittlepony.model.capabilities.IModelUnicorn; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; @@ -31,7 +31,7 @@ public class LayerHeldPonyItemMagical extends LayerH @Override protected void postItemRender(T entity, ItemStack drop, TransformType transform, EnumHandSide hand) { if (isUnicorn()) { - MineLittlePony.getInstance().getRenderManager().getMagicRenderer().renderItemGlow(entity, drop, transform, hand, this.getPonyModel().getMagicColor()); + PonyRenderManager.getInstance().getMagicRenderer().renderItemGlow(entity, drop, transform, hand, this.getPonyModel().getMagicColor()); } } diff --git a/src/client/java/com/minelittlepony/render/ponies/MobRenderers.java b/src/client/java/com/minelittlepony/render/ponies/MobRenderers.java index 886922b5..c23610a5 100644 --- a/src/client/java/com/minelittlepony/render/ponies/MobRenderers.java +++ b/src/client/java/com/minelittlepony/render/ponies/MobRenderers.java @@ -71,7 +71,7 @@ public enum MobRenderers implements Setting { @Override public void set(boolean value) { Setting.super.set(value); - apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager()); + apply(PonyRenderManager.getInstance(), Minecraft.getMinecraft().getRenderManager()); } public void apply(PonyRenderManager pony, RenderManager manager) { diff --git a/src/client/java/com/minelittlepony/render/skull/PonySkullRenderer.java b/src/client/java/com/minelittlepony/render/skull/PonySkullRenderer.java index 791aefa5..b11ec7b7 100644 --- a/src/client/java/com/minelittlepony/render/skull/PonySkullRenderer.java +++ b/src/client/java/com/minelittlepony/render/skull/PonySkullRenderer.java @@ -48,7 +48,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende * Original/Existing renderer is stored to a backup variable as a fallback in case of mods. */ public static TileEntitySkullRenderer resolve() { - if (MineLittlePony.getConfig().ponyskulls) { + if (MineLittlePony.getInstance().getConfig().ponyskulls) { if (!(instance instanceof PonySkullRenderer)) { backup = instance; ModUtilities.addRenderer(TileEntitySkull.class, ponyInstance); @@ -75,7 +75,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende ISkull skull = skullMap.get(skullType); - if (skull == null || !skull.canRender(MineLittlePony.getConfig())) { + if (skull == null || !skull.canRender(MineLittlePony.getInstance().getConfig())) { if (backup != null) { backup.renderSkull(x, y, z, facing, rotation, skullType, profile, destroyStage, animateTicks); } else { diff --git a/src/common/java/com/minelittlepony/MineLittlePony.java b/src/common/java/com/minelittlepony/MineLittlePony.java new file mode 100644 index 00000000..e337e878 --- /dev/null +++ b/src/common/java/com/minelittlepony/MineLittlePony.java @@ -0,0 +1,43 @@ +package com.minelittlepony; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.minelittlepony.pony.data.IPonyManager; + +public abstract class MineLittlePony { + + private static MineLittlePony instance; + + public static final Logger logger = LogManager.getLogger("MineLittlePony"); + + public static final String MOD_NAME = "Mine Little Pony"; + public static final String MOD_VERSION = "@VERSION@"; + + MineLittlePony() { + instance = this; + } + + /** + * Gets the global MineLP instance. + */ + public static MineLittlePony getInstance() { + return instance; + } + + /** + * Gets the global MineLP client configuration. + */ + public abstract PonyConfig getConfig(); + + /** + * Gets the static pony manager instance. + */ + public abstract IPonyManager getManager(); + + /** + * Gets the global revision number, used for reloading models on demand. + */ + public abstract int getModelRevisionNumber(); +} + diff --git a/src/common/java/com/minelittlepony/pony/data/IPonyManager.java b/src/common/java/com/minelittlepony/pony/data/IPonyManager.java new file mode 100644 index 00000000..1465c49e --- /dev/null +++ b/src/common/java/com/minelittlepony/pony/data/IPonyManager.java @@ -0,0 +1,77 @@ +package com.minelittlepony.pony.data; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; + +import java.util.UUID; + +/** + * The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin. + * + */ +public interface IPonyManager { + + public static final ResourceLocation STEVE = new ResourceLocation("minelittlepony", "textures/entity/steve_pony.png"); + public static final ResourceLocation ALEX = new ResourceLocation("minelittlepony", "textures/entity/alex_pony.png"); + + public static final String BGPONIES_JSON = "textures/entity/pony/bgponies.json"; + + /** + * Gets or creates a pony for the given player. + * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. + * + * @param player the player + */ + public IPony getPony(EntityPlayer player); + + /** + * Gets or creates a pony for the given skin resource and vanilla model type. + * + * @param resource A texture resource + */ + public IPony getPony(ResourceLocation resource); + + /** + * Gets or creates a pony for the given skin resource and entity id. + * + * Whether is has slim arms is determined by the id. + * + * Delegates to the background-ponies registry if no pony skins were available and client settings allows it. + * + * @param resource A texture resource + * @param uuid id of a player or entity + */ + IPony getPony(ResourceLocation resource, UUID uuid); + + /** + * Gets the default pony. Either STEVE/ALEX, or a background pony based on client settings. + * + * @param uuid id of a player or entity + */ + IPony getDefaultPony(UUID uuid); + + /** + * Gets a random background pony determined by the given uuid. + * + * Useful for mods that offer customisation, especially ones that have a whole lot of NPCs. + * + * @param uuid A UUID. Either a user or an entity. + */ + IPony getBackgroundPony(UUID uuid); + + /** + * De-registers a pony from the cache. + */ + IPony removePony(ResourceLocation resource); + + public static ResourceLocation getDefaultSkin(UUID uuid) { + return isSlimSkin(uuid) ? ALEX : STEVE; + } + + /** + * Returns true if the given uuid is of a player would would use the ALEX skin type. + */ + public static boolean isSlimSkin(UUID uuid) { + return (uuid.hashCode() & 1) == 1; + } +} diff --git a/src/common/java/com/minelittlepony/pony/data/PonySize.java b/src/common/java/com/minelittlepony/pony/data/PonySize.java index cc7bf6af..315b4c0e 100644 --- a/src/common/java/com/minelittlepony/pony/data/PonySize.java +++ b/src/common/java/com/minelittlepony/pony/data/PonySize.java @@ -26,11 +26,11 @@ public enum PonySize implements ITriggerPixelMapped { } public float getShadowSize() { - return shadowSize * MineLittlePony.getConfig().getGlobalScaleFactor(); + return shadowSize * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); } public float getScaleFactor() { - return scale * MineLittlePony.getConfig().getGlobalScaleFactor(); + return scale * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); } public PonyTransformation getTranformation() { @@ -43,6 +43,6 @@ public enum PonySize implements ITriggerPixelMapped { } public PonySize getEffectiveSize() { - return MineLittlePony.getConfig().sizes ? this : PonySize.NORMAL; + return MineLittlePony.getInstance().getConfig().sizes ? this : PonySize.NORMAL; } }