mirror of
https://github.com/Lucaslah/WeatherChanger.git
synced 2026-01-02 11:37:50 +00:00
Added forge support + update architectury loom
This commit is contained in:
@@ -35,6 +35,8 @@ To set the keybindings you can do so in the minecraft keybinding settings.
|
||||
|
||||
For supported mod loaders and minecraft versions see [release history](#release-history)
|
||||
|
||||
<!-- modrinth_exclude.start -->
|
||||
|
||||
## Download
|
||||
You can download the mod from any of the platforms below.
|
||||
|
||||
@@ -43,6 +45,8 @@ You can download the mod from any of the platforms below.
|
||||
**GitHub Releases:** https://github.com/Lucaslah/WeatherChanger/releases <br>
|
||||
**Release Server**: https://release.cssudii.xyz/projects/weatherchanger
|
||||
|
||||
<!-- modrinth_exclude.end -->
|
||||
|
||||
## Release History
|
||||
| Branch | Version | MC Version | Mod loaders | Git Tag | CI | Supported |
|
||||
|--------|---------|---------------|-------------|------------------------------------------------------------------------|-----|-----------|
|
||||
@@ -57,6 +61,7 @@ You can download the mod from any of the platforms below.
|
||||
## Minecraft Versions
|
||||
| Version | Status |
|
||||
|---------|---------------------------------|
|
||||
| 1.20.4 | Supported |
|
||||
| 1.20.3 | Supported |
|
||||
| 1.20.2 | Supported |
|
||||
| 1.20.1 | Supported |
|
||||
|
||||
@@ -4,7 +4,7 @@ import io.github.themrmilchmann.gradle.publish.curseforge.ReleaseType
|
||||
|
||||
plugins {
|
||||
id("architectury-plugin") version "3.4-SNAPSHOT"
|
||||
id ("dev.architectury.loom") version "1.3-SNAPSHOT" apply false
|
||||
id ("dev.architectury.loom") version "1.4-SNAPSHOT" apply false
|
||||
id("com.modrinth.minotaur") version "2.+"
|
||||
id("io.github.themrmilchmann.curseforge-publish") version "0.6.1"
|
||||
}
|
||||
@@ -65,6 +65,7 @@ modrinth {
|
||||
}
|
||||
|
||||
curseforge {
|
||||
apiToken = System.getenv("CURSEFORGE_TOKEN")
|
||||
publications {
|
||||
register("curseForge") {
|
||||
projectId = "682513"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package me.lucaslah.weatherchanger.fabric;
|
||||
|
||||
import me.lucaslah.weatherchanger.keybinding.Key;
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
|
||||
public class FabricKeybindingManager extends KeybindingManager {
|
||||
@Override
|
||||
public void registerKeys() {
|
||||
for (Key key : getEntries()) {
|
||||
KeyBindingHelper.registerKeyBinding(key.getKeyBinding());
|
||||
}
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
for (Key key : getEntries()) {
|
||||
if (key.isEnabled() && key.getKeyBinding().wasPressed()) {
|
||||
key.onPress(client);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,39 @@
|
||||
package me.lucaslah.weatherchanger.fabric;
|
||||
|
||||
import me.lucaslah.weatherchanger.WeatherChanger;
|
||||
import me.lucaslah.weatherchanger.command.Command;
|
||||
import me.lucaslah.weatherchanger.keybinding.Key;
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
|
||||
public class WeatherChangerFabric implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
WeatherChanger.init(new WeatherChangerPlatformImpl());
|
||||
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> WeatherChanger.shutdown());
|
||||
|
||||
KeybindingManager keybindingManager = WeatherChanger.getKeybindingManager();
|
||||
|
||||
for (Key key : keybindingManager.getEntries()) {
|
||||
KeyBindingHelper.registerKeyBinding(key.getKeyBinding());
|
||||
}
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
for (Key key : keybindingManager.getEntries()) {
|
||||
if (key.isEnabled() && key.getKeyBinding().wasPressed()) {
|
||||
key.onPress(client);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||
for (Command command : WeatherChanger.getCommandManager().getEntries()) {
|
||||
command.register(dispatcher);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.lucaslah.weatherchanger.fabric;
|
||||
|
||||
import me.lucaslah.weatherchanger.WeatherChangerPlatform;
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -11,9 +10,4 @@ public class WeatherChangerPlatformImpl implements WeatherChangerPlatform {
|
||||
public Path getConfigDirectory() {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeybindingManager getKeybindingManager() {
|
||||
return new FabricKeybindingManager();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package me.lucaslah.weatherchanger.forge;
|
||||
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
|
||||
public class ForgeKeybindingManager extends KeybindingManager {
|
||||
@Override
|
||||
public void registerKeys() {
|
||||
// forge handles keybindings in a event
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package me.lucaslah.weatherchanger.forge;
|
||||
|
||||
import me.lucaslah.weatherchanger.WeatherChanger;
|
||||
import me.lucaslah.weatherchanger.command.Command;
|
||||
import me.lucaslah.weatherchanger.command.CommandManager;
|
||||
import me.lucaslah.weatherchanger.keybinding.Key;
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
@@ -14,32 +18,25 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod("weatherchanger")
|
||||
public class WeatherChangerForge {
|
||||
private static WeatherChangerForge instance;
|
||||
private ForgeKeybindingManager forgeKeybindingManager;
|
||||
private final KeybindingManager keybindingManager;
|
||||
private final CommandManager commandManager;
|
||||
|
||||
public WeatherChangerForge() {
|
||||
WeatherChanger.init(new WeatherChangerPlatformImpl());
|
||||
keybindingManager = WeatherChanger.getKeybindingManager();
|
||||
commandManager = WeatherChanger.getCommandManager();
|
||||
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
modEventBus.addListener(this::onClientSetup);
|
||||
modEventBus.addListener(this::registerBindings);
|
||||
}
|
||||
|
||||
private void onClientSetup(FMLClientSetupEvent event) {
|
||||
instance = this;
|
||||
forgeKeybindingManager = new ForgeKeybindingManager();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
WeatherChanger.init(new WeatherChangerPlatformImpl());
|
||||
}
|
||||
|
||||
public static WeatherChangerForge getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ForgeKeybindingManager getKeybindingManager() {
|
||||
return forgeKeybindingManager;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerBindings(RegisterKeyMappingsEvent event) {
|
||||
for (Key key : forgeKeybindingManager.getEntries()) {
|
||||
for (Key key : keybindingManager.getEntries()) {
|
||||
event.register(key.getKeyBinding());
|
||||
}
|
||||
}
|
||||
@@ -47,11 +44,18 @@ public class WeatherChangerForge {
|
||||
@SubscribeEvent
|
||||
public void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.END) {
|
||||
for (Key key : forgeKeybindingManager.getEntries()) {
|
||||
for (Key key : keybindingManager.getEntries()) {
|
||||
if (key.isEnabled() && key.getKeyBinding().wasPressed()) {
|
||||
key.onPress(MinecraftClient.getInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onCommandRegister(RegisterClientCommandsEvent event) {
|
||||
for (Command command : commandManager.getEntries()) {
|
||||
command.register(event.getDispatcher());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.lucaslah.weatherchanger.forge;
|
||||
|
||||
import me.lucaslah.weatherchanger.WeatherChangerPlatform;
|
||||
import me.lucaslah.weatherchanger.keybinding.KeybindingManager;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -11,9 +10,4 @@ public class WeatherChangerPlatformImpl implements WeatherChangerPlatform {
|
||||
public Path getConfigDirectory() {
|
||||
return FMLPaths.CONFIGDIR.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeybindingManager getKeybindingManager() {
|
||||
return WeatherChangerForge.getInstance().getKeybindingManager();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user