diff options
Diffstat (limited to 'src/main/java')
8 files changed, 113 insertions, 45 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java index 05495af..6a6ec22 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/api/CITGlobalProperties.java @@ -2,7 +2,7 @@ package shcm.shsupercm.fabric.citresewn.api; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyValue; -import javax.annotation.Nullable; +import blue.endless.jankson.annotation.Nullable; /** * @see #globalProperty(String, PropertyValue) diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java index cfc10f8..0a44915 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITContext.java @@ -11,7 +11,7 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import javax.annotation.Nullable; +import blue.endless.jankson.annotation.Nullable; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java new file mode 100644 index 0000000..ee5c125 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasLoaderMixin.java @@ -0,0 +1,45 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.texture.atlas.AtlasLoader; +import net.minecraft.client.texture.atlas.AtlasSource; +import net.minecraft.client.texture.atlas.AtlasSourceType; +import net.minecraft.resource.Resource; +import net.minecraft.resource.ResourceFinder; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +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.pack.PackParser; + +import java.util.List; +import java.util.Map; + +@Mixin(AtlasLoader.class) +public class AtlasLoaderMixin { + @Shadow @Final private List<AtlasSource> sources; + + @Inject(method = "of", at = @At("RETURN"), cancellable = true) + private static void citresewn$atlasSource(ResourceManager resourceManager, Identifier id, CallbackInfoReturnable<AtlasLoader> cir) { + if (id.getPath().equals("blocks") && id.getNamespace().equals("minecraft")) { + ((AtlasLoaderMixin) (Object) cir.getReturnValue()).sources.add(new AtlasSource() { + @Override + public void load(ResourceManager resourceManager, SpriteRegions regions) { + for (String root : PackParser.ROOTS) { + ResourceFinder resourceFinder = new ResourceFinder(root + "/cit", ".png"); + for (Map.Entry<Identifier, Resource> entry : resourceFinder.findResources(resourceManager).entrySet()) + regions.add(resourceFinder.toResourceId(entry.getKey()).withPrefixedPath(root + "/cit/"), entry.getValue()); + } + } + + @Override + public AtlasSourceType getType() { + return null; + } + }); + } + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java new file mode 100644 index 0000000..7a6cfa1 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/AtlasPreparationMixin.java @@ -0,0 +1,22 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.render.model.SpriteAtlasManager; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(SpriteAtlasManager.AtlasPreparation.class) +public abstract class AtlasPreparationMixin { + + @ModifyVariable(method = "getSprite", argsOnly = true, at = @At("HEAD")) + private Identifier citresewn$unwrapTexturePaths(Identifier id) { + if (id.getPath().endsWith(".png")) { + id = id.withPath(path -> path.substring(0, path.length() - 4)); + + if (id.getPath().startsWith("textures/")) + id = id.withPath(path -> path.substring(9)); + } + return id; + } +} 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/ResourceFinderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourceFinderMixin.java new file mode 100644 index 0000000..0abdf76 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ResourceFinderMixin.java @@ -0,0 +1,23 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.resource.ResourceFinder; +import net.minecraft.util.Identifier; +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; + +@Mixin(ResourceFinder.class) +public class ResourceFinderMixin { + + @Shadow @Final private String fileExtension; + + @Inject(method = "toResourcePath", cancellable = true, at = + @At("HEAD")) + private void citresewn$forceAbsoluteTextureIdentifier(Identifier id, CallbackInfoReturnable<Identifier> cir) { + if (id.getPath().endsWith(".png") && this.fileExtension.equals(".png")) + cir.setReturnValue(id); + } +} 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..aa367b7 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; @@ -28,7 +26,7 @@ public final class PackParser { private PackParser() {} /** * Possible CIT roots in resourcepacks ordered in increasing order of priority. */ - private static final String[] ROOTS = new String[] { "mcpatcher", "optifine", "citresewn" }; + public static final List<String> ROOTS = List.of("mcpatcher", "optifine", "citresewn"); /** * Loads a merged global property group from loaded packs making sure to respect order. @@ -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()); |