JSON cache
This commit is contained in:
parent
3a5a264436
commit
90c8362c95
2 changed files with 8 additions and 3 deletions
|
@ -14,6 +14,8 @@ import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PatternsHelper {
|
public class PatternsHelper {
|
||||||
|
private static final Map<ResourceLocation, String> JSON_CACHE = Maps.newConcurrentMap();
|
||||||
|
|
||||||
public static Optional<String> createItemGenerated(ResourceLocation itemId) {
|
public static Optional<String> createItemGenerated(ResourceLocation itemId) {
|
||||||
return createJson(BasePatterns.ITEM_GENERATED, itemId);
|
return createJson(BasePatterns.ITEM_GENERATED, itemId);
|
||||||
}
|
}
|
||||||
|
@ -52,8 +54,11 @@ public class PatternsHelper {
|
||||||
public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
|
public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
|
||||||
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
||||||
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
||||||
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines()
|
String json = JSON_CACHE.get(patternId);
|
||||||
.collect(Collectors.joining());
|
if (json == null) {
|
||||||
|
json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining());
|
||||||
|
JSON_CACHE.put(patternId, json);
|
||||||
|
}
|
||||||
for (Map.Entry<String, String> texture : textures.entrySet()) {
|
for (Map.Entry<String, String> texture : textures.entrySet()) {
|
||||||
json = json.replace(texture.getKey(), texture.getValue());
|
json = json.replace(texture.getKey(), texture.getValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public abstract class ModelBakeryMixin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
states.stream().parallel().forEach(blockState -> {
|
states.forEach(blockState -> {
|
||||||
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
|
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
|
||||||
UnbakedModel model = provider.getModelVariant(stateID, blockState, cache);
|
UnbakedModel model = provider.getModelVariant(stateID, blockState, cache);
|
||||||
cache.put(stateID, model);
|
cache.put(stateID, model);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue