2019-03-23 21:49:34 +02:00
|
|
|
package com.minelittlepony.client;
|
2015-08-01 18:36:33 -04:00
|
|
|
|
2022-12-11 00:38:00 +00:00
|
|
|
import com.minelittlepony.api.config.PonyConfig;
|
2021-02-03 18:42:35 +02:00
|
|
|
import com.minelittlepony.api.pony.network.fabric.Channel;
|
2019-11-25 17:49:20 +02:00
|
|
|
import com.minelittlepony.client.model.ModelType;
|
2019-03-23 21:49:34 +02:00
|
|
|
import com.minelittlepony.client.pony.PonyManager;
|
2022-06-17 23:42:17 +02:00
|
|
|
import com.minelittlepony.client.pony.VariatedTextureSupplier;
|
2019-11-30 13:12:46 +02:00
|
|
|
import com.minelittlepony.client.render.PonyRenderDispatcher;
|
2019-06-02 19:20:00 +02:00
|
|
|
import com.minelittlepony.client.settings.ClientPonyConfig;
|
2019-07-10 17:09:40 +02:00
|
|
|
import com.minelittlepony.common.client.gui.VisibilityMode;
|
2019-07-07 22:47:13 -04:00
|
|
|
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;
|
2019-07-03 23:26:19 -04:00
|
|
|
import com.minelittlepony.common.event.SkinFilterCallback;
|
2019-07-02 19:57:45 -04:00
|
|
|
import com.minelittlepony.common.util.GamePaths;
|
2019-07-08 11:05:32 +02:00
|
|
|
|
2019-07-07 22:47:13 -04:00
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
2021-03-07 17:46:09 +02:00
|
|
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
2020-06-19 17:03:08 +02:00
|
|
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
2019-07-03 14:16:03 +02:00
|
|
|
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
2019-07-07 22:47:13 -04:00
|
|
|
import net.fabricmc.loader.api.FabricLoader;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.MinecraftClient;
|
2019-07-07 22:47:13 -04:00
|
|
|
import net.minecraft.client.gui.screen.Screen;
|
2019-06-01 15:40:06 -04:00
|
|
|
import net.minecraft.client.gui.screen.TitleScreen;
|
2021-02-07 11:43:25 +02:00
|
|
|
import net.minecraft.client.option.KeyBinding;
|
2019-05-27 17:59:15 +02:00
|
|
|
import net.minecraft.client.util.InputUtil;
|
2019-07-03 14:16:03 +02:00
|
|
|
import net.minecraft.resource.ResourceType;
|
2019-06-30 12:05:38 +02:00
|
|
|
import net.minecraft.util.Identifier;
|
2019-07-07 22:47:13 -04:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2019-03-24 22:03:39 +02:00
|
|
|
import org.lwjgl.glfw.GLFW;
|
|
|
|
|
2019-07-08 11:05:32 +02:00
|
|
|
/**
|
|
|
|
* Client Mod implementation
|
|
|
|
*/
|
2019-07-07 23:50:38 -04:00
|
|
|
public class MineLittlePony implements ClientModInitializer {
|
2019-07-07 22:47:13 -04:00
|
|
|
|
|
|
|
private static MineLittlePony instance;
|
|
|
|
|
|
|
|
public static final Logger logger = LogManager.getLogger("MineLittlePony");
|
2018-04-25 21:29:49 +02:00
|
|
|
|
2019-11-30 13:12:46 +02:00
|
|
|
private final PonyRenderDispatcher renderManager = PonyRenderDispatcher.getInstance();
|
2019-07-08 11:05:32 +02:00
|
|
|
|
2019-07-10 17:09:40 +02:00
|
|
|
private ClientPonyConfig config;
|
2019-03-23 19:48:20 +02:00
|
|
|
private PonyManager ponyManager;
|
2022-06-17 23:42:17 +02:00
|
|
|
private VariatedTextureSupplier variatedTextures;
|
2019-07-08 11:05:32 +02:00
|
|
|
|
2020-06-19 17:03:08 +02:00
|
|
|
private final KeyBinding keyBinding = new KeyBinding("key.minelittlepony.settings", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F9, "key.categories.misc");
|
2019-05-30 14:09:24 +02:00
|
|
|
|
2019-07-10 17:09:40 +02:00
|
|
|
private boolean hasHdSkins;
|
|
|
|
private boolean hasModMenu;
|
|
|
|
|
2019-07-07 22:47:13 -04:00
|
|
|
public MineLittlePony() {
|
|
|
|
instance = this;
|
2019-03-24 01:04:54 +02:00
|
|
|
}
|
|
|
|
|
2019-07-07 22:47:13 -04:00
|
|
|
/**
|
|
|
|
* Gets the global MineLP instance.
|
|
|
|
*/
|
|
|
|
public static MineLittlePony getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
2019-07-02 19:57:45 -04:00
|
|
|
|
2019-07-07 22:47:13 -04:00
|
|
|
@Override
|
|
|
|
public void onInitializeClient() {
|
2019-07-10 17:09:40 +02:00
|
|
|
hasHdSkins = FabricLoader.getInstance().isModLoaded("hdskins");
|
|
|
|
hasModMenu = FabricLoader.getInstance().isModLoaded("modmenu");
|
|
|
|
|
2019-08-05 11:32:27 +02:00
|
|
|
config = new ClientPonyConfig(GamePaths.getConfigDirectory().resolve("minelp.json"));
|
2019-07-07 22:47:13 -04:00
|
|
|
ponyManager = new PonyManager(config);
|
2022-06-17 23:42:17 +02:00
|
|
|
variatedTextures = new VariatedTextureSupplier();
|
2019-07-07 22:47:13 -04:00
|
|
|
|
2020-06-19 17:03:08 +02:00
|
|
|
KeyBindingHelper.registerKeyBinding(keyBinding);
|
2019-07-03 14:16:03 +02:00
|
|
|
|
|
|
|
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(ponyManager);
|
2022-06-17 23:42:17 +02:00
|
|
|
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(variatedTextures);
|
2019-07-03 23:26:19 -04:00
|
|
|
|
|
|
|
// convert legacy pony skins
|
|
|
|
SkinFilterCallback.EVENT.register(new LegacySkinConverter());
|
2016-01-26 03:20:39 -05:00
|
|
|
|
2019-07-07 22:47:13 -04:00
|
|
|
// general events
|
|
|
|
ClientReadyCallback.Handler.register();
|
2021-03-07 17:46:09 +02:00
|
|
|
ClientTickEvents.END_CLIENT_TICK.register(this::onTick);
|
2019-07-08 11:05:32 +02:00
|
|
|
ClientReadyCallback.EVENT.register(this::onClientReady);
|
2019-07-07 22:47:13 -04:00
|
|
|
ScreenInitCallback.EVENT.register(this::onScreenInit);
|
2019-08-05 11:32:27 +02:00
|
|
|
|
|
|
|
config.load();
|
2019-07-07 22:47:13 -04:00
|
|
|
|
2021-02-03 13:45:52 +02:00
|
|
|
Channel.bootstrap();
|
2019-11-25 17:49:20 +02:00
|
|
|
ModelType.bootstrap();
|
2021-02-06 21:37:27 +02:00
|
|
|
|
|
|
|
FabricLoader.getInstance().getEntrypoints("minelittlepony", ClientModInitializer.class).forEach(ClientModInitializer::onInitializeClient);
|
2019-06-30 12:05:38 +02:00
|
|
|
}
|
|
|
|
|
2019-07-08 11:05:32 +02:00
|
|
|
private void onClientReady(MinecraftClient client) {
|
2020-08-16 23:48:26 +02:00
|
|
|
renderManager.initialise(client.getEntityRenderDispatcher());
|
2018-06-20 23:12:12 +02:00
|
|
|
}
|
2018-06-10 21:55:13 +02:00
|
|
|
|
2019-07-08 11:05:32 +02:00
|
|
|
private void onTick(MinecraftClient client) {
|
2019-05-30 21:25:20 +02:00
|
|
|
|
2019-07-08 11:05:32 +02:00
|
|
|
boolean inGame = client.world != null && client.player != null && client.currentScreen == null;
|
|
|
|
boolean mainMenu = client.currentScreen instanceof TitleScreen;
|
2019-05-30 21:25:20 +02:00
|
|
|
|
|
|
|
if (!inGame && mainMenu) {
|
|
|
|
KeyBinding.updatePressedStates();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mainMenu || inGame) && keyBinding.isPressed()) {
|
2021-11-25 00:09:34 +02:00
|
|
|
client.setScreen(new GuiPonySettings(client.currentScreen));
|
2018-06-20 23:21:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 22:47:13 -04:00
|
|
|
private void onScreenInit(Screen screen, ScreenInitCallback.ButtonList buttons) {
|
|
|
|
if (screen instanceof TitleScreen) {
|
2019-07-11 19:20:13 +02:00
|
|
|
VisibilityMode mode = config.horseButton.get();
|
2019-07-10 17:09:40 +02:00
|
|
|
boolean show = mode == VisibilityMode.ON || (mode == VisibilityMode.AUTO
|
|
|
|
&& !(hasHdSkins || hasModMenu
|
2019-07-07 22:47:13 -04:00
|
|
|
));
|
2019-07-10 17:09:40 +02:00
|
|
|
|
|
|
|
if (show) {
|
2019-07-16 17:13:36 +02:00
|
|
|
int y = hasHdSkins ? 75 : 50;
|
2021-06-06 20:38:11 +02:00
|
|
|
Button button = buttons.addButton(new Button(screen.width - 50, screen.height - y, 20, 20))
|
2021-11-25 00:09:34 +02:00
|
|
|
.onClick(sender -> MinecraftClient.getInstance().setScreen(new GuiPonySettings(screen)));
|
2019-07-16 17:13:36 +02:00
|
|
|
button.getStyle()
|
2019-07-10 17:09:40 +02:00
|
|
|
.setIcon(new TextureSprite()
|
|
|
|
.setPosition(2, 2)
|
|
|
|
.setTexture(new Identifier("minelittlepony", "textures/gui/pony.png"))
|
|
|
|
.setTextureSize(16, 16)
|
2021-05-18 00:09:16 +02:00
|
|
|
.setSize(16, 16))
|
|
|
|
.setTooltip("minelp.options.title", 0, 10);
|
2022-12-08 01:53:59 +00:00
|
|
|
button.setY(screen.height - y); // ModMenu
|
2019-07-10 17:09:40 +02:00
|
|
|
}
|
2019-07-07 22:47:13 -04:00
|
|
|
}
|
2018-10-02 00:04:27 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 21:29:49 +02:00
|
|
|
/**
|
|
|
|
* Gets the global MineLP client configuration.
|
|
|
|
*/
|
2019-03-23 20:17:46 +02:00
|
|
|
public PonyConfig getConfig() {
|
|
|
|
return config;
|
2015-08-01 18:36:33 -04:00
|
|
|
}
|
2019-03-24 01:04:54 +02:00
|
|
|
|
2022-12-11 00:38:00 +00:00
|
|
|
public PonyManager getManager() {
|
2019-07-07 22:47:13 -04:00
|
|
|
return ponyManager;
|
|
|
|
}
|
2022-06-17 23:42:17 +02:00
|
|
|
|
|
|
|
public VariatedTextureSupplier getVariatedTextures() {
|
|
|
|
return variatedTextures;
|
|
|
|
}
|
2015-08-01 18:36:33 -04:00
|
|
|
}
|
2019-07-07 22:47:13 -04:00
|
|
|
|