aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-09-14 20:43:51 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-09-14 20:43:51 +0300
commit04503b155395836605f8463f2e71520eabc67bfc (patch)
tree4f1cbdc6399a74c189a4264497a50eacebd948b9 /src/main/java
parentbfa600f2829a29b77c90063041a9db057aa70b14 (diff)
downloadCITResewn-04503b155395836605f8463f2e71520eabc67bfc.tar.gz
CITResewn-04503b155395836605f8463f2e71520eabc67bfc.tar.bz2
CITResewn-04503b155395836605f8463f2e71520eabc67bfc.zip
Moved cloth config support into OptionalCompat
• Added a notice screen to config when cloth is not present.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java4
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java39
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java6
3 files changed, 35 insertions, 14 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
index bb99d49..b7f16aa 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java
@@ -18,8 +18,6 @@ public class CITResewn implements ClientModInitializer {
public CITResewnConfig config = null;
- public OptionalCompat compat = null;
-
public boolean processingBrokenPaths = false;
@@ -28,8 +26,6 @@ public class CITResewn implements ClientModInitializer {
INSTANCE = this;
config = CITResewnConfig.read();
-
- compat = new OptionalCompat(s -> FabricLoader.getInstance().isModLoaded(s));
}
public static void info(String message) {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java b/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java
index ea77f5e..580aef5 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java
@@ -1,27 +1,43 @@
package shcm.shsupercm.fabric.citresewn;
import io.github.apace100.cosmetic_armor.CosmeticArmor;
+import net.fabricmc.loader.api.FabricLoader;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.screen.NoticeScreen;
+import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
+import net.minecraft.text.Text;
+import shcm.shsupercm.fabric.citresewn.config.CITResewnConfigScreenFactory;
+import java.util.function.Function;
import java.util.function.Predicate;
public final class OptionalCompat {
- public static OptionalCompat INSTANCE() {
- return CITResewn.INSTANCE.compat;
- }
+ private static final OptionalCompat INSTANCE = new OptionalCompat(s -> FabricLoader.getInstance().isModLoaded(s));
+
+ public final CompatClothConfig compatClothConfig;
public final CompatCosmeticArmor compatCosmeticArmor;
- public OptionalCompat(Predicate<String> isLoaded) {
+ private OptionalCompat(Predicate<String> isLoaded) {
+ compatClothConfig = isLoaded.test("cloth-config2") ? CompatClothConfig.impl() : null;
compatCosmeticArmor = isLoaded.test("cosmetic-armor") ? CompatCosmeticArmor.impl() : null;
}
+ public static Function<Screen, Screen> getModConfigScreenFactory() {
+ if (INSTANCE.compatClothConfig != null) {
+ return INSTANCE.compatClothConfig.getModConfigScreenFactory();
+ }
+
+ return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("CIT Resewn"), Text.of("CIT Resewn requires Cloth Config 2 to be able to show the config."));
+ }
+
public static ItemStack getCosmeticArmor(ItemStack original, LivingEntity entity, EquipmentSlot slot, boolean elytra) {
- if (INSTANCE().compatCosmeticArmor != null) {
- ItemStack stackInCosmeticSlot = INSTANCE().compatCosmeticArmor.getStackInCosmeticSlot(entity, slot);
+ if (INSTANCE.compatCosmeticArmor != null) {
+ ItemStack stackInCosmeticSlot = INSTANCE.compatCosmeticArmor.getStackInCosmeticSlot(entity, slot);
if (!stackInCosmeticSlot.isEmpty() && (!elytra || stackInCosmeticSlot.isOf(Items.ELYTRA)))
return stackInCosmeticSlot;
}
@@ -30,6 +46,17 @@ public final class OptionalCompat {
}
/**
+ * Compatibility with 'cloth-config2': Custom gui for CITResewn's config
+ */
+ public interface CompatClothConfig {
+ private static CompatClothConfig impl() {
+ return () -> CITResewnConfigScreenFactory::create;
+ }
+
+ Function<Screen, Screen> getModConfigScreenFactory();
+ }
+
+ /**
* Compatibility with 'cosmetic-armor': Display cits for cosmetic armors instead of equipped armors
*/
public interface CompatCosmeticArmor {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java
index 4c3f20a..7a4954c 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java
@@ -3,13 +3,11 @@ package shcm.shsupercm.fabric.citresewn.config;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import net.fabricmc.loader.api.FabricLoader;
+import shcm.shsupercm.fabric.citresewn.OptionalCompat;
public class CITResewnModMenu implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
- if (FabricLoader.getInstance().isModLoaded("cloth-config2"))
- return CITResewnConfigScreenFactory::create;
-
- return parent -> null;
+ return OptionalCompat.getModConfigScreenFactory()::apply;
}
}