mirror of
https://github.com/Lucaslah/WeatherChanger.git
synced 2026-01-03 03:57:50 +00:00
Added forge support + update architectury loom
This commit is contained in:
@@ -2,6 +2,8 @@ package me.lucaslah.weatherchanger;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.lucaslah.weatherchanger.command.CommandManager;
|
||||
import me.lucaslah.weatherchanger.commands.WeatherChangerCommand;
|
||||
import me.lucaslah.weatherchanger.config.WcConfig;
|
||||
import me.lucaslah.weatherchanger.config.WcMode;
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
@@ -9,6 +11,8 @@ import me.lucaslah.weatherchanger.keys.ToggleClearKey;
|
||||
import me.lucaslah.weatherchanger.keys.ToggleOffKey;
|
||||
import me.lucaslah.weatherchanger.keys.ToggleRainKey;
|
||||
import me.lucaslah.weatherchanger.keys.ToggleThunderKey;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -21,6 +25,8 @@ public class WeatherChanger {
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private static WcMode currentMode = WcMode.OFF;
|
||||
private static WeatherChangerPlatform platform;
|
||||
private static KeybindingManager keybindingManager;
|
||||
private static CommandManager commandManager;
|
||||
|
||||
public static void init(WeatherChangerPlatform platform) {
|
||||
WeatherChanger.platform = platform;
|
||||
@@ -41,7 +47,8 @@ public class WeatherChanger {
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
KeybindingManager keybindingManager = platform.getKeybindingManager();
|
||||
keybindingManager = new KeybindingManager();
|
||||
commandManager = new CommandManager();
|
||||
|
||||
keybindingManager
|
||||
.add(new ToggleClearKey())
|
||||
@@ -49,7 +56,7 @@ public class WeatherChanger {
|
||||
.add(new ToggleRainKey())
|
||||
.add(new ToggleThunderKey());
|
||||
|
||||
keybindingManager.registerKeys();
|
||||
commandManager.add(new WeatherChangerCommand());
|
||||
}
|
||||
|
||||
private static void loadConfig() {
|
||||
@@ -132,4 +139,16 @@ public class WeatherChanger {
|
||||
public static void shutdown() {
|
||||
writeConfig();
|
||||
}
|
||||
|
||||
public static KeybindingManager getKeybindingManager() {
|
||||
return keybindingManager;
|
||||
}
|
||||
|
||||
public static CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public static void sendClientMessage(String message) {
|
||||
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal(message));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package me.lucaslah.weatherchanger;
|
||||
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface WeatherChangerPlatform {
|
||||
Path getConfigDirectory();
|
||||
KeybindingManager getKeybindingManager();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.lucaslah.weatherchanger.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public abstract class Command {
|
||||
public abstract <T> void register(CommandDispatcher<T> dispatcher);
|
||||
public abstract Identifier getId();
|
||||
public abstract boolean isEnabled();
|
||||
}
|
||||
@@ -1,4 +1,28 @@
|
||||
package me.lucaslah.weatherchanger.command;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager {
|
||||
private final HashMap<Identifier, Command> entries = new HashMap<>();
|
||||
|
||||
public CommandManager add(Command entry) {
|
||||
entries.put(entry.getId(), entry);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command get(Identifier identifier) {
|
||||
return entries.get(identifier);
|
||||
}
|
||||
|
||||
public List<Command> getEntries() {
|
||||
if (!entries.isEmpty()) {
|
||||
return new ArrayList<>(entries.values());
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package me.lucaslah.weatherchanger.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import me.lucaslah.weatherchanger.WeatherChanger;
|
||||
import me.lucaslah.weatherchanger.command.Command;
|
||||
import me.lucaslah.weatherchanger.config.WcMode;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import static me.lucaslah.weatherchanger.WeatherChanger.sendClientMessage;
|
||||
|
||||
public class WeatherChangerCommand extends Command {
|
||||
@Override
|
||||
public <T> void register(CommandDispatcher<T> dispatcher) {
|
||||
LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal("clientweather");
|
||||
|
||||
command.then(LiteralArgumentBuilder.<T>literal("off")
|
||||
.executes(context -> {
|
||||
WeatherChanger.setMode(WcMode.OFF);
|
||||
sendClientMessage("Set client weather to: Off");
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
|
||||
command.then(LiteralArgumentBuilder.<T>literal("clear")
|
||||
.executes(context -> {
|
||||
WeatherChanger.setMode(WcMode.CLEAR);
|
||||
sendClientMessage("Set client weather to: Clear");
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
|
||||
command.then(LiteralArgumentBuilder.<T>literal("rain")
|
||||
.executes(context -> {
|
||||
WeatherChanger.setMode(WcMode.RAIN);
|
||||
sendClientMessage("Set client weather to: Rain");
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
|
||||
command.then(LiteralArgumentBuilder.<T>literal("thunder")
|
||||
.executes(context -> {
|
||||
WeatherChanger.setMode(WcMode.THUNDER);
|
||||
sendClientMessage("Set client weather to: Thunder");
|
||||
return 1;
|
||||
})
|
||||
);
|
||||
|
||||
LiteralCommandNode<T> node = dispatcher.register(command);
|
||||
dispatcher.register((LiteralArgumentBuilder<T>) LiteralArgumentBuilder.literal("cweather").redirect((CommandNode<Object>) node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getId() {
|
||||
return new Identifier("weatherchanger", "corecommand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KeybindingManager {
|
||||
public class KeybindingManager {
|
||||
private final HashMap<Identifier, Key> entries = new HashMap<>();
|
||||
|
||||
public KeybindingManager add(Key entry) {
|
||||
@@ -25,6 +25,4 @@ public abstract class KeybindingManager {
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public abstract void registerKeys();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user