diff --git a/src/main/java/com/minelittlepony/PonyConfig.java b/src/main/java/com/minelittlepony/PonyConfig.java index 1cd5a732..29e3a16d 100644 --- a/src/main/java/com/minelittlepony/PonyConfig.java +++ b/src/main/java/com/minelittlepony/PonyConfig.java @@ -2,54 +2,71 @@ package com.minelittlepony; import com.google.gson.annotations.Expose; import com.minelittlepony.pony.data.PonyLevel; -import com.minelittlepony.settings.SensibleConfig; +import com.minelittlepony.settings.Value; +import com.minelittlepony.settings.ValueConfig; import com.mumfrey.liteloader.modconfig.ConfigStrategy; -import com.mumfrey.liteloader.modconfig.Exposable; import com.mumfrey.liteloader.modconfig.ExposableOptions; +import java.util.function.Function; + /** * Storage container for MineLP client settings. - * */ @ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned) -public class PonyConfig extends SensibleConfig implements Exposable { +public class PonyConfig extends ValueConfig { @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; - @Expose public boolean fpsmagic = true; - @Expose public boolean ponyskulls = true; + @Expose private final Value sizes = Value.of(true); + @Expose private final Value snuzzles = Value.of(true); + @Expose private final Value hd = Value.of(true); + @Expose private final Value showscale = Value.of(true); + @Expose private final Value fpsmagic = Value.of(true); + @Expose private final Value ponyskulls = Value.of(true); - public enum PonySettings implements Setting { - SIZES, - SNUZZLES, - HD, - SHOWSCALE, - FPSMAGIC, - PONYSKULLS; + @Expose private final Value villagers = Value.of(true); + @Expose private final Value zombies = Value.of(true); + @Expose private final Value pigzombies = Value.of(true); + @Expose private final Value skeletons = Value.of(true); + @Expose private final Value illagers = Value.of(true); + @Expose private final Value guardians = Value.of(true); + + public enum PonySettings implements Value { + + SIZES(PonyConfig::getSizes), + SNUZZLES(PonyConfig::getSnuzzles), + HD(PonyConfig::getHd), + SHOWSCALE(PonyConfig::getShowscale), + FPSMAGIC(PonyConfig::getFpsmagic), + PONYSKULLS(PonyConfig::getPonyskulls); + + private Value config; + + PonySettings(Function> config) { + this.config = config.apply(MineLittlePony.getConfig()); + } + + @Override + public Boolean get() { + return config.get(); + } + + @Override + public void set(Boolean value) { + config.set(value); + } } - @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(); + return ignorePony ? PonyLevel.BOTH : ponylevel; } - /** - * Actually gets the pony level value. No option to ignore reality here. - */ public PonyLevel getPonyLevel() { if (ponylevel == null) { ponylevel = PonyLevel.PONIES; @@ -59,9 +76,58 @@ public class PonyConfig extends SensibleConfig implements Exposable { /** * Sets the pony level. Want MOAR PONEHS? Well here you go. + * * @param ponylevel */ public void setPonyLevel(PonyLevel ponylevel) { this.ponylevel = ponylevel; } + + public Value getSizes() { + return sizes; + } + + public Value getSnuzzles() { + return snuzzles; + } + + public Value getHd() { + return hd; + } + + public Value getShowscale() { + return showscale; + } + + public Value getFpsmagic() { + return fpsmagic; + } + + public Value getPonyskulls() { + return ponyskulls; + } + + public Value getVillagers() { + return villagers; + } + + public Value getZombies() { + return zombies; + } + + public Value getPigzombies() { + return pigzombies; + } + + public Value getSkeletons() { + return skeletons; + } + + public Value getIllagers() { + return illagers; + } + + public Value getGuardians() { + return guardians; + } } diff --git a/src/main/java/com/minelittlepony/gui/Checkbox.java b/src/main/java/com/minelittlepony/gui/Checkbox.java index 51a2421f..c0c4b475 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.minelittlepony.settings.Value; import com.mumfrey.liteloader.client.gui.GuiCheckbox; - import net.minecraft.client.resources.I18n; public class Checkbox extends GuiCheckbox implements IActionable { - private final IGUIAction action; + private final Value setting; - public Checkbox(int x, int y, String displayString, boolean value, IGUIAction callback) { + public Checkbox(int x, int y, String displayString, Value setting) { super(0, x, y, I18n.format(displayString)); - action = callback; - checked = value; + this.setting = setting; + checked = setting.get(); } @Override public void perform() { - checked = action.perform(!checked); + setting.set(checked ^= true); } } diff --git a/src/main/java/com/minelittlepony/gui/GuiPonySettings.java b/src/main/java/com/minelittlepony/gui/GuiPonySettings.java index f11f25f2..21b55bba 100644 --- a/src/main/java/com/minelittlepony/gui/GuiPonySettings.java +++ b/src/main/java/com/minelittlepony/gui/GuiPonySettings.java @@ -1,18 +1,17 @@ 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 net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; +import java.io.IOException; + /** * In-Game options menu. * @@ -46,7 +45,7 @@ public class GuiPonySettings extends GuiScreen { 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()); }, v -> { - PonyLevel level = PonyLevel.valueFor(v); + PonyLevel level = PonyLevel.valueFor((float) v); config.setPonyLevel(level); return (float)level.ordinal(); })); @@ -54,7 +53,7 @@ public class GuiPonySettings extends GuiScreen { 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)); + addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i)); } if (mustScroll()) { @@ -65,7 +64,7 @@ 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)); } } 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/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 6b25367c..c83961b7 100644 --- a/src/main/java/com/minelittlepony/model/components/PonySnout.java +++ b/src/main/java/com/minelittlepony/model/components/PonySnout.java @@ -1,14 +1,12 @@ package com.minelittlepony.model.components; -import com.minelittlepony.pony.data.PonyGender; -import com.minelittlepony.render.plane.PlaneRenderer; - -import net.minecraft.client.model.ModelBase; - import static com.minelittlepony.model.PonyModelConstants.*; import com.minelittlepony.MineLittlePony; import com.minelittlepony.model.capabilities.ICapitated; +import com.minelittlepony.pony.data.PonyGender; +import com.minelittlepony.render.plane.PlaneRenderer; +import net.minecraft.client.model.ModelBase; public class PonySnout { @@ -59,7 +57,7 @@ public class PonySnout { } public void setGender(PonyGender gender) { - boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getConfig().snuzzles; + boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getConfig().getSnuzzles().get(); mare.isHidden = !show || gender == PonyGender.STALLION; stallion.isHidden = !show || gender == PonyGender.MARE; diff --git a/src/main/java/com/minelittlepony/pony/data/PonyData.java b/src/main/java/com/minelittlepony/pony/data/PonyData.java index 46accf3a..3b4847bb 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyData.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyData.java @@ -62,7 +62,7 @@ public class PonyData implements IPonyData { @Override public PonySize getSize() { - return MineLittlePony.getConfig().sizes ? size : PonySize.NORMAL; + return MineLittlePony.getConfig().getSizes().get() ? size : PonySize.NORMAL; } @Override diff --git a/src/main/java/com/minelittlepony/pony/data/PonySize.java b/src/main/java/com/minelittlepony/pony/data/PonySize.java index 88588424..8f6135c9 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonySize.java +++ b/src/main/java/com/minelittlepony/pony/data/PonySize.java @@ -24,14 +24,14 @@ public enum PonySize implements ITriggerPixelMapped { } public float getShadowSize() { - if (MineLittlePony.getConfig().showscale) { + if (MineLittlePony.getConfig().getShowscale().get()) { return shadowSize * 0.9F; } return shadowSize; } public float getScaleFactor() { - if (MineLittlePony.getConfig().showscale) { + if (MineLittlePony.getConfig().getShowscale().get()) { 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 977b8da8..c9cdffd1 100644 --- a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -1,13 +1,12 @@ 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 +16,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 { @@ -70,7 +69,7 @@ public class LevitatingItemRenderer { pushMatrix(); - boolean doMagic = MineLittlePony.getConfig().fpsmagic && pony.getMetadata().hasMagic(); + boolean doMagic = MineLittlePony.getConfig().getFpsmagic().get() && pony.getMetadata().hasMagic(); if (doMagic) { setupPerspective(entity, stack, left); diff --git a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java index 3f5a8a26..eff17fe4 100644 --- a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java @@ -1,12 +1,5 @@ package com.minelittlepony.render; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; - -import org.lwjgl.opengl.GL11; - import com.minelittlepony.MineLittlePony; import com.minelittlepony.PonyConfig; import com.minelittlepony.ducks.IRenderItem; @@ -18,6 +11,12 @@ import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer; import net.minecraft.tileentity.TileEntitySkull; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; /** * PonySkullRenderer! It renders ponies as skulls, or something... @@ -36,7 +35,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende * Original/Existing renderer is stored to a backup variable as a fallback in case of mods. */ public static TileEntitySkullRenderer resolve() { - if (MineLittlePony.getConfig().ponyskulls) { + if (MineLittlePony.getConfig().getPonyskulls().get()) { if (!(instance instanceof PonySkullRenderer)) { backup = instance; ModUtilities.addRenderer(TileEntitySkull.class, ponyInstance); diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index 603f1353..41f7635c 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -1,8 +1,5 @@ package com.minelittlepony.render.player; -import java.util.Map; -import java.util.Optional; - import com.minelittlepony.MineLittlePony; import com.minelittlepony.PonyConfig; import com.minelittlepony.ducks.IRenderPony; @@ -11,8 +8,8 @@ import com.minelittlepony.model.components.ModelDeadMau5Ears; import com.minelittlepony.pony.data.Pony; import com.minelittlepony.pony.data.PonyLevel; import com.minelittlepony.render.PonySkull; -import com.minelittlepony.render.RenderPony; import com.minelittlepony.render.PonySkullRenderer.ISkull; +import com.minelittlepony.render.RenderPony; import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder; import com.minelittlepony.render.layer.LayerHeldPonyItemMagical; import com.minelittlepony.render.layer.LayerPonyCape; @@ -22,19 +19,20 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.voxelmodpack.hdskins.HDSkinManager; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderManager; - +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.renderer.entity.layers.LayerArrow; import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.EnumHandSide; import net.minecraft.util.ResourceLocation; -import net.minecraft.client.renderer.entity.RenderPlayer; -import net.minecraft.client.renderer.entity.layers.LayerArrow; -import net.minecraft.entity.Entity; + +import java.util.Map; +import java.util.Optional; public class RenderPonyPlayer extends RenderPlayer implements IRenderPony { diff --git a/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java b/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java index e7f17034..18fe1b80 100644 --- a/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java +++ b/src/main/java/com/minelittlepony/render/ponies/MobRenderers.java @@ -1,21 +1,37 @@ package com.minelittlepony.render.ponies; import com.minelittlepony.MineLittlePony; +import com.minelittlepony.PonyConfig; import com.minelittlepony.PonyRenderManager; -import com.minelittlepony.settings.SensibleConfig.Setting; - +import com.minelittlepony.settings.Value; 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 java.util.function.Function; /** * 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 { - VILLAGERS { +public enum MobRenderers implements Value { + VILLAGERS(PonyConfig::getVillagers) { @Override public void register(boolean state, PonyRenderManager pony, RenderManager manager) { pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager)); @@ -23,7 +39,7 @@ public enum MobRenderers implements Setting { pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager)); } }, - ZOMBIES { + ZOMBIES(PonyConfig::getZombies) { @Override public void register(boolean state, PonyRenderManager pony, RenderManager manager) { pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager)); @@ -31,13 +47,13 @@ public enum MobRenderers implements Setting { pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager)); } }, - PIGZOMBIES { + PIGZOMBIES(PonyConfig::getPigzombies) { @Override public void register(boolean state, PonyRenderManager pony, RenderManager manager) { pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager)); } }, - SKELETONS { + SKELETONS(PonyConfig::getSkeletons) { @Override public void register(boolean state, PonyRenderManager pony, RenderManager manager) { pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager)); @@ -45,7 +61,7 @@ public enum MobRenderers implements Setting { pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager)); } }, - ILLAGERS { + ILLAGERS(PonyConfig::getIllagers) { @Override public void register(boolean state, PonyRenderManager pony, RenderManager manager) { pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager)); @@ -54,7 +70,7 @@ public enum MobRenderers implements Setting { pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager)); } }, - GUARDIANS { + GUARDIANS(PonyConfig::getGuardians) { @Override public void register(boolean state, PonyRenderManager pony, RenderManager manager) { pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager)); @@ -62,14 +78,25 @@ public enum MobRenderers implements Setting { } }; + private final Value setting; + + MobRenderers(Function> setting) { + this.setting = setting.apply(MineLittlePony.getConfig()); + } + @Override - public void set(boolean value) { - Setting.super.set(value); + public Boolean get() { + return setting.get(); + } + + @Override + public void set(Boolean value) { + setting.set(value); apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager()); } public void apply(PonyRenderManager pony, RenderManager manager) { - boolean state = get(); + boolean state = setting.get(); register(state, pony, manager); if (state) { MineLittlePony.logger.info(name() + " are now ponies."); @@ -79,4 +106,4 @@ public enum MobRenderers implements Setting { } public abstract void register(boolean state, PonyRenderManager pony, RenderManager manager); -} \ No newline at end of file +} diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java index 82fa7ca9..2651f408 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonySkeleton.java @@ -25,7 +25,7 @@ public class RenderPonySkeleton extends Rende public static final ISkull SKULL = new PonySkull() { @Override public boolean canRender(PonyConfig config) { - return config.skeletons; + return config.getSkeletons().get(); } @Override @@ -73,7 +73,7 @@ public class RenderPonySkeleton extends Rende public static final ISkull SKULL = new PonySkull() { @Override public boolean canRender(PonyConfig config) { - return config.skeletons; + return config.getSkeletons().get(); } @Override diff --git a/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java b/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java index 541d8092..445c29eb 100644 --- a/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java +++ b/src/main/java/com/minelittlepony/render/ponies/RenderPonyZombie.java @@ -22,7 +22,7 @@ public class RenderPonyZombie extends RenderPonyMob public static final ISkull SKULL = new PonySkull() { @Override public boolean canRender(PonyConfig config) { - return config.zombies; + return config.getZombies().get(); } @Override diff --git a/src/main/java/com/minelittlepony/render/transform/PonyPosture.java b/src/main/java/com/minelittlepony/render/transform/PonyPosture.java new file mode 100644 index 00000000..15116bb6 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/PonyPosture.java @@ -0,0 +1,17 @@ +package com.minelittlepony.render.transform; + +import com.minelittlepony.model.AbstractPonyModel; +import net.minecraft.entity.EntityLivingBase; + +public interface PonyPosture { + PonyPosture ELYTRA = new PostureElytra(); + PonyPosture FLIGHT = new PostureFlight(); + PonyPosture SWIMMING = new PostureSwimming(); + PonyPosture FALLING = new PostureFalling(); + + default boolean applies(EntityLivingBase entity) { + return true; + } + + void transform(AbstractPonyModel model, T entity, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks); +} diff --git a/src/main/java/com/minelittlepony/render/transform/PonyTransformation.java b/src/main/java/com/minelittlepony/render/transform/PonyTransformation.java new file mode 100644 index 00000000..a6f5f371 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/PonyTransformation.java @@ -0,0 +1,108 @@ +package com.minelittlepony.render.transform; + +import static net.minecraft.client.renderer.GlStateManager.scale; +import static net.minecraft.client.renderer.GlStateManager.translate; + +import com.minelittlepony.model.BodyPart; +import com.minelittlepony.model.capabilities.IModel; + +public enum PonyTransformation { + + NORMAL { + @Override + public void transform(IModel model, BodyPart part) { + if (model.isSleeping()) translate(0, -0.61F, 0); + + switch (part) { + case NECK: + if (model.isCrouching()) translate(-0.03F, 0.03F, 0.1F); + default: + } + } + }, + LARGE { + @Override + public void transform(IModel model, BodyPart part) { + if (model.isSleeping()) translate(0, -0.98F, 0.2F); + + switch (part) { + case NECK: + translate(0, -0.15F, -0.07F); + if (model.isCrouching()) translate(-0.03F, 0.16F, 0.07F); + break; + case HEAD: + translate(0, -0.17F, -0.04F); + if (model.isSleeping()) translate(0, 0, -0.1F); + if (model.isCrouching()) translate(0, 0.15F, 0); + break; + case BODY: + translate(0, -0.2F, -0.04F); + scale(1.15F, 1.2F, 1.2F); + break; + case TAIL: + translate(0, -0.2F, 0.08F); + break; + case LEGS: + translate(0, -0.14F, 0); + scale(1.15F, 1.12F, 1.15F); + break; + } + } + }, + FOAL { + @Override + public void transform(IModel model, BodyPart part) { + if (model.isCrouching()) translate(0, -0.3F, 0); + if (model.isSleeping()) translate(0, -0.6F, -0.5F); + if (model.isRiding()) translate(0, -0.4F, 0); + + translate(0, 0.2F, 0); + + switch (part) { + case NECK: + scale(1.3F, 1.3F, 1.3F); + if (model.isCrouching()) translate(0, -0.01F, 0.15F); + break; + case HEAD: + scale(1.3F, 1.3F, 1.3F); + break; + case LEGS: + translate(0, 0.1F, 0); + scale(1, 0.81F, 1); + break; + default: + } + } + }, + TALL { + @Override + public void transform(IModel model, BodyPart part) { + if (model.isSleeping()) translate(0, -0.5F, 0.25F); + + switch (part) { + case NECK: + translate(0, -0.09F, -0.01F); + scale(1, 1.1F, 1); + if (model.isCrouching()) translate(-0.02F, -0.02F, 0.1F); + break; + case HEAD: + translate(0, -0.15F, 0.01F); + if (model.isCrouching()) translate(0, 0.05F, 0); + break; + case BODY: + translate(0, -0.1F, 0); + break; + case TAIL: + translate(0, -0.1F, 0); + break; + case LEGS: + translate(0, -0.25F, 0.03F); + scale(1, 1.18F, 1); + if (model.isGoingFast()) translate(0, 0.05F, 0); + break; + } + } + }; + + public abstract void transform(IModel model, BodyPart part); +} diff --git a/src/main/java/com/minelittlepony/render/transform/PostureElytra.java b/src/main/java/com/minelittlepony/render/transform/PostureElytra.java new file mode 100644 index 00000000..e089fff5 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/PostureElytra.java @@ -0,0 +1,13 @@ +package com.minelittlepony.render.transform; + +import com.minelittlepony.model.AbstractPonyModel; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.EntityLivingBase; + +public class PostureElytra implements PonyPosture { + @Override + public void transform(AbstractPonyModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks) { + GlStateManager.rotate(90, 1, 0, 0); + GlStateManager.translate(0, entity.isSneaking() ? 0.2F : -1, 0); + } +} diff --git a/src/main/java/com/minelittlepony/render/transform/PostureFalling.java b/src/main/java/com/minelittlepony/render/transform/PostureFalling.java new file mode 100644 index 00000000..1aaf1a80 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/PostureFalling.java @@ -0,0 +1,11 @@ +package com.minelittlepony.render.transform; + +import com.minelittlepony.model.AbstractPonyModel; +import net.minecraft.entity.EntityLivingBase; + +public class PostureFalling implements PonyPosture { + @Override + public void transform(AbstractPonyModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks) { + model.motionPitch = 0; + } +} diff --git a/src/main/java/com/minelittlepony/render/transform/PostureFlight.java b/src/main/java/com/minelittlepony/render/transform/PostureFlight.java new file mode 100644 index 00000000..2a45390b --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/PostureFlight.java @@ -0,0 +1,65 @@ +package com.minelittlepony.render.transform; + +import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.util.math.MathUtil; +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.math.MathHelper; + +public class PostureFlight implements PonyPosture { + @Override + public boolean applies(EntityLivingBase entity) { + return entity instanceof AbstractClientPlayer; + } + + protected double calculateRoll(AbstractClientPlayer player, double motionX, double motionY, double motionZ) { + + // since model roll should probably be calculated from model rotation rather than entity rotation... + double roll = MathUtil.sensibleAngle(player.prevRenderYawOffset - player.renderYawOffset); + double horMotion = Math.sqrt(motionX * motionX + motionZ * motionZ); + float modelYaw = MathUtil.sensibleAngle(player.renderYawOffset); + + // detecting that we're flying backwards and roll must be inverted + if (Math.abs(MathUtil.sensibleAngle((float) Math.toDegrees(Math.atan2(motionX, motionZ)) + modelYaw)) > 90) { + roll *= -1; + } + + // ayyy magic numbers (after 5 - an approximation of nice looking coefficients calculated by hand) + + // roll might be zero, in which case Math.pow produces +Infinity. Anything x Infinity = NaN. + double pow = roll != 0 ? Math.pow(Math.abs(roll), -0.191) : 0; + + roll *= horMotion * 5 * (3.6884f * pow); + + assert !Float.isNaN((float)roll); + + return MathHelper.clamp(roll, -54, 54); + } + + protected double calculateIncline(AbstractClientPlayer player, double motionX, double motionY, double motionZ) { + double dist = Math.sqrt(motionX * motionX + motionZ * motionZ); + double angle = Math.atan2(motionY, dist); + + if (!player.capabilities.isFlying) { + angle /= 2; + } + + angle = MathUtil.clampLimit(angle, Math.PI / 3); + + return Math.toDegrees(angle); + } + + @Override + public void transform(AbstractPonyModel model, AbstractClientPlayer player, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks) { + model.motionPitch = (float) calculateIncline(player, motionX, motionY, motionZ); + + GlStateManager.rotate(model.motionPitch, 1, 0, 0); + + float roll = (float)calculateRoll(player, motionX, motionY, motionZ); + + roll = model.getMetadata().getInterpolator().interpolate("pegasusRoll", roll, 10); + + GlStateManager.rotate((float)roll, 0, 0, 1); + } +} diff --git a/src/main/java/com/minelittlepony/render/transform/PostureSwimming.java b/src/main/java/com/minelittlepony/render/transform/PostureSwimming.java new file mode 100644 index 00000000..b2e7792c --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/PostureSwimming.java @@ -0,0 +1,20 @@ +package com.minelittlepony.render.transform; + +import net.minecraft.client.entity.AbstractClientPlayer; + +public class PostureSwimming extends PostureFlight { + + @Override + protected double calculateRoll(AbstractClientPlayer player, double motionX, double motionY, double motionZ) { + + motionX *= 2; + motionZ *= 2; + + return super.calculateRoll(player, motionX, motionY, motionZ); + } + + @Override + protected double calculateIncline(AbstractClientPlayer player, double motionX, double motionY, double motionZ) { + return super.calculateIncline(player, motionX, motionY, motionZ); + } +} diff --git a/src/main/java/com/minelittlepony/render/transform/package-info.java b/src/main/java/com/minelittlepony/render/transform/package-info.java new file mode 100644 index 00000000..21b71079 --- /dev/null +++ b/src/main/java/com/minelittlepony/render/transform/package-info.java @@ -0,0 +1,8 @@ +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +package com.minelittlepony.render.transform; + +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/src/main/java/com/minelittlepony/settings/BaseValue.java b/src/main/java/com/minelittlepony/settings/BaseValue.java new file mode 100644 index 00000000..0631938a --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/BaseValue.java @@ -0,0 +1,20 @@ +package com.minelittlepony.settings; + +public class BaseValue implements Value { + + private T value; + + public BaseValue(T value) { + this.value = value; + } + + @Override + public T get() { + return value; + } + + @Override + public void set(T value) { + this.value = value; + } +} 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/Value.java b/src/main/java/com/minelittlepony/settings/Value.java new file mode 100644 index 00000000..31a0eb71 --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/Value.java @@ -0,0 +1,12 @@ +package com.minelittlepony.settings; + +public interface Value { + + T get(); + + void set(T value); + + static Value of(T value) { + return new BaseValue<>(value); + } +} diff --git a/src/main/java/com/minelittlepony/settings/ValueConfig.java b/src/main/java/com/minelittlepony/settings/ValueConfig.java new file mode 100644 index 00000000..6e3f7cc7 --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/ValueConfig.java @@ -0,0 +1,26 @@ +package com.minelittlepony.settings; + +import com.google.gson.GsonBuilder; +import com.mumfrey.liteloader.modconfig.AdvancedExposable; + +import java.io.File; + +/** + * A sensible config container that actually lets us programatically index values by a key. + * + * Reflection because Mumfrey pls. + * + */ +// Mumfrey pls. +public class ValueConfig implements AdvancedExposable { + + @Override + public void setupGsonSerialiser(GsonBuilder gsonBuilder) { + gsonBuilder.registerTypeAdapter(Value.class, new ValueSerializer()); + } + + @Override + public File getConfigFile(File configFile, File configFileLocation, String defaultFileName) { + return null; + } +} diff --git a/src/main/java/com/minelittlepony/settings/ValueSerializer.java b/src/main/java/com/minelittlepony/settings/ValueSerializer.java new file mode 100644 index 00000000..5f138fcd --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/ValueSerializer.java @@ -0,0 +1,25 @@ +package com.minelittlepony.settings; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +public class ValueSerializer implements JsonSerializer>, JsonDeserializer> { + + @Override + public Value deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + ParameterizedType type = (ParameterizedType) typeOfT; + return Value.of(context.deserialize(json, type.getActualTypeArguments()[0])); + } + + @Override + public JsonElement serialize(Value src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src.get()); + } +}