From 2692193e54e4dd6c0117dcdb85368dc83bb04f1a Mon Sep 17 00:00:00 2001 From: Roman / Nea Date: Mon, 18 Apr 2022 17:33:32 +0200 Subject: Mob loot recipe PR (#81) * entity renderer (somewhat functionaL) * more modifiers and entities * Fix cookie fuckup * add neu repo as resource pack, cause why not at this point * add tabs, because i can * add extra skin parts and make less tabs * hot tall men * fix texture offsets and also parts:true * some untested changes * still broken, but better (just like me (stop being edgy nea ( no u )))) * stuff (with er skeletons * niceities * skytils interop * horseys * horseys ouch * panos * stupid tests :angery: * NPE * add drop chance * colored leather armo * finish off * move shit into hover cause items look pretty terrible * Update 2.1.md * better recipe display name * always show mobs toggle * moving parts --- .../moulberry/notenoughupdates/util/JsonUtils.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java new file mode 100644 index 00000000..916631b7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/JsonUtils.java @@ -0,0 +1,42 @@ +package io.github.moulberry.notenoughupdates.util; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class JsonUtils { + public static Stream getJsonArrayAsStream(JsonArray array) { + return StreamSupport.stream(array.spliterator(), false); + } + + public static List transformJsonArrayToList(JsonArray array, Function mapper) { + return getJsonArrayAsStream(array).map(mapper).collect(Collectors.toList()); + } + + public static List getJsonArrayOrEmpty(JsonObject rootObject, String name, Function mapper) { + if (!rootObject.has(name)) { + return Collections.emptyList(); + } + JsonElement jsonElement = rootObject.get(name); + if (jsonElement.isJsonArray()) { + return transformJsonArrayToList(jsonElement.getAsJsonArray(), mapper); + } + return Collections.emptyList(); + } + + public static JsonArray transformListToJsonArray(List things, Function mapper) { + JsonArray array = new JsonArray(); + for (T t : things) { + array.add(mapper.apply(t)); + } + return array; + } + +} -- cgit