Config support
can prob be improved but that will be done later :trollface:
This commit is contained in:
parent
2023ae3cd1
commit
88dc82eb1e
17 changed files with 738 additions and 664 deletions
43
src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java
Normal file → Executable file
43
src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java
Normal file → Executable file
|
@ -1,14 +1,24 @@
|
|||
package land.chipmunk.chipmunkmod;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ChipmunkMod implements ModInitializer {
|
||||
// This logger is used to write text to the console and the log file.
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("chipmunkmod");
|
||||
public static Configuration CONFIG;
|
||||
|
||||
@Override
|
||||
public void onInitialize () {
|
||||
|
@ -16,6 +26,39 @@ public class ChipmunkMod implements ModInitializer {
|
|||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
try {
|
||||
new File("config").mkdirs(); // TODO: Clean this up
|
||||
CONFIG = loadConfig();
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException("Could not load the config", exception);
|
||||
}
|
||||
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
}
|
||||
|
||||
public static Configuration loadConfig () throws IOException {
|
||||
final Gson gson = new Gson();
|
||||
final File file = new File("config/chipmunkmod.json");
|
||||
|
||||
if (!file.exists()) {
|
||||
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default_config.json");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
while (reader.ready()) sb.append((char) reader.read());
|
||||
final String defaultConfig = sb.toString();
|
||||
|
||||
// Write the default config
|
||||
BufferedWriter configWriter = new BufferedWriter(new FileWriter(file));
|
||||
configWriter.write(defaultConfig);
|
||||
configWriter.close();
|
||||
|
||||
return gson.fromJson(defaultConfig, Configuration.class);
|
||||
}
|
||||
|
||||
InputStream is = new FileInputStream(file);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
return gson.fromJson(reader, Configuration.class);
|
||||
}
|
||||
}
|
||||
|
|
17
src/main/java/land/chipmunk/chipmunkmod/Configuration.java
Executable file
17
src/main/java/land/chipmunk/chipmunkmod/Configuration.java
Executable file
|
@ -0,0 +1,17 @@
|
|||
package land.chipmunk.chipmunkmod;
|
||||
|
||||
import land.chipmunk.chipmunkmod.data.BlockArea;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class Configuration {
|
||||
public CommandManager commands = new CommandManager();
|
||||
public CommandCore core = new CommandCore();
|
||||
|
||||
public class CommandManager {
|
||||
public String prefix = ".";
|
||||
}
|
||||
|
||||
public class CommandCore {
|
||||
public BlockArea relativeArea = new BlockArea(new BlockPos(0, 0, 0), new BlockPos(15, 0, 15));
|
||||
}
|
||||
}
|
3
src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java
Normal file → Executable file
3
src/main/java/land/chipmunk/chipmunkmod/command/CommandManager.java
Normal file → Executable file
|
@ -13,11 +13,12 @@ import net.minecraft.text.MutableText;
|
|||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.commands.*;
|
||||
|
||||
public class CommandManager {
|
||||
public static CommandDispatcher<FabricClientCommandSource> dispatcher = new CommandDispatcher();
|
||||
public static String prefix = ".";
|
||||
public static String prefix = ChipmunkMod.CONFIG.commands.prefix;
|
||||
|
||||
public static void executeCommand (String command) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
|
0
src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/commands/CoreCommand.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/commands/TestCommand.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/commands/TestCommand.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/data/BlockArea.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/data/BlockArea.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ChatInputSuggestorMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ChatInputSuggestorMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayerEntityMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayerEntityMixin.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/mixin/MinecraftClientAccessor.java
Normal file → Executable file
9
src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java
Normal file → Executable file
9
src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java
Normal file → Executable file
|
@ -15,20 +15,21 @@ import java.util.Timer;
|
|||
import java.util.TimerTask;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.data.BlockArea;
|
||||
|
||||
public class CommandCore {
|
||||
private MinecraftClient client;
|
||||
@Getter @Setter private boolean ready = false;
|
||||
@Getter @Setter private BlockPos origin;
|
||||
// TODO: Make it configurable
|
||||
@Getter private final BlockArea relativeArea = new BlockArea(new BlockPos(0, 0, 0), new BlockPos(15, 0, 15));
|
||||
@Getter private final BlockArea relativeArea;
|
||||
@Getter @Setter private BlockPos currentBlockRelative;
|
||||
|
||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance());
|
||||
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance(), ChipmunkMod.CONFIG.core.relativeArea);
|
||||
|
||||
public CommandCore (MinecraftClient client) {
|
||||
public CommandCore (MinecraftClient client, BlockArea relativeArea) {
|
||||
this.client = client;
|
||||
this.relativeArea = relativeArea;
|
||||
}
|
||||
|
||||
public void move (Vec3d position) {
|
||||
|
|
0
src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java
Normal file → Executable file
0
src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java
Normal file → Executable file
12
src/main/resources/default_config.json
Normal file
12
src/main/resources/default_config.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"commands": {
|
||||
"prefix": "."
|
||||
},
|
||||
|
||||
"core": {
|
||||
"relativeArea": {
|
||||
"start": { "x": 0, "y": 0, "z": 0 },
|
||||
"end": { "x": 15, "y": 0, "z": 15 }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue