Skip to content

Commit

Permalink
Minor updates to the new datapack loaders.
Browse files Browse the repository at this point in the history
- Biolith 3.1 datapack API has changed; see the wiki
  • Loading branch information
gniftygnome committed Oct 2, 2024
1 parent ea76b24 commit 2fef00c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected List<BiomePlacementMarshaller> prepare(ResourceManager manager, Profil
profiler.startTick();
List<BiomePlacementMarshaller> marshallers = new ArrayList<>();

profiler.push("biolith/biome_placement");
try {
for (Map.Entry<Identifier, Resource> entry : BIOME_PLACEMENT_FINDER.findResources(manager).entrySet()) {
Resource resource = entry.getValue();
Expand All @@ -41,15 +42,13 @@ protected List<BiomePlacementMarshaller> prepare(ResourceManager manager, Profil
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
try {
profiler.push("parse");

JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
BiomePlacementMarshaller marshaller = get(BiomePlacementMarshaller.CODEC, jsonObject);
if (marshaller != null) {
marshallers.add(marshaller);
} else {
throw new RuntimeException();
}

profiler.pop();
} catch (Throwable throwable) {
try {
Expand Down Expand Up @@ -81,6 +80,7 @@ protected List<BiomePlacementMarshaller> prepare(ResourceManager manager, Profil
}
profiler.pop();

profiler.endTick();
return marshallers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,59 +31,55 @@ protected List<SurfaceGenerationMarshaller> prepare(ResourceManager manager, Pro
profiler.startTick();
List<SurfaceGenerationMarshaller> marshallers = new ArrayList<>();

for (String namespace : manager.getAllNamespaces()) {
profiler.push(namespace);
try {
for (Map.Entry<Identifier, Resource> entry : SURFACE_GENERATION_FINDER.findResources(manager).entrySet()) {
Resource resource = entry.getValue();
profiler.push("biolith/surface_generation");
try {
for (Map.Entry<Identifier, Resource> entry : SURFACE_GENERATION_FINDER.findResources(manager).entrySet()) {
Resource resource = entry.getValue();

profiler.push(resource.getPackId());
profiler.push(resource.getPackId());
try {
InputStream inputStream = resource.getInputStream();
try {
InputStream inputStream = resource.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
try {
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
try {
profiler.push("parse");

JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
SurfaceGenerationMarshaller marshaller = get(SurfaceGenerationMarshaller.CODEC, jsonObject);
if (marshaller != null) {
marshallers.add(marshaller);
} else {
throw new RuntimeException();
}

profiler.pop();
} catch (Throwable throwable) {
try {
reader.close();
} catch (Throwable closeBreak) {
throwable.addSuppressed(closeBreak);
}
throw throwable;
profiler.push("parse");
JsonObject jsonObject = JsonParser.parseReader(reader).getAsJsonObject();
SurfaceGenerationMarshaller marshaller = get(SurfaceGenerationMarshaller.CODEC, jsonObject);
if (marshaller != null) {
marshallers.add(marshaller);
} else {
throw new RuntimeException();
}
reader.close();
profiler.pop();
} catch (Throwable throwable) {
if (inputStream != null) {
try {
inputStream.close();
} catch (Throwable closeBreak) {
throwable.addSuppressed(closeBreak);
}
try {
reader.close();
} catch (Throwable closeBreak) {
throwable.addSuppressed(closeBreak);
}
throw throwable;
}
inputStream.close();
} catch (RuntimeException runtimeBreak) {
Biolith.LOGGER.warn("Parsing error loading surface generation '{}': '{}'", resource.getPackId(), runtimeBreak);
reader.close();
} catch (Throwable throwable) {
if (inputStream != null) {
try {
inputStream.close();
} catch (Throwable closeBreak) {
throwable.addSuppressed(closeBreak);
}
}
throw throwable;
}
profiler.pop();
inputStream.close();
} catch (RuntimeException runtimeBreak) {
Biolith.LOGGER.warn("Parsing error loading surface generation '{}': '{}'", resource.getPackId(), runtimeBreak);
}
} catch (IOException ignored) {
// No surface generation
profiler.pop();
}
profiler.pop();
} catch (IOException ignored) {
// No surface generation
}
profiler.pop();

profiler.endTick();
return marshallers;
Expand Down

0 comments on commit 2fef00c

Please sign in to comment.