Move configs to the api package and remove some references to client classes

This commit is contained in:
Sollace 2022-12-11 00:38:00 +00:00
parent 64d1e10b0f
commit 3fb9b46013
25 changed files with 59 additions and 52 deletions

View file

@ -1,10 +1,10 @@
package com.minelittlepony.settings;
package com.minelittlepony.api.config;
import net.minecraft.util.math.MathHelper;
import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.api.pony.meta.Sizes;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.common.util.GamePaths;
import com.minelittlepony.common.util.settings.*;
import java.nio.file.Path;
@ -13,6 +13,15 @@ import java.nio.file.Path;
* Storage container for MineLP client settings.
*/
public class PonyConfig extends Config {
private static PonyConfig instance;
public static PonyConfig getInstance() {
if (instance != null) {
return instance;
}
return new PonyConfig(GamePaths.getConfigDirectory().resolve("minelp.json"));
}
/**
* Sets the pony level. Want MOAR PONEHS? Well here you go.
*/
@ -59,6 +68,7 @@ public class PonyConfig extends Config {
public PonyConfig(Path path) {
super(HEIRARCHICAL_JSON_ADAPTER, path);
instance = this;
}
public float setGlobalScaleFactor(float f) {
@ -103,12 +113,12 @@ public class PonyConfig extends Config {
*/
public static Race getEffectiveRace(Race race) {
Race override = MineLittlePony.getInstance().getConfig().raceOverride.get();
Race override = instance.raceOverride.get();
if (override != Race.HUMAN) {
return override;
}
if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.HUMANS) {
if (instance.ponyLevel.get() == PonyLevel.HUMANS) {
return Race.HUMAN;
}

View file

@ -1,4 +1,4 @@
package com.minelittlepony.settings;
package com.minelittlepony.api.config;
public enum PonyLevel {
PONIES,

View file

@ -5,9 +5,8 @@ import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.ComparisonChain;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.settings.PonyConfig;
public interface IPony extends Comparable<IPony> {
@ -15,7 +14,7 @@ public interface IPony extends Comparable<IPony> {
* Gets the global pony manager instance.
*/
static IPonyManager getManager() {
return MineLittlePony.getInstance().getManager();
return IPonyManager.Instance.instance;
}
/**

View file

@ -63,4 +63,8 @@ public interface IPonyManager {
void removePony(Identifier resource);
interface ForcedPony {}
final class Instance {
public static IPonyManager instance;
}
}

View file

@ -1,6 +1,6 @@
package com.minelittlepony.api.pony.meta;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.api.config.PonyConfig;
/**
* Represents the different model sizes that are possible.
@ -35,28 +35,28 @@ public enum Sizes implements Size {
@Override
public float getShadowSize() {
return shadowSize * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor();
return shadowSize * PonyConfig.getInstance().getGlobalScaleFactor();
}
@Override
public float getScaleFactor() {
return scale * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor();
return scale * PonyConfig.getInstance().getGlobalScaleFactor();
}
@Override
public float getEyeHeightFactor() {
if (!MineLittlePony.getInstance().getConfig().fillycam.get()) {
if (!PonyConfig.getInstance().fillycam.get()) {
return 1;
}
return camera * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor();
return camera * PonyConfig.getInstance().getGlobalScaleFactor();
}
@Override
public float getEyeDistanceFactor() {
if (!MineLittlePony.getInstance().getConfig().fillycam.get()) {
if (!PonyConfig.getInstance().fillycam.get()) {
return 1;
}
return camera * MineLittlePony.getInstance().getConfig().getGlobalScaleFactor();
return camera * PonyConfig.getInstance().getGlobalScaleFactor();
}
@Override

View file

@ -35,7 +35,7 @@ public class Channel {
ClientPlayNetworking.registerGlobalReceiver(REQUEST_PONY_DATA, (client, handler, ignored, sender) -> {
if (client.player != null) {
IPony pony = MineLittlePony.getInstance().getManager().getPony(client.player);
IPony pony = IPony.getManager().getPony(client.player);
registered = true;
MineLittlePony.logger.info("Server has just consented");

View file

@ -45,7 +45,7 @@ public class HorseCam {
return pitch;
}
IPony pony = MineLittlePony.getInstance().getManager().getPony(player);
IPony pony = IPony.getManager().getPony(player);
if (!pony.race().isHuman()) {
Setting<Boolean> fillyCam = MineLittlePony.getInstance().getConfig().fillycam;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client;
import com.minelittlepony.api.pony.IPonyManager;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.network.fabric.Channel;
import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.client.pony.PonyManager;
@ -14,7 +14,6 @@ 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.settings.PonyConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -142,7 +141,7 @@ public class MineLittlePony implements ClientModInitializer {
return config;
}
public IPonyManager getManager() {
public PonyManager getManager() {
return ponyManager;
}

View file

@ -6,7 +6,6 @@ import com.minelittlepony.api.model.ModelAttributes;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.IPonyManager;
import com.minelittlepony.client.IPreviewModel;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.EquineRenderManager;
import com.minelittlepony.hdskins.client.dummy.*;
@ -34,7 +33,7 @@ class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Sw
if (getTextures().getPosture().getActiveSkinType() == MineLPHDSkins.seaponySkinType) {
return getTextures().usesThinSkin() ? "slimseapony" : "seapony";
}
return MineLittlePony.getInstance().getManager()
return IPony.getManager()
.getPony(this)
.metadata()
.getRace()

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.hdskins;
import com.minelittlepony.api.pony.IPonyManager;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.GuiPonySettings;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.common.client.gui.element.Button;
@ -21,8 +21,6 @@ import org.lwjgl.glfw.GLFW;
*/
class GuiSkinsMineLP extends GuiSkins {
private IPonyManager ponyManager = MineLittlePony.getInstance().getManager();
private static final String[] PANORAMAS = new String[] {
"minelittlepony:textures/cubemap/sugarcubecorner",
"minelittlepony:textures/cubemap/quillsandsofas",
@ -77,7 +75,7 @@ class GuiSkinsMineLP extends GuiSkins {
MineLittlePony.logger.debug("Invalidating old local skin, checking updated local skin");
if (type == SkinType.SKIN) {
previewer.getLocal().ifPresent(local -> ponyManager.removePony(local.getTextures().get(SkinType.SKIN).getId()));
previewer.getLocal().ifPresent(local -> IPony.getManager().removePony(local.getTextures().get(SkinType.SKIN).getId()));
}
}
@ -87,7 +85,7 @@ class GuiSkinsMineLP extends GuiSkins {
MineLittlePony.logger.debug("Invalidating old remote skin, checking updated remote skin");
if (type == SkinType.SKIN) {
ponyManager.removePony(location);
IPony.getManager().removePony(location);
}
}
}

View file

@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.api.pony.*;
import com.minelittlepony.api.pony.meta.TriggerPixel;
import com.minelittlepony.api.pony.meta.Wearable;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.entity.SeaponyRenderer;
import com.minelittlepony.common.client.gui.dimension.Bounds;
import com.minelittlepony.hdskins.client.dummy.*;
@ -56,7 +55,7 @@ class PonyPreview extends PlayerPreview {
MatrixStack matrices, @Nullable Consumer<DummyPlayer> postAction) {
super.renderWorldAndPlayer(thePlayer, frame, horizon, mouseX, mouseY, ticks, partialTick, scale, matrices, postAction);
thePlayer.ifPresent(p -> {
IPonyData data = MineLittlePony.getInstance().getManager().getPony(p).metadata();
IPonyData data = IPony.getManager().getPony(p).metadata();
int[] index = new int[1];
data.getTriggerPixels().forEach((key, value) -> {
drawLegendBlock(matrices, index[0]++, frame.left, frame.top, mouseX, mouseY, key, value);

View file

@ -6,7 +6,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.MineLittlePony;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
@ -19,7 +18,7 @@ abstract class MixinCamera {
private void redirectCameraDistance(double initial, CallbackInfoReturnable<Double> info) {
double value = info.getReturnValueD();
IPony pony = MineLittlePony.getInstance().getManager().getPony(MinecraftClient.getInstance().player);
IPony pony = IPony.getManager().getPony(MinecraftClient.getInstance().player);
if (!pony.race().isHuman()) {
value *= pony.metadata().getSize().getEyeDistanceFactor();

View file

@ -1,7 +1,6 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.pony.Pony;
import com.minelittlepony.client.render.EquineRenderManager;
@ -48,7 +47,7 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implem
public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
float value = super.getActiveEyeHeight(pose, dimensions);
IPony pony = MineLittlePony.getInstance().getManager().getPony(this);
IPony pony = IPony.getManager().getPony(this);
if (!pony.race().isHuman()) {
float factor = pony.metadata().getSize().getEyeHeightFactor();

View file

@ -1,8 +1,9 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.api.config.PonyLevel;
import com.minelittlepony.api.pony.DefaultPonySkinHelper;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.settings.PonyLevel;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.util.Identifier;
@ -38,7 +39,7 @@ abstract class MixinDefaultSkinHelper {
cancellable = true)
private static void onGetModel(UUID uuid, CallbackInfoReturnable<String> cir) {
if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) {
cir.setReturnValue(MineLittlePony.getInstance().getManager()
cir.setReturnValue(IPony.getManager()
.getPony(DefaultSkinHelper.getTexture(uuid), uuid)
.race()
.getModelId("slim".equalsIgnoreCase(cir.getReturnValue())));

View file

@ -1,7 +1,7 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.IPreviewModel;
import com.minelittlepony.client.MineLittlePony;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
@ -21,7 +21,7 @@ abstract class MixinEntityRenderDispatcher {
if (player instanceof IPreviewModel) {
return player.getModel();
}
return MineLittlePony.getInstance().getManager()
return IPony.getManager()
.getPony(player)
.race()
.getModelId(player.getModel().contains("slim"));

View file

@ -3,6 +3,7 @@ package com.minelittlepony.client.pony;
import net.minecraft.client.texture.NativeImage;
import com.google.common.base.MoreObjects;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.IPonyData;
import com.minelittlepony.api.pony.TriggerPixelSet;
import com.minelittlepony.api.pony.TriggerPixelType;
@ -10,7 +11,6 @@ import com.minelittlepony.api.pony.TriggerPixelValue;
import com.minelittlepony.api.pony.meta.*;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.common.util.animation.Interpolator;
import com.minelittlepony.settings.PonyConfig;
import java.util.Map;
import java.util.TreeMap;

View file

@ -4,13 +4,13 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;
import com.google.common.base.MoreObjects;
import com.google.gson.annotations.Expose;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.IPonyData;
import com.minelittlepony.api.pony.TriggerPixelType;
import com.minelittlepony.api.pony.meta.*;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.util.render.NativeUtil;
import com.minelittlepony.common.util.animation.Interpolator;
import com.minelittlepony.settings.PonyConfig;
import java.io.IOException;
import java.util.*;

View file

@ -1,13 +1,14 @@
package com.minelittlepony.client.pony;
import com.google.common.cache.*;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.config.PonyLevel;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.IPonyManager;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.PonyRenderDispatcher;
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer;
import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
@ -44,6 +45,7 @@ public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloa
public PonyManager(PonyConfig config) {
this.config = config;
Instance.instance = this;
}
@Override

View file

@ -80,7 +80,7 @@ public class LevitatingItemRenderer {
if (entity instanceof PlayerEntity && (mode.isFirstPerson() || mode == ModelTransformation.Mode.THIRD_PERSON_LEFT_HAND || mode == ModelTransformation.Mode.THIRD_PERSON_RIGHT_HAND)) {
IPony pony = MineLittlePony.getInstance().getManager().getPony((PlayerEntity)entity);
IPony pony = IPony.getManager().getPony((PlayerEntity)entity);
matrix.push();

View file

@ -1,12 +1,12 @@
package com.minelittlepony.client.render.blockentity.skull;
import com.google.common.base.Suppliers;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.model.AbstractPonyModel;
import com.minelittlepony.client.render.MobRenderers;
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull;
import com.minelittlepony.mson.api.ModelKey;
import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile;
import java.util.function.Supplier;

View file

@ -1,13 +1,13 @@
package com.minelittlepony.client.render.blockentity.skull;
import com.google.common.base.Suppliers;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.config.PonyLevel;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.model.*;
import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull;
import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
import com.mojang.authlib.GameProfile;
import java.util.HashMap;

View file

@ -1,6 +1,7 @@
package com.minelittlepony.client.render.blockentity.skull;
import com.google.common.collect.Maps;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.ModelType;
@ -8,7 +9,6 @@ import com.minelittlepony.client.render.LevitatingItemRenderer;
import com.minelittlepony.client.render.MobRenderers;
import com.minelittlepony.client.render.entity.SkeleponyRenderer;
import com.minelittlepony.client.render.entity.ZomponyRenderer;
import com.minelittlepony.settings.PonyConfig;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.SkullBlock;
@ -69,7 +69,7 @@ public class PonySkullRenderer {
return false;
}
if (!selectedSkull.bindPony(MineLittlePony.getInstance().getManager().getPony(selectedSkin))) {
if (!selectedSkull.bindPony(IPony.getManager().getPony(selectedSkin))) {
return false;
}

View file

@ -4,7 +4,6 @@ import com.minelittlepony.api.model.ModelAttributes;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.meta.Race;
import com.minelittlepony.api.pony.meta.Wearable;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.model.ClientPonyModel;
import com.minelittlepony.client.model.ModelWrapper;
@ -194,7 +193,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen
@Override
public IPony getEntityPony(AbstractClientPlayerEntity entity) {
return MineLittlePony.getInstance().getManager().getPony(entity);
return IPony.getManager().getPony(entity);
}
@Override

View file

@ -2,7 +2,6 @@ package com.minelittlepony.client.render.entity;
import com.minelittlepony.api.pony.IPony;
import com.minelittlepony.api.pony.meta.Wearable;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.ClientPonyModel;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.model.ModelWrapper;
@ -123,7 +122,7 @@ public abstract class PonyRenderer<T extends MobEntity, M extends EntityModel<T>
@Override
public IPony getEntityPony(T entity) {
return MineLittlePony.getInstance().getManager().getPony(getTexture(entity));
return IPony.getManager().getPony(getTexture(entity));
}
public abstract static class Caster<T extends MobEntity, M extends ClientPonyModel<T>> extends PonyRenderer<T, M> {

View file

@ -3,10 +3,10 @@ package com.minelittlepony.client.settings;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import com.minelittlepony.api.config.PonyConfig;
import com.minelittlepony.client.render.MobRenderers;
import com.minelittlepony.common.client.gui.VisibilityMode;
import com.minelittlepony.common.util.settings.Setting;
import com.minelittlepony.settings.PonyConfig;
import java.nio.file.Path;