mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 14:27:59 +01:00
Reorganise how settings work, and renderers change immediately when you toggle an option
This commit is contained in:
parent
e56611c3fc
commit
bc65369964
5 changed files with 179 additions and 114 deletions
|
@ -2,22 +2,32 @@ 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 contained for MineLP client settings.
|
||||
* Storage container for MineLP client settings.
|
||||
*
|
||||
*/
|
||||
@ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned)
|
||||
public class PonyConfig implements Exposable {
|
||||
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;
|
||||
|
|
|
@ -9,36 +9,12 @@ import com.minelittlepony.hdskins.gui.RenderPonyModel;
|
|||
import com.minelittlepony.model.player.PlayerModels;
|
||||
import com.minelittlepony.render.LevitatingItemRenderer;
|
||||
import com.minelittlepony.render.player.RenderPonyPlayer;
|
||||
import com.minelittlepony.render.ponies.RenderPonyGuardian;
|
||||
import com.minelittlepony.render.ponies.RenderPonyIllager;
|
||||
import com.minelittlepony.render.ponies.RenderPonyPigman;
|
||||
import com.minelittlepony.render.ponies.RenderPonySkeleton;
|
||||
import com.minelittlepony.render.ponies.RenderPonyVex;
|
||||
import com.minelittlepony.render.ponies.RenderPonyVillager;
|
||||
import com.minelittlepony.render.ponies.RenderPonyWitch;
|
||||
import com.minelittlepony.render.ponies.RenderPonyZombie;
|
||||
import com.minelittlepony.render.ponies.RenderPonyZombieVillager;
|
||||
import com.minelittlepony.render.ponies.MobRenderers;
|
||||
import com.mumfrey.liteloader.util.ModUtilities;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Render manager responsible for replacing and restoring entity renderers when the client settings change.
|
||||
|
@ -80,92 +56,32 @@ public class PonyRenderManager {
|
|||
* Registers all entity model replacements. (except for players).
|
||||
*/
|
||||
public void initializeMobRenderers(RenderManager manager, PonyConfig config) {
|
||||
|
||||
if (config.villagers) {
|
||||
pushNewRenderer(manager, EntityVillager.class, new RenderPonyVillager(manager));
|
||||
pushNewRenderer(manager, EntityWitch.class, new RenderPonyWitch(manager));
|
||||
pushNewRenderer(manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager));
|
||||
MineLittlePony.logger.info("Villagers are now ponies.");
|
||||
} else {
|
||||
restoreRenderer(EntityVillager.class);
|
||||
restoreRenderer(EntityWitch.class);
|
||||
restoreRenderer(EntityZombieVillager.class);
|
||||
}
|
||||
|
||||
if (config.zombies) {
|
||||
pushNewRenderer(manager, EntityZombie.class, new RenderPonyZombie<>(manager));
|
||||
pushNewRenderer(manager, EntityHusk.class, new RenderPonyZombie.Husk(manager));
|
||||
pushNewRenderer(manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager));
|
||||
MineLittlePony.logger.info("Zombies are now ponies.");
|
||||
} else {
|
||||
restoreRenderer(EntityZombie.class);
|
||||
restoreRenderer(EntityHusk.class);
|
||||
restoreRenderer(EntityGiantZombie.class);
|
||||
}
|
||||
|
||||
if (config.pigzombies) {
|
||||
pushNewRenderer(manager, EntityPigZombie.class, new RenderPonyPigman(manager));
|
||||
MineLittlePony.logger.info("Zombie pigmen are now ponies.");
|
||||
} else {
|
||||
restoreRenderer(EntityPigZombie.class);
|
||||
}
|
||||
|
||||
if (config.skeletons) {
|
||||
pushNewRenderer(manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager));
|
||||
pushNewRenderer(manager, EntityStray.class, new RenderPonySkeleton.Stray(manager));
|
||||
pushNewRenderer(manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager));
|
||||
MineLittlePony.logger.info("Skeletons are now ponies.");
|
||||
} else {
|
||||
restoreRenderer(EntitySkeleton.class);
|
||||
restoreRenderer(EntityStray.class);
|
||||
restoreRenderer(EntityWitherSkeleton.class);
|
||||
}
|
||||
|
||||
if (config.illagers) {
|
||||
pushNewRenderer(manager, EntityVex.class, new RenderPonyVex(manager));
|
||||
pushNewRenderer(manager, EntityEvoker.class, new RenderPonyIllager.Evoker(manager));
|
||||
pushNewRenderer(manager, EntityVindicator.class, new RenderPonyIllager.Vindicator(manager));
|
||||
pushNewRenderer(manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager));
|
||||
MineLittlePony.logger.info("Illagers are now ponies.");
|
||||
} else {
|
||||
restoreRenderer(EntityVex.class);
|
||||
restoreRenderer(EntityEvoker.class);
|
||||
restoreRenderer(EntityVindicator.class);
|
||||
restoreRenderer(EntityIllusionIllager.class);
|
||||
}
|
||||
|
||||
if (config.guardians) {
|
||||
pushNewRenderer(manager, EntityGuardian.class, new RenderPonyGuardian(manager));
|
||||
pushNewRenderer(manager, EntityElderGuardian.class, new RenderPonyGuardian.Elder(manager));
|
||||
MineLittlePony.logger.info("Guardians are now ponies.");
|
||||
} else {
|
||||
restoreRenderer(EntityGuardian.class);
|
||||
restoreRenderer(EntityElderGuardian.class);
|
||||
for (MobRenderers i : MobRenderers.values()) {
|
||||
i.apply(this, manager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a new renderer replacement storing the original internally. This change can be undone with {@link #restoreRenderer(Class)}
|
||||
*
|
||||
* Replaces an entity renderer depending on whether we want ponies or not.
|
||||
*
|
||||
* @param state True if we want ponies (the original will be stored)
|
||||
* @param manager The render manager
|
||||
* @param type The type to replace
|
||||
* @param renderer The replacement value
|
||||
* @param <T> The entity type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Entity, V extends T> void pushNewRenderer(RenderManager manager, Class<V> type, Render<T> renderer) {
|
||||
public <T extends Entity, V extends T> void switchRenderer(boolean state, RenderManager manager, Class<V> type, Render<T> renderer) {
|
||||
if (state) {
|
||||
if (!renderMap.containsKey(type)) {
|
||||
renderMap.put(type, manager.getEntityClassRenderObject(type));
|
||||
}
|
||||
ModUtilities.addRenderer((Class<T>)type, renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores a renderer to its previous value.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Entity> void restoreRenderer(Class<T> type) {
|
||||
} else {
|
||||
if (renderMap.containsKey(type)) {
|
||||
ModUtilities.addRenderer(type, (Render<T>)renderMap.get(type));
|
||||
ModUtilities.addRenderer(type, (Render<V>)renderMap.get(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ 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;
|
||||
|
@ -51,10 +53,9 @@ public class GuiPonySettings extends GuiScreen {
|
|||
|
||||
row += 15;
|
||||
addButton(new Label(LEFT, row += 15, OPTIONS_PREFIX + "options", -1));
|
||||
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + "hd", config.hd, v -> config.hd = v));
|
||||
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + "snuzzles", config.snuzzles, v -> config.snuzzles = v));
|
||||
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + "sizes", config.sizes, v -> config.sizes = v));
|
||||
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + "showscale", config.showscale, v -> config.showscale = v));
|
||||
for (PonySettings i : PonySettings.values()) {
|
||||
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i.get(), i));
|
||||
}
|
||||
|
||||
if (mustScroll()) {
|
||||
row += 15;
|
||||
|
@ -63,12 +64,9 @@ public class GuiPonySettings extends GuiScreen {
|
|||
}
|
||||
|
||||
addButton(new Label(RIGHT, row += 15, MOB_PREFIX + "title", -1));
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + "villagers", config.villagers, v -> config.villagers = v));
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + "zombies", config.zombies, v -> config.zombies = v));
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + "zombiepigmen", config.pigzombies, v -> config.pigzombies = v));
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + "skeletons", config.skeletons, v -> config.skeletons = v));
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + "illagers", config.illagers, v -> config.illagers = v));
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + "guardians", config.guardians, v -> config.guardians = v));
|
||||
for (MobRenderers i : MobRenderers.values()) {
|
||||
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + i.name().toLowerCase(), i.get(), i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,7 +85,6 @@ public class GuiPonySettings extends GuiScreen {
|
|||
@Override
|
||||
public void onGuiClosed() {
|
||||
LiteLoader.getInstance().writeConfig(config);
|
||||
MineLittlePony.getInstance().getRenderManager().initializeMobRenderers(mc.getRenderManager(), config);
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package com.minelittlepony.render.ponies;
|
||||
|
||||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.PonyRenderManager;
|
||||
import com.minelittlepony.settings.SensibleConfig.Setting;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.monster.*;
|
||||
import net.minecraft.entity.passive.*;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
@Override
|
||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||
pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager));
|
||||
pony.switchRenderer(state, manager, EntityWitch.class, new RenderPonyWitch(manager));
|
||||
pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager));
|
||||
}
|
||||
},
|
||||
ZOMBIES {
|
||||
@Override
|
||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||
pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager));
|
||||
pony.switchRenderer(state, manager, EntityHusk.class, new RenderPonyZombie.Husk(manager));
|
||||
pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager));
|
||||
}
|
||||
},
|
||||
PIGZOMBIES {
|
||||
@Override
|
||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||
pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager));
|
||||
}
|
||||
},
|
||||
SKELETONS {
|
||||
@Override
|
||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||
pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager));
|
||||
pony.switchRenderer(state, manager, EntityStray.class, new RenderPonySkeleton.Stray(manager));
|
||||
pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager));
|
||||
}
|
||||
},
|
||||
ILLAGERS {
|
||||
@Override
|
||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||
pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager));
|
||||
pony.switchRenderer(state, manager, EntityEvoker.class, new RenderPonyIllager.Evoker(manager));
|
||||
pony.switchRenderer(state, manager, EntityVindicator.class, new RenderPonyIllager.Vindicator(manager));
|
||||
pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager));
|
||||
}
|
||||
},
|
||||
GUARDIANS {
|
||||
@Override
|
||||
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
|
||||
pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager));
|
||||
pony.switchRenderer(state, manager, EntityElderGuardian.class, new RenderPonyGuardian.Elder(manager));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void set(boolean value) {
|
||||
Setting.super.set(value);
|
||||
apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager());
|
||||
}
|
||||
|
||||
public void apply(PonyRenderManager pony, RenderManager manager) {
|
||||
boolean state = get();
|
||||
register(state, pony, manager);
|
||||
if (state) {
|
||||
MineLittlePony.logger.info(name() + " are now ponies.");
|
||||
} else {
|
||||
MineLittlePony.logger.info(name() + " are no longer ponies.");
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void register(boolean state, PonyRenderManager pony, RenderManager manager);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue