diff --git a/src/main/java/com/minelittlepony/client/HorseCam.java b/src/main/java/com/minelittlepony/client/HorseCam.java index 442f19aa..5576839b 100644 --- a/src/main/java/com/minelittlepony/client/HorseCam.java +++ b/src/main/java/com/minelittlepony/client/HorseCam.java @@ -1,5 +1,6 @@ package com.minelittlepony.client; +import com.minelittlepony.settings.PonyConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.hit.HitResult; @@ -13,7 +14,7 @@ public class HorseCam { */ public static float transformCameraAngle(float pitch) { - if (!MineLittlePony.getInstance().getConfig().fillycam.get()) { + if (!PonyConfig.INSTANCE.fillycam.get()) { return pitch; } diff --git a/src/main/java/com/minelittlepony/client/MineLittlePony.java b/src/main/java/com/minelittlepony/client/MineLittlePony.java index aabef234..1fdb1fb2 100644 --- a/src/main/java/com/minelittlepony/client/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/client/MineLittlePony.java @@ -4,15 +4,13 @@ import com.minelittlepony.client.gui.GuiPonySettings; import com.minelittlepony.client.hdskins.IndirectHDSkins; import com.minelittlepony.client.pony.PonyManager; import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer; -import com.minelittlepony.client.settings.ClientPonyConfig; import com.minelittlepony.common.client.gui.VisibilityMode; import com.minelittlepony.common.client.gui.element.Button; import com.minelittlepony.common.client.gui.sprite.TextureSprite; +import com.minelittlepony.common.config.ConfigManager; import com.minelittlepony.common.event.ClientReadyCallback; import com.minelittlepony.common.event.ScreenInitCallback; import com.minelittlepony.common.event.SkinFilterCallback; -import com.minelittlepony.common.util.GamePaths; -import com.minelittlepony.common.util.settings.JsonConfig; import com.minelittlepony.pony.IPonyManager; import com.minelittlepony.settings.PonyConfig; @@ -53,7 +51,6 @@ public class MineLittlePony implements ClientModInitializer { private final PonyRenderManager renderManager = PonyRenderManager.getInstance(); - private ClientPonyConfig config; private PonyManager ponyManager; private FabricKeyBinding keyBinding; @@ -63,6 +60,7 @@ public class MineLittlePony implements ClientModInitializer { public MineLittlePony() { instance = this; + ConfigManager.register("minelp.json", PonyConfig.INSTANCE); } /** @@ -77,8 +75,8 @@ public class MineLittlePony implements ClientModInitializer { hasHdSkins = FabricLoader.getInstance().isModLoaded("hdskins"); hasModMenu = FabricLoader.getInstance().isModLoaded("modmenu"); - config = JsonConfig.of(GamePaths.getConfigDirectory().resolve("minelp.json"), ClientPonyConfig::new); - ponyManager = new PonyManager(config); + + ponyManager = new PonyManager(); keyBinding = FabricKeyBinding.Builder.create(new Identifier("minelittlepony", "settings"), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F9, "key.categories.misc").build(); KeyBindingRegistry.INSTANCE.register(keyBinding); @@ -141,7 +139,7 @@ public class MineLittlePony implements ClientModInitializer { private void onScreenInit(Screen screen, ScreenInitCallback.ButtonList buttons) { if (screen instanceof TitleScreen) { - VisibilityMode mode = config.horseButton.get(); + VisibilityMode mode = PonyConfig.INSTANCE.horseButton.get(); boolean show = mode == VisibilityMode.ON || (mode == VisibilityMode.AUTO && !(hasHdSkins || hasModMenu )); @@ -161,13 +159,6 @@ public class MineLittlePony implements ClientModInitializer { } } - /** - * Gets the global MineLP client configuration. - */ - public PonyConfig getConfig() { - return config; - } - public IPonyManager getManager() { return ponyManager; } diff --git a/src/main/java/com/minelittlepony/client/gui/GuiPonySettings.java b/src/main/java/com/minelittlepony/client/gui/GuiPonySettings.java index 152bb21b..b13c65a8 100644 --- a/src/main/java/com/minelittlepony/client/gui/GuiPonySettings.java +++ b/src/main/java/com/minelittlepony/client/gui/GuiPonySettings.java @@ -1,12 +1,16 @@ package com.minelittlepony.client.gui; +import com.minelittlepony.common.config.ConfigManager; +import com.minelittlepony.common.config.Value; +import com.minelittlepony.common.config.ValueSignature; +import com.minelittlepony.settings.PonyConfig; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resource.language.I18n; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.LiteralText; -import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.render.entities.MobRenderers; -import com.minelittlepony.client.settings.ClientPonyConfig; import com.minelittlepony.common.client.gui.GameGui; import com.minelittlepony.common.client.gui.ScrollContainer; import com.minelittlepony.common.client.gui.element.Button; @@ -16,10 +20,13 @@ import com.minelittlepony.common.client.gui.element.Slider; import com.minelittlepony.common.client.gui.element.Toggle; import com.minelittlepony.common.util.settings.Setting; import com.minelittlepony.settings.PonyLevel; +import org.apache.logging.log4j.LogManager; + +import java.io.IOException; +import java.util.Map; /** * In-Game options menu. - * */ public class GuiPonySettings extends GameGui { @@ -29,8 +36,6 @@ public class GuiPonySettings extends GameGui { private static final String MOB_PREFIX = "minelp.mobs."; - private ClientPonyConfig config; - private final ScrollContainer content = new ScrollContainer(); private final boolean hiddenOptions; @@ -38,8 +43,6 @@ public class GuiPonySettings extends GameGui { public GuiPonySettings() { super(new LiteralText(OPTIONS_PREFIX + "title")); - config = (ClientPonyConfig)MineLittlePony.getInstance().getConfig(); - content.margin.top = 30; content.margin.bottom = 30; content.padding.top = 10; @@ -72,42 +75,54 @@ public class GuiPonySettings extends GameGui { addButton(new Label(width / 2, 5).setCentered()).getStyle().setText(getTitle().getString()); addButton(new Button(width / 2 - 100, height - 25)) - .onClick(sender -> onClose()) - .getStyle() + .onClick(sender -> onClose()) + .getStyle() .setText("gui.done"); content.addButton(new Label(LEFT, row)).getStyle().setText(PONY_LEVEL); - content.addButton(new Slider(LEFT, row += 20, 0, 2, config.ponyLevel.get().ordinal()) + content.addButton(new Slider(LEFT, row += 20, 0, 2, PonyConfig.INSTANCE.ponyLevel.get().ordinal()) .onChange(v -> { PonyLevel level = PonyLevel.valueFor(v); - config.ponyLevel.set(level); - return (float)level.ordinal(); + PonyConfig.INSTANCE.ponyLevel.set(level); + return (float) level.ordinal(); }) .setFormatter(value -> I18n.translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase()))); if (hiddenOptions) { content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.scale"); - content.addButton(new Slider(LEFT, row += 15, 0.1F, 3, config.getGlobalScaleFactor()) - .onChange(config::setGlobalScaleFactor) + content.addButton(new Slider(LEFT, row += 15, 0.1F, 3, PonyConfig.INSTANCE.getGlobalScaleFactor()) + .onChange(PonyConfig.INSTANCE::setGlobalScaleFactor) .setFormatter(value -> I18n.translate("minelp.debug.scale.value", I18n.translate(describeCurrentScale(value))))); content.addButton(new Label(LEFT, row += 30)).getStyle().setText("minelp.debug.size"); - content.addButton(new EnumSlider<>(LEFT, row += 15, config.sizeOverride.get()) - .onChange(config.sizeOverride::set)); + content.addButton(new EnumSlider<>(LEFT, row += 15, PonyConfig.INSTANCE.sizeOverride.get()) + .onChange(i -> { + PonyConfig.INSTANCE.sizeOverride.set(i); + return i; + })); } row += 20; content.addButton(new Label(LEFT, row)).getStyle().setText(OPTIONS_PREFIX + "options"); - for (Setting i : MineLittlePony.getInstance().getConfig().getByCategory("settings")) { - content.addButton(new Toggle(LEFT, row += 20, ((Setting)i).get())) - .onChange((Setting)i) - .getStyle().setText(OPTIONS_PREFIX + i.name().toLowerCase()); + for (Map.Entry> i : ConfigManager.getCatagory(PonyConfig.INSTANCE, "settings").entrySet()) { + if (i.getValue().type == Boolean.class) { + Value v = (Value) i.getValue().value; + content.addButton(new Toggle(LEFT, row += 20, v.get())) + .onChange(b -> { + v.set(b); + return b; + }) + .getStyle().setText(OPTIONS_PREFIX + i.getKey().toLowerCase()); + } } content.addButton(new Label(LEFT, row += 20)).getStyle().setText(OPTIONS_PREFIX + "button"); - content.addButton(new EnumSlider<>(LEFT, row += 20, config.horseButton.get()) - .onChange(config.horseButton::set)); + content.addButton(new EnumSlider<>(LEFT, row += 20, PonyConfig.INSTANCE.horseButton.get()) + .onChange(value -> { + PonyConfig.INSTANCE.horseButton.set(value); + return value; + })); if (RIGHT != LEFT) { row = 0; @@ -118,8 +133,8 @@ public class GuiPonySettings extends GameGui { content.addButton(new Label(RIGHT, row)).getStyle().setText(MOB_PREFIX + "title"); for (MobRenderers i : MobRenderers.registry) { content.addButton(new Toggle(RIGHT, row += 20, i.get())) - .onChange(i::set) - .getStyle().setText(MOB_PREFIX + i.name().toLowerCase()); + .onChange(i::set) + .getStyle().setText(MOB_PREFIX + i.name().toLowerCase()); } } @@ -152,6 +167,14 @@ public class GuiPonySettings extends GameGui { @Override public void onClose() { super.onClose(); - config.save(); + try { + ConfigManager.save(PonyConfig.INSTANCE); + PlayerEntity player = MinecraftClient.getInstance().player; + if (player != null) { + player.calculateDimensions(); + } + } catch (IOException e) { + LogManager.getLogger().warn("Unable to save config", e); + } } } diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java b/src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java index edaf47ff..594f0a12 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinDefaultPlayerSkin.java @@ -3,6 +3,7 @@ package com.minelittlepony.client.mixin; import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.model.races.PlayerModels; import com.minelittlepony.pony.IPonyManager; +import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyLevel; import net.minecraft.client.util.DefaultSkinHelper; @@ -21,7 +22,7 @@ public abstract class MixinDefaultPlayerSkin { at = @At("HEAD"), cancellable = true) private static void legacySkin(CallbackInfoReturnable cir) { - if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { + if (PonyConfig.INSTANCE.ponyLevel.get() == PonyLevel.PONIES) { cir.setReturnValue(IPonyManager.STEVE); } } @@ -30,7 +31,7 @@ public abstract class MixinDefaultPlayerSkin { at = @At("HEAD"), cancellable = true) private static void defaultSkin(UUID uuid, CallbackInfoReturnable cir) { - if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { + if (PonyConfig.INSTANCE.ponyLevel.get() == PonyLevel.PONIES) { cir.setReturnValue(IPonyManager.getDefaultSkin(uuid)); } } @@ -39,7 +40,7 @@ public abstract class MixinDefaultPlayerSkin { at = @At("HEAD"), cancellable = true) private static void skinType(UUID uuid, CallbackInfoReturnable cir) { - if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) { + if (PonyConfig.INSTANCE.ponyLevel.get() == PonyLevel.PONIES) { cir.setReturnValue(PlayerModels.forRace(MineLittlePony.getInstance().getManager() .getPony(IPonyManager.getDefaultSkin(uuid), uuid) diff --git a/src/main/java/com/minelittlepony/client/model/components/PonySnout.java b/src/main/java/com/minelittlepony/client/model/components/PonySnout.java index ea1beff1..fce706e2 100644 --- a/src/main/java/com/minelittlepony/client/model/components/PonySnout.java +++ b/src/main/java/com/minelittlepony/client/model/components/PonySnout.java @@ -1,9 +1,9 @@ package com.minelittlepony.client.model.components; +import com.minelittlepony.settings.PonyConfig; import net.minecraft.client.model.Cuboid; import net.minecraft.client.model.Model; -import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.util.render.plane.PlaneRenderer; import com.minelittlepony.model.ICapitated; import com.minelittlepony.pony.meta.Gender; @@ -59,7 +59,7 @@ public class PonySnout { } public void setGender(Gender gender) { - boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getInstance().getConfig().snuzzles.get(); + boolean show = !head.hasHeadGear() && !isHidden && PonyConfig.INSTANCE.snuzzles.get(); mare.field_3664 = !(show && gender.isMare()); stallion.field_3664 = !(show && gender.isStallion()); diff --git a/src/main/java/com/minelittlepony/client/pony/PonyManager.java b/src/main/java/com/minelittlepony/client/pony/PonyManager.java index 7b35f6cc..ef423702 100644 --- a/src/main/java/com/minelittlepony/client/pony/PonyManager.java +++ b/src/main/java/com/minelittlepony/client/pony/PonyManager.java @@ -54,16 +54,10 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList */ private List backgroundPonyList = Lists.newArrayList(); - private final PonyConfig config; - private final LoadingCache poniesCache = CacheBuilder.newBuilder() .expireAfterAccess(30, TimeUnit.SECONDS) .build(CacheLoader.from(Pony::new)); - public PonyManager(PonyConfig config) { - this.config = config; - } - @Override public IPony getPony(Identifier resource) { return poniesCache.getUnchecked(resource); @@ -109,7 +103,7 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList public IPony getPony(Identifier resource, UUID uuid) { IPony pony = getPony(resource); - if (config.ponyLevel.get() == PonyLevel.PONIES && pony.getMetadata().getRace().isHuman()) { + if (PonyConfig.INSTANCE.ponyLevel.get() == PonyLevel.PONIES && pony.getMetadata().getRace().isHuman()) { return getBackgroundPony(uuid); } @@ -118,7 +112,7 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList @Override public IPony getDefaultPony(UUID uuid) { - if (config.ponyLevel.get() != PonyLevel.PONIES) { + if (PonyConfig.INSTANCE.ponyLevel.get() != PonyLevel.PONIES) { return getPony(DefaultSkinHelper.getTexture(uuid)); } diff --git a/src/main/java/com/minelittlepony/client/render/LevitatingItemRenderer.java b/src/main/java/com/minelittlepony/client/render/LevitatingItemRenderer.java index 48d1e9e8..871716db 100644 --- a/src/main/java/com/minelittlepony/client/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/LevitatingItemRenderer.java @@ -1,5 +1,6 @@ package com.minelittlepony.client.render; +import com.minelittlepony.settings.PonyConfig; import org.lwjgl.opengl.GL14; import com.minelittlepony.client.MineLittlePony; @@ -79,7 +80,7 @@ public class LevitatingItemRenderer { pushMatrix(); - boolean doMagic = MineLittlePony.getInstance().getConfig().fpsmagic.get() && pony.getMetadata().hasMagic(); + boolean doMagic = PonyConfig.INSTANCE.fpsmagic.get() && pony.getMetadata().hasMagic(); ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer(); diff --git a/src/main/java/com/minelittlepony/client/render/RenderPony.java b/src/main/java/com/minelittlepony/client/render/RenderPony.java index 5c2d5704..94676e72 100644 --- a/src/main/java/com/minelittlepony/client/render/RenderPony.java +++ b/src/main/java/com/minelittlepony/client/render/RenderPony.java @@ -1,11 +1,11 @@ package com.minelittlepony.client.render; -import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.PonyRenderManager; import com.minelittlepony.client.model.IPonyModel; import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.transform.PonyPosture; import com.minelittlepony.pony.IPony; +import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.util.math.MathUtil; import com.mojang.blaze3d.platform.GlStateManager; @@ -41,7 +41,7 @@ public class RenderPony & IPony } public VisibleRegion getFrustrum(T entity, VisibleRegion vanilla) { - if (entity.isSleeping() || !MineLittlePony.getInstance().getConfig().frustrum.get()) { + if (entity.isSleeping() || !PonyConfig.INSTANCE.frustrum.get()) { return vanilla; } return frustrum.withCamera(entity, vanilla); diff --git a/src/main/java/com/minelittlepony/client/render/entities/MobRenderers.java b/src/main/java/com/minelittlepony/client/render/entities/MobRenderers.java index 0beb3796..d25430d2 100644 --- a/src/main/java/com/minelittlepony/client/render/entities/MobRenderers.java +++ b/src/main/java/com/minelittlepony/client/render/entities/MobRenderers.java @@ -2,12 +2,14 @@ package com.minelittlepony.client.render.entities; import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.PonyRenderManager; +import com.minelittlepony.common.config.Value; import com.minelittlepony.common.util.settings.Setting; import java.util.Arrays; import java.util.List; import java.util.function.BiConsumer; +import com.minelittlepony.settings.PonyConfig; import net.minecraft.entity.mob.*; import net.minecraft.entity.passive.*; @@ -15,61 +17,59 @@ import net.minecraft.entity.passive.*; * Central location where new entity renderers are registered and applied. */ public enum MobRenderers { - VILLAGERS((state, pony) -> { + VILLAGERS(PonyConfig.INSTANCE.villagers, (state, pony) -> { pony.switchRenderer(state, VillagerEntity.class, RenderPonyVillager::new); pony.switchRenderer(state, WitchEntity.class, RenderPonyWitch::new); pony.switchRenderer(state, ZombieVillagerEntity.class, RenderPonyZombieVillager::new); pony.switchRenderer(state, WanderingTraderEntity.class, RenderPonyTrader::new); pony.switchRenderer(state, PillagerEntity.class, RenderPonyPillager::new); }), - ZOMBIES((state, pony) -> { + ZOMBIES(PonyConfig.INSTANCE.zombies, (state, pony) -> { pony.switchRenderer(state, ZombieEntity.class, RenderPonyZombie::new); pony.switchRenderer(state, HuskEntity.class, RenderPonyZombie.Husk::new); pony.switchRenderer(state, GiantEntity.class, RenderPonyZombie.Giant::new); pony.switchRenderer(state, DrownedEntity.class, RenderPonyZombie.Drowned::new); }), - PIGZOMBIES((state, pony) -> { + PIGZOMBIES(PonyConfig.INSTANCE.pigzombies, (state, pony) -> { pony.switchRenderer(state, ZombiePigmanEntity.class, RenderPonyZombie.Pigman::new); }), - SKELETONS((state, pony) -> { + SKELETONS(PonyConfig.INSTANCE.skeletons, (state, pony) -> { pony.switchRenderer(state, SkeletonEntity.class, RenderPonySkeleton::new); pony.switchRenderer(state, StrayEntity.class, RenderPonySkeleton.Stray::new); pony.switchRenderer(state, WitherSkeletonEntity.class, RenderPonySkeleton.Wither::new); }), - ILLAGERS((state, pony) -> { + ILLAGERS(PonyConfig.INSTANCE.illagers, (state, pony) -> { pony.switchRenderer(state, VexEntity.class, RenderPonyVex::new); pony.switchRenderer(state, EvokerEntity.class, RenderPonyIllager.Evoker::new); pony.switchRenderer(state, VindicatorEntity.class, RenderPonyIllager.Vindicator::new); pony.switchRenderer(state, IllusionerEntity.class, RenderPonyIllager.Illusionist::new); }), - GUARDIANS((state, pony) -> { + GUARDIANS(PonyConfig.INSTANCE.guardians, (state, pony) -> { pony.switchRenderer(state, GuardianEntity.class, RenderPonyGuardian::new); pony.switchRenderer(state, ElderGuardianEntity.class, RenderPonyGuardian.Elder::new); }), - ENDERMEN((state, pony) -> { + ENDERMEN(PonyConfig.INSTANCE.endermen, (state, pony) -> { pony.switchRenderer(state, EndermanEntity.class, RenderEnderStallion::new); }); public static final List registry = Arrays.asList(values()); + private final Value config; private final BiConsumer changer; - MobRenderers(BiConsumer changer) { + MobRenderers(Value config, BiConsumer changer) { + this.config = config; this.changer = changer; } - public Setting option() { - return MineLittlePony.getInstance().getConfig().get(name().toLowerCase()); - } - public boolean set(boolean value) { - value = option().set(value); + config.set(value); apply(PonyRenderManager.getInstance()); - return value; + return config.get(); } public boolean get() { - return option().get(); + return config.get(); } public void apply(PonyRenderManager pony) { diff --git a/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java index 2d8f95ac..b2435b84 100644 --- a/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java @@ -19,8 +19,8 @@ public class PlayerSkullRenderer extends PonySkull { private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears(); @Override - public boolean canRender(PonyConfig config) { - return config.ponyLevel.get() != PonyLevel.HUMANS; + public boolean canRender() { + return PonyConfig.INSTANCE.ponyLevel.get() != PonyLevel.HUMANS; } @Override diff --git a/src/main/java/com/minelittlepony/client/render/tileentities/skull/PonySkullRenderer.java b/src/main/java/com/minelittlepony/client/render/tileentities/skull/PonySkullRenderer.java index f16cb909..fbe4b8df 100644 --- a/src/main/java/com/minelittlepony/client/render/tileentities/skull/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/tileentities/skull/PonySkullRenderer.java @@ -44,7 +44,7 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { * Original/Existing renderer is stored to a backup variable as a fallback in case of mods. */ public static SkullBlockEntityRenderer resolve() { - if (MineLittlePony.getInstance().getConfig().ponyskulls.get()) { + if (PonyConfig.INSTANCE.ponyskulls.get()) { if (!(INSTANCE instanceof PonySkullRenderer)) { backup = INSTANCE; BlockEntityRendererRegistry.INSTANCE.register(SkullBlockEntity.class, ponyInstance); @@ -69,7 +69,7 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { ISkull skull = skullMap.get(skullType); - if (skull == null || !skull.canRender(MineLittlePony.getInstance().getConfig())) { + if (skull == null || !skull.canRender()) { if (backup != null) { backup.render(x, y, z, facing, rotation, skullType, profile, destroyStage, animateTicks); } else { @@ -154,7 +154,7 @@ public class PonySkullRenderer extends SkullBlockEntityRenderer { void render(float animateTicks, float rotation, float scale); - boolean canRender(PonyConfig config); + boolean canRender(); Identifier getSkinResource(@Nullable GameProfile profile); diff --git a/src/main/java/com/minelittlepony/client/render/tileentities/skull/SkeletonSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/tileentities/skull/SkeletonSkullRenderer.java index f5f72de5..b9cd2a24 100644 --- a/src/main/java/com/minelittlepony/client/render/tileentities/skull/SkeletonSkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/tileentities/skull/SkeletonSkullRenderer.java @@ -1,6 +1,5 @@ package com.minelittlepony.client.render.tileentities.skull; -import com.minelittlepony.client.render.entities.MobRenderers; import com.minelittlepony.client.render.entities.RenderPonySkeleton; import com.minelittlepony.settings.PonyConfig; import com.mojang.authlib.GameProfile; @@ -11,8 +10,8 @@ import javax.annotation.Nullable; public class SkeletonSkullRenderer extends PonySkull { @Override - public boolean canRender(PonyConfig config) { - return MobRenderers.SKELETONS.get(); + public boolean canRender() { + return PonyConfig.INSTANCE.skeletons.get(); } @Override diff --git a/src/main/java/com/minelittlepony/client/render/tileentities/skull/WitherSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/tileentities/skull/WitherSkullRenderer.java index 4e773e5e..c21cb2fb 100644 --- a/src/main/java/com/minelittlepony/client/render/tileentities/skull/WitherSkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/tileentities/skull/WitherSkullRenderer.java @@ -1,6 +1,5 @@ package com.minelittlepony.client.render.tileentities.skull; -import com.minelittlepony.client.render.entities.MobRenderers; import com.minelittlepony.client.render.entities.RenderPonySkeleton; import com.minelittlepony.settings.PonyConfig; import com.mojang.authlib.GameProfile; @@ -11,8 +10,8 @@ import javax.annotation.Nullable; public class WitherSkullRenderer extends PonySkull { @Override - public boolean canRender(PonyConfig config) { - return MobRenderers.SKELETONS.get(); + public boolean canRender() { + return PonyConfig.INSTANCE.skeletons.get(); } @Override diff --git a/src/main/java/com/minelittlepony/client/render/tileentities/skull/ZombieSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/tileentities/skull/ZombieSkullRenderer.java index 20df3b22..6e49ee83 100644 --- a/src/main/java/com/minelittlepony/client/render/tileentities/skull/ZombieSkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/tileentities/skull/ZombieSkullRenderer.java @@ -1,6 +1,5 @@ package com.minelittlepony.client.render.tileentities.skull; -import com.minelittlepony.client.render.entities.MobRenderers; import com.minelittlepony.client.render.entities.RenderPonyZombie; import com.minelittlepony.settings.PonyConfig; import com.mojang.authlib.GameProfile; @@ -11,8 +10,8 @@ import javax.annotation.Nullable; public class ZombieSkullRenderer extends PonySkull { @Override - public boolean canRender(PonyConfig config) { - return MobRenderers.ZOMBIES.get(); + public boolean canRender() { + return PonyConfig.INSTANCE.zombies.get(); } @Override diff --git a/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java b/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java deleted file mode 100644 index d26ff320..00000000 --- a/src/main/java/com/minelittlepony/client/settings/ClientPonyConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.minelittlepony.client.settings; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.player.PlayerEntity; - -import com.minelittlepony.client.render.entities.MobRenderers; -import com.minelittlepony.common.client.gui.VisibilityMode; -import com.minelittlepony.common.util.settings.Setting; -import com.minelittlepony.settings.PonyConfig; - -public class ClientPonyConfig extends PonyConfig { - - /** - * Visibility mode for the horse button. - */ - public final Setting horseButton = value("horseButton", VisibilityMode.AUTO); - - public ClientPonyConfig() { - MobRenderers.registry.forEach(r -> value(r.name().toLowerCase(), true)); - } - - @Override - public void save() { - super.save(); - PlayerEntity player = MinecraftClient.getInstance().player; - if (player != null) { - player.calculateDimensions(); - } - } -} diff --git a/src/main/java/com/minelittlepony/client/settings/package-info.java b/src/main/java/com/minelittlepony/client/settings/package-info.java deleted file mode 100644 index a2026d44..00000000 --- a/src/main/java/com/minelittlepony/client/settings/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@ParametersAreNonnullByDefault -package com.minelittlepony.client.settings; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/com/minelittlepony/pony/meta/Race.java b/src/main/java/com/minelittlepony/pony/meta/Race.java index feeca3d3..948bb0e2 100644 --- a/src/main/java/com/minelittlepony/pony/meta/Race.java +++ b/src/main/java/com/minelittlepony/pony/meta/Race.java @@ -1,7 +1,7 @@ package com.minelittlepony.pony.meta; -import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.pony.ITriggerPixelMapped; +import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyLevel; import javax.annotation.Nonnull; @@ -94,7 +94,7 @@ public enum Race implements ITriggerPixelMapped { * PonyLevel.PONIES (should) return a pony if this is a human. Don't be fooled, though. It doesn't. */ public Race getEffectiveRace(boolean ignorePony) { - if (MineLittlePony.getInstance().getConfig().getEffectivePonyLevel(ignorePony) == PonyLevel.HUMANS) { + if (PonyConfig.INSTANCE.getEffectivePonyLevel(ignorePony) == PonyLevel.HUMANS) { return HUMAN; } diff --git a/src/main/java/com/minelittlepony/pony/meta/Size.java b/src/main/java/com/minelittlepony/pony/meta/Size.java index b41d928a..ad60ae31 100644 --- a/src/main/java/com/minelittlepony/pony/meta/Size.java +++ b/src/main/java/com/minelittlepony/pony/meta/Size.java @@ -1,7 +1,7 @@ package com.minelittlepony.pony.meta; -import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.pony.ITriggerPixelMapped; +import com.minelittlepony.settings.PonyConfig; public enum Size implements ITriggerPixelMapped { TALL (0x764b53, 0.45f, 1.1F, 1.15F), @@ -28,25 +28,25 @@ public enum Size implements ITriggerPixelMapped { } public float getShadowSize() { - return shadowSize * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); + return shadowSize * PonyConfig.INSTANCE.getGlobalScaleFactor(); } public float getScaleFactor() { - return scale * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); + return scale * PonyConfig.INSTANCE.getGlobalScaleFactor(); } public float getEyeHeightFactor() { - if (!MineLittlePony.getInstance().getConfig().fillycam.get()) { + if (!PonyConfig.INSTANCE.fillycam.get()) { return 1; } - return camera * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); + return camera * PonyConfig.INSTANCE.getGlobalScaleFactor(); } public float getEyeDistanceFactor() { - if (!MineLittlePony.getInstance().getConfig().fillycam.get()) { + if (!PonyConfig.INSTANCE.fillycam.get()) { return 1; } - return camera * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor(); + return camera * PonyConfig.INSTANCE.getGlobalScaleFactor(); } @Override @@ -55,13 +55,13 @@ public enum Size implements ITriggerPixelMapped { } public Size getEffectiveSize() { - Size sz = MineLittlePony.getInstance().getConfig().sizeOverride.get(); + Size sz = PonyConfig.INSTANCE.sizeOverride.get(); if (sz != UNSET) { return sz; } - if (this == UNSET || !MineLittlePony.getInstance().getConfig().sizes.get()) { + if (this == UNSET || !PonyConfig.INSTANCE.sizes.get()) { return NORMAL; } diff --git a/src/main/java/com/minelittlepony/settings/PonyConfig.java b/src/main/java/com/minelittlepony/settings/PonyConfig.java index bace3e56..9e32a60d 100644 --- a/src/main/java/com/minelittlepony/settings/PonyConfig.java +++ b/src/main/java/com/minelittlepony/settings/PonyConfig.java @@ -1,34 +1,69 @@ package com.minelittlepony.settings; +import com.minelittlepony.common.client.gui.VisibilityMode; +import com.minelittlepony.common.config.JsonConfig; +import com.minelittlepony.common.config.Setting; +import com.minelittlepony.common.config.Value; import net.minecraft.util.math.MathHelper; -import com.minelittlepony.common.util.settings.JsonConfig; -import com.minelittlepony.common.util.settings.Setting; import com.minelittlepony.pony.meta.Size; /** * Storage container for MineLP client settings. */ -public class PonyConfig extends JsonConfig { +public class PonyConfig implements JsonConfig { + + public static final PonyConfig INSTANCE = new PonyConfig(); + + private PonyConfig() { + } /** * Sets the pony level. Want MOAR PONEHS? Well here you go. */ - public final Setting ponyLevel = value("ponylevel", PonyLevel.PONIES); - private final Setting scaleFactor = value("globalScaleFactor", 0.9F); + public final Value ponyLevel = new Value<>(PonyLevel.PONIES); + @Setting(name = "globalScaleFactor") + private final Value scaleFactor = new Value<>(0.9F); - public final Setting sizes = value("settings", "sizes", false); - public final Setting snuzzles = value("settings", "snuzzles", false); - public final Setting fillycam = value("settings", "fillycam", false); - private final Setting showscale = value("settings", "showscale", false); - public final Setting fpsmagic = value("settings", "fpsmagic", false); - public final Setting ponyskulls = value("settings", "ponyskulls", false); - public final Setting frustrum = value("settings", "frustrum", false); + @Setting(category = "settings") + public final Value sizes = new Value<>(false); + @Setting(category = "settings") + public final Value snuzzles = new Value<>(false); + @Setting(category = "settings") + public final Value fillycam = new Value<>(false); + @Setting(category = "settings") + private final Value showscale = new Value<>(false); + @Setting(category = "settings") + public final Value fpsmagic = new Value<>(false); + @Setting(category = "settings") + public final Value ponyskulls = new Value<>(false); + @Setting(category = "settings") + public final Value frustrum = new Value<>(false); /** * Debug override for pony sizes. */ - public final Setting sizeOverride = value("sizeOverride", Size.UNSET); + public final Value sizeOverride = new Value<>(Size.UNSET); + + /** + * Visibility mode for the horse button. + */ + public final Value horseButton = new Value<>(VisibilityMode.AUTO); + + @Setting(category = "entities") + public final Value villagers = new Value<>(true); + @Setting(category = "entities") + public final Value zombies = new Value<>(true); + @Setting(category = "entities") + public final Value pigzombies = new Value<>(true); + @Setting(category = "entities") + public final Value skeletons = new Value<>(true); + @Setting(category = "entities") + public final Value illagers = new Value<>(true); + @Setting(category = "entities") + public final Value guardians = new Value<>(true); + @Setting(category = "entities") + public final Value endermen = new Value<>(true); /** * Gets the current PonyLevel. That is the level of ponies you would like to see.