diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-10-27 15:45:43 +0300 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-10-27 17:20:37 +0300 |
commit | a75d755df8e0c551cd40701017018719667ff6eb (patch) | |
tree | cf15d133065ffa864bbe56f1780b0dc9cf40a9f4 /src | |
parent | 237adf03cc55b4120330e2fbc4bc4178c0361f2d (diff) | |
download | CITResewn-a75d755df8e0c551cd40701017018719667ff6eb.tar.gz CITResewn-a75d755df8e0c551cd40701017018719667ff6eb.tar.bz2 CITResewn-a75d755df8e0c551cd40701017018719667ff6eb.zip |
22w43a Bandage
Diffstat (limited to 'src')
3 files changed, 20 insertions, 42 deletions
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 df11ac9..215c596 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java @@ -1,5 +1,6 @@ package shcm.shsupercm.fabric.citresewn.mixin; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.render.model.ModelLoader; import net.minecraft.resource.ResourceManager; @@ -10,6 +11,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +import java.util.Map; + /** * Initializes the (re)loading of active cits in the resource manager. * @see ActiveCITs @@ -21,9 +24,9 @@ public class ModelLoaderMixin { */ @Inject(method = "<init>", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V")) - private void citresewn$loadCITs(ResourceManager resourceManager, BlockColors blockColors, Profiler profiler, int i, CallbackInfo ci) { + private void citresewn$loadCITs(BlockColors blockColors, Profiler profiler, Map jsonUnbakedModels, Map blockStates, CallbackInfo ci) { profiler.push("citresewn:reloading_cits"); - ActiveCITs.load(resourceManager, profiler); + ActiveCITs.load(MinecraftClient.getInstance().getResourceManager(), profiler); profiler.pop(); } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java index b241fff..673ddbf 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java @@ -1,26 +1,17 @@ package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; import net.minecraft.resource.AbstractFileResourcePack; -import net.minecraft.resource.DirectoryResourcePack; import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ZipResourcePack; +import net.minecraft.resource.ResourceType; import net.minecraft.resource.metadata.PackResourceMetadata; import net.minecraft.resource.metadata.ResourceMetadataReader; -import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -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.BrokenPaths; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.zip.ZipFile; - /** * Adds a resourcepack compatibility error message when broken paths are enabled and are detected in a pack. * @see BrokenPaths @@ -28,32 +19,17 @@ import java.util.zip.ZipFile; */ @Mixin(AbstractFileResourcePack.class) public abstract class AbstractFileResourcePackMixin implements ResourcePack { - @Shadow @Final protected File base; - @SuppressWarnings({"unchecked", "ConstantConditions", "EqualsBetweenInconvertibleTypes"}) + @SuppressWarnings({"unchecked"}) @Inject(method = "parseMetadata(Lnet/minecraft/resource/metadata/ResourceMetadataReader;)Ljava/lang/Object;", cancellable = true, at = @At("RETURN")) public <T extends PackResourceMetadata> void citresewn$brokenpaths$parseMetadata(ResourceMetadataReader<T> metaReader, CallbackInfoReturnable<T> cir) { - if (cir.getReturnValue() != null) - try { - if (this.getClass().equals(ZipResourcePack.class)) { - try (ZipFile zipFile = new ZipFile(base)) { - zipFile.stream() - .forEach(entry -> { - if (entry.getName().startsWith("assets") && !entry.getName().endsWith(".DS_Store")) - new Identifier("minecraft", entry.getName()); - }); - } - } else if (this.getClass().equals(DirectoryResourcePack.class)) { - final Path assets = new File(base, "assets").toPath(); - Files.walk(assets) - .forEach(fullPath -> { - String path = assets.relativize(fullPath).toString().replace('\\', '/'); - if (!path.endsWith(".DS_Store")) - new Identifier("minecraft", path); - }); - } - } catch (InvalidIdentifierException e) { - cir.setReturnValue((T) new PackResourceMetadata(cir.getReturnValue().getDescription(), Integer.MAX_VALUE - 53)); - } catch (Exception ignored) {} + if (cir.getReturnValue() != null) try { + for (String namespace : getNamespaces(ResourceType.CLIENT_RESOURCES)) { + findResources(ResourceType.CLIENT_RESOURCES, namespace, "", (identifier, inputStreamInputSupplier) -> { + }); + } + } catch (InvalidIdentifierException e) { + cir.setReturnValue((T) new PackResourceMetadata(cir.getReturnValue().getDescription(), Integer.MAX_VALUE - 53)); + } catch (Exception ignored) { } } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java index ffc242f..590f5a0 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/PackParser.java @@ -1,9 +1,6 @@ package shcm.shsupercm.fabric.citresewn.pack; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ResourceType; +import net.minecraft.resource.*; import net.minecraft.util.Identifier; import shcm.shsupercm.fabric.citresewn.CITResewn; import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.core.FallbackCondition; @@ -18,6 +15,7 @@ import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; import java.io.FileNotFoundException; +import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; @@ -44,8 +42,9 @@ public final class PackParser { private PackParser() {} for (String root : ROOTS) { Identifier identifier = new Identifier(namespace, root + "/cit.properties"); try { - if (pack.contains(ResourceType.CLIENT_RESOURCES, identifier)) - globalProperties.load(pack.getName(), identifier, pack.open(ResourceType.CLIENT_RESOURCES, identifier)); + InputSupplier<InputStream> citPropertiesSupplier = pack.open(ResourceType.CLIENT_RESOURCES, identifier); + if (citPropertiesSupplier != null) + globalProperties.load(pack.getName(), identifier, citPropertiesSupplier.get()); } catch (FileNotFoundException ignored) { } catch (Exception e) { CITResewn.logErrorLoading("Errored while loading global properties: " + identifier + " from " + pack.getName()); |