aboutsummaryrefslogtreecommitdiff
path: root/fabric/src
diff options
context:
space:
mode:
authorhackthetime <l4bg0jb7@duck.com>2023-10-13 11:04:38 +0200
committerhackthetime <l4bg0jb7@duck.com>2023-10-13 11:04:38 +0200
commitf69caf7f9053112b336b5edb25e67350e816d297 (patch)
treef3dff3e5abf6fb60c48b7e79349dd4e39d552988 /fabric/src
parent741ce9276eea13e62da3777a6f2ba23fa5ba375a (diff)
downloadBBsentials-f69caf7f9053112b336b5edb25e67350e816d297.tar.gz
BBsentials-f69caf7f9053112b336b5edb25e67350e816d297.tar.bz2
BBsentials-f69caf7f9053112b336b5edb25e67350e816d297.zip
more changes
Diffstat (limited to 'fabric/src')
-rw-r--r--fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java170
1 files changed, 170 insertions, 0 deletions
diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java
index ed8c622..fde98a1 100644
--- a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java
+++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java
@@ -1,8 +1,26 @@
package de.hype.bbsentials.fabric;
+import com.mojang.brigadier.arguments.StringArgumentType;
+import de.hype.bbsentials.common.chat.Chat;
import de.hype.bbsentials.common.client.BBsentials;
+import de.hype.bbsentials.common.client.Config;
import net.fabricmc.api.ClientModInitializer;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
+import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
+import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.option.KeyBinding;
+import net.minecraft.client.util.InputUtil;
+import net.minecraft.command.CommandSource;
+import org.lwjgl.glfw.GLFW;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static de.hype.bbsentials.common.client.BBsentials.*;
public class ModInitialiser implements ClientModInitializer {
@Override
@@ -11,4 +29,156 @@ public class ModInitialiser implements ClientModInitializer {
BBsentials.onServerSwap();
});
}
+
+ {
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("bbi")
+ .then(ClientCommandManager.literal("reconnect")
+ .executes((context) -> {
+ connectToBBserver();
+ return 1;
+ }))
+ .then(ClientCommandManager.literal("reconnect-stable-server")
+ .executes((context) -> {
+ connectToBBserver(false);
+ return 1;
+ }))
+ .then(ClientCommandManager.literal("reconnect-test-server")
+ .executes((context) -> {
+ connectToBBserver(true);
+ return 1;
+ }))
+ .then(ClientCommandManager.literal("config")
+ .then(ClientCommandManager.argument("category", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for config subfolder
+ return CommandSource.suggestMatching(new String[]{"save", "reset", "load"}, builder);
+ }).executes((context) -> {
+ String category = StringArgumentType.getString(context, "category");
+ switch (category) {
+ case "save":
+ getConfig().save();
+ Chat.sendPrivateMessageToSelfSuccess("Saved config successfully");
+ break;
+ case "load":
+ config = Config.load();
+ break;
+ case "reset":
+ // Reset logic here
+ break;
+ }
+ return 1;
+ }))
+ .then(ClientCommandManager.literal("set-value")
+ .then(ClientCommandManager.argument("className", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for classes
+ ArrayList<String> classNames = new ArrayList<>();
+ classNames.add("Config");
+ // Replace with your own logic to retrieve class names
+ return CommandSource.suggestMatching(classNames, builder);
+ })
+ .then(ClientCommandManager.argument("variableName", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for variable names
+ List<String> variableNames;
+ variableNames = List.of(Chat.getVariableInfo("de.hype.bbsentials.client", "Config"));
+ return CommandSource.suggestMatching(variableNames, builder);
+ })
+ .then(ClientCommandManager.argument("variableValue", StringArgumentType.string())
+ .executes((context) -> {
+ // Handle "variableName" and "variableValue" logic here
+ String variableName = StringArgumentType.getString(context, "variableName");
+ String variableValue = StringArgumentType.getString(context, "variableValue");
+ try {
+ if (!variableName.toLowerCase().contains("dev") || config.hasBBRoles("dev")) {
+ Chat.setVariableValue(getConfig(), variableName, variableValue);
+ }
+ getConfig().save();
+ } catch (ClassNotFoundException |
+ NoSuchFieldException |
+ IllegalAccessException |
+ InstantiationException |
+ InvocationTargetException |
+ NoSuchMethodException e) {
+ Chat.sendPrivateMessageToSelfError("Invalid variable or value");
+ }
+ return 1;
+ })))))
+ .then(ClientCommandManager.literal("get-value")
+ .then(ClientCommandManager.argument("className", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for classes
+ ArrayList<String> classNames = new ArrayList<>();
+ classNames.add("Config");
+ // Replace with your own logic to retrieve class names
+ return CommandSource.suggestMatching(classNames, builder);
+ })
+ .then(ClientCommandManager.argument("variableName", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for variable names
+ List<String> variableNames;
+ variableNames = List.of(Chat.getVariableInfo("de.hype.bbsentials.client", "Config"));
+ return CommandSource.suggestMatching(variableNames, builder);
+ })
+ .executes((context) -> {
+ // Handle "variableName" and "variableValue" logic here
+ String variableName = StringArgumentType.getString(context, "variableName");
+ try {
+ Chat.getVariableValue(getConfig(), variableName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return 1;
+ }))).executes((context) -> {
+ // Handle the case when "config" argument is not provided
+ // ...
+ return 1;
+ })))
+ );
+ }); //bbi
+
+ KeyBinding devKeyBind = new KeyBinding("Open Mod Menu Config", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_ADD, "BBsentials: Developing Tools");
+ KeyBindingHelper.registerKeyBinding(devKeyBind);
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (devKeyBind.wasPressed()) {
+ MinecraftClient.getInstance().setScreen(BBsentialsConfigScreemFactory.create(MinecraftClient.getInstance().currentScreen));
+ }
+ });
+
+ KeyBinding promptKeyBind = new KeyBinding("Chat Prompt Yes / Open Menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "BBsentials");
+ KeyBindingHelper.registerKeyBinding(promptKeyBind);
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (promptKeyBind.wasPressed()) {
+ if (config.getLastChatPromptAnswer() != null) {
+ if (config.isDetailedDevModeEnabled()) {
+ Chat.sendPrivateMessageToSelfDebug(config.getLastChatPromptAnswer());
+ }
+ MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(config.getLastChatPromptAnswer());
+ }
+ config.setLastChatPromptAnswer(null);
+ }
+ });
+ KeyBinding craftKeyBind = new KeyBinding("Craft", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V, "BBsentials");
+ KeyBindingHelper.registerKeyBinding(craftKeyBind);
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (craftKeyBind.wasPressed()) MinecraftClient.getInstance().getNetworkHandler().sendChatMessage("/craft");
+ });
+ KeyBinding petKeyBind = new KeyBinding("Open Pet Menu", InputUtil.Type.KEYSYM, -1, "BBsentials");
+ KeyBindingHelper.registerKeyBinding(petKeyBind);
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (petKeyBind.wasPressed()) MinecraftClient.getInstance().getNetworkHandler().sendChatMessage("/pets");
+ });
+ for (int i = 1; i <= 9; i++) {
+ KeyBinding ecPageKeyBind = new KeyBinding("Ender Chest Page " + i, InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_1 + (i - 1), "BBsentials");
+ KeyBindingHelper.registerKeyBinding(ecPageKeyBind);
+ int pageNum = i; // Capture the page number for lambda
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (ecPageKeyBind.wasPressed()) {
+ getConfig().sender.addImmediateSendTask("/ec " + pageNum);
+ }
+ });
+ }
+ } // KeyBinds
+
}