diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-03-04 10:52:27 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-03-04 10:52:27 +0200 |
commit | badaaeaae77bb8bc74b4e08cbce1087c68252914 (patch) | |
tree | 5eb3c82175c35072dc41632d379759efa2898e70 /src/main/java/shcm/shsupercm | |
parent | d2a7a6b219ff2b229774dba336417822ec019b7b (diff) | |
download | CITResewn-badaaeaae77bb8bc74b4e08cbce1087c68252914.tar.gz CITResewn-badaaeaae77bb8bc74b4e08cbce1087c68252914.tar.bz2 CITResewn-badaaeaae77bb8bc74b4e08cbce1087c68252914.zip |
Readded citresewn command
Diffstat (limited to 'src/main/java/shcm/shsupercm')
3 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index 482d757..79e49aa 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -2,6 +2,7 @@ package shcm.shsupercm.fabric.citresewn; import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.loader.api.FabricLoader; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; @@ -15,6 +16,9 @@ public class CITResewn implements ClientModInitializer { @Override public void onInitializeClient() { CITRegistry.registerAll(); + + if (FabricLoader.getInstance().isModLoaded("fabric-command-api-v1")) + CITResewnCommand.register(); } public static void info(String message) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java new file mode 100644 index 0000000..b06a8ba --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java @@ -0,0 +1,39 @@ +package shcm.shsupercm.fabric.citresewn; + +import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; +import net.fabricmc.loader.api.FabricLoader; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +import shcm.shsupercm.fabric.citresewn.cit.CITRegistry; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; + +import java.util.Collection; + +import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; +import static net.minecraft.text.Text.of; + +public class CITResewnCommand { + public static boolean openConfig = false; + + public static void register() { + ClientCommandManager.DISPATCHER.register(literal("citresewn") + .executes(context -> { + context.getSource().sendFeedback(of("CIT Resewn v" + FabricLoader.getInstance().getModContainer("citresewn").orElseThrow().getMetadata().getVersion() + ":")); + context.getSource().sendFeedback(of(" Registered: " + CITRegistry.TYPES.values().stream().distinct().count() + " types and " + CITRegistry.CONDITIONS.values().stream().distinct().count() + " conditions")); + + final boolean active = CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive(); + context.getSource().sendFeedback(of(" Active: " + (active ? "yes" : ("no, " + (CITResewnConfig.INSTANCE.enabled ? "no cit packs loaded" : "disabled in config"))))); + if (active) { + context.getSource().sendFeedback(of(" Loaded: " + ActiveCITs.getActive().cits.values().stream().mapToLong(Collection::size).sum() + " CITs from " + ActiveCITs.getActive().cits.values().stream().flatMap(Collection::stream).map(cit -> cit.packName).distinct().count() + " resourcepacks")); + } + context.getSource().sendFeedback(of("")); + + return 1; + }) + .then(literal("config") + .executes(context -> { + openConfig = true; + + return 1; + }))); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java new file mode 100644 index 0000000..5bacbde --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ChatScreenMixin.java @@ -0,0 +1,29 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ChatScreen; +import net.minecraft.client.gui.screen.NoticeScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfigScreenFactory; + +import static shcm.shsupercm.fabric.citresewn.CITResewnCommand.openConfig; + +@Mixin(ChatScreen.class) +public class ChatScreenMixin { + @ModifyArg(method = "keyPressed", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V")) + public Screen redirectConfigScreen(Screen original) { + if (openConfig) { + openConfig = false; + return FabricLoader.getInstance().isModLoaded("cloth-config2") ? + CITResewnConfigScreenFactory.create(null) : + new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(null), Text.of("CIT Resewn"), Text.of("CIT Resewn requires Cloth Config to be able to show the config.")); + } + + return original; + } +} |