Use MineLittlePony as entrypoint and move it to client package

If a server side mod needs to use it, a proper API class should be made.
This commit is contained in:
Matthew Messinger 2019-07-07 22:47:13 -04:00
parent d8e1e08df4
commit 9c344c1554
30 changed files with 88 additions and 199 deletions

View file

@ -49,7 +49,7 @@ dependencies {
modApi "net.fabricmc.fabric-api:fabric-events-lifecycle-v0:0.1.0+"
modApi "net.fabricmc.fabric-api:fabric-resource-loader-v0:0.1.0+"
modCompile "com.minelittlepony:Kirin:${project.kirin_version}"
modApi "com.minelittlepony:Kirin:${project.kirin_version}"
include "com.minelittlepony:Kirin:${project.kirin_version}"
modImplementation "com.minelittlepony:HDSkins:${project.hd_skins_version}"

View file

@ -18,5 +18,5 @@ org.gradle.daemon=false
# Dependencies
fabric_version=0.3.0+
kirin_version=1.14.3-1.3.0-SNAPSHOT
kirin_version=1.14.3-1.3.1-SNAPSHOT
hd_skins_version=1.14.3-5.3-SNAPSHOT

View file

@ -1,44 +0,0 @@
package com.minelittlepony;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.minelittlepony.pony.IPonyManager;
import com.minelittlepony.settings.PonyConfig;
public abstract class MineLittlePony {
private static MineLittlePony instance;
public static final Logger logger = LogManager.getLogger("MineLittlePony");
public static final String MOD_NAME = "Mine Little Pony";
public static final String MOD_VERSION = "@VERSION@";
protected MineLittlePony() {
instance = this;
}
/**
* Gets the global MineLP instance.
*/
public static MineLittlePony getInstance() {
return instance;
}
/**
* Gets the global MineLP client configuration.
*/
public abstract PonyConfig getConfig();
/**
* Gets the static pony manager instance.
*/
public abstract IPonyManager getManager();
/**
* Gets the global revision number, used for reloading models on demand.
*/
public abstract int getModelRevisionNumber();
}

View file

@ -1,9 +0,0 @@
package com.minelittlepony;
public class MissingRendererException extends RuntimeException {
private static final long serialVersionUID = -6059469512902628663L;
public MissingRendererException(Class<?> cl) {
super("Could not find a renderer for " + cl.getName() + ". This is a bug.");
}
}

View file

@ -1,43 +0,0 @@
package com.minelittlepony.client;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.minecraft.client.MinecraftClient;
public interface ClientReadyCallback {
Event<ClientReadyCallback> EVENT = EventFactory.createArrayBacked(ClientReadyCallback.class, listeners -> client -> {
for (ClientReadyCallback event : listeners) {
event.onClientPostInit(client);
}
});
void onClientPostInit(MinecraftClient client);
class Handler implements ClientTickCallback {
private static Handler instance;
private boolean firstTick = true;
private Handler() {}
public static void register() {
// make sure to only register once
if (instance == null) {
instance = new Handler();
ClientTickCallback.EVENT.register(instance);
}
}
@Override
public void tick(MinecraftClient client) {
if (firstTick) {
ClientReadyCallback.EVENT.invoker().onClientPostInit(client);
firstTick = false;
}
}
}
}

View file

@ -1,48 +0,0 @@
package com.minelittlepony.client;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.util.Identifier;
import com.minelittlepony.client.gui.GuiPonySettings;
import com.minelittlepony.client.hdskins.IndirectHDSkins;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.common.client.gui.sprite.TextureSprite;
import com.minelittlepony.common.client.gui.style.Style;
import com.minelittlepony.common.event.ScreenInitCallback;
public class FabMod implements ClientModInitializer {
@Override
public void onInitializeClient() {
MineLPClient mlp = new MineLPClient();
ClientReadyCallback.Handler.register();
ClientTickCallback.EVENT.register(mlp::onTick);
ClientReadyCallback.EVENT.register(mlp::postInit);
ScreenInitCallback.EVENT.register(this::onScreenInit);
if (FabricLoader.getInstance().isModLoaded("hdskins")) {
IndirectHDSkins.initialize();
}
}
private void onScreenInit(Screen screen, ScreenInitCallback.ButtonList buttons) {
if (screen instanceof TitleScreen) {
int y = FabricLoader.getInstance().isModLoaded("hdskins") ? 80 : 50;
buttons.add(new Button(screen.width - 50, screen.height - y, 20, 20).onClick(sender -> {
MinecraftClient.getInstance().openScreen(new GuiPonySettings());
}).setStyle(new Style()
.setIcon(new TextureSprite()
.setPosition(2, 2)
.setTexture(new Identifier("minelittlepony", "textures/gui/pony.png"))
.setTextureSize(16, 16)
.setSize(16, 16))
));
}
}
}

View file

@ -1,18 +1,25 @@
package com.minelittlepony.client;
import com.minelittlepony.MineLittlePony;
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.element.Button;
import com.minelittlepony.common.client.gui.sprite.TextureSprite;
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.JsonConfig;
import com.minelittlepony.settings.PonyConfig;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
@ -24,42 +31,58 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.SystemUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.minelittlepony.settings.PonyConfig;
import org.lwjgl.glfw.GLFW;
/**
* Static MineLittlePony singleton class. Everything's controlled from up here.
*/
public class MineLPClient extends MineLittlePony {
public abstract class MineLittlePony implements ClientModInitializer {
private static MineLittlePony instance;
public static final Logger logger = LogManager.getLogger("MineLittlePony");
private static int modelUpdateCounter = 0;
private static boolean reloadingModels = false;
private final PonyRenderManager renderManager = PonyRenderManager.getInstance();
private PonyConfig config;
private PonyManager ponyManager;
private final PonyRenderManager renderManager = PonyRenderManager.getInstance();
private FabricKeyBinding keyBinding;
public static MineLPClient getInstance() {
return (MineLPClient)MineLittlePony.getInstance();
public MineLittlePony() {
instance = this;
}
public MineLPClient() {
config = JsonConfig.of(GamePaths.getConfigDirectory().resolve("minelp.json"), this::createConfig);
ponyManager = new PonyManager(config);
/**
* Gets the global MineLP instance.
*/
public static MineLittlePony getInstance() {
return instance;
}
@Override
public void onInitializeClient() {
config = JsonConfig.of(GamePaths.getConfigDirectory().resolve("minelp.json"), ClientPonyConfig::new);
ponyManager = new PonyManager(config);
keyBinding = FabricKeyBinding.Builder.create(new Identifier("minelittlepony", "settings"), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F9, "key.categories.misc").build();
KeyBindingRegistry.INSTANCE.register(keyBinding);
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(ponyManager);
// convert legacy pony skins
SkinFilterCallback.EVENT.register(new LegacySkinConverter());
}
protected ClientPonyConfig createConfig() {
return new ClientPonyConfig();
// general events
ClientReadyCallback.Handler.register();
ClientTickCallback.EVENT.register(this::onTick);
ClientReadyCallback.EVENT.register(this::postInit);
ScreenInitCallback.EVENT.register(this::onScreenInit);
if (FabricLoader.getInstance().isModLoaded("hdskins")) {
IndirectHDSkins.initialize();
}
}
/**
@ -106,22 +129,35 @@ public class MineLPClient extends MineLittlePony {
PonySkullRenderer.resolve();
}
@Override
public PonyManager getManager() {
return ponyManager;
}
private void onScreenInit(Screen screen, ScreenInitCallback.ButtonList buttons) {
if (screen instanceof TitleScreen) {
int y = FabricLoader.getInstance().isModLoaded("hdskins") ? 80 : 50;
@Override
public int getModelRevisionNumber() {
return modelUpdateCounter;
buttons.add(new Button(screen.width - 50, screen.height - y, 20, 20).onClick(sender -> {
MinecraftClient.getInstance().openScreen(new GuiPonySettings());
}).setStyle(new com.minelittlepony.common.client.gui.style.Style()
.setIcon(new TextureSprite()
.setPosition(2, 2)
.setTexture(new Identifier("minelittlepony", "textures/gui/pony.png"))
.setTextureSize(16, 16)
.setSize(16, 16))
));
}
}
/**
* Gets the global MineLP client configuration.
*/
@Override
public PonyConfig getConfig() {
return config;
}
public PonyManager getManager() {
return ponyManager;
}
public int getModelRevisionNumber() {
return modelUpdateCounter;
}
}

View file

@ -1,11 +1,10 @@
package com.minelittlepony.client.gui;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.LiteralText;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.entities.MobRenderers;
import com.minelittlepony.common.client.gui.GameGui;
import com.minelittlepony.common.client.gui.ScrollContainer;
@ -18,8 +17,6 @@ import com.minelittlepony.settings.PonyConfig;
import com.minelittlepony.settings.PonyLevel;
import com.minelittlepony.settings.PonySettings;
import java.util.List;
/**
* In-Game options menu.
*

View file

@ -1,11 +1,11 @@
package com.minelittlepony.client.hdskins;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.ClientReadyCallback;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.SkinsProxy;
import com.minelittlepony.client.hdskins.gui.DummyPony;
import com.minelittlepony.client.hdskins.gui.GuiSkinsMineLP;
import com.minelittlepony.client.hdskins.gui.RenderDummyPony;
import com.minelittlepony.common.event.ClientReadyCallback;
import net.fabricmc.fabric.api.client.render.EntityRendererRegistry;
import net.minecraft.client.MinecraftClient;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.hdskins.gui;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.common.client.gui.element.IconicToggle;
import com.minelittlepony.common.client.gui.style.Style;
import com.minelittlepony.hdskins.dummy.PlayerPreview;

View file

@ -2,7 +2,7 @@ package com.minelittlepony.client.hdskins.gui;
import net.minecraft.util.Identifier;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.pony.Pony;
import com.minelittlepony.hdskins.dummy.DummyPlayer;
import com.minelittlepony.hdskins.dummy.PlayerPreview;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.hdskins.gui;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.ClientPonyModel;
import com.minelittlepony.client.model.ModelWrapper;
import com.minelittlepony.client.model.races.PlayerModels;

View file

@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.pony.IPony;
import net.minecraft.client.MinecraftClient;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.pony.IPony;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.network.AbstractClientPlayerEntity;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.races.PlayerModels;
import com.minelittlepony.pony.IPonyManager;
import com.minelittlepony.settings.PonyLevel;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.mixin;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.races.PlayerModels;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.entity.EntityRenderDispatcher;

View file

@ -2,7 +2,7 @@ package com.minelittlepony.client.model;
import net.minecraft.entity.LivingEntity;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.model.IModel;
import com.minelittlepony.model.armour.IArmour;
import com.minelittlepony.model.armour.IEquestrianArmour;

View file

@ -1,7 +1,7 @@
package com.minelittlepony.client.pony;
import com.google.common.base.MoreObjects;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.PonyRenderManager;
import com.minelittlepony.client.render.IPonyRender;
import com.minelittlepony.client.transform.PonyTransformation;

View file

@ -6,7 +6,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.common.util.MoreStreams;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.pony.IPonyManager;

View file

@ -2,7 +2,7 @@ package com.minelittlepony.client.render;
import org.lwjgl.opengl.GL14;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.util.render.Color;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.settings.PonySettings;

View file

@ -1,7 +1,7 @@
package com.minelittlepony.client.render.entities;
import com.google.common.collect.Lists;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.PonyRenderManager;
import com.minelittlepony.settings.Config;
import com.minelittlepony.settings.Config.Setting;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.render.entities;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.ClientPonyModel;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.client.model.ModelWrapper;

View file

@ -8,7 +8,7 @@ import net.minecraft.village.VillagerDataContainer;
import net.minecraft.village.VillagerProfession;
import net.minecraft.village.VillagerType;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.util.resources.ITextureSupplier;
import java.util.HashMap;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.client.render.entities.player;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.model.ClientPonyModel;
import com.minelittlepony.client.model.ModelWrapper;
import com.minelittlepony.client.render.DebugBoundingBoxRenderer;

View file

@ -1,7 +1,7 @@
package com.minelittlepony.client.render.tileentities.skull;
import com.google.common.collect.Maps;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.client.render.LevitatingItemRenderer;
import com.minelittlepony.pony.IPony;
import com.minelittlepony.settings.PonyConfig;

View file

@ -6,7 +6,7 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.pony.meta.Race;
public interface IPony {

View file

@ -1,6 +1,6 @@
package com.minelittlepony.pony.meta;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.pony.ITriggerPixelMapped;
import com.minelittlepony.settings.PonyLevel;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.pony.meta;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.pony.ITriggerPixelMapped;
import com.minelittlepony.settings.PonySettings;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.settings;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.client.MineLittlePony;
import com.minelittlepony.settings.Config.Setting;
/**

View file

@ -17,7 +17,7 @@
"environment": "client",
"entrypoints": {
"client": [
"com.minelittlepony.client.FabMod"
"com.minelittlepony.client.MineLittlePony"
],
"modmenu": [
"com.minelittlepony.client.modmenu.MineLPModMenuFactory"