mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 15:03:04 +00:00
1.20.6 Initial Update
New Decompiler Runtime Official mappings ItemStacks arnt Capability providers anymore, use Vanilla's system. Co-authored-by: RealMangoRage <[email protected]> Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
1114 files changed
+24245
-28536
No files matched your search
@@ -18,12 +18,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.AbstractPackResources;
|
||||
import net.minecraft.server.packs.PackLocationInfo;
|
||||
import net.minecraft.server.packs.PackResources;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.metadata.MetadataSectionSerializer;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
import net.minecraft.server.packs.repository.Pack.Info;
|
||||
import net.minecraft.server.packs.repository.Pack.Metadata;
|
||||
import net.minecraft.server.packs.resources.IoSupplier;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -36,8 +37,8 @@ public class DelegatingPackResources extends AbstractPackResources {
|
||||
private final Map<String, List<PackResources>> namespacesAssets;
|
||||
private final Map<String, List<PackResources>> namespacesData;
|
||||
|
||||
public DelegatingPackResources(String packId, boolean isBuiltin, PackMetadataSection packMeta, List<? extends PackResources> packs) {
|
||||
super(packId, isBuiltin);
|
||||
public DelegatingPackResources(PackLocationInfo info, PackMetadataSection packMeta, List<? extends PackResources> packs) {
|
||||
super(info);
|
||||
this.packMeta = packMeta;
|
||||
this.delegates = ImmutableList.copyOf(packs);
|
||||
this.namespacesAssets = this.buildNamespaceMap(PackType.CLIENT_RESOURCES, delegates);
|
||||
@@ -114,12 +115,12 @@ public class DelegatingPackResources extends AbstractPackResources {
|
||||
|
||||
private class Supplier implements Pack.ResourcesSupplier {
|
||||
@Override
|
||||
public PackResources openPrimary(String path) {
|
||||
public PackResources openPrimary(PackLocationInfo p_332103_) {
|
||||
return DelegatingPackResources.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openFull(String path, Info info) {
|
||||
public PackResources openFull(PackLocationInfo p_330351_, Metadata p_333429_) {
|
||||
return DelegatingPackResources.this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.resource;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import net.minecraft.FileUtil;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.AbstractPackResources;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.resources.IoSupplier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Defines a resource pack from an arbitrary Path.
|
||||
* <p>
|
||||
* This is primarily intended to support including optional resource packs inside a mod,
|
||||
* such as to have alternative textures to use along with Programmer Art, or optional
|
||||
* alternative recipes for compatibility to to replace vanilla recipes.
|
||||
*/
|
||||
public class PathPackResources extends AbstractPackResources {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final Path source;
|
||||
|
||||
/**
|
||||
* Constructs a java.nio.Path-based resource pack.
|
||||
*
|
||||
* @param packId the identifier of the pack.
|
||||
* This identifier should be unique within the pack finder, preferably the name of the file or folder containing the resources.
|
||||
* @param isBuiltin whether this pack resources should be considered builtin
|
||||
* @param source the root path of the pack. This needs to point to the folder that contains "assets" and/or "data", not the asset folder itself!
|
||||
*/
|
||||
public PathPackResources(String packId, boolean isBuiltin, final Path source) {
|
||||
super(packId, isBuiltin);
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source path containing the resource pack.
|
||||
* This is used for error display.
|
||||
*
|
||||
* @return the root path of the resources.
|
||||
*/
|
||||
public Path getSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement to return a file or folder path for the given set of path components.
|
||||
*
|
||||
* @param paths One or more path strings to resolve. Can include slash-separated paths.
|
||||
* @return the resulting path, which may not exist.
|
||||
*/
|
||||
protected Path resolve(String... paths) {
|
||||
Path path = getSource();
|
||||
for (String name : paths)
|
||||
path = path.resolve(name);
|
||||
return path;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IoSupplier<InputStream> getRootResource(String... paths) {
|
||||
final Path path = resolve(paths);
|
||||
if (!Files.exists(path))
|
||||
return null;
|
||||
|
||||
return IoSupplier.create(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listResources(PackType type, String namespace, String path, ResourceOutput resourceOutput) {
|
||||
FileUtil.decomposePath(path).get()
|
||||
.ifLeft(parts -> net.minecraft.server.packs.PathPackResources.listPath(namespace, resolve(type.getDirectory(), namespace).toAbsolutePath(), parts, resourceOutput))
|
||||
.ifRight(dataResult -> LOGGER.error("Invalid path {}: {}", path, dataResult.message()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getNamespaces(PackType type) {
|
||||
return getNamespacesFromDisk(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Set<String> getNamespacesFromDisk(final PackType type) {
|
||||
try {
|
||||
Path root = resolve(type.getDirectory());
|
||||
try (Stream<Path> walker = Files.walk(root, 1)) {
|
||||
return walker
|
||||
.filter(Files::isDirectory)
|
||||
.map(root::relativize)
|
||||
.filter(p -> p.getNameCount() > 0) // Skip the root entry
|
||||
.map(p -> p.toString().replaceAll("/$", "")) // Remove the trailing slash, if present
|
||||
.filter(s -> !s.isEmpty()) // Filter empty strings, otherwise empty strings default to minecraft namespace in ResourceLocations
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (type == PackType.SERVER_DATA) // We still have to add the resource namespace if client resources exist, as we load langs (which are in assets) on server
|
||||
return this.getNamespaces(PackType.CLIENT_RESOURCES);
|
||||
else
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IoSupplier<InputStream> getResource(PackType type, ResourceLocation location) {
|
||||
return this.getRootResource(getPathFromLocation(location.getPath().startsWith("lang/") ? PackType.CLIENT_RESOURCES : type, location));
|
||||
}
|
||||
|
||||
private static String[] getPathFromLocation(PackType type, ResourceLocation location) {
|
||||
String[] parts = location.getPath().split("/");
|
||||
String[] result = new String[parts.length + 2];
|
||||
result[0] = type.getDirectory();
|
||||
result[1] = location.getNamespace();
|
||||
System.arraycopy(parts, 0, result, 2, parts.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.ROOT, "%s: %s (%s)", getClass().getName(), this.packId(), getSource());
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,16 @@ import java.util.stream.Collectors;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import net.minecraft.server.packs.repository.Pack.Info;
|
||||
import net.minecraft.server.packs.repository.Pack.Metadata;
|
||||
import net.minecraft.server.packs.repository.Pack.Position;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.packs.CompositePackResources;
|
||||
import net.minecraft.server.packs.PackLocationInfo;
|
||||
import net.minecraft.server.packs.PackResources;
|
||||
import net.minecraft.server.packs.PackSelectionConfig;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.PathPackResources;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
@@ -47,60 +51,6 @@ public class ResourcePackLoader {
|
||||
resourcePacks.addPackFinder(repo -> findPacks(repo, client));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PathPackResources createPackForMod(IModFileInfo mf) {
|
||||
return new ModPathPackResources(mf.getFile());
|
||||
}
|
||||
|
||||
private static class ModPathPackResources extends PathPackResources {
|
||||
private final IModFile mod;
|
||||
private final String[] prefix;
|
||||
|
||||
private ModPathPackResources(IModFile mod, String... prefix) {
|
||||
super(mod.getFileName(), true, mod.getFilePath());
|
||||
this.mod = mod;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Path resolve(@NotNull String... paths) {
|
||||
if (prefix != null && prefix.length > 0) {
|
||||
var tmp = new String[prefix.length + paths.length];
|
||||
System.arraycopy(prefix, 0, tmp, 0, prefix.length);
|
||||
System.arraycopy(paths, 0, tmp, prefix.length, paths.length);
|
||||
return this.mod.findResource(tmp);
|
||||
}
|
||||
return this.mod.findResource(paths);
|
||||
}
|
||||
|
||||
private static class Supplier implements Pack.ResourcesSupplier {
|
||||
private final IModFile mod;
|
||||
|
||||
private Supplier(IModFile mod) {
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openPrimary(String packId) {
|
||||
return new ModPathPackResources(mod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openFull(String packId, Info info) {
|
||||
var primary = openPrimary(packId);
|
||||
if (info.overlays().isEmpty())
|
||||
return primary;
|
||||
|
||||
var lst = new ArrayList<PackResources>(info.overlays().size());
|
||||
for (var overlay : info.overlays())
|
||||
lst.add(new ModPathPackResources(mod, overlay));
|
||||
|
||||
return new CompositePackResources(primary, lst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getPackNames() {
|
||||
return ModList.get().applyForEachModFile(mf->"mod:"+mf.getModInfos().get(0).getModId()).filter(n->!n.equals("mod:minecraft")).collect(Collectors.toList());
|
||||
}
|
||||
@@ -145,14 +95,16 @@ public class ResourcePackLoader {
|
||||
|
||||
var file = mod.getFile();
|
||||
|
||||
var supplier = new ModPathPackResources.Supplier(file);
|
||||
var root = file.findResource("");
|
||||
var supplier = new PathPackResources.PathResourcesSupplier(root);
|
||||
|
||||
var modinfo = file.getModInfos().get(0);
|
||||
var name = "mod:" + modinfo.getModId();
|
||||
var meta = Pack.readPackInfo(name, supplier, version);
|
||||
var info = new PackLocationInfo(name, Component.literal(file.getFileName()), PackSource.DEFAULT, Optional.empty());
|
||||
var meta = Pack.readPackMetadata(info, supplier, version);
|
||||
Pack pack = null;
|
||||
if (meta != null)
|
||||
pack = Pack.create(name, Component.literal(file.getFileName()), false, supplier, meta, Pack.Position.BOTTOM, false, PackSource.DEFAULT);
|
||||
pack = new Pack(info, supplier, meta, new PackSelectionConfig(false, Position.BOTTOM, false));
|
||||
|
||||
if (pack == null) {
|
||||
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
|
||||
@@ -168,8 +120,9 @@ public class ResourcePackLoader {
|
||||
}
|
||||
|
||||
if (!hiddenPacks.isEmpty()) {
|
||||
var info = new PackLocationInfo("mod_resources", Component.translatable("fml.resources.modresources", hiddenPacks.size()), PackSource.DEFAULT, Optional.empty());
|
||||
@SuppressWarnings("resource")
|
||||
var delegating = new DelegatingPackResources("mod_resources", false,
|
||||
var delegating = new DelegatingPackResources(info,
|
||||
new PackMetadataSection(
|
||||
Component.translatable("fml.resources.modresources", hiddenPacks.size()),
|
||||
version,
|
||||
@@ -181,7 +134,9 @@ public class ResourcePackLoader {
|
||||
var supplier = delegating.supplier();
|
||||
|
||||
// Create a resource pack merging all mod resources that should be hidden
|
||||
var modResourcesPack = Pack.readMetaAndCreate("mod_resources", Component.literal("Mod Resources"), true, supplier, type, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
var wrapper = new PackLocationInfo("mod_resources", Component.literal("Mod Resources"), PackSource.DEFAULT, Optional.empty());
|
||||
var wrapperCfg = new PackSelectionConfig(true, Position.BOTTOM, false);
|
||||
var modResourcesPack = Pack.readMetaAndCreate(wrapper, supplier, type, wrapperCfg);
|
||||
packAcceptor.accept(modResourcesPack);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user