diff options
author | SHsuperCM <shsupercm@gmail.com> | 2021-08-28 18:40:09 +0300 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2021-08-28 18:40:09 +0300 |
commit | 89d8435e80c8955d8299fe60d9a2169067f8ac75 (patch) | |
tree | 717306cc492fc470f27207c61cc5316b31fb0fb3 /src/main/java/shcm/shsupercm/fabric | |
parent | da30d30d62caae66255ca6892736df75e12cef6f (diff) | |
download | CITResewn-89d8435e80c8955d8299fe60d9a2169067f8ac75.tar.gz CITResewn-89d8435e80c8955d8299fe60d9a2169067f8ac75.tar.bz2 CITResewn-89d8435e80c8955d8299fe60d9a2169067f8ac75.zip |
Added config as well as support for modmenu/cloth
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric')
7 files changed, 125 insertions, 2 deletions
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) { |