mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-08 12:34:52 +00:00
Fix model loading from folder resource packs (#382)
This commit is contained in:
1 parent
c3cc3dc1d7
commit
47c4c69731
2 files changed
+19
-9
No files matched your search
@@ -16,14 +16,20 @@ import org.joml.Vector4f;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelDeserializer.ModelElement;
|
||||
import com.gtnewhorizon.gtnhlib.client.model.loading.ModelDeserializer.ModelElement.Face;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
|
||||
public class MissingModel extends JSONModel {
|
||||
|
||||
private static final Object2ObjectArrayMap<String, String> TEXTURES = new Object2ObjectArrayMap<>();
|
||||
static {
|
||||
TEXTURES.put("missingno", "minecraft:missingno");
|
||||
}
|
||||
|
||||
/// This has to be after [#TEXTURES] to make sure the former is initialized.
|
||||
public static final MissingModel MISSING_MODEL = new MissingModel();
|
||||
|
||||
public MissingModel() {
|
||||
super(null, true, null, Object2ObjectMaps.emptyMap(), new ArrayList<>());
|
||||
super(null, true, null, TEXTURES, new ArrayList<>());
|
||||
|
||||
final var uv = new Vector4f(0, 0, 16, 16);
|
||||
final var faces = new ArrayList<Face>();
|
||||
|
||||
+11
-7
@@ -37,21 +37,24 @@ public abstract class MixinFolderResourcePack extends AbstractResourcePack imple
|
||||
final var models = new ArrayList<String>();
|
||||
|
||||
try (var files = walk(resourcePackFile.toPath(), FileVisitOption.FOLLOW_LINKS)) {
|
||||
|
||||
final var jsons = files.filter(p -> {
|
||||
// This does two things while walking the files:
|
||||
// 1) Enumerate blockstate files and store their names
|
||||
// 2) Collect InputStreams from the model files, and pass those on for further analysis
|
||||
final var jsons = files.filter(path -> {
|
||||
// Get the relative path
|
||||
final var path = resourcePackFile.toPath().relativize(p);
|
||||
final var relPath = resourcePackFile.toPath().relativize(path);
|
||||
|
||||
// Make sure it's long enough (<domain>/<subdomain>/something.json), make sure the subdomain is
|
||||
// Make sure it's long enough (assets/<namespace>/models/something.json), make sure the subnamespace is
|
||||
// "models", make sure it's a file, and make sure it's a JSON
|
||||
if (path.getNameCount() != 3) return false;
|
||||
if (relPath.getNameCount() < 4) return false;
|
||||
if (!path.toFile().isFile()) return false;
|
||||
|
||||
final var filename = path.getFileName().toString();
|
||||
if (!filename.endsWith(".json")) return false;
|
||||
final var subdomain = path.getName(1).toString();
|
||||
|
||||
final var subdomain = relPath.getName(2).toString();
|
||||
if (subdomain.equals("blockstates")) {
|
||||
models.add(path.getName(0) + ":" + filename.split("\\.")[0]);
|
||||
models.add(relPath.getName(1) + ":" + filename.split("\\.")[0]);
|
||||
return false;
|
||||
} else return subdomain.equals("models");
|
||||
}).map(p -> {
|
||||
@@ -62,6 +65,7 @@ public abstract class MixinFolderResourcePack extends AbstractResourcePack imple
|
||||
}
|
||||
});
|
||||
|
||||
// This is the "further analysis". We read the files and scrape them for textures to load.
|
||||
textures = nhlib$getReferencedTextures(jsons, jsonParser);
|
||||
} catch (Exception e) {
|
||||
MODEL_LOGGER.warn("Failed to walk resource pack {}", this);
|
||||
|
||||
Reference in new issue
Block a user