Skip to content

Commit

Permalink
Reduce memory usage of GTDynamicDataPack (GregTechCEu#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored May 12, 2024
1 parent f4f0ec2 commit 5883bc1
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class GTDynamicDataPack implements PackResources {

protected static final ObjectSet<String> SERVER_DOMAINS = new ObjectOpenHashSet<>();
protected static final Map<ResourceLocation, JsonObject> DATA = new HashMap<>();
protected static final Map<ResourceLocation, byte[]> DATA = new HashMap<>();

private final String name;

Expand Down Expand Up @@ -70,13 +70,13 @@ public static void addRecipe(FinishedRecipe recipe) {
if (DATA.containsKey(recipeId)) {
GTCEu.LOGGER.error("duplicated recipe: {}", recipeId);
}
DATA.put(getRecipeLocation(recipeId), recipeJson);
DATA.put(getRecipeLocation(recipeId), recipeJson.toString().getBytes(StandardCharsets.UTF_8));
if (recipe.serializeAdvancement() != null) {
JsonObject advancement = recipe.serializeAdvancement();
if (ConfigHolder.INSTANCE.dev.dumpRecipes) {
writeJson(recipe.getAdvancementId(), "advancements", parent, advancement);
}
DATA.put(getAdvancementLocation(Objects.requireNonNull(recipe.getAdvancementId())), advancement);
DATA.put(getAdvancementLocation(Objects.requireNonNull(recipe.getAdvancementId())), advancement.toString().getBytes(StandardCharsets.UTF_8));
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public static void writeJson(ResourceLocation id, @Nullable String subdir, Path
public static void addAdvancement(ResourceLocation loc, JsonObject obj) {
ResourceLocation l = getAdvancementLocation(loc);
synchronized (DATA) {
DATA.put(l, obj);
DATA.put(l, obj.toString().getBytes(StandardCharsets.UTF_8));
}
}

Expand All @@ -121,8 +121,9 @@ public IoSupplier<InputStream> getRootResource(String... elements) {
@Override
public IoSupplier<InputStream> getResource(PackType type, ResourceLocation location) {
if (type == PackType.SERVER_DATA) {
if (DATA.containsKey(location))
return () -> new ByteArrayInputStream(DATA.get(location).toString().getBytes(StandardCharsets.UTF_8));
var byteArray = DATA.get(location);
if (byteArray != null)
return () -> new ByteArrayInputStream(byteArray);
else return null;
} else {
return null;
Expand Down

0 comments on commit 5883bc1

Please sign in to comment.