diff --git a/build.gradle b/build.gradle index e571d7ac..d0a21a8c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,19 @@ buildscript { - repositories { - jcenter() - maven { - name 'forge' - url 'http://files.minecraftforge.net/maven' - } - maven { - name = 'sponge' - url = 'https://repo.spongepowered.org/maven' - } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' - } + repositories { + jcenter() + maven { + name 'forge' + url 'http://files.minecraftforge.net/maven' + } + maven { + name = 'sponge' + url = 'https://repo.spongepowered.org/maven' + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' + classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' + } } apply plugin: 'net.minecraftforge.gradle.forge' @@ -27,66 +27,70 @@ targetCompatibility = 1.8 sourceCompatibility = 1.8 minecraft { - version = "1.12.2-14.23.4.2705" - mappings = 'snapshot_20180606' - runDir = 'run' - replace '@VERSION@', project.version + version = "1.12.2-14.23.4.2705" + mappings = 'snapshot_20180606' + runDir = 'run' + replace '@VERSION@', project.version + + clientJvmArgs += '-Dfml.coreMod.load=com.minelittlepony.core.MLPLoadingPlugin' } sourceSets { - hdskins { - compileClasspath += main.compileClasspath - ext.refMap = 'hdskins.mixin.refmap.json' - } - main { - compileClasspath += hdskins.output - ext.refMap = 'minelp.mixin.refmap.json' - } + hdskins { + compileClasspath += main.compileClasspath + ext.refMap = 'hdskins.mixin.refmap.json' + } + main { + compileClasspath += hdskins.output + ext.refMap = 'minelp.mixin.refmap.json' + } } repositories { - maven { - url = 'https://repo.spongepowered.org/maven' - } + maven { + url = 'https://repo.spongepowered.org/maven' + } } dependencies { - compile('org.spongepowered:mixin:0.7.8-SNAPSHOT') {transitive = false} + compile('org.spongepowered:mixin:0.7.8-SNAPSHOT') {transitive = false} } //litemod.json { -// mcversion = '1.12.r2' -// author = 'Verdana, Rene_Z, Mumfrey, Killjoy1221' -// description = 'Mine Little Pony turns players and mobs into ponies' -// description.minelittlepony = '''\ -// Mine Little Pony turns players and mobs into ponies -// Press F9 ingame to access settings'''.stripIndent() -// description.hdskinsmod = '''\ -// Separate skin server for Mine Little Pony that also supports HD skins. -// Access via button on the main menu.'''.stripIndent() +// mcversion = '1.12.r2' +// author = 'Verdana, Rene_Z, Mumfrey, Killjoy1221' +// description = 'Mine Little Pony turns players and mobs into ponies' +// description.minelittlepony = '''\ +// Mine Little Pony turns players and mobs into ponies +// Press F9 ingame to access settings'''.stripIndent() +// description.hdskinsmod = '''\ +// Separate skin server for Mine Little Pony that also supports HD skins. +// Access via button on the main menu.'''.stripIndent() // -// mixinConfigs += [ -// 'minelp.mixin.json', -// 'hdskins.mixin.json' -// ] +// mixinConfigs += [ +// 'minelp.mixin.json', +// 'hdskins.mixin.json' +// ] //} jar { - from sourceSets.hdskins.output + from sourceSets.hdskins.output + manifest.attributes FMLCorePlugin: 'com.minelittlepony.core.MLPLoadingPlugin', + FMLCorePluginContainsFMLMod: 'true' } sourceJar { - // add hdskins sources - from sourceSets.hdskins.allSource + // add hdskins sources + from sourceSets.hdskins.allSource } task skinZip(type: Zip) { - from fileTree('skins') - baseName 'Pony Skin Resources' - version 'v1' + from fileTree('skins') + baseName 'Pony Skin Resources' + version 'v1' } mixin { - defaultObfuscationEnv notch + defaultObfuscationEnv notch } // windows only task deploy(type: Copy, dependsOn: build) { - from jar.archivePath - into file("$System.env.APPDATA/.minecraft/mods") + from jar.archivePath + into file("$System.env.APPDATA/.minecraft/mods") } diff --git a/src/api/java/mcp/MethodsReturnNonnullByDefault.java b/src/api/java/mcp/MethodsReturnNonnullByDefault.java deleted file mode 100644 index fb02ffca..00000000 --- a/src/api/java/mcp/MethodsReturnNonnullByDefault.java +++ /dev/null @@ -1,26 +0,0 @@ -package mcp; - -import javax.annotation.Nonnull; -import javax.annotation.meta.TypeQualifierDefault; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * This annotation can be applied to a package, class or method to indicate that - * the method in that element are nonnull by default unless there is: - * - * - */ -@Documented -@Nonnull -@TypeQualifierDefault(ElementType.METHOD) // Note: This is a copy of javax.annotation.ParametersAreNonnullByDefault with target changed to METHOD -@Retention(RetentionPolicy.RUNTIME) -public @interface MethodsReturnNonnullByDefault {} diff --git a/src/api/java/net/minecraftforge/client/ForgeHooksClient.java b/src/api/java/net/minecraftforge/client/ForgeHooksClient.java deleted file mode 100644 index 97899be4..00000000 --- a/src/api/java/net/minecraftforge/client/ForgeHooksClient.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.minecraftforge.client; - -import net.minecraft.client.model.ModelBiped; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.item.ItemStack; - -// stub -public class ForgeHooksClient { - - public static String getArmorTexture(Entity entity, ItemStack armor, String def, EntityEquipmentSlot slot, String type) { - return def; - } - - public static ModelBiped getArmorModel(EntityLivingBase entity, ItemStack item, EntityEquipmentSlot slot, ModelBiped def) { - return def; - } - -} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java index 965aba4d..a11afdff 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java @@ -16,8 +16,6 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.authlib.properties.Property; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.util.UUIDTypeAdapter; -import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.liteloader.util.log.LiteLoaderLogger; import com.voxelmodpack.hdskins.resource.SkinResourceManager; import com.voxelmodpack.hdskins.skins.AsyncCacheLoader; import com.voxelmodpack.hdskins.skins.SkinServer; @@ -29,9 +27,12 @@ import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManagerReloadListener; import net.minecraft.client.resources.SkinManager.SkinAvailableCallback; +import net.minecraft.launchwrapper.Launch; import net.minecraft.util.ResourceLocation; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.awt.Graphics; import java.awt.image.BufferedImage; @@ -47,12 +48,13 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; - import javax.annotation.Nonnull; import javax.annotation.Nullable; public final class HDSkinManager implements IResourceManagerReloadListener { + private static final Logger LOGGER = LogManager.getLogger(); + private static final ResourceLocation LOADING = new ResourceLocation("LOADING"); private static final Gson GSON = new GsonBuilder() .registerTypeAdapter(UUID.class, new UUIDTypeAdapter()) @@ -139,7 +141,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener { String skinDir = type.toString().toLowerCase() + "s/"; final ResourceLocation skin = new ResourceLocation("hdskins", skinDir + texture.getHash()); - File file2 = new File(LiteLoader.getAssetsDirectory(), "hd/" + skinDir + texture.getHash().substring(0, 2) + "/" + texture.getHash()); + File file2 = new File(Launch.assetsDir, "hd/" + skinDir + texture.getHash().substring(0, 2) + "/" + texture.getHash()); final IImageBuffer imagebufferdownload = type == Type.SKIN ? new ImageBufferDownloadHD() : null; @@ -237,11 +239,11 @@ public final class HDSkinManager implements IResourceManagerReloadListener { } public static void clearSkinCache() { - LiteLoaderLogger.info("Clearing local player skin cache"); + LOGGER.info("Clearing local player skin cache"); try { - FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "skins")); - FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "hd")); + FileUtils.deleteDirectory(new File(Launch.assetsDir, "skins")); + FileUtils.deleteDirectory(new File(Launch.assetsDir, "hd")); TextureManager textures = Minecraft.getMinecraft().getTextureManager(); INSTANCE.skinCache.values().stream() .flatMap(m -> m.values().stream()) @@ -261,7 +263,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener { try { return callback.onSkinCacheCleared(); } catch (Exception e) { - LiteLoaderLogger.warning("Exception ancountered calling skin listener '{}'. It will be removed.", callback.getClass().getName()); + LOGGER.warn("Exception encountered calling skin listener '{}'. It will be removed.", callback.getClass().getName()); e.printStackTrace(); return false; } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java new file mode 100644 index 00000000..4c3263a3 --- /dev/null +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkins.java @@ -0,0 +1,68 @@ +package com.voxelmodpack.hdskins; + +import com.google.common.base.Joiner; +import com.voxelmodpack.hdskins.gui.EntityPlayerModel; +import com.voxelmodpack.hdskins.gui.GLWindow; +import com.voxelmodpack.hdskins.gui.RenderPlayerModel; +import com.voxelmodpack.hdskins.skins.SkinServer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IReloadableResourceManager; +import net.minecraftforge.fml.client.registry.RenderingRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.util.List; + +@Mod(modid = "hdskins", name = "HD Skins", version = "4.0.0") +@Mod.EventBusSubscriber +public class HDSkins { + + @Mod.EventHandler + public void init(FMLPreInitializationEvent event) { + + Path json = event.getModConfigurationDirectory().toPath().resolve("skinservers.txt"); + List list = SkinServer.defaultServers; + try { + list = Files.readAllLines(json); + } catch (NoSuchFileException e) { + // ignore this + } catch (IOException e) { + event.getModLog().warn("Error reading skin servers. Using defaults.", e); + } + + event.getModLog().info("Using skin servers:\n" + Joiner.on('\n').join(list)); + + IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); + irrm.registerReloadListener(HDSkinManager.INSTANCE); + + RenderingRegistry.registerEntityRenderingHandler(EntityPlayerModel.class, RenderPlayerModel::new); + // register skin servers. + for (String s : list) { + try { + HDSkinManager.INSTANCE.addSkinServer(SkinServer.from(s)); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + } + +// GLWindow.current(); + } + + private static boolean fullscreen; + + @SubscribeEvent + public static void onFullScreenToggled(TickEvent.ClientTickEvent event) { + if (event.phase == TickEvent.Phase.START) { + fullscreen = Minecraft.getMinecraft().isFullScreen(); + } else if (Minecraft.getMinecraft().isFullScreen() != fullscreen) { + // fullscreen has changed since beginning of tick. + GLWindow.refresh(Minecraft.getMinecraft().isFullScreen()); + } + } +} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/Later.java b/src/hdskins/java/com/voxelmodpack/hdskins/Later.java deleted file mode 100644 index 2e979663..00000000 --- a/src/hdskins/java/com/voxelmodpack/hdskins/Later.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.voxelmodpack.hdskins; - -public final class Later extends Thread { - - private final int delay; - - protected Later(int delay, Runnable runnable) { - super(runnable); - this.delay = delay; - setDaemon(true); - setName("Later#" + getId()); - } - - public static void performLater(int delay, Runnable callable) { - new Later(delay, callable).start(); - } - - public static void performNow(Runnable callable) { - new Later(0, callable).start(); - } - - @Override - public void run() { - try { - if (delay > 0) sleep(delay); - } catch (InterruptedException e) {} - super.run(); - } -} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java index 794c678d..61cd4003 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java @@ -96,7 +96,7 @@ public class GLWindow extends DropTarget { frame = new JFrame(Display.getTitle()); frame.add(canvas); - frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent windowEvent) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java index fcb76eb0..43208dcd 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java @@ -8,7 +8,6 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mumfrey.liteloader.util.log.LiteLoaderLogger; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.skins.SkinUploadResponse; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG; @@ -33,6 +32,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.TextFormatting; import org.apache.commons.io.FilenameUtils; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.GLU; @@ -47,6 +47,9 @@ import javax.imageio.ImageIO; import javax.swing.*; public class GuiSkins extends GuiScreen implements FutureCallback { + + private static final Logger LOGGER = LogManager.getLogger(); + private static final int MAX_SKIN_DIMENSION = 1024; private int updateCounter = 0; private ResourceLocation viewportTexture; @@ -672,7 +675,7 @@ public class GuiSkins extends GuiScreen implements FutureCallback skin_servers = SkinServer.defaultServers; - - @Override - public String getName() { - return "HD Skins"; - } - - @Override - public String getVersion() { - return "4.0.0"; - } - - @Override - public void init(File configPath) { - - // register config - LiteLoader.getInstance().registerExposable(this, null); - - // try it initialize voxelmenu button - try { - Class ex = Class.forName("com.thevoxelbox.voxelmenu.GuiMainMenuVoxelBox"); - Method mRegisterCustomScreen = ex.getDeclaredMethod("registerCustomScreen", Class.class, String.class); - mRegisterCustomScreen.invoke(null, GuiSkins.class, "HD Skins Manager"); - } catch (ClassNotFoundException var4) { - // voxelmenu's not here, man - } catch (Exception var5) { - var5.printStackTrace(); - } - - IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); - irrm.registerReloadListener(HDSkinManager.INSTANCE); - - GLWindow.current(); - } - - @Override - public void upgradeSettings(String version, File configPath, File oldConfigPath) { - HDSkinManager.clearSkinCache(); - } - - @Override - public Class getConfigPanelClass() { - return HDSkinsConfigPanel.class; - } - - @Override - public void onInitCompleted(Minecraft minecraft, LiteLoader loader) { - ModUtilities.addRenderer(EntityPlayerModel.class, new RenderPlayerModel<>(minecraft.getRenderManager())); - - // register skin servers. - for (String s : skin_servers) { - try { - HDSkinManager.INSTANCE.addSkinServer(SkinServer.from(s)); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } - } - - } - - @Override - public void onViewportResized(ScaledResolution resolution, int displayWidth, int displayHeight) { - - } - - @Override - public void onFullScreenToggled(boolean fullScreen) { - GLWindow.refresh(fullScreen); - } -} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mod/package-info.java b/src/hdskins/java/com/voxelmodpack/hdskins/mod/package-info.java deleted file mode 100644 index 71bed627..00000000 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mod/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -@MethodsReturnNonnullByDefault -@ParametersAreNonnullByDefault -package com.voxelmodpack.hdskins.mod; - -import mcp.MethodsReturnNonnullByDefault; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/resource/SkinResourceManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/resource/SkinResourceManager.java index d02b22df..863c2761 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/resource/SkinResourceManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/resource/SkinResourceManager.java @@ -5,15 +5,14 @@ import com.google.gson.Gson; import com.google.gson.JsonParseException; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; -import com.mumfrey.liteloader.util.log.LiteLoaderLogger; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManagerReloadListener; import net.minecraft.util.ResourceLocation; import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; -import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -23,9 +22,12 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import javax.annotation.Nullable; public class SkinResourceManager implements IResourceManagerReloadListener { + private static final Logger logger = LogManager.getLogger(); + private ExecutorService executor = Executors.newSingleThreadExecutor(); private Map uuidSkins = Maps.newHashMap(); @@ -55,7 +57,7 @@ public class SkinResourceManager implements IResourceManagerReloadListener { } } } catch (JsonParseException je) { - LiteLoaderLogger.warning(je, "Invalid skins.json in %s", res.getResourcePackName()); + logger.warn("Invalid skins.json in %s", res.getResourcePackName(), je); } } } catch (IOException e) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java b/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java index 7735c96a..6190f95d 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/upload/awt/ThreadOpenFile.java @@ -2,16 +2,8 @@ package com.voxelmodpack.hdskins.upload.awt; import net.minecraft.client.Minecraft; -import java.awt.AWTEvent; -import java.awt.event.MouseEvent; - -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.filechooser.FileFilter; - -import org.lwjgl.opengl.Display; - -import com.voxelmodpack.hdskins.Later; +import javax.swing.*; +import javax.swing.filechooser.*; /** * Base class for "open file" dialog threads @@ -41,18 +33,6 @@ public abstract class ThreadOpenFile extends Thread { this.dialogTitle = dialogTitle; } - @Override - public void start() { - Later.performLater(0, this); - } - - public ThreadOpenFile setParent(JFrame parent) { - this.parent = parent; - this.parent.setAlwaysOnTop(true); - - return this; - } - @Override public void run() { if (parent == null) { diff --git a/src/main/java/com/minelittlepony/ForgeProxy.java b/src/main/java/com/minelittlepony/ForgeProxy.java deleted file mode 100644 index 09d5b6a5..00000000 --- a/src/main/java/com/minelittlepony/ForgeProxy.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.minelittlepony; - -import com.mumfrey.liteloader.util.ModUtilities; -import net.minecraft.client.model.ModelBiped; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.client.ForgeHooksClient; - -import javax.annotation.Nullable; - -/** - * Proxy class for accessing forge fields and methods. - */ -public class ForgeProxy { - - /** - * True if forge is present. - */ - private static boolean forgeLoaded = ModUtilities.fmlIsPresent(); - - /** - * Gets the mod armour texture for an associated item and slot. - * - * @param entity The entity to get armour for. - * @param item The armour item - * @param def Default return value if no mods present - * @param slot The slot this armour piece is place in. - * @param type unknown - * @return - */ - public static String getArmorTexture(Entity entity, ItemStack item, String def, EntityEquipmentSlot slot, @Nullable String type) { - if (forgeLoaded) - return ForgeHooksClient.getArmorTexture(entity, item, def, slot, type); - return def; - } - - /** - * Gets the mod armour model for an associated item and slot. - * - * @param entity The entity to get armour for. - * @param item The armour item - * @param slot The slot this armour piece is place in. - * @param def Default return value if no mods present - */ - public static ModelBiped getArmorModel(EntityLivingBase entity, ItemStack item, EntityEquipmentSlot slot, ModelBiped def) { - if (forgeLoaded) - return ForgeHooksClient.getArmorModel(entity, item, slot, def); - return def; - } -} diff --git a/src/main/java/com/minelittlepony/LiteModMineLittlePony.java b/src/main/java/com/minelittlepony/LiteModMineLittlePony.java deleted file mode 100644 index aa8893da..00000000 --- a/src/main/java/com/minelittlepony/LiteModMineLittlePony.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.minelittlepony; - -import com.minelittlepony.gui.PonySettingsPanel; -import com.mumfrey.liteloader.Configurable; -import com.mumfrey.liteloader.InitCompleteListener; -import com.mumfrey.liteloader.Tickable; -import com.mumfrey.liteloader.core.LiteLoader; -import com.mumfrey.liteloader.modconfig.ConfigPanel; - -import net.minecraft.client.Minecraft; - -import java.io.File; - -public class LiteModMineLittlePony implements Tickable, InitCompleteListener, Configurable { - - private MineLittlePony mlp; - - @Override - public String getName() { - return MineLittlePony.MOD_NAME; - } - - @Override - public String getVersion() { - return MineLittlePony.MOD_VERSION; - } - - @Override - public void upgradeSettings(String version, File configPath, File oldConfigPath) { - } - - @Override - public void init(File configPath) { - mlp = new MineLittlePony(); - } - - @Override - public void onInitCompleted(Minecraft minecraft, LiteLoader loader) { - mlp.postInit(minecraft); - } - - @Override - public void onTick(Minecraft minecraft, float partialTicks, boolean inGame, boolean clock) { - mlp.onTick(minecraft, inGame); - } - - @Override - public Class getConfigPanelClass() { - return PonySettingsPanel.class; - } -} diff --git a/src/main/java/com/minelittlepony/MineLittlePony.java b/src/main/java/com/minelittlepony/MineLittlePony.java index 2fd40e63..381bcfe4 100644 --- a/src/main/java/com/minelittlepony/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/MineLittlePony.java @@ -4,53 +4,49 @@ import com.minelittlepony.gui.GuiPonySettings; import com.minelittlepony.hdskins.gui.GuiSkinsMineLP; import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.PonyDataSerialzier; -import com.mumfrey.liteloader.core.LiteLoader; +import com.minelittlepony.settings.PonyConfig; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.gui.GuiSkins; import com.voxelmodpack.hdskins.skins.SkinServer; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.client.resources.data.MetadataSerializer; import net.minecraft.client.settings.KeyBinding; -import org.apache.logging.log4j.LogManager; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; -/** - * Static MineLittlePony singleton class. Everything's controlled from up here. - */ + @Mod(modid = "minelittlepony", name = MineLittlePony.MOD_NAME, version = MineLittlePony.MOD_VERSION, clientSideOnly = true) public class MineLittlePony { - public static final Logger logger = LogManager.getLogger("MineLittlePony"); + public static Logger logger; public static final String MOD_NAME = "Mine Little Pony"; public static final String MOD_VERSION = "@VERSION@"; private static final String MINELP_LEGACY_SERVER = "legacy:http://minelpskins.voxelmodpack.com;http://minelpskinmanager.voxelmodpack.com"; + // TODO Replace this with a config screen private static final KeyBinding SETTINGS_GUI = new KeyBinding("Settings", Keyboard.KEY_F9, "Mine Little Pony"); private static MineLittlePony instance; - private final PonyConfig config; - private final PonyManager ponyManager; + private PonyConfig.Loader configLoader; + private PonyManager ponyManager; - private final PonyRenderManager renderManager; + private PonyRenderManager renderManager; @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { instance = this; + logger = event.getModLog(); - LiteLoader.getInput().registerKeyBinding(SETTINGS_GUI); + configLoader = new PonyConfig.Loader(event.getModConfigurationDirectory().toPath().resolve("minelittlepony.json")); + ponyManager = new PonyManager(configLoader.getConfig()); - config = new PonyConfig(); - ponyManager = new PonyManager(config); - - renderManager = new PonyRenderManager(); - - LiteLoader.getInstance().registerExposable(config, null); IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); irrm.registerReloadListener(ponyManager); @@ -63,7 +59,9 @@ public class MineLittlePony { } @Mod.EventHandler - public void postInit(FMLPostInitializationEvent event) { + public void postInit(FMLLoadCompleteEvent event) { + + renderManager = new PonyRenderManager(Minecraft.getMinecraft().getRenderManager()); HDSkinManager manager = HDSkinManager.INSTANCE; // manager.setSkinUrl(SKIN_SERVER_URL); @@ -72,9 +70,8 @@ public class MineLittlePony { // logger.info("Set MineLP skin server URL."); manager.addClearListener(ponyManager); - RenderManager rm = minecraft.getRenderManager(); - renderManager.initialisePlayerRenderers(rm); - renderManager.initializeMobRenderers(rm, config); + renderManager.initialisePlayerRenderers(); + renderManager.initializeMobRenderers(configLoader.getConfig()); } /** @@ -91,7 +88,7 @@ public class MineLittlePony { if (skins) { minecraft.displayGuiScreen(new GuiSkinsMineLP(ponyManager)); } - HDSkinManager.INSTANCE.setEnabled(config.hd); + HDSkinManager.INSTANCE.setEnabled(configLoader.getConfig().hd); } @@ -119,8 +116,8 @@ public class MineLittlePony { /** * Gets the global MineLP client configuration. */ - public static PonyConfig getConfig() { - return getInstance().config; + public static PonyConfig.Loader getConfigLoader() { + return getInstance().configLoader; } } diff --git a/src/main/java/com/minelittlepony/PonyConfig.java b/src/main/java/com/minelittlepony/PonyConfig.java deleted file mode 100644 index b4f969d4..00000000 --- a/src/main/java/com/minelittlepony/PonyConfig.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.minelittlepony; - -import com.google.gson.annotations.Expose; -import com.minelittlepony.pony.data.PonyLevel; -import com.minelittlepony.settings.SensibleConfig; -import com.mumfrey.liteloader.modconfig.ConfigStrategy; -import com.mumfrey.liteloader.modconfig.Exposable; -import com.mumfrey.liteloader.modconfig.ExposableOptions; - -/** - * Storage container for MineLP client settings. - * - */ -@ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned) -public class PonyConfig extends SensibleConfig implements Exposable { - - @Expose private PonyLevel ponylevel = PonyLevel.PONIES; - - @Expose public boolean sizes = true; - @Expose public boolean snuzzles = true; - @Expose public boolean hd = true; - @Expose public boolean showscale = true; - - public enum PonySettings implements Setting { - SIZES, - SNUZZLES, - HD, - SHOWSCALE; - } - - @Expose public boolean villagers = true; - @Expose public boolean zombies = true; - @Expose public boolean pigzombies = true; - @Expose public boolean skeletons = true; - @Expose public boolean illagers = true; - @Expose public boolean guardians = true; - - /** - * Gets the current PonyLevel. That is the level of ponies you would like to see. - * @param ignorePony true to ignore whatever value the setting has. - */ - public PonyLevel getEffectivePonyLevel(boolean ignorePony) { - return ignorePony ? PonyLevel.BOTH : getPonyLevel(); - } - - /** - * Actually gets the pony level value. No option to ignore reality here. - */ - public PonyLevel getPonyLevel() { - if (ponylevel == null) { - ponylevel = PonyLevel.PONIES; - } - return ponylevel; - } - - /** - * Sets the pony level. Want MOAR PONEHS? Well here you go. - * @param ponylevel - */ - public void setPonyLevel(PonyLevel ponylevel) { - this.ponylevel = ponylevel; - } -} diff --git a/src/main/java/com/minelittlepony/PonyManager.java b/src/main/java/com/minelittlepony/PonyManager.java index d92b2c46..5098dc60 100644 --- a/src/main/java/com/minelittlepony/PonyManager.java +++ b/src/main/java/com/minelittlepony/PonyManager.java @@ -7,6 +7,7 @@ import com.google.gson.JsonParseException; import com.minelittlepony.model.PMAPI; import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.PonyLevel; +import com.minelittlepony.settings.PonyConfig; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.ISkinCacheClearListener; diff --git a/src/main/java/com/minelittlepony/PonyRenderManager.java b/src/main/java/com/minelittlepony/PonyRenderManager.java index b235f3c1..830638d2 100644 --- a/src/main/java/com/minelittlepony/PonyRenderManager.java +++ b/src/main/java/com/minelittlepony/PonyRenderManager.java @@ -1,20 +1,22 @@ package com.minelittlepony; -import java.util.Map; - import com.google.common.collect.Maps; -import com.minelittlepony.mixin.MixinRenderManager; import com.minelittlepony.hdskins.gui.EntityPonyModel; import com.minelittlepony.hdskins.gui.RenderPonyModel; import com.minelittlepony.model.player.PlayerModels; import com.minelittlepony.render.LevitatingItemRenderer; import com.minelittlepony.render.player.RenderPonyPlayer; import com.minelittlepony.render.ponies.MobRenderers; -import com.mumfrey.liteloader.util.ModUtilities; - +import com.minelittlepony.settings.PonyConfig; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.entity.RenderPlayer; import net.minecraft.entity.Entity; +import net.minecraftforge.fml.client.registry.IRenderFactory; +import net.minecraftforge.fml.client.registry.RenderingRegistry; +import net.minecraftforge.fml.relauncher.ReflectionHelper; + +import java.util.Map; /** * Render manager responsible for replacing and restoring entity renderers when the client settings change. @@ -24,65 +26,77 @@ public class PonyRenderManager { private LevitatingItemRenderer magicRenderer = new LevitatingItemRenderer(); - private final Map, Render> renderMap = Maps.newHashMap(); + private final RenderManager manager; + private final Map skinMap; + + public PonyRenderManager(RenderManager manager) { + this.manager = manager; + skinMap = ReflectionHelper.getPrivateValue(RenderManager.class, manager, "field_178636_l", "skinMap"); + } + /** * Registers all new player skin types. (currently only pony and slimpony). */ - public void initialisePlayerRenderers(RenderManager manager) { + public void initialisePlayerRenderers() { // Preview on the select skin gui - ModUtilities.addRenderer(EntityPonyModel.class, new RenderPonyModel(manager)); + RenderingRegistry.registerEntityRenderingHandler(EntityPonyModel.class, RenderPonyModel::new); for (PlayerModels i : PlayerModels.values()) { if (i != PlayerModels.HUMAN) { - registerPlayerSkin(manager, i); + registerPlayerSkin(i); } } } - private void registerPlayerSkin(RenderManager manager, PlayerModels playerModel) { - addPlayerSkin(manager, false, playerModel); - addPlayerSkin(manager, true, playerModel); + private void registerPlayerSkin(PlayerModels playerModel) { + addPlayerSkin(false, playerModel); + addPlayerSkin(true, playerModel); } - private void addPlayerSkin(RenderManager manager, boolean slimArms, PlayerModels playerModel) { + private void addPlayerSkin(boolean slimArms, PlayerModels playerModel) { RenderPonyPlayer renderer = new RenderPonyPlayer(manager, slimArms, playerModel.getModel(slimArms)); - ((MixinRenderManager)manager).getSkinMap().put(playerModel.getId(slimArms), renderer); + Map skinMap = ReflectionHelper.getPrivateValue(RenderManager.class, manager, "field_178636_l", "skinMap"); + + skinMap.put(playerModel.getId(slimArms), renderer); } /** * Registers all entity model replacements. (except for players). */ - public void initializeMobRenderers(RenderManager manager, PonyConfig config) { + public void initializeMobRenderers(PonyConfig config) { for (MobRenderers i : MobRenderers.values()) { - i.apply(this, manager); + boolean state = i.get(config); + i.register(state, this); + if (state) { + MineLittlePony.logger.info(i.name() + " are now ponies."); + } } + + RenderingRegistry.loadEntityRenderers(manager, manager.entityRenderMap); } /** - * * Replaces an entity renderer depending on whether we want ponies or not. * - * @param state True if we want ponies (the original will be stored) - * @param manager The render manager - * @param type The type to replace + * @param state True if we want ponies (the original will be stored) + * @param type The type to replace * @param renderer The replacement value * @param The entity type */ @SuppressWarnings("unchecked") - public void switchRenderer(boolean state, RenderManager manager, Class type, Render renderer) { + public void switchRenderer(boolean state, Class type, IRenderFactory renderer) { if (state) { if (!renderMap.containsKey(type)) { renderMap.put(type, manager.getEntityClassRenderObject(type)); } - ModUtilities.addRenderer((Class)type, renderer); - } else { - if (renderMap.containsKey(type)) { - ModUtilities.addRenderer(type, (Render)renderMap.get(type)); - } + RenderingRegistry.registerEntityRenderingHandler(type, renderer); + } else if (renderMap.containsKey(type)) { + RenderingRegistry.registerEntityRenderingHandler(type, mngr -> (Render) renderMap.get(type)); } + } public LevitatingItemRenderer getMagicRenderer() { diff --git a/src/main/java/com/minelittlepony/core/MLPLoadingPlugin.java b/src/main/java/com/minelittlepony/core/MLPLoadingPlugin.java new file mode 100644 index 00000000..921e5a91 --- /dev/null +++ b/src/main/java/com/minelittlepony/core/MLPLoadingPlugin.java @@ -0,0 +1,43 @@ +package com.minelittlepony.core; + +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.mixin.Mixins; + +import java.util.Map; +import javax.annotation.Nullable; + +@IFMLLoadingPlugin.MCVersion("1.12.2") +public class MLPLoadingPlugin implements IFMLLoadingPlugin { + + public MLPLoadingPlugin() { + MixinBootstrap.init(); + Mixins.addConfigurations("minelp.mixin.json", "hdskins.mixin.json"); + } + + @Override + public String[] getASMTransformerClass() { + return new String[0]; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Nullable + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map data) { + + } + + @Override + public String getAccessTransformerClass() { + return null; + } +} diff --git a/src/main/java/com/minelittlepony/gui/Checkbox.java b/src/main/java/com/minelittlepony/gui/Checkbox.java index 51a2421f..aac4f4b6 100644 --- a/src/main/java/com/minelittlepony/gui/Checkbox.java +++ b/src/main/java/com/minelittlepony/gui/Checkbox.java @@ -1,22 +1,22 @@ package com.minelittlepony.gui; -import com.mumfrey.liteloader.client.gui.GuiCheckbox; - import net.minecraft.client.resources.I18n; +import net.minecraftforge.fml.client.config.GuiCheckBox; -public class Checkbox extends GuiCheckbox implements IActionable { +import java.util.function.Consumer; - private final IGUIAction action; +public class Checkbox extends GuiCheckBox implements IActionable { - public Checkbox(int x, int y, String displayString, boolean value, IGUIAction callback) { - super(0, x, y, I18n.format(displayString)); - action = callback; - checked = value; + private final Consumer callback; + + public Checkbox(int x, int y, String displayString, boolean value, Consumer callback) { + super(0, x, y, I18n.format(displayString), value); + this.callback = callback; } @Override public void perform() { - checked = action.perform(!checked); + this.callback.accept(isChecked()); } } diff --git a/src/main/java/com/minelittlepony/gui/GuiPonySettings.java b/src/main/java/com/minelittlepony/gui/GuiPonySettings.java index f11f25f2..ffb86635 100644 --- a/src/main/java/com/minelittlepony/gui/GuiPonySettings.java +++ b/src/main/java/com/minelittlepony/gui/GuiPonySettings.java @@ -1,23 +1,19 @@ package com.minelittlepony.gui; -import java.io.IOException; - import com.minelittlepony.MineLittlePony; -import com.minelittlepony.PonyConfig; -import com.minelittlepony.PonyConfig.PonySettings; import com.minelittlepony.pony.data.PonyLevel; import com.minelittlepony.render.ponies.MobRenderers; -import com.mumfrey.liteloader.core.LiteLoader; - +import com.minelittlepony.settings.PonyConfig; +import com.minelittlepony.settings.Setting; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; +import net.minecraftforge.fml.client.config.GuiConfig; /** * In-Game options menu. * */ -public class GuiPonySettings extends GuiScreen { +public class GuiPonySettings extends GuiConfig { private static final String OPTIONS_PREFIX = "minelp.options."; @@ -25,10 +21,13 @@ public class GuiPonySettings extends GuiScreen { private static final String MOB_PREFIX = "minelp.mobs."; + private PonyConfig.Loader configLoader; private PonyConfig config; public GuiPonySettings() { - config = MineLittlePony.getConfig(); + super(null, "minelittlepony", "Mine Little Pony"); + configLoader = MineLittlePony.getConfigLoader(); + config = configLoader.getConfig(); } @Override @@ -44,17 +43,17 @@ public class GuiPonySettings extends GuiScreen { addButton(new Label(LEFT, row += 15, PONY_LEVEL, -1)); addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal(), (int id, String name, float value) -> { - return I18n.format(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase()); + return I18n.format(PONY_LEVEL + "." + PonyLevel.valueFor((int) value).name().toLowerCase()); }, v -> { - PonyLevel level = PonyLevel.valueFor(v); + PonyLevel level = PonyLevel.valueFor((int) v); config.setPonyLevel(level); return (float)level.ordinal(); })); row += 15; addButton(new Label(LEFT, row += 15, OPTIONS_PREFIX + "options", -1)); - for (PonySettings i : PonySettings.values()) { - addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i.get(), i)); + for (Setting i : PonyConfig.PonySettings.values()) { + addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i.get(config), b -> i.set(config, b))); } if (mustScroll()) { @@ -65,12 +64,12 @@ public class GuiPonySettings extends GuiScreen { addButton(new Label(RIGHT, row += 15, MOB_PREFIX + "title", -1)); for (MobRenderers i : MobRenderers.values()) { - addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + i.name().toLowerCase(), i.get(), i)); + addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + i.name().toLowerCase(), i.get(config), v -> i.set(config, v))); } } @Override - protected void actionPerformed(GuiButton button) throws IOException { + protected void actionPerformed(GuiButton button) { if (button instanceof IActionable) { ((IActionable)button).perform(); } @@ -84,7 +83,7 @@ public class GuiPonySettings extends GuiScreen { @Override public void onGuiClosed() { - LiteLoader.getInstance().writeConfig(config); + configLoader.save(); } protected String getTitle() { diff --git a/src/main/java/com/minelittlepony/gui/IGUIAction.java b/src/main/java/com/minelittlepony/gui/IGUIAction.java deleted file mode 100644 index 48aa5efa..00000000 --- a/src/main/java/com/minelittlepony/gui/IGUIAction.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.minelittlepony.gui; - -/** - * Response actions for UI events. - */ -@FunctionalInterface -public interface IGUIAction { - /** - * Performs this action now. - * - * @param value New Value of the field being changed - * @return Adjusted value the field must take on - */ - T perform(T value); -} diff --git a/src/main/java/com/minelittlepony/gui/PonySettingsPanel.java b/src/main/java/com/minelittlepony/gui/PonySettingsPanel.java deleted file mode 100644 index d0b173b5..00000000 --- a/src/main/java/com/minelittlepony/gui/PonySettingsPanel.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.minelittlepony.gui; - -import java.io.IOException; - -import com.mumfrey.liteloader.modconfig.ConfigPanel; -import com.mumfrey.liteloader.modconfig.ConfigPanelHost; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.resources.I18n; - -/** - * Boilerplate because LiteLoader has to be such a 'special flower' -_- - */ -public class PonySettingsPanel extends GuiPonySettings implements ConfigPanel { - - private int contentHeight; - - @Override - public String getPanelTitle() { - return I18n.format(getTitle()); - } - - @Override - public int getContentHeight() { - return contentHeight + 40; - } - - @Override - protected T addButton(T button) { - if (button.y > contentHeight) { - contentHeight = button.y; - } - return super.addButton(button); - } - - @Override - public void onPanelShown(ConfigPanelHost host) { - mc = Minecraft.getMinecraft(); - width = host.getWidth(); - buttonList.clear(); - initGui(); - } - - @Override - public void onPanelResize(ConfigPanelHost host) { - width = host.getWidth(); - buttonList.clear(); - initGui(); - } - - @Override - public void onPanelHidden() { - onGuiClosed(); - } - - @Override - public void onTick(ConfigPanelHost host) { - updateScreen(); - } - - @Override - public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { - drawScreen(mouseX, mouseY, partialTicks); - } - - @Override - public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) { - try { - mouseClicked(mouseX, mouseY, mouseButton); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void mouseReleased(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) { - mouseReleased(mouseX, mouseY, mouseButton); - } - - @Override - public void mouseMoved(ConfigPanelHost host, int mouseX, int mouseY) { - - } - - @Override - public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) { - try { - keyTyped(keyChar, keyCode); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void drawWorldBackground(int tint) { - - } - - protected boolean mustScroll() { - return true; - } - -} diff --git a/src/main/java/com/minelittlepony/gui/Slider.java b/src/main/java/com/minelittlepony/gui/Slider.java index a5f4ac41..1e3e4a69 100644 --- a/src/main/java/com/minelittlepony/gui/Slider.java +++ b/src/main/java/com/minelittlepony/gui/Slider.java @@ -3,11 +3,13 @@ package com.minelittlepony.gui; import net.minecraft.client.gui.GuiSlider; import net.minecraft.client.gui.GuiPageButtonList.GuiResponder; +import java.util.function.DoubleUnaryOperator; + public class Slider extends GuiSlider { private static Responder callback; - public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, IGUIAction action) { + public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, DoubleUnaryOperator action) { super(callback = new Responder(action), 0, x, y, "", minIn, maxIn, defaultValue, formatter); callback.owner = this; callback = null; @@ -15,11 +17,11 @@ public class Slider extends GuiSlider { private static final class Responder implements GuiResponder { - private final IGUIAction action; + private final DoubleUnaryOperator action; private Slider owner; - private Responder(IGUIAction callback) { + private Responder(DoubleUnaryOperator callback) { action = callback; } @@ -28,7 +30,7 @@ public class Slider extends GuiSlider { @Override public void setEntryValue(int id, float value) { - owner.setSliderValue(action.perform(value), false); + owner.setSliderValue((float) action.applyAsDouble(value), false); } @Override diff --git a/src/main/java/com/minelittlepony/model/components/PonySnout.java b/src/main/java/com/minelittlepony/model/components/PonySnout.java index 785eb33d..ba5b06cf 100644 --- a/src/main/java/com/minelittlepony/model/components/PonySnout.java +++ b/src/main/java/com/minelittlepony/model/components/PonySnout.java @@ -1,12 +1,11 @@ package com.minelittlepony.model.components; -import com.minelittlepony.pony.data.PonyGender; -import com.minelittlepony.render.plane.PlaneRenderer; - import static com.minelittlepony.model.PonyModelConstants.*; import com.minelittlepony.MineLittlePony; import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.pony.data.PonyGender; +import com.minelittlepony.render.plane.PlaneRenderer; public class PonySnout { @@ -51,7 +50,7 @@ public class PonySnout { } public void setGender(PonyGender gender) { - boolean show = !isHidden && MineLittlePony.getConfig().snuzzles; + boolean show = !isHidden && MineLittlePony.getConfigLoader().getConfig().snuzzles; mare.isHidden = !show || gender == PonyGender.STALLION; stallion.isHidden = !show || gender == PonyGender.MARE; diff --git a/src/main/java/com/minelittlepony/pony/data/Pony.java b/src/main/java/com/minelittlepony/pony/data/Pony.java index d3b1b7b5..759b392c 100644 --- a/src/main/java/com/minelittlepony/pony/data/Pony.java +++ b/src/main/java/com/minelittlepony/pony/data/Pony.java @@ -117,7 +117,7 @@ public class Pony { } public PonyRace getRace(boolean ignorePony) { - return metadata.getRace().getEffectiveRace(MineLittlePony.getConfig().getEffectivePonyLevel(ignorePony)); + return metadata.getRace().getEffectiveRace(MineLittlePony.getConfigLoader().getConfig().getEffectivePonyLevel(ignorePony)); } public ResourceLocation getTexture() { diff --git a/src/main/java/com/minelittlepony/pony/data/PonyData.java b/src/main/java/com/minelittlepony/pony/data/PonyData.java index 74cd7eb3..e4803ecc 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyData.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyData.java @@ -58,7 +58,7 @@ public class PonyData implements IPonyData { @Override public PonySize getSize() { - return MineLittlePony.getConfig().sizes ? size : PonySize.NORMAL; + return MineLittlePony.getConfigLoader().getConfig().sizes ? size : PonySize.NORMAL; } @Override diff --git a/src/main/java/com/minelittlepony/pony/data/PonyLevel.java b/src/main/java/com/minelittlepony/pony/data/PonyLevel.java index cf26cde3..0a51d644 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyLevel.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyLevel.java @@ -5,11 +5,11 @@ public enum PonyLevel { HUMANS, BOTH; - public static PonyLevel valueFor(float index) { + public static PonyLevel valueFor(int index) { PonyLevel[] values = values(); if (index < 0) { index = 0; } - return values[(int)Math.round(index) % values.length]; + return values[Math.round(index) % values.length]; } } diff --git a/src/main/java/com/minelittlepony/pony/data/PonySize.java b/src/main/java/com/minelittlepony/pony/data/PonySize.java index dee84d29..5ba235c2 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonySize.java +++ b/src/main/java/com/minelittlepony/pony/data/PonySize.java @@ -20,14 +20,14 @@ public enum PonySize implements ITriggerPixelMapped { } public float getShadowSize() { - if (MineLittlePony.getConfig().showscale) { + if (MineLittlePony.getConfigLoader().getConfig().showscale) { return shadowSize * 0.9F; } return shadowSize; } public float getScaleFactor() { - if (MineLittlePony.getConfig().showscale) { + if (MineLittlePony.getConfigLoader().getConfig().showscale) { return scale * 0.9F; } return scale; diff --git a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java index 5a2d8f64..887a4a5b 100644 --- a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -1,13 +1,11 @@ package com.minelittlepony.render; -import org.lwjgl.opengl.GL14; +import static net.minecraft.client.renderer.GlStateManager.*; import com.minelittlepony.MineLittlePony; import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.pony.data.Pony; import com.minelittlepony.util.coordinates.Color; -import com.mumfrey.liteloader.client.overlays.IMinecraft; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.ItemRenderer; @@ -17,7 +15,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHandSide; -import static net.minecraft.client.renderer.GlStateManager.*; +import org.lwjgl.opengl.GL14; public class LevitatingItemRenderer { @@ -112,7 +110,7 @@ public class LevitatingItemRenderer { boolean doBow = doNormal && stack.getItemUseAction() == EnumAction.BOW; if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items. - float ticks = ((IMinecraft)Minecraft.getMinecraft()).getTimer().elapsedPartialTicks - entity.ticksExisted; + float ticks = Minecraft.getMinecraft().getTickLength() - entity.ticksExisted; float floatAmount = (float)Math.sin(ticks / 9) / 40; float driftAmount = (float)Math.cos(ticks / 10) / 40; diff --git a/src/main/java/com/minelittlepony/render/RenderPonyMob.java b/src/main/java/com/minelittlepony/render/RenderPonyMob.java index 26c4a346..c2027178 100644 --- a/src/main/java/com/minelittlepony/render/RenderPonyMob.java +++ b/src/main/java/com/minelittlepony/render/RenderPonyMob.java @@ -83,7 +83,7 @@ public abstract class RenderPonyMob extends RenderLiving public float getShadowScale() { if (mainModel.isChild) { return 0.25F; - } else if (MineLittlePony.getConfig().showscale) { + } else if (MineLittlePony.getConfigLoader().getConfig().showscale) { return 0.4F; } return 0.5F; @@ -91,7 +91,7 @@ public abstract class RenderPonyMob extends RenderLiving @Override public float getScaleFactor() { - if (MineLittlePony.getConfig().showscale) return 0.9F; + if (MineLittlePony.getConfigLoader().getConfig().showscale) return 0.9F; return 1; } diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java index e609ca13..5b94b3f1 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java @@ -1,12 +1,10 @@ package com.minelittlepony.render.layer; import com.google.common.collect.Maps; -import com.minelittlepony.ForgeProxy; import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.armour.ModelPonyArmor; import com.minelittlepony.util.coordinates.Color; - import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; @@ -21,11 +19,11 @@ import net.minecraft.item.ItemArmor.ArmorMaterial; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Tuple; - -import javax.annotation.Nullable; +import net.minecraftforge.client.ForgeHooksClient; import java.io.IOException; import java.util.Map; +import javax.annotation.Nullable; public class LayerPonyArmor extends AbstractPonyLayer { @@ -157,11 +155,11 @@ public class LayerPonyArmor extends AbstractPonyLaye } private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, EntityEquipmentSlot slot, @Nullable String type) { - return ForgeProxy.getArmorTexture(entity, item, def, slot, type); + return ForgeHooksClient.getArmorTexture(entity, item, def, slot, type); } private static ModelPonyArmor getArmorModel(EntityLivingBase entity, ItemStack itemstack, EntityEquipmentSlot slot, ModelPonyArmor def) { - ModelBase model = ForgeProxy.getArmorModel(entity, itemstack, slot, def); + ModelBase model = ForgeHooksClient.getArmorModel(entity, itemstack, slot, def); if (model instanceof ModelPonyArmor) { return (ModelPonyArmor) model; } diff --git a/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java b/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java index e7f17034..3c42303b 100644 --- a/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java +++ b/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java @@ -2,75 +2,92 @@ package com.minelittlepony.render.ponies; import com.minelittlepony.MineLittlePony; import com.minelittlepony.PonyRenderManager; -import com.minelittlepony.settings.SensibleConfig.Setting; - +import com.minelittlepony.settings.PonyConfig; +import com.minelittlepony.settings.Setting; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.entity.monster.*; -import net.minecraft.entity.passive.*; +import net.minecraft.entity.monster.EntityElderGuardian; +import net.minecraft.entity.monster.EntityEvoker; +import net.minecraft.entity.monster.EntityGiantZombie; +import net.minecraft.entity.monster.EntityGuardian; +import net.minecraft.entity.monster.EntityHusk; +import net.minecraft.entity.monster.EntityIllusionIllager; +import net.minecraft.entity.monster.EntityPigZombie; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntityStray; +import net.minecraft.entity.monster.EntityVex; +import net.minecraft.entity.monster.EntityVindicator; +import net.minecraft.entity.monster.EntityWitch; +import net.minecraft.entity.monster.EntityWitherSkeleton; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.monster.EntityZombieVillager; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraftforge.fml.client.registry.RenderingRegistry; /** * Central location where new entity renderers are registered and applied. * * Due to the limitations in Mumfrey's framework, needs to be paired with a field in PonyConfig. */ -public enum MobRenderers implements Setting { +public enum MobRenderers implements Setting { VILLAGERS { @Override - public void register(boolean state, PonyRenderManager pony, RenderManager manager) { - pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager)); - pony.switchRenderer(state, manager, EntityWitch.class, new RenderPonyWitch(manager)); - pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager)); + public void register(boolean state, PonyRenderManager pony) { + pony.switchRenderer(state, EntityVillager.class, RenderPonyVillager::new); + pony.switchRenderer(state, EntityWitch.class, RenderPonyWitch::new); + pony.switchRenderer(state, EntityZombieVillager.class, RenderPonyZombieVillager::new); } }, ZOMBIES { @Override - public void register(boolean state, PonyRenderManager pony, RenderManager manager) { - pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager)); - pony.switchRenderer(state, manager, EntityHusk.class, new RenderPonyZombie.Husk(manager)); - pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager)); + public void register(boolean state, PonyRenderManager pony) { + pony.switchRenderer(state, EntityZombie.class, RenderPonyZombie::new); + pony.switchRenderer(state, EntityHusk.class, RenderPonyZombie.Husk::new); + pony.switchRenderer(state, EntityGiantZombie.class, RenderPonyZombie.Giant::new); } }, PIGZOMBIES { @Override - public void register(boolean state, PonyRenderManager pony, RenderManager manager) { - pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager)); + public void register(boolean state, PonyRenderManager pony) { + pony.switchRenderer(state, EntityPigZombie.class, RenderPonyPigman::new); } }, SKELETONS { @Override - public void register(boolean state, PonyRenderManager pony, RenderManager manager) { - pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager)); - pony.switchRenderer(state, manager, EntityStray.class, new RenderPonySkeleton.Stray(manager)); - pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager)); + public void register(boolean state, PonyRenderManager pony) { + pony.switchRenderer(state, EntitySkeleton.class, RenderPonySkeleton::new); + pony.switchRenderer(state, EntityStray.class, RenderPonySkeleton.Stray::new); + pony.switchRenderer(state, EntityWitherSkeleton.class, RenderPonySkeleton.Wither::new); } }, ILLAGERS { @Override - public void register(boolean state, PonyRenderManager pony, RenderManager manager) { - pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager)); - pony.switchRenderer(state, manager, EntityEvoker.class, new RenderPonyIllager.Evoker(manager)); - pony.switchRenderer(state, manager, EntityVindicator.class, new RenderPonyIllager.Vindicator(manager)); - pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager)); + public void register(boolean state, PonyRenderManager pony) { + pony.switchRenderer(state, EntityVex.class, RenderPonyVex::new); + pony.switchRenderer(state, EntityEvoker.class, RenderPonyIllager.Evoker::new); + pony.switchRenderer(state, EntityVindicator.class, RenderPonyIllager.Vindicator::new); + pony.switchRenderer(state, EntityIllusionIllager.class, RenderPonyIllager.Illusionist::new); } }, GUARDIANS { @Override - public void register(boolean state, PonyRenderManager pony, RenderManager manager) { - pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager)); - pony.switchRenderer(state, manager, EntityElderGuardian.class, new RenderPonyGuardian.Elder(manager)); + public void register(boolean state, PonyRenderManager pony) { + pony.switchRenderer(state, EntityGuardian.class, RenderPonyGuardian::new); + pony.switchRenderer(state, EntityElderGuardian.class, RenderPonyGuardian.Elder::new); } }; @Override - public void set(boolean value) { - Setting.super.set(value); - apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager()); + public void set(PonyConfig config, boolean value) { + Setting.super.set(config, value); + apply(value, MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager()); } - public void apply(PonyRenderManager pony, RenderManager manager) { - boolean state = get(); - register(state, pony, manager); + public void apply(boolean state, PonyRenderManager pony, RenderManager manager) { + register(state, pony); + + RenderingRegistry.loadEntityRenderers(manager, manager.entityRenderMap); + if (state) { MineLittlePony.logger.info(name() + " are now ponies."); } else { @@ -78,5 +95,5 @@ public enum MobRenderers implements Setting { } } - public abstract void register(boolean state, PonyRenderManager pony, RenderManager manager); -} \ No newline at end of file + public abstract void register(boolean state, PonyRenderManager pony); +} diff --git a/src/main/java/com/minelittlepony/settings/PonyConfig.java b/src/main/java/com/minelittlepony/settings/PonyConfig.java new file mode 100644 index 00000000..aa5f24db --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/PonyConfig.java @@ -0,0 +1,113 @@ +package com.minelittlepony.settings; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.minelittlepony.MineLittlePony; +import com.minelittlepony.pony.data.PonyLevel; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; + +/** + * Storage container for MineLP client settings. + */ +public class PonyConfig { + + private PonyLevel ponylevel = PonyLevel.PONIES; + + public boolean sizes = true; + public boolean snuzzles = true; + public boolean hd = true; + public boolean showscale = true; + + public boolean villagers = true; + public boolean zombies = true; + public boolean pigzombies = true; + public boolean skeletons = true; + public boolean illagers = true; + public boolean guardians = true; + + public enum PonySettings implements Setting { + SIZES, + SNUZZLES, + HD, + SHOWSCALE + + } + + /** + * Gets the current PonyLevel. That is the level of ponies you would like to see. + * + * @param ignorePony true to ignore whatever value the setting has. + */ + public PonyLevel getEffectivePonyLevel(boolean ignorePony) { + return ignorePony ? PonyLevel.BOTH : getPonyLevel(); + } + + /** + * Actually gets the pony level value. No option to ignore reality here. + */ + public PonyLevel getPonyLevel() { + if (ponylevel == null) { + ponylevel = PonyLevel.PONIES; + } + return ponylevel; + } + + /** + * Sets the pony level. Want MOAR PONEHS? Well here you go. + * + * @param ponylevel + */ + public void setPonyLevel(PonyLevel ponylevel) { + this.ponylevel = ponylevel; + } + + public void save() { + + } + + public static class Loader { + + private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + private final Path path; + + private PonyConfig config; + + public Loader(Path path) { + this.path = path; + } + + public PonyConfig getConfig() { + if (config == null) { + reload(); + } + return config; + } + + public void reload() { + try (BufferedReader reader = Files.newBufferedReader(path)) { + config = gson.fromJson(reader, PonyConfig.class); + } catch (NoSuchFileException e) { + config = new PonyConfig(); + } catch (IOException e) { + MineLittlePony.logger.warn("Error while loading config. Using defaults.", e); + config = new PonyConfig(); + } + save(); + } + + public void save() { + try (BufferedWriter writer = Files.newBufferedWriter(path)) { + gson.toJson(getConfig(), writer); + } catch (IOException e) { + MineLittlePony.logger.warn("Unable to save config.", e); + } + } + } +} diff --git a/src/main/java/com/minelittlepony/settings/SensibleConfig.java b/src/main/java/com/minelittlepony/settings/SensibleConfig.java deleted file mode 100644 index a12f1f3f..00000000 --- a/src/main/java/com/minelittlepony/settings/SensibleConfig.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.minelittlepony.settings; - -import com.minelittlepony.gui.IGUIAction; - -/** - * A sensible config container that actually lets us programatically index values by a key. - * - * Reflection because Mumfrey pls. - * - */ -// Mumfrey pls. -public abstract class SensibleConfig { - - private static SensibleConfig instance; - - public SensibleConfig() { - instance = this; - } - - public interface Setting extends IGUIAction { - String name(); - - /** - * Gets the config value associated with this entry. - */ - default boolean get() { - return instance.getValue(this); - } - - - /** - * Sets the config value associated with this entry. - */ - default void set(boolean value) { - instance.setValue(this, value); - } - - @Override - default Boolean perform(Boolean v) { - set(v); - return v; - } - } - - public boolean getValue(Setting key) { - try { - return this.getClass().getField(key.name().toLowerCase()).getBoolean(this); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignored) { - return true; - } - } - - public boolean setValue(Setting key, boolean value) { - try { - this.getClass().getField(key.name().toLowerCase()).setBoolean(this, value); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignored) { - } - return value; - } -} diff --git a/src/main/java/com/minelittlepony/settings/Setting.java b/src/main/java/com/minelittlepony/settings/Setting.java new file mode 100644 index 00000000..45d0cb5d --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/Setting.java @@ -0,0 +1,35 @@ +package com.minelittlepony.settings; + + +import java.lang.reflect.Field; + +public interface Setting { + + String name(); + + default boolean get(Config config) { + try { + Field field = getField(config.getClass()); + return field.getBoolean(config); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + default void set(Config config, boolean value) { + try { + Field field = getField(config.getClass()); + field.setBoolean(config, value); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + default Field getField(Class owner) { + try { + return owner.getField(name().toLowerCase()); + } catch (NoSuchFieldException e) { + throw new IllegalArgumentException(e); + } + } +}