It runs on forge now. Probably has some bugs or unimplemented things.

This commit is contained in:
Matthew Messinger 2018-06-10 01:01:59 -04:00
parent af88f75de7
commit 8ddee9f65e
38 changed files with 511 additions and 804 deletions

View file

@ -31,6 +31,8 @@ minecraft {
mappings = 'snapshot_20180606' mappings = 'snapshot_20180606'
runDir = 'run' runDir = 'run'
replace '@VERSION@', project.version replace '@VERSION@', project.version
clientJvmArgs += '-Dfml.coreMod.load=com.minelittlepony.core.MLPLoadingPlugin'
} }
sourceSets { sourceSets {
@ -70,6 +72,8 @@ dependencies {
jar { jar {
from sourceSets.hdskins.output from sourceSets.hdskins.output
manifest.attributes FMLCorePlugin: 'com.minelittlepony.core.MLPLoadingPlugin',
FMLCorePluginContainsFMLMod: 'true'
} }
sourceJar { sourceJar {
// add hdskins sources // add hdskins sources

View file

@ -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:
* <ul>
* <li>An explicit nullness annotation
* <li>The method overrides a method in a superclass (in which case the
* annotation of the corresponding method in the superclass applies)
* <li> there is a default parameter annotation applied to a more tightly nested
* element.
* </ul>
*
*/
@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 {}

View file

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

View file

@ -16,8 +16,6 @@ import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload; import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
import com.mojang.util.UUIDTypeAdapter; 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.resource.SkinResourceManager;
import com.voxelmodpack.hdskins.skins.AsyncCacheLoader; import com.voxelmodpack.hdskins.skins.AsyncCacheLoader;
import com.voxelmodpack.hdskins.skins.SkinServer; 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.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener; import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.resources.SkinManager.SkinAvailableCallback; import net.minecraft.client.resources.SkinManager.SkinAvailableCallback;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils; 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.Graphics;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -47,12 +48,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public final class HDSkinManager implements IResourceManagerReloadListener { public final class HDSkinManager implements IResourceManagerReloadListener {
private static final Logger LOGGER = LogManager.getLogger();
private static final ResourceLocation LOADING = new ResourceLocation("LOADING"); private static final ResourceLocation LOADING = new ResourceLocation("LOADING");
private static final Gson GSON = new GsonBuilder() private static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter()) .registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
@ -139,7 +141,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
String skinDir = type.toString().toLowerCase() + "s/"; String skinDir = type.toString().toLowerCase() + "s/";
final ResourceLocation skin = new ResourceLocation("hdskins", skinDir + texture.getHash()); 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; final IImageBuffer imagebufferdownload = type == Type.SKIN ? new ImageBufferDownloadHD() : null;
@ -237,11 +239,11 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
} }
public static void clearSkinCache() { public static void clearSkinCache() {
LiteLoaderLogger.info("Clearing local player skin cache"); LOGGER.info("Clearing local player skin cache");
try { try {
FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "skins")); FileUtils.deleteDirectory(new File(Launch.assetsDir, "skins"));
FileUtils.deleteDirectory(new File(LiteLoader.getAssetsDirectory(), "hd")); FileUtils.deleteDirectory(new File(Launch.assetsDir, "hd"));
TextureManager textures = Minecraft.getMinecraft().getTextureManager(); TextureManager textures = Minecraft.getMinecraft().getTextureManager();
INSTANCE.skinCache.values().stream() INSTANCE.skinCache.values().stream()
.flatMap(m -> m.values().stream()) .flatMap(m -> m.values().stream())
@ -261,7 +263,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
try { try {
return callback.onSkinCacheCleared(); return callback.onSkinCacheCleared();
} catch (Exception e) { } 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(); e.printStackTrace();
return false; return false;
} }

View file

@ -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<String> 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());
}
}
}

View file

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

View file

@ -96,7 +96,7 @@ public class GLWindow extends DropTarget {
frame = new JFrame(Display.getTitle()); frame = new JFrame(Display.getTitle());
frame.add(canvas); frame.add(canvas);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosed(WindowEvent windowEvent) { public void windowClosed(WindowEvent windowEvent) {

View file

@ -8,7 +8,6 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.skins.SkinUploadResponse; import com.voxelmodpack.hdskins.skins.SkinUploadResponse;
import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG;
@ -33,6 +32,7 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU; import org.lwjgl.util.glu.GLU;
@ -47,6 +47,9 @@ import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
public class GuiSkins extends GuiScreen implements FutureCallback<SkinUploadResponse> { public class GuiSkins extends GuiScreen implements FutureCallback<SkinUploadResponse> {
private static final Logger LOGGER = LogManager.getLogger();
private static final int MAX_SKIN_DIMENSION = 1024; private static final int MAX_SKIN_DIMENSION = 1024;
private int updateCounter = 0; private int updateCounter = 0;
private ResourceLocation viewportTexture; private ResourceLocation viewportTexture;
@ -672,7 +675,7 @@ public class GuiSkins extends GuiScreen implements FutureCallback<SkinUploadResp
} }
private void onUploadComplete(SkinUploadResponse response) { private void onUploadComplete(SkinUploadResponse response) {
LiteLoaderLogger.info("Upload completed with: %s", response); LOGGER.info("Upload completed with: %s", response);
this.uploadingSkin = false; this.uploadingSkin = false;
if (!"OK".equalsIgnoreCase(response.getMessage())) { if (!"OK".equalsIgnoreCase(response.getMessage())) {
this.setUploadError(response.getMessage()); this.setUploadError(response.getMessage());

View file

@ -1,64 +1,28 @@
package com.voxelmodpack.hdskins.gui; package com.voxelmodpack.hdskins.gui;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraftforge.fml.client.config.GuiConfig;
public class HDSkinsConfigPanel implements ConfigPanel { public class HDSkinsConfigPanel extends GuiConfig {
private GuiButton button; private GuiButton button;
@Override public HDSkinsConfigPanel() {
public void onPanelShown(ConfigPanelHost host) { super(null, "hdskins", "HD Skins");
this.button = new GuiButton(0, 40, 10, 100, 20, "Clear Skin Cache");
} }
@Override @Override
public void drawPanel(ConfigPanelHost host, int mouseX, int mouseY, float partialTicks) { public void initGui() {
this.button.drawButton(Minecraft.getMinecraft(), mouseX, mouseY, partialTicks); this.addButton(new GuiButton(0, 40, 10, 100, 20, "Clear Skin Cache"));
} }
@Override @Override
public void mousePressed(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) { protected void actionPerformed(GuiButton button) {
if (button.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { super.actionPerformed(button);
if (button.id == 0) {
HDSkinManager.clearSkinCache(); HDSkinManager.clearSkinCache();
} }
} }
@Override
public String getPanelTitle() {
return "HD Skins Settings";
}
@Override
public int getContentHeight() {
return 0;
}
@Override
public void keyPressed(ConfigPanelHost host, char keyChar, int keyCode) {
}
@Override
public void mouseMoved(ConfigPanelHost host, int mouseX, int mouseY) {
}
@Override
public void mouseReleased(ConfigPanelHost host, int mouseX, int mouseY, int mouseButton) {
}
@Override
public void onPanelHidden() {
}
@Override
public void onPanelResize(ConfigPanelHost host) {
}
@Override
public void onTick(ConfigPanelHost host) {
}
} }

View file

@ -1,8 +0,0 @@
package com.voxelmodpack.hdskins.mod;
import com.mumfrey.liteloader.Configurable;
import com.mumfrey.liteloader.InitCompleteListener;
import com.mumfrey.liteloader.ViewportListener;
public interface HDSkinsMod extends InitCompleteListener, ViewportListener, Configurable {
}

View file

@ -1,97 +0,0 @@
package com.voxelmodpack.hdskins.mod;
import com.google.gson.annotations.Expose;
import com.mumfrey.liteloader.core.LiteLoader;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.modconfig.ConfigStrategy;
import com.mumfrey.liteloader.modconfig.ExposableOptions;
import com.mumfrey.liteloader.util.ModUtilities;
import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.gui.EntityPlayerModel;
import com.voxelmodpack.hdskins.gui.GLWindow;
import com.voxelmodpack.hdskins.gui.GuiSkins;
import com.voxelmodpack.hdskins.gui.HDSkinsConfigPanel;
import com.voxelmodpack.hdskins.gui.RenderPlayerModel;
import com.voxelmodpack.hdskins.skins.SkinServer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.resources.IReloadableResourceManager;
import java.io.File;
import java.lang.reflect.Method;
import java.util.List;
@ExposableOptions(strategy = ConfigStrategy.Unversioned, filename = "hdskins")
public class LiteModHDSkinsMod implements HDSkinsMod {
@Expose
public List<String> 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<? extends ConfigPanel> 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);
}
}

View file

@ -1,7 +0,0 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.mod;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -5,15 +5,14 @@ import com.google.gson.Gson;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; 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.IResource;
import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener; import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -23,9 +22,12 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.annotation.Nullable;
public class SkinResourceManager implements IResourceManagerReloadListener { public class SkinResourceManager implements IResourceManagerReloadListener {
private static final Logger logger = LogManager.getLogger();
private ExecutorService executor = Executors.newSingleThreadExecutor(); private ExecutorService executor = Executors.newSingleThreadExecutor();
private Map<UUID, Skin> uuidSkins = Maps.newHashMap(); private Map<UUID, Skin> uuidSkins = Maps.newHashMap();
@ -55,7 +57,7 @@ public class SkinResourceManager implements IResourceManagerReloadListener {
} }
} }
} catch (JsonParseException je) { } 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) { } catch (IOException e) {

View file

@ -2,16 +2,8 @@ package com.voxelmodpack.hdskins.upload.awt;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import java.awt.AWTEvent; import javax.swing.*;
import java.awt.event.MouseEvent; import javax.swing.filechooser.*;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileFilter;
import org.lwjgl.opengl.Display;
import com.voxelmodpack.hdskins.Later;
/** /**
* Base class for "open file" dialog threads * Base class for "open file" dialog threads
@ -41,18 +33,6 @@ public abstract class ThreadOpenFile extends Thread {
this.dialogTitle = dialogTitle; 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 @Override
public void run() { public void run() {
if (parent == null) { if (parent == null) {

View file

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

View file

@ -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<? extends ConfigPanel> getConfigPanelClass() {
return PonySettingsPanel.class;
}
}

View file

@ -4,53 +4,49 @@ import com.minelittlepony.gui.GuiPonySettings;
import com.minelittlepony.hdskins.gui.GuiSkinsMineLP; import com.minelittlepony.hdskins.gui.GuiSkinsMineLP;
import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.IPonyData;
import com.minelittlepony.pony.data.PonyDataSerialzier; 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.HDSkinManager;
import com.voxelmodpack.hdskins.gui.GuiSkins; import com.voxelmodpack.hdskins.gui.GuiSkins;
import com.voxelmodpack.hdskins.skins.SkinServer; import com.voxelmodpack.hdskins.skins.SkinServer;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.data.MetadataSerializer; import net.minecraft.client.resources.data.MetadataSerializer;
import net.minecraft.client.settings.KeyBinding; 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.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard; 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) @Mod(modid = "minelittlepony", name = MineLittlePony.MOD_NAME, version = MineLittlePony.MOD_VERSION, clientSideOnly = true)
public class MineLittlePony { 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_NAME = "Mine Little Pony";
public static final String MOD_VERSION = "@VERSION@"; public static final String MOD_VERSION = "@VERSION@";
private static final String MINELP_LEGACY_SERVER = "legacy:http://minelpskins.voxelmodpack.com;http://minelpskinmanager.voxelmodpack.com"; 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 final KeyBinding SETTINGS_GUI = new KeyBinding("Settings", Keyboard.KEY_F9, "Mine Little Pony");
private static MineLittlePony instance; private static MineLittlePony instance;
private final PonyConfig config; private PonyConfig.Loader configLoader;
private final PonyManager ponyManager; private PonyManager ponyManager;
private final PonyRenderManager renderManager; private PonyRenderManager renderManager;
@Mod.EventHandler @Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
instance = this; 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(); IReloadableResourceManager irrm = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
irrm.registerReloadListener(ponyManager); irrm.registerReloadListener(ponyManager);
@ -63,7 +59,9 @@ public class MineLittlePony {
} }
@Mod.EventHandler @Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) { public void postInit(FMLLoadCompleteEvent event) {
renderManager = new PonyRenderManager(Minecraft.getMinecraft().getRenderManager());
HDSkinManager manager = HDSkinManager.INSTANCE; HDSkinManager manager = HDSkinManager.INSTANCE;
// manager.setSkinUrl(SKIN_SERVER_URL); // manager.setSkinUrl(SKIN_SERVER_URL);
@ -72,9 +70,8 @@ public class MineLittlePony {
// logger.info("Set MineLP skin server URL."); // logger.info("Set MineLP skin server URL.");
manager.addClearListener(ponyManager); manager.addClearListener(ponyManager);
RenderManager rm = minecraft.getRenderManager(); renderManager.initialisePlayerRenderers();
renderManager.initialisePlayerRenderers(rm); renderManager.initializeMobRenderers(configLoader.getConfig());
renderManager.initializeMobRenderers(rm, config);
} }
/** /**
@ -91,7 +88,7 @@ public class MineLittlePony {
if (skins) { if (skins) {
minecraft.displayGuiScreen(new GuiSkinsMineLP(ponyManager)); 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. * Gets the global MineLP client configuration.
*/ */
public static PonyConfig getConfig() { public static PonyConfig.Loader getConfigLoader() {
return getInstance().config; return getInstance().configLoader;
} }
} }

View file

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

View file

@ -7,6 +7,7 @@ import com.google.gson.JsonParseException;
import com.minelittlepony.model.PMAPI; import com.minelittlepony.model.PMAPI;
import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyLevel; import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.settings.PonyConfig;
import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.ISkinCacheClearListener; import com.voxelmodpack.hdskins.ISkinCacheClearListener;

View file

@ -1,20 +1,22 @@
package com.minelittlepony; package com.minelittlepony;
import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.minelittlepony.mixin.MixinRenderManager;
import com.minelittlepony.hdskins.gui.EntityPonyModel; import com.minelittlepony.hdskins.gui.EntityPonyModel;
import com.minelittlepony.hdskins.gui.RenderPonyModel; import com.minelittlepony.hdskins.gui.RenderPonyModel;
import com.minelittlepony.model.player.PlayerModels; import com.minelittlepony.model.player.PlayerModels;
import com.minelittlepony.render.LevitatingItemRenderer; import com.minelittlepony.render.LevitatingItemRenderer;
import com.minelittlepony.render.player.RenderPonyPlayer; import com.minelittlepony.render.player.RenderPonyPlayer;
import com.minelittlepony.render.ponies.MobRenderers; 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.Render;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.entity.Entity; 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. * 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 LevitatingItemRenderer magicRenderer = new LevitatingItemRenderer();
private final Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap(); private final Map<Class<? extends Entity>, Render<?>> renderMap = Maps.newHashMap();
private final RenderManager manager;
private final Map<String, RenderPlayer> 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). * 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 // Preview on the select skin gui
ModUtilities.addRenderer(EntityPonyModel.class, new RenderPonyModel(manager)); RenderingRegistry.registerEntityRenderingHandler(EntityPonyModel.class, RenderPonyModel::new);
for (PlayerModels i : PlayerModels.values()) { for (PlayerModels i : PlayerModels.values()) {
if (i != PlayerModels.HUMAN) { if (i != PlayerModels.HUMAN) {
registerPlayerSkin(manager, i); registerPlayerSkin(i);
} }
} }
} }
private void registerPlayerSkin(RenderManager manager, PlayerModels playerModel) { private void registerPlayerSkin(PlayerModels playerModel) {
addPlayerSkin(manager, false, playerModel); addPlayerSkin(false, playerModel);
addPlayerSkin(manager, true, 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)); RenderPonyPlayer renderer = new RenderPonyPlayer(manager, slimArms, playerModel.getModel(slimArms));
((MixinRenderManager)manager).getSkinMap().put(playerModel.getId(slimArms), renderer); Map<String, RenderPlayer> skinMap = ReflectionHelper.getPrivateValue(RenderManager.class, manager, "field_178636_l", "skinMap");
skinMap.put(playerModel.getId(slimArms), renderer);
} }
/** /**
* Registers all entity model replacements. (except for players). * 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()) { 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. * 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 state True if we want ponies (the original will be stored)
* @param manager The render manager
* @param type The type to replace * @param type The type to replace
* @param renderer The replacement value * @param renderer The replacement value
* @param <T> The entity type * @param <T> The entity type
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends Entity, V extends T> void switchRenderer(boolean state, RenderManager manager, Class<V> type, Render<T> renderer) { public <T extends Entity> void switchRenderer(boolean state, Class<T> type, IRenderFactory<T> renderer) {
if (state) { if (state) {
if (!renderMap.containsKey(type)) { if (!renderMap.containsKey(type)) {
renderMap.put(type, manager.getEntityClassRenderObject(type)); renderMap.put(type, manager.getEntityClassRenderObject(type));
} }
ModUtilities.addRenderer((Class<T>)type, renderer); RenderingRegistry.registerEntityRenderingHandler(type, renderer);
} else { } else if (renderMap.containsKey(type)) {
if (renderMap.containsKey(type)) { RenderingRegistry.registerEntityRenderingHandler(type, mngr -> (Render<T>) renderMap.get(type));
ModUtilities.addRenderer(type, (Render<V>)renderMap.get(type));
}
} }
} }
public LevitatingItemRenderer getMagicRenderer() { public LevitatingItemRenderer getMagicRenderer() {

View file

@ -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<String, Object> data) {
}
@Override
public String getAccessTransformerClass() {
return null;
}
}

View file

@ -1,22 +1,22 @@
package com.minelittlepony.gui; package com.minelittlepony.gui;
import com.mumfrey.liteloader.client.gui.GuiCheckbox;
import net.minecraft.client.resources.I18n; 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<Boolean> action; public class Checkbox extends GuiCheckBox implements IActionable {
public Checkbox(int x, int y, String displayString, boolean value, IGUIAction<Boolean> callback) { private final Consumer<Boolean> callback;
super(0, x, y, I18n.format(displayString));
action = callback; public Checkbox(int x, int y, String displayString, boolean value, Consumer<Boolean> callback) {
checked = value; super(0, x, y, I18n.format(displayString), value);
this.callback = callback;
} }
@Override @Override
public void perform() { public void perform() {
checked = action.perform(!checked); this.callback.accept(isChecked());
} }
} }

View file

@ -1,23 +1,19 @@
package com.minelittlepony.gui; package com.minelittlepony.gui;
import java.io.IOException;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.PonyConfig.PonySettings;
import com.minelittlepony.pony.data.PonyLevel; import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.render.ponies.MobRenderers; 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.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.config.GuiConfig;
/** /**
* In-Game options menu. * In-Game options menu.
* *
*/ */
public class GuiPonySettings extends GuiScreen { public class GuiPonySettings extends GuiConfig {
private static final String OPTIONS_PREFIX = "minelp.options."; 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 static final String MOB_PREFIX = "minelp.mobs.";
private PonyConfig.Loader configLoader;
private PonyConfig config; private PonyConfig config;
public GuiPonySettings() { public GuiPonySettings() {
config = MineLittlePony.getConfig(); super(null, "minelittlepony", "Mine Little Pony");
configLoader = MineLittlePony.getConfigLoader();
config = configLoader.getConfig();
} }
@Override @Override
@ -44,17 +43,17 @@ public class GuiPonySettings extends GuiScreen {
addButton(new Label(LEFT, row += 15, PONY_LEVEL, -1)); 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) -> { 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 -> { }, v -> {
PonyLevel level = PonyLevel.valueFor(v); PonyLevel level = PonyLevel.valueFor((int) v);
config.setPonyLevel(level); config.setPonyLevel(level);
return (float)level.ordinal(); return (float)level.ordinal();
})); }));
row += 15; row += 15;
addButton(new Label(LEFT, row += 15, OPTIONS_PREFIX + "options", -1)); addButton(new Label(LEFT, row += 15, OPTIONS_PREFIX + "options", -1));
for (PonySettings i : PonySettings.values()) { for (Setting<PonyConfig> i : PonyConfig.PonySettings.values()) {
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i.get(), i)); addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i.get(config), b -> i.set(config, b)));
} }
if (mustScroll()) { if (mustScroll()) {
@ -65,12 +64,12 @@ public class GuiPonySettings extends GuiScreen {
addButton(new Label(RIGHT, row += 15, MOB_PREFIX + "title", -1)); addButton(new Label(RIGHT, row += 15, MOB_PREFIX + "title", -1));
for (MobRenderers i : MobRenderers.values()) { 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 @Override
protected void actionPerformed(GuiButton button) throws IOException { protected void actionPerformed(GuiButton button) {
if (button instanceof IActionable) { if (button instanceof IActionable) {
((IActionable)button).perform(); ((IActionable)button).perform();
} }
@ -84,7 +83,7 @@ public class GuiPonySettings extends GuiScreen {
@Override @Override
public void onGuiClosed() { public void onGuiClosed() {
LiteLoader.getInstance().writeConfig(config); configLoader.save();
} }
protected String getTitle() { protected String getTitle() {

View file

@ -1,15 +0,0 @@
package com.minelittlepony.gui;
/**
* Response actions for UI events.
*/
@FunctionalInterface
public interface IGUIAction<T> {
/**
* 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);
}

View file

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

View file

@ -3,11 +3,13 @@ package com.minelittlepony.gui;
import net.minecraft.client.gui.GuiSlider; import net.minecraft.client.gui.GuiSlider;
import net.minecraft.client.gui.GuiPageButtonList.GuiResponder; import net.minecraft.client.gui.GuiPageButtonList.GuiResponder;
import java.util.function.DoubleUnaryOperator;
public class Slider extends GuiSlider { public class Slider extends GuiSlider {
private static Responder callback; private static Responder callback;
public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, IGUIAction<Float> 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); super(callback = new Responder(action), 0, x, y, "", minIn, maxIn, defaultValue, formatter);
callback.owner = this; callback.owner = this;
callback = null; callback = null;
@ -15,11 +17,11 @@ public class Slider extends GuiSlider {
private static final class Responder implements GuiResponder { private static final class Responder implements GuiResponder {
private final IGUIAction<Float> action; private final DoubleUnaryOperator action;
private Slider owner; private Slider owner;
private Responder(IGUIAction<Float> callback) { private Responder(DoubleUnaryOperator callback) {
action = callback; action = callback;
} }
@ -28,7 +30,7 @@ public class Slider extends GuiSlider {
@Override @Override
public void setEntryValue(int id, float value) { public void setEntryValue(int id, float value) {
owner.setSliderValue(action.perform(value), false); owner.setSliderValue((float) action.applyAsDouble(value), false);
} }
@Override @Override

View file

@ -1,12 +1,11 @@
package com.minelittlepony.model.components; package com.minelittlepony.model.components;
import com.minelittlepony.pony.data.PonyGender;
import com.minelittlepony.render.plane.PlaneRenderer;
import static com.minelittlepony.model.PonyModelConstants.*; import static com.minelittlepony.model.PonyModelConstants.*;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.AbstractPonyModel;
import com.minelittlepony.pony.data.PonyGender;
import com.minelittlepony.render.plane.PlaneRenderer;
public class PonySnout { public class PonySnout {
@ -51,7 +50,7 @@ public class PonySnout {
} }
public void setGender(PonyGender gender) { public void setGender(PonyGender gender) {
boolean show = !isHidden && MineLittlePony.getConfig().snuzzles; boolean show = !isHidden && MineLittlePony.getConfigLoader().getConfig().snuzzles;
mare.isHidden = !show || gender == PonyGender.STALLION; mare.isHidden = !show || gender == PonyGender.STALLION;
stallion.isHidden = !show || gender == PonyGender.MARE; stallion.isHidden = !show || gender == PonyGender.MARE;

View file

@ -117,7 +117,7 @@ public class Pony {
} }
public PonyRace getRace(boolean ignorePony) { 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() { public ResourceLocation getTexture() {

View file

@ -58,7 +58,7 @@ public class PonyData implements IPonyData {
@Override @Override
public PonySize getSize() { public PonySize getSize() {
return MineLittlePony.getConfig().sizes ? size : PonySize.NORMAL; return MineLittlePony.getConfigLoader().getConfig().sizes ? size : PonySize.NORMAL;
} }
@Override @Override

View file

@ -5,11 +5,11 @@ public enum PonyLevel {
HUMANS, HUMANS,
BOTH; BOTH;
public static PonyLevel valueFor(float index) { public static PonyLevel valueFor(int index) {
PonyLevel[] values = values(); PonyLevel[] values = values();
if (index < 0) { if (index < 0) {
index = 0; index = 0;
} }
return values[(int)Math.round(index) % values.length]; return values[Math.round(index) % values.length];
} }
} }

View file

@ -20,14 +20,14 @@ public enum PonySize implements ITriggerPixelMapped<PonySize> {
} }
public float getShadowSize() { public float getShadowSize() {
if (MineLittlePony.getConfig().showscale) { if (MineLittlePony.getConfigLoader().getConfig().showscale) {
return shadowSize * 0.9F; return shadowSize * 0.9F;
} }
return shadowSize; return shadowSize;
} }
public float getScaleFactor() { public float getScaleFactor() {
if (MineLittlePony.getConfig().showscale) { if (MineLittlePony.getConfigLoader().getConfig().showscale) {
return scale * 0.9F; return scale * 0.9F;
} }
return scale; return scale;

View file

@ -1,13 +1,11 @@
package com.minelittlepony.render; package com.minelittlepony.render;
import org.lwjgl.opengl.GL14; import static net.minecraft.client.renderer.GlStateManager.*;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.ducks.IRenderItem;
import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.util.coordinates.Color; import com.minelittlepony.util.coordinates.Color;
import com.mumfrey.liteloader.client.overlays.IMinecraft;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.ItemRenderer;
@ -17,7 +15,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumAction; import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHandSide; import net.minecraft.util.EnumHandSide;
import static net.minecraft.client.renderer.GlStateManager.*; import org.lwjgl.opengl.GL14;
public class LevitatingItemRenderer { public class LevitatingItemRenderer {
@ -112,7 +110,7 @@ public class LevitatingItemRenderer {
boolean doBow = doNormal && stack.getItemUseAction() == EnumAction.BOW; boolean doBow = doNormal && stack.getItemUseAction() == EnumAction.BOW;
if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items. 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 floatAmount = (float)Math.sin(ticks / 9) / 40;
float driftAmount = (float)Math.cos(ticks / 10) / 40; float driftAmount = (float)Math.cos(ticks / 10) / 40;

View file

@ -83,7 +83,7 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
public float getShadowScale() { public float getShadowScale() {
if (mainModel.isChild) { if (mainModel.isChild) {
return 0.25F; return 0.25F;
} else if (MineLittlePony.getConfig().showscale) { } else if (MineLittlePony.getConfigLoader().getConfig().showscale) {
return 0.4F; return 0.4F;
} }
return 0.5F; return 0.5F;
@ -91,7 +91,7 @@ public abstract class RenderPonyMob<T extends EntityLiving> extends RenderLiving
@Override @Override
public float getScaleFactor() { public float getScaleFactor() {
if (MineLittlePony.getConfig().showscale) return 0.9F; if (MineLittlePony.getConfigLoader().getConfig().showscale) return 0.9F;
return 1; return 1;
} }

View file

@ -1,12 +1,10 @@
package com.minelittlepony.render.layer; package com.minelittlepony.render.layer;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.minelittlepony.ForgeProxy;
import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.ModelWrapper;
import com.minelittlepony.model.armour.ModelPonyArmor; import com.minelittlepony.model.armour.ModelPonyArmor;
import com.minelittlepony.util.coordinates.Color; import com.minelittlepony.util.coordinates.Color;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
@ -21,11 +19,11 @@ import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraftforge.client.ForgeHooksClient;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLayer<T> { public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLayer<T> {
@ -157,11 +155,11 @@ public class LayerPonyArmor<T extends EntityLivingBase> extends AbstractPonyLaye
} }
private static String getArmorTexture(EntityLivingBase entity, ItemStack item, String def, EntityEquipmentSlot slot, @Nullable String type) { 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) { 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) { if (model instanceof ModelPonyArmor) {
return (ModelPonyArmor) model; return (ModelPonyArmor) model;
} }

View file

@ -2,75 +2,92 @@ package com.minelittlepony.render.ponies;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyRenderManager; 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.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.monster.*; import net.minecraft.entity.monster.EntityElderGuardian;
import net.minecraft.entity.passive.*; 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. * 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. * 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<PonyConfig> {
VILLAGERS { VILLAGERS {
@Override @Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) { public void register(boolean state, PonyRenderManager pony) {
pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager)); pony.switchRenderer(state, EntityVillager.class, RenderPonyVillager::new);
pony.switchRenderer(state, manager, EntityWitch.class, new RenderPonyWitch(manager)); pony.switchRenderer(state, EntityWitch.class, RenderPonyWitch::new);
pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager)); pony.switchRenderer(state, EntityZombieVillager.class, RenderPonyZombieVillager::new);
} }
}, },
ZOMBIES { ZOMBIES {
@Override @Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) { public void register(boolean state, PonyRenderManager pony) {
pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager)); pony.switchRenderer(state, EntityZombie.class, RenderPonyZombie::new);
pony.switchRenderer(state, manager, EntityHusk.class, new RenderPonyZombie.Husk(manager)); pony.switchRenderer(state, EntityHusk.class, RenderPonyZombie.Husk::new);
pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager)); pony.switchRenderer(state, EntityGiantZombie.class, RenderPonyZombie.Giant::new);
} }
}, },
PIGZOMBIES { PIGZOMBIES {
@Override @Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) { public void register(boolean state, PonyRenderManager pony) {
pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager)); pony.switchRenderer(state, EntityPigZombie.class, RenderPonyPigman::new);
} }
}, },
SKELETONS { SKELETONS {
@Override @Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) { public void register(boolean state, PonyRenderManager pony) {
pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager)); pony.switchRenderer(state, EntitySkeleton.class, RenderPonySkeleton::new);
pony.switchRenderer(state, manager, EntityStray.class, new RenderPonySkeleton.Stray(manager)); pony.switchRenderer(state, EntityStray.class, RenderPonySkeleton.Stray::new);
pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager)); pony.switchRenderer(state, EntityWitherSkeleton.class, RenderPonySkeleton.Wither::new);
} }
}, },
ILLAGERS { ILLAGERS {
@Override @Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) { public void register(boolean state, PonyRenderManager pony) {
pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager)); pony.switchRenderer(state, EntityVex.class, RenderPonyVex::new);
pony.switchRenderer(state, manager, EntityEvoker.class, new RenderPonyIllager.Evoker(manager)); pony.switchRenderer(state, EntityEvoker.class, RenderPonyIllager.Evoker::new);
pony.switchRenderer(state, manager, EntityVindicator.class, new RenderPonyIllager.Vindicator(manager)); pony.switchRenderer(state, EntityVindicator.class, RenderPonyIllager.Vindicator::new);
pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager)); pony.switchRenderer(state, EntityIllusionIllager.class, RenderPonyIllager.Illusionist::new);
} }
}, },
GUARDIANS { GUARDIANS {
@Override @Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) { public void register(boolean state, PonyRenderManager pony) {
pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager)); pony.switchRenderer(state, EntityGuardian.class, RenderPonyGuardian::new);
pony.switchRenderer(state, manager, EntityElderGuardian.class, new RenderPonyGuardian.Elder(manager)); pony.switchRenderer(state, EntityElderGuardian.class, RenderPonyGuardian.Elder::new);
} }
}; };
@Override @Override
public void set(boolean value) { public void set(PonyConfig config, boolean value) {
Setting.super.set(value); Setting.super.set(config, value);
apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager()); apply(value, MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager());
} }
public void apply(PonyRenderManager pony, RenderManager manager) { public void apply(boolean state, PonyRenderManager pony, RenderManager manager) {
boolean state = get(); register(state, pony);
register(state, pony, manager);
RenderingRegistry.loadEntityRenderers(manager, manager.entityRenderMap);
if (state) { if (state) {
MineLittlePony.logger.info(name() + " are now ponies."); MineLittlePony.logger.info(name() + " are now ponies.");
} else { } else {
@ -78,5 +95,5 @@ public enum MobRenderers implements Setting {
} }
} }
public abstract void register(boolean state, PonyRenderManager pony, RenderManager manager); public abstract void register(boolean state, PonyRenderManager pony);
} }

View file

@ -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<PonyConfig> {
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);
}
}
}
}

View file

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

View file

@ -0,0 +1,35 @@
package com.minelittlepony.settings;
import java.lang.reflect.Field;
public interface Setting<Config> {
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);
}
}
}