mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-12-01 16:27:59 +01:00
Rewrite pony configs
This commit is contained in:
parent
6337b055c9
commit
538c9c1b89
21 changed files with 137 additions and 218 deletions
|
@ -81,7 +81,7 @@ public class MineLittlePony {
|
||||||
|
|
||||||
RenderManager rm = minecraft.getRenderManager();
|
RenderManager rm = minecraft.getRenderManager();
|
||||||
renderManager.initialisePlayerRenderers(rm);
|
renderManager.initialisePlayerRenderers(rm);
|
||||||
renderManager.initializeMobRenderers(rm, config);
|
renderManager.initializeMobRenderers(rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onTick(Minecraft minecraft, boolean inGame) {
|
void onTick(Minecraft minecraft, boolean inGame) {
|
||||||
|
|
|
@ -2,69 +2,40 @@ package com.minelittlepony;
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import com.minelittlepony.pony.data.PonyLevel;
|
import com.minelittlepony.pony.data.PonyLevel;
|
||||||
import com.minelittlepony.settings.Value;
|
|
||||||
import com.minelittlepony.settings.ValueConfig;
|
import com.minelittlepony.settings.ValueConfig;
|
||||||
import com.mumfrey.liteloader.modconfig.ConfigStrategy;
|
import com.mumfrey.liteloader.modconfig.ConfigStrategy;
|
||||||
import com.mumfrey.liteloader.modconfig.ExposableOptions;
|
import com.mumfrey.liteloader.modconfig.ExposableOptions;
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage container for MineLP client settings.
|
* Storage container for MineLP client settings.
|
||||||
*/
|
*/
|
||||||
@ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned)
|
@ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned)
|
||||||
public class PonyConfig extends ValueConfig {
|
public class PonyConfig extends ValueConfig {
|
||||||
|
|
||||||
@Expose private PonyLevel ponylevel = PonyLevel.PONIES;
|
@Expose
|
||||||
|
private PonyLevel ponylevel = PonyLevel.PONIES;
|
||||||
|
|
||||||
@Expose private final Value<Boolean> sizes = Value.of(true);
|
public enum PonySettings implements ValueConfig.Flag {
|
||||||
@Expose private final Value<Boolean> snuzzles = Value.of(true);
|
SIZES,
|
||||||
@Expose private final Value<Boolean> hd = Value.of(true);
|
SNUZZLES,
|
||||||
@Expose private final Value<Boolean> showscale = Value.of(true);
|
HD,
|
||||||
@Expose private final Value<Boolean> fpsmagic = Value.of(true);
|
SHOWSCALE,
|
||||||
@Expose private final Value<Boolean> ponyskulls = Value.of(true);
|
FPSMAGIC,
|
||||||
|
PONYSKULLS;
|
||||||
@Expose private final Value<Boolean> villagers = Value.of(true);
|
|
||||||
@Expose private final Value<Boolean> zombies = Value.of(true);
|
|
||||||
@Expose private final Value<Boolean> pigzombies = Value.of(true);
|
|
||||||
@Expose private final Value<Boolean> skeletons = Value.of(true);
|
|
||||||
@Expose private final Value<Boolean> illagers = Value.of(true);
|
|
||||||
@Expose private final Value<Boolean> guardians = Value.of(true);
|
|
||||||
|
|
||||||
public enum PonySettings implements Value<Boolean> {
|
|
||||||
|
|
||||||
SIZES(PonyConfig::getSizes),
|
|
||||||
SNUZZLES(PonyConfig::getSnuzzles),
|
|
||||||
HD(PonyConfig::getHd),
|
|
||||||
SHOWSCALE(PonyConfig::getShowscale),
|
|
||||||
FPSMAGIC(PonyConfig::getFpsmagic),
|
|
||||||
PONYSKULLS(PonyConfig::getPonyskulls);
|
|
||||||
|
|
||||||
private Value<Boolean> config;
|
|
||||||
|
|
||||||
PonySettings(Function<PonyConfig, Value<Boolean>> config) {
|
|
||||||
this.config = config.apply(MineLittlePony.getConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean get() {
|
public ValueConfig config() {
|
||||||
return config.get();
|
return MineLittlePony.getConfig();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(Boolean value) {
|
|
||||||
config.set(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current PonyLevel. That is the level of ponies you would like to see.
|
* 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.
|
* @param ignorePony true to ignore whatever value the setting has.
|
||||||
*/
|
*/
|
||||||
public PonyLevel getEffectivePonyLevel(boolean ignorePony) {
|
public PonyLevel getEffectivePonyLevel(boolean ignorePony) {
|
||||||
return ignorePony ? PonyLevel.BOTH : ponylevel;
|
return ignorePony ? PonyLevel.BOTH : getPonyLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PonyLevel getPonyLevel() {
|
public PonyLevel getPonyLevel() {
|
||||||
|
@ -79,55 +50,8 @@ public class PonyConfig extends ValueConfig {
|
||||||
*
|
*
|
||||||
* @param ponylevel
|
* @param ponylevel
|
||||||
*/
|
*/
|
||||||
public void setPonyLevel(PonyLevel ponylevel) {
|
public void setPonyLevel(PonyLevel newlevel) {
|
||||||
this.ponylevel = ponylevel;
|
ponylevel = newlevel;
|
||||||
}
|
write();
|
||||||
|
|
||||||
public Value<Boolean> getSizes() {
|
|
||||||
return sizes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getSnuzzles() {
|
|
||||||
return snuzzles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getHd() {
|
|
||||||
return hd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getShowscale() {
|
|
||||||
return showscale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getFpsmagic() {
|
|
||||||
return fpsmagic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getPonyskulls() {
|
|
||||||
return ponyskulls;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getVillagers() {
|
|
||||||
return villagers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getZombies() {
|
|
||||||
return zombies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getPigzombies() {
|
|
||||||
return pigzombies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getSkeletons() {
|
|
||||||
return skeletons;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getIllagers() {
|
|
||||||
return illagers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Value<Boolean> getGuardians() {
|
|
||||||
return guardians;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class PonyRenderManager {
|
||||||
/**
|
/**
|
||||||
* 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(RenderManager manager) {
|
||||||
for (MobRenderers i : MobRenderers.values()) {
|
for (MobRenderers i : MobRenderers.values()) {
|
||||||
i.apply(this, manager);
|
i.apply(this, manager);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
package com.minelittlepony.gui;
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
import com.minelittlepony.settings.Value;
|
|
||||||
import com.mumfrey.liteloader.client.gui.GuiCheckbox;
|
import com.mumfrey.liteloader.client.gui.GuiCheckbox;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
|
|
||||||
public class Checkbox extends GuiCheckbox implements IActionable {
|
public class Checkbox extends GuiCheckbox implements IActionable {
|
||||||
|
|
||||||
private final Value<Boolean> setting;
|
private final IGuiCallback<Boolean> action;
|
||||||
|
|
||||||
public Checkbox(int x, int y, String displayString, Value<Boolean> setting) {
|
public Checkbox(int x, int y, String displayString, boolean value, IGuiCallback<Boolean> callback) {
|
||||||
super(0, x, y, I18n.format(displayString));
|
super(0, x, y, I18n.format(displayString));
|
||||||
this.setting = setting;
|
action = callback;
|
||||||
checked = setting.get();
|
checked = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform() {
|
public void performAction() {
|
||||||
setting.set(checked ^= true);
|
checked = action.perform(checked ^= true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.minelittlepony.PonyConfig;
|
||||||
import com.minelittlepony.PonyConfig.PonySettings;
|
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 net.minecraft.client.gui.GuiButton;
|
import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
|
@ -53,7 +52,7 @@ public class GuiPonySettings extends GuiScreen {
|
||||||
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 (PonySettings i : PonySettings.values()) {
|
||||||
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i));
|
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.key(), i.get(), i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mustScroll()) {
|
if (mustScroll()) {
|
||||||
|
@ -64,14 +63,14 @@ 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));
|
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + i.key(), i.get(), i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton button) throws IOException {
|
protected void actionPerformed(GuiButton button) throws IOException {
|
||||||
if (button instanceof IActionable) {
|
if (button instanceof IActionable) {
|
||||||
((IActionable)button).perform();
|
((IActionable)button).performAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +80,6 @@ public class GuiPonySettings extends GuiScreen {
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGuiClosed() {
|
|
||||||
LiteLoader.getInstance().writeConfig(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getTitle() {
|
protected String getTitle() {
|
||||||
return OPTIONS_PREFIX + "title";
|
return OPTIONS_PREFIX + "title";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.minelittlepony.gui;
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An element that can perform an action.
|
* An element that responds to interface events.
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IActionable {
|
public interface IActionable {
|
||||||
/**
|
/**
|
||||||
* Does whatever.
|
* Does whatever.
|
||||||
*/
|
*/
|
||||||
void perform();
|
void performAction();
|
||||||
}
|
}
|
||||||
|
|
15
src/main/java/com/minelittlepony/gui/IGuiAction.java
Normal file
15
src/main/java/com/minelittlepony/gui/IGuiAction.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response actions for UI events.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IGuiAction<T> {
|
||||||
|
/**
|
||||||
|
* Performs this action now.
|
||||||
|
*
|
||||||
|
* @param sender the element handling this event
|
||||||
|
*/
|
||||||
|
void perform(T sender);
|
||||||
|
|
||||||
|
}
|
15
src/main/java/com/minelittlepony/gui/IGuiCallback.java
Normal file
15
src/main/java/com/minelittlepony/gui/IGuiCallback.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package com.minelittlepony.gui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response actions for UI events.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IGuiCallback<T> {
|
||||||
|
/**
|
||||||
|
* Performs this action now.
|
||||||
|
*
|
||||||
|
* @param value New Value of the field being changed
|
||||||
|
* @return Adjusted value the field must take on
|
||||||
|
*/
|
||||||
|
public T perform(T in);
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ package com.minelittlepony.model.components;
|
||||||
|
|
||||||
import static com.minelittlepony.model.PonyModelConstants.*;
|
import static com.minelittlepony.model.PonyModelConstants.*;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.PonyConfig.PonySettings;
|
||||||
import com.minelittlepony.model.capabilities.ICapitated;
|
import com.minelittlepony.model.capabilities.ICapitated;
|
||||||
import com.minelittlepony.pony.data.PonyGender;
|
import com.minelittlepony.pony.data.PonyGender;
|
||||||
import com.minelittlepony.render.plane.PlaneRenderer;
|
import com.minelittlepony.render.plane.PlaneRenderer;
|
||||||
|
@ -57,7 +57,7 @@ public class PonySnout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGender(PonyGender gender) {
|
public void setGender(PonyGender gender) {
|
||||||
boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getConfig().getSnuzzles().get();
|
boolean show = !head.hasHeadGear() && !isHidden && PonySettings.SNUZZLES.get();
|
||||||
|
|
||||||
mare.isHidden = !show || gender == PonyGender.STALLION;
|
mare.isHidden = !show || gender == PonyGender.STALLION;
|
||||||
stallion.isHidden = !show || gender == PonyGender.MARE;
|
stallion.isHidden = !show || gender == PonyGender.MARE;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.minelittlepony.pony.data;
|
package com.minelittlepony.pony.data;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.PonyConfig.PonySettings;
|
||||||
import com.minelittlepony.model.anim.BasicEasingInterpolator;
|
import com.minelittlepony.model.anim.BasicEasingInterpolator;
|
||||||
import com.minelittlepony.model.anim.IInterpolator;
|
import com.minelittlepony.model.anim.IInterpolator;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class PonyData implements IPonyData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PonySize getSize() {
|
public PonySize getSize() {
|
||||||
return MineLittlePony.getConfig().getSizes().get() ? size : PonySize.NORMAL;
|
return PonySettings.SIZES.get() ? size : PonySize.NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.minelittlepony.pony.data;
|
package com.minelittlepony.pony.data;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.PonyConfig.PonySettings;
|
||||||
import com.minelittlepony.transform.PonyTransformation;
|
import com.minelittlepony.transform.PonyTransformation;
|
||||||
|
|
||||||
public enum PonySize implements ITriggerPixelMapped<PonySize> {
|
public enum PonySize implements ITriggerPixelMapped<PonySize> {
|
||||||
|
@ -24,14 +24,14 @@ public enum PonySize implements ITriggerPixelMapped<PonySize> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getShadowSize() {
|
public float getShadowSize() {
|
||||||
if (MineLittlePony.getConfig().getShowscale().get()) {
|
if (PonySettings.SHOWSCALE.get()) {
|
||||||
return shadowSize * 0.9F;
|
return shadowSize * 0.9F;
|
||||||
}
|
}
|
||||||
return shadowSize;
|
return shadowSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScaleFactor() {
|
public float getScaleFactor() {
|
||||||
if (MineLittlePony.getConfig().getShowscale().get()) {
|
if (PonySettings.SHOWSCALE.get()) {
|
||||||
return scale * 0.9F;
|
return scale * 0.9F;
|
||||||
}
|
}
|
||||||
return scale;
|
return scale;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.render;
|
||||||
import static net.minecraft.client.renderer.GlStateManager.*;
|
import static net.minecraft.client.renderer.GlStateManager.*;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
|
import com.minelittlepony.PonyConfig.PonySettings;
|
||||||
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;
|
||||||
|
@ -69,7 +70,7 @@ public class LevitatingItemRenderer {
|
||||||
|
|
||||||
pushMatrix();
|
pushMatrix();
|
||||||
|
|
||||||
boolean doMagic = MineLittlePony.getConfig().getFpsmagic().get() && pony.getMetadata().hasMagic();
|
boolean doMagic = PonySettings.FPSMAGIC.get() && pony.getMetadata().hasMagic();
|
||||||
|
|
||||||
if (doMagic) {
|
if (doMagic) {
|
||||||
setupPerspective(entity, stack, left);
|
setupPerspective(entity, stack, left);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.render;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.PonyConfig;
|
import com.minelittlepony.PonyConfig;
|
||||||
|
import com.minelittlepony.PonyConfig.PonySettings;
|
||||||
import com.minelittlepony.ducks.IRenderItem;
|
import com.minelittlepony.ducks.IRenderItem;
|
||||||
import com.minelittlepony.pony.data.Pony;
|
import com.minelittlepony.pony.data.Pony;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
@ -35,7 +36,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende
|
||||||
* Original/Existing renderer is stored to a backup variable as a fallback in case of mods.
|
* Original/Existing renderer is stored to a backup variable as a fallback in case of mods.
|
||||||
*/
|
*/
|
||||||
public static TileEntitySkullRenderer resolve() {
|
public static TileEntitySkullRenderer resolve() {
|
||||||
if (MineLittlePony.getConfig().getPonyskulls().get()) {
|
if (PonySettings.PONYSKULLS.get()) {
|
||||||
if (!(instance instanceof PonySkullRenderer)) {
|
if (!(instance instanceof PonySkullRenderer)) {
|
||||||
backup = instance;
|
backup = instance;
|
||||||
ModUtilities.addRenderer(TileEntitySkull.class, ponyInstance);
|
ModUtilities.addRenderer(TileEntitySkull.class, ponyInstance);
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class LayerPonyCustomHead<T extends EntityLivingBase> implements LayerRen
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelWrapper getModel() {
|
private ModelWrapper getModel() {
|
||||||
return ((IRenderPony) renderer).getModelWrapper();
|
return ((IRenderPony<?>) renderer).getModelWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package com.minelittlepony.render.ponies;
|
package com.minelittlepony.render.ponies;
|
||||||
|
|
||||||
import com.minelittlepony.MineLittlePony;
|
import com.minelittlepony.MineLittlePony;
|
||||||
import com.minelittlepony.PonyConfig;
|
|
||||||
import com.minelittlepony.PonyRenderManager;
|
import com.minelittlepony.PonyRenderManager;
|
||||||
import com.minelittlepony.settings.Value;
|
import com.minelittlepony.settings.ValueConfig;
|
||||||
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.EntityElderGuardian;
|
import net.minecraft.entity.monster.EntityElderGuardian;
|
||||||
|
@ -23,15 +22,13 @@ import net.minecraft.entity.monster.EntityZombie;
|
||||||
import net.minecraft.entity.monster.EntityZombieVillager;
|
import net.minecraft.entity.monster.EntityZombieVillager;
|
||||||
import net.minecraft.entity.passive.EntityVillager;
|
import net.minecraft.entity.passive.EntityVillager;
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 Value<Boolean> {
|
public enum MobRenderers implements ValueConfig.Flag {
|
||||||
VILLAGERS(PonyConfig::getVillagers) {
|
VILLAGERS {
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||||
pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager));
|
pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager));
|
||||||
|
@ -39,7 +36,7 @@ public enum MobRenderers implements Value<Boolean> {
|
||||||
pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager));
|
pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ZOMBIES(PonyConfig::getZombies) {
|
ZOMBIES {
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||||
pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager));
|
pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager));
|
||||||
|
@ -47,13 +44,13 @@ public enum MobRenderers implements Value<Boolean> {
|
||||||
pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager));
|
pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PIGZOMBIES(PonyConfig::getPigzombies) {
|
PIGZOMBIES {
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||||
pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager));
|
pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SKELETONS(PonyConfig::getSkeletons) {
|
SKELETONS {
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||||
pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager));
|
pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager));
|
||||||
|
@ -61,7 +58,7 @@ public enum MobRenderers implements Value<Boolean> {
|
||||||
pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager));
|
pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ILLAGERS(PonyConfig::getIllagers) {
|
ILLAGERS {
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||||
pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager));
|
pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager));
|
||||||
|
@ -70,7 +67,7 @@ public enum MobRenderers implements Value<Boolean> {
|
||||||
pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager));
|
pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
GUARDIANS(PonyConfig::getGuardians) {
|
GUARDIANS {
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||||
pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager));
|
pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager));
|
||||||
|
@ -78,25 +75,14 @@ public enum MobRenderers implements Value<Boolean> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Value<Boolean> setting;
|
|
||||||
|
|
||||||
MobRenderers(Function<PonyConfig, Value<Boolean>> setting) {
|
|
||||||
this.setting = setting.apply(MineLittlePony.getConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean get() {
|
|
||||||
return setting.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(Boolean value) {
|
public void set(Boolean value) {
|
||||||
setting.set(value);
|
ValueConfig.Flag.super.set(value);
|
||||||
apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager());
|
apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(PonyRenderManager pony, RenderManager manager) {
|
public void apply(PonyRenderManager pony, RenderManager manager) {
|
||||||
boolean state = setting.get();
|
boolean state = get();
|
||||||
register(state, pony, manager);
|
register(state, pony, manager);
|
||||||
if (state) {
|
if (state) {
|
||||||
MineLittlePony.logger.info(name() + " are now ponies.");
|
MineLittlePony.logger.info(name() + " are now ponies.");
|
||||||
|
@ -106,4 +92,9 @@ public enum MobRenderers implements Value<Boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void register(boolean state, PonyRenderManager pony, RenderManager manager);
|
public abstract void register(boolean state, PonyRenderManager pony, RenderManager manager);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ValueConfig config() {
|
||||||
|
return MineLittlePony.getConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
|
||||||
public static final ISkull SKULL = new PonySkull() {
|
public static final ISkull SKULL = new PonySkull() {
|
||||||
@Override
|
@Override
|
||||||
public boolean canRender(PonyConfig config) {
|
public boolean canRender(PonyConfig config) {
|
||||||
return config.getSkeletons().get();
|
return MobRenderers.SKELETONS.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,7 +73,7 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
|
||||||
public static final ISkull SKULL = new PonySkull() {
|
public static final ISkull SKULL = new PonySkull() {
|
||||||
@Override
|
@Override
|
||||||
public boolean canRender(PonyConfig config) {
|
public boolean canRender(PonyConfig config) {
|
||||||
return config.getSkeletons().get();
|
return MobRenderers.SKELETONS.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
|
||||||
public static final ISkull SKULL = new PonySkull() {
|
public static final ISkull SKULL = new PonySkull() {
|
||||||
@Override
|
@Override
|
||||||
public boolean canRender(PonyConfig config) {
|
public boolean canRender(PonyConfig config) {
|
||||||
return config.getZombies().get();
|
return MobRenderers.ZOMBIES.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.minelittlepony.settings;
|
|
||||||
|
|
||||||
public class BaseValue<T> implements Value<T> {
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.minelittlepony.settings;
|
|
||||||
|
|
||||||
public interface Value<T> {
|
|
||||||
|
|
||||||
T get();
|
|
||||||
|
|
||||||
void set(T value);
|
|
||||||
|
|
||||||
static <T> Value<T> of(T value) {
|
|
||||||
return new BaseValue<>(value);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +1,62 @@
|
||||||
package com.minelittlepony.settings;
|
package com.minelittlepony.settings;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import java.util.HashMap;
|
||||||
import com.mumfrey.liteloader.modconfig.AdvancedExposable;
|
import java.util.Map;
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import java.io.File;
|
import com.minelittlepony.gui.IGuiCallback;
|
||||||
|
import com.mumfrey.liteloader.core.LiteLoader;
|
||||||
|
import com.mumfrey.liteloader.modconfig.Exposable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A sensible config container that actually lets us programatically index values by a key.
|
* A sensible config container that actually lets us programatically index values by a key.
|
||||||
*
|
*
|
||||||
* Reflection because Mumfrey pls.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
// Mumfrey pls.
|
// Mumfrey pls.
|
||||||
public class ValueConfig implements AdvancedExposable {
|
public abstract class ValueConfig implements Exposable {
|
||||||
|
|
||||||
@Override
|
// TODO: Mumfrey pls. ValueConfig cannot extend from HashMap directly.
|
||||||
public void setupGsonSerialiser(GsonBuilder gsonBuilder) {
|
@Expose
|
||||||
gsonBuilder.registerTypeAdapter(Value.class, new ValueSerializer());
|
private Map<String, Object> properties = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
protected void write() {
|
||||||
|
LiteLoader.getInstance().writeConfig(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public interface Flag extends Setting<Boolean> {
|
||||||
public File getConfigFile(File configFile, File configFileLocation, String defaultFileName) {
|
default Boolean initial() {
|
||||||
return null;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Setting<T> extends IGuiCallback<T> {
|
||||||
|
|
||||||
|
ValueConfig config();
|
||||||
|
|
||||||
|
String name();
|
||||||
|
|
||||||
|
T initial();
|
||||||
|
|
||||||
|
default String key() {
|
||||||
|
return name().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
default T get() {
|
||||||
|
if (!config().properties.containsKey(key())) {
|
||||||
|
set(initial());
|
||||||
|
}
|
||||||
|
return (T)config().properties.get(key());
|
||||||
|
}
|
||||||
|
|
||||||
|
default void set(T value) {
|
||||||
|
config().properties.put(key(), value);
|
||||||
|
config().write();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default T perform(T in) {
|
||||||
|
set(in);
|
||||||
|
return get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
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<Value<?>>, JsonDeserializer<Value<?>> {
|
|
||||||
|
|
||||||
@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());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue