diff options
11 files changed, 143 insertions, 10 deletions
diff --git a/build.gradle b/build.gradle index c309de8..a611ca3 100644 --- a/build.gradle +++ b/build.gradle @@ -7,11 +7,8 @@ version = project.mod_version group = project.maven_group repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. + maven { url "https://maven.shedaniel.me/" } + maven { url "https://maven.terraformersmc.com/releases" } } dependencies { @@ -20,9 +17,13 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modApi("com.terraformersmc:modmenu:2.0.6") { + exclude(group: "net.fabricmc.fabric-api") + } - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. + modApi("me.shedaniel.cloth:cloth-config-fabric:5.0.38") { + exclude(group: "net.fabricmc.fabric-api") + } } processResources { diff --git a/gradle.properties b/gradle.properties index 2eafb12..e32e107 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.17.1 yarn_mappings=1.17.1+build.39 loader_version=0.11.6 # Mod Properties -mod_version=0.2.0 +mod_version=0.3.0 maven_group=shcm.shsupercm.fabric archives_base_name=CITResewn diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index 1c45468..cbc7342 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -5,6 +5,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; @Environment(EnvType.CLIENT) public class CITResewn implements ClientModInitializer { @@ -13,9 +14,14 @@ public class CITResewn implements ClientModInitializer { public ActiveCITs activeCITs = null; + public CITResewnConfig config = null; + @Override public void onInitializeClient() { INSTANCE = this; + + config = CITResewnConfig.read(); + /*net.minecraft.client.render.entity.feature.ArmorFeatureRenderer#renderArmor take entity.getEquippedStack(armorSlot) eval override diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java new file mode 100644 index 0000000..38995ca --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java @@ -0,0 +1,51 @@ +package shcm.shsupercm.fabric.citresewn.config; + +import com.google.gson.Gson; +import com.google.gson.stream.JsonWriter; +import org.apache.commons.io.IOUtils; +import shcm.shsupercm.fabric.citresewn.CITResewn; + +import java.io.*; + +public class CITResewnConfig { + public boolean enabled = true; + + private static final File FILE = new File("config/citresewn.json"); + public static CITResewnConfig INSTANCE() { + return CITResewn.INSTANCE.config; + } + + public static CITResewnConfig read() { + if (!FILE.exists()) + return new CITResewnConfig().write(); + + Reader reader = null; + try { + return new Gson().fromJson(reader = new FileReader(FILE), CITResewnConfig.class); + } catch (Exception e) { + CITResewn.LOG.error("Couldn't load config"); + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + IOUtils.closeQuietly(reader); + } + } + + public CITResewnConfig write() { + Gson gson = new Gson(); + JsonWriter writer = null; + try { + writer = gson.newJsonWriter(new FileWriter(FILE)); + writer.setIndent(" "); + + gson.toJson(gson.toJsonTree(this, CITResewnConfig.class), writer); + } catch (Exception e) { + CITResewn.LOG.error("Couldn't save config"); + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + IOUtils.closeQuietly(writer); + } + return this; + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java new file mode 100644 index 0000000..bc00d2b --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java @@ -0,0 +1,36 @@ +package shcm.shsupercm.fabric.citresewn.config; + +import me.shedaniel.clothconfig2.api.ConfigBuilder; +import me.shedaniel.clothconfig2.api.ConfigCategory; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.LiteralText; +import net.minecraft.text.TranslatableText; + +public class CITResewnConfigScreenFactory { + public static Screen create(Screen parent) { + CITResewnConfig currentConfig = CITResewnConfig.INSTANCE(), defaultConfig = new CITResewnConfig(); + + ConfigBuilder builder = ConfigBuilder.create() + .setParentScreen(parent) + .setTitle(new TranslatableText("config.citresewn.title")) + .setSavingRunnable(currentConfig::write); + + ConfigCategory category = builder.getOrCreateCategory(new LiteralText("")); + ConfigEntryBuilder entryBuilder = builder.entryBuilder(); + + category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.citsEnabled.title"), currentConfig.enabled) + .setTooltip(new TranslatableText("config.citresewn.citsEnabled.tooltip")) + .setSaveConsumer(newConfig -> { + if (currentConfig.enabled != newConfig) { + currentConfig.enabled = newConfig; + MinecraftClient.getInstance().reloadResources(); + } + }) + .setDefaultValue(defaultConfig.enabled) + .build()); + + return builder.build(); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java new file mode 100644 index 0000000..4c3f20a --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java @@ -0,0 +1,15 @@ +package shcm.shsupercm.fabric.citresewn.config; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import net.fabricmc.loader.api.FabricLoader; + +public class CITResewnModMenu implements ModMenuApi { + @Override + public ConfigScreenFactory<?> getModConfigScreenFactory() { + if (FabricLoader.getInstance().isModLoaded("cloth-config2")) + return CITResewnConfigScreenFactory::create; + + return parent -> null; + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java index 39dfa73..37f0dd9 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java @@ -14,6 +14,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import java.lang.ref.WeakReference; @@ -24,7 +25,7 @@ public class ElytraFeatureRendererMixin { @Inject(method = "render", cancellable = true, at = @At("HEAD")) public void injectCIT(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { - if (CITResewn.INSTANCE.activeCITs == null) + if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) return; this.elytraItemCached = new WeakReference<>(livingEntity.getEquippedStack(EquipmentSlot.CHEST)); @@ -33,6 +34,9 @@ public class ElytraFeatureRendererMixin { @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getArmorCutoutNoCull(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;")) public RenderLayer getArmorCutoutNoCull(Identifier originalIdentifier) { + if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) + return RenderLayer.getArmorCutoutNoCull(originalIdentifier); + ItemStack itemStack = this.elytraItemCached.get(); LivingEntity livingEntity = livingEntityCached.get(); if (itemStack != null && livingEntity != null) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java index f2c15ec..58b5fe2 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java @@ -10,12 +10,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; @Mixin(ItemRenderer.class) public class ItemRendererMixin { @Inject(method = "getHeldItemModel", cancellable = true, at = @At("RETURN")) public void injectCIT(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { - if (CITResewn.INSTANCE.activeCITs == null) + if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) return; BakedModel citModel = CITResewn.INSTANCE.activeCITs.getItemModel(stack, cir.getReturnValue(), world, entity); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java index c6681d3..f0fa82d 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java @@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.ActiveCITs; import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; import shcm.shsupercm.fabric.citresewn.pack.CITParser; import shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier; import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; @@ -41,6 +42,9 @@ public abstract class ModelLoaderMixin { CITResewn.INSTANCE.activeCITs = null; } + if (!CITResewnConfig.INSTANCE().enabled) + return; + Collection<CIT> parsed = CITParser.parse(resourceManager.streamResourcePacks().collect(Collectors.toCollection(ArrayList::new))); for (CIT cit : parsed) @@ -65,11 +69,17 @@ public abstract class ModelLoaderMixin { @Inject(method = "bake", at = @At("RETURN")) public void onBake(Identifier id, ModelBakeSettings settings, CallbackInfoReturnable<BakedModel> cir) { + if (CITResewn.INSTANCE.activeCITs == null) + return; + this.citOverrideCacheMap.put(id, cir.getReturnValue()); } @Inject(method = "upload", at = @At("RETURN")) public void linkBakedModels(TextureManager textureManager, Profiler profiler, CallbackInfoReturnable<SpriteAtlasManager> cir) { + if (CITResewn.INSTANCE.activeCITs == null) + return; + profiler.push("citresewn_linking"); if (CITResewn.INSTANCE.activeCITs != null) { diff --git a/src/main/resources/assets/citresewn/lang/en_us.json b/src/main/resources/assets/citresewn/lang/en_us.json new file mode 100644 index 0000000..84fc464 --- /dev/null +++ b/src/main/resources/assets/citresewn/lang/en_us.json @@ -0,0 +1,6 @@ +{ + "config.citresewn.title": "CIT Resewn Configuration", + + "config.citresewn.citsEnabled.title": "Enabled", + "config.citresewn.citsEnabled.tooltip": "Should CITResewn load and inject cits from resourcepacks" +}
\ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5e2421e..45c4721 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -14,6 +14,9 @@ "entrypoints": { "client": [ "shcm.shsupercm.fabric.citresewn.CITResewn" + ], + "modmenu": [ + "shcm.shsupercm.fabric.citresewn.config.CITResewnModMenu" ] }, "mixins": [ |