diff options
author | SHsuperCM <shsupercm@gmail.com> | 2021-09-09 18:12:31 +0300 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2021-09-09 18:12:31 +0300 |
commit | b111faed7feca0e2384fcafb095a70e35434241d (patch) | |
tree | 04615755be91dc2f823342c17ca412c3f1141045 /src | |
parent | ab5f5e5beb99f592af538b5525e8e826ebda6dd1 (diff) | |
download | CITResewn-b111faed7feca0e2384fcafb095a70e35434241d.tar.gz CITResewn-b111faed7feca0e2384fcafb095a70e35434241d.tar.bz2 CITResewn-b111faed7feca0e2384fcafb095a70e35434241d.zip |
v0.5.1, "Broken Path" mixins wont be injected if config is turned off
• Changing config for broken paths now requires a restart to apply and it being disabled completely removes the effects it has on the game.
• Organized mixins into packages
fixes #14
Diffstat (limited to 'src')
19 files changed, 86 insertions, 49 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java index 5bc059e..c1c5148 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java @@ -24,13 +24,10 @@ public class CITResewnConfig { if (!FILE.exists()) return new CITResewnConfig().write(); - CITParser.REGISTRY.put("test", CITItem::new); - 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 { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java index b85a55c..6fd51f7 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java @@ -45,13 +45,9 @@ public class CITResewnConfigScreenFactory { category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.broken_paths.title"), currentConfig.broken_paths) .setTooltip(new TranslatableText("config.citresewn.broken_paths.tooltip")) - .setSaveConsumer(newConfig -> { - if (currentConfig.broken_paths != newConfig) { - currentConfig.broken_paths = newConfig; - MinecraftClient.getInstance().reloadResources(); - } - }) + .setSaveConsumer(newConfig -> currentConfig.broken_paths = newConfig) .setDefaultValue(defaultConfig.broken_paths) + .requireRestart() .build()); return builder.build(); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnMixinConfiguration.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnMixinConfiguration.java new file mode 100644 index 0000000..e3d8243 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnMixinConfiguration.java @@ -0,0 +1,45 @@ +package shcm.shsupercm.fabric.citresewn.config; + +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class CITResewnMixinConfiguration implements IMixinConfigPlugin { + private static final String MIXINS_ROOT = "shcm.shsupercm.fabric.citresewn.mixin"; + + private boolean broken_paths; + + @Override + public void onLoad(String mixinPackage) { + CITResewnConfig launchConfig = CITResewnConfig.read(); + + this.broken_paths = launchConfig.broken_paths; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if (!mixinClassName.startsWith(MIXINS_ROOT)) + return false; + mixinClassName = mixinClassName.substring(MIXINS_ROOT.length() + 1); + + if (mixinClassName.startsWith("broken_paths")) + return broken_paths; + + return true; + } + + + @Override + public String getRefMapperConfig() { return null; } + @Override + public List<String> getMixins() { return null; } + @Override + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { } + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AbstractFileResourcePackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java index acc0f38..b6d2474 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AbstractFileResourcePackMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; import net.minecraft.resource.AbstractFileResourcePack; import net.minecraft.resource.DirectoryResourcePack; @@ -14,21 +14,20 @@ import org.spongepowered.asm.mixin.Shadow; 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.config.CITResewnConfig; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.util.zip.ZipFile; -@Mixin(AbstractFileResourcePack.class) +@Mixin(AbstractFileResourcePack.class) // Only registered if CITResewnConfig#broken_paths is true public abstract class AbstractFileResourcePackMixin implements ResourcePack { @Shadow @Final protected File base; @SuppressWarnings({"unchecked", "ConstantConditions", "EqualsBetweenInconvertibleTypes"}) @Inject(method = "parseMetadata(Lnet/minecraft/resource/metadata/ResourceMetadataReader;)Ljava/lang/Object;", cancellable = true, at = @At("RETURN")) public <T extends PackResourceMetadata> void parseMetadata(ResourceMetadataReader<T> metaReader, CallbackInfoReturnable<T> cir) { - if (CITResewnConfig.INSTANCE().broken_paths && cir.getReturnValue() != null) + if (cir.getReturnValue() != null) try { if (this.getClass().equals(ZipResourcePack.class)) { try (ZipFile zipFile = new ZipFile(base)) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java index 4892abc..0ae5291 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/IdentifierMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Mixin; @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.CITResewn; -@Mixin(Identifier.class) +@Mixin(Identifier.class) // Only registered if CITResewnConfig#broken_paths is true public class IdentifierMixin { @Inject(method = "isPathValid", cancellable = true, at = @At("HEAD")) private static void processBrokenPaths(String path, CallbackInfoReturnable<Boolean> cir) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java index 8ee0498..8833b4c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ReloadableResourceManagerImplMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; import net.minecraft.resource.ReloadableResourceManagerImpl; import net.minecraft.resource.ResourcePack; @@ -12,21 +12,18 @@ 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; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -@Mixin(ReloadableResourceManagerImpl.class) +@Mixin(ReloadableResourceManagerImpl.class) // Only registered if CITResewnConfig#broken_paths is true public class ReloadableResourceManagerImplMixin { @Shadow @Final private ResourceType type; @Inject(method = "reload", at = @At("RETURN")) public void onReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs, CallbackInfoReturnable<ResourceReload> cir) { - if (CITResewn.INSTANCE.processingBrokenPaths = (this.type == ResourceType.CLIENT_RESOURCES && CITResewnConfig.INSTANCE().broken_paths)) - cir.getReturnValue().whenComplete().thenRun(() -> { - CITResewn.INSTANCE.processingBrokenPaths = false; - }); + if (CITResewn.INSTANCE.processingBrokenPaths = this.type == ResourceType.CLIENT_RESOURCES) + cir.getReturnValue().whenComplete().thenRun(() -> CITResewn.INSTANCE.processingBrokenPaths = false); } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourcePackCompatibilityMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java index c41ddad..4fe07ce 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourcePackCompatibilityMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; import net.minecraft.resource.ResourcePackCompatibility; import net.minecraft.resource.ResourceType; @@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ResourcePackCompatibility.class) +@Mixin(ResourcePackCompatibility.class) // Only registered if CITResewnConfig#broken_paths is true public abstract class ResourcePackCompatibilityMixin { private static final ResourcePackCompatibility BROKEN_PATHS = ResourcePackCompatibility("BROKEN_PATHS", -1, "broken_paths"); diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ArmorFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java index 02f4689..5fe1965 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ArmorFeatureRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.citarmor; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java index a774de4..f44871b 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.citelytra; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemRendererMixin.java index 58b5fe2..1014a44 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemRendererMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.cititem; import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.client.render.model.BakedModel; @@ -15,7 +15,7 @@ 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) { + public void getItemModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) return; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/JsonUnbakedModelAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/JsonUnbakedModelAccessor.java index 70a3815..aa582bf 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/JsonUnbakedModelAccessor.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/JsonUnbakedModelAccessor.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.core; import com.mojang.datafixers.util.Either; import net.minecraft.client.render.model.json.JsonUnbakedModel; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ModelLoaderMixin.java index af55496..0ece247 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ModelLoaderMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.core; import com.mojang.datafixers.util.Either; import net.minecraft.client.render.model.*; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/NbtCompoundAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/NbtCompoundAccessor.java index 2264638..8ced305 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/NbtCompoundAccessor.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/NbtCompoundAccessor.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.core; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/SpriteAtlasTextureMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/SpriteAtlasTextureMixin.java index dc21ae1..8cc195b 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/SpriteAtlasTextureMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/SpriteAtlasTextureMixin.java @@ -1,4 +1,4 @@ -package shcm.shsupercm.fabric.citresewn.mixin; +package shcm.shsupercm.fabric.citresewn.mixin.core; import net.minecraft.client.texture.SpriteAtlasTexture; import net.minecraft.util.Identifier; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java index baa1018..c531983 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java @@ -1,10 +1,11 @@ package shcm.shsupercm.fabric.citresewn.pack; import net.minecraft.util.Identifier; +import shcm.shsupercm.fabric.citresewn.mixin.core.ModelLoaderMixin; /** * Marks models as cit item models. - * @see shcm.shsupercm.fabric.citresewn.mixin.ModelLoaderMixin + * @see ModelLoaderMixin */ public class ResewnItemModelIdentifier extends Identifier { public ResewnItemModelIdentifier(String id) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java index 4a13bc2..033c567 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java @@ -1,10 +1,11 @@ package shcm.shsupercm.fabric.citresewn.pack; import net.minecraft.util.Identifier; +import shcm.shsupercm.fabric.citresewn.mixin.core.SpriteAtlasTextureMixin; /** * Marks path identifiers as forced literal texture paths. - * @see shcm.shsupercm.fabric.citresewn.mixin.SpriteAtlasTextureMixin + * @see SpriteAtlasTextureMixin */ public class ResewnTextureIdentifier extends Identifier { public ResewnTextureIdentifier(Identifier identifier) { diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java index 5c0bcf7..e618a6f 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java @@ -6,8 +6,6 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ResourceType; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; @@ -15,7 +13,7 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.apache.commons.lang3.StringEscapeUtils; import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.mixin.NbtCompoundAccessor; +import shcm.shsupercm.fabric.citresewn.mixin.core.NbtCompoundAccessor; import shcm.shsupercm.fabric.citresewn.pack.CITPack; import java.util.*; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java index 68eccea..7df8a17 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java @@ -20,7 +20,7 @@ import org.apache.commons.io.IOUtils; import shcm.shsupercm.fabric.citresewn.CITResewn; import shcm.shsupercm.fabric.citresewn.ex.CITLoadException; import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.mixin.JsonUnbakedModelAccessor; +import shcm.shsupercm.fabric.citresewn.mixin.core.JsonUnbakedModelAccessor; import shcm.shsupercm.fabric.citresewn.pack.CITPack; import shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier; import shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier; diff --git a/src/main/resources/citresewn.mixins.json b/src/main/resources/citresewn.mixins.json index 5753a8a..ccf70eb 100644 --- a/src/main/resources/citresewn.mixins.json +++ b/src/main/resources/citresewn.mixins.json @@ -3,18 +3,21 @@ "minVersion": "0.8", "package": "shcm.shsupercm.fabric.citresewn.mixin", "compatibilityLevel": "JAVA_16", + "plugin": "shcm.shsupercm.fabric.citresewn.config.CITResewnMixinConfiguration", "mixins": [ - "AbstractFileResourcePackMixin", - "ArmorFeatureRendererMixin", - "ElytraFeatureRendererMixin", - "IdentifierMixin", - "ItemRendererMixin", - "JsonUnbakedModelAccessor", - "ModelLoaderMixin", - "NbtCompoundAccessor", - "ReloadableResourceManagerImplMixin", - "ResourcePackCompatibilityMixin", - "SpriteAtlasTextureMixin" + "core.ModelLoaderMixin", + "core.SpriteAtlasTextureMixin", + "core.JsonUnbakedModelAccessor", + "core.NbtCompoundAccessor", + + "cititem.ItemRendererMixin", + "citarmor.ArmorFeatureRendererMixin", + "citelytra.ElytraFeatureRendererMixin", + + "broken_paths.AbstractFileResourcePackMixin", + "broken_paths.ReloadableResourceManagerImplMixin", + "broken_paths.IdentifierMixin", + "broken_paths.ResourcePackCompatibilityMixin" ], "injectors": { "defaultRequire": 1 |