File size: 1,647 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package net.minecraft.resources;

import java.util.List;
import java.util.Map;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;

public class FileToIdConverter {
    private final String prefix;
    private final String extension;

    public FileToIdConverter(String p_248876_, String p_251478_) {
        this.prefix = p_248876_;
        this.extension = p_251478_;
    }

    public static FileToIdConverter json(String p_248754_) {
        return new FileToIdConverter(p_248754_, ".json");
    }

    public static FileToIdConverter registry(ResourceKey<? extends Registry<?>> p_375453_) {
        return json(Registries.elementsDirPath(p_375453_));
    }

    public ResourceLocation idToFile(ResourceLocation p_251878_) {
        return p_251878_.withPath(this.prefix + "/" + p_251878_.getPath() + this.extension);
    }

    public ResourceLocation fileToId(ResourceLocation p_249595_) {
        String s = p_249595_.getPath();
        return p_249595_.withPath(s.substring(this.prefix.length() + 1, s.length() - this.extension.length()));
    }

    public Map<ResourceLocation, Resource> listMatchingResources(ResourceManager p_252045_) {
        return p_252045_.listResources(this.prefix, p_251986_ -> p_251986_.getPath().endsWith(this.extension));
    }

    public Map<ResourceLocation, List<Resource>> listMatchingResourceStacks(ResourceManager p_249881_) {
        return p_249881_.listResourceStacks(this.prefix, p_248700_ -> p_248700_.getPath().endsWith(this.extension));
    }
}