From fb2f94a6939e236f7b1d81c56e66b05845915545 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Thu, 15 Feb 2024 17:52:26 +0100 Subject: [PATCH] only load actions for action order that are available --- .../vampirism/client/ClientConfigHelper.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java b/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java index 5f81efe70f..d92c3d70f7 100644 --- a/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java +++ b/src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java @@ -37,7 +37,7 @@ public class ClientConfigHelper { public static final Gson GSON = new GsonBuilder() - .registerTypeHierarchyAdapter(IAction.class, new IActionTypeAdapter()) + .registerTypeHierarchyAdapter(List.class, new IActionListTypeAdapter()) .registerTypeHierarchyAdapter(ResourceLocation.class, new ResourceLocationTypeAdapter()) .registerTypeHierarchyAdapter(SelectMinionTaskRadialScreen.Entry.class, new EntryTypeAdapter()) .create(); @@ -192,23 +192,31 @@ public static void saveMinionTaskOrder(@Nullable IFaction faction, @NotNull } - /** - * Gson type adapter for {@link IAction} - */ - private static final class IActionTypeAdapter extends TypeAdapter> { + private static final class IActionListTypeAdapter extends TypeAdapter>> { @Override - public @NotNull IAction read(@NotNull JsonReader in) throws IOException { - return RegUtil.getAction(new ResourceLocation(in.nextString())); + public @NotNull List> read(@NotNull JsonReader in) throws IOException { + List> actions = new ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + IAction action = RegUtil.getAction(new ResourceLocation(in.nextString())); + if (action != null) { + actions.add(action); + } + } + in.endArray(); + return actions; } @Override - public void write(@NotNull JsonWriter out, @Nullable IAction value) throws IOException { - if (value == null) { - out.nullValue(); - return; + public void write(@NotNull JsonWriter out, @Nullable List> value) throws IOException { + out.beginArray(); + if (value != null) { + for (IAction action : value) { + out.value(RegUtil.id(action).toString()); + } } - out.value(RegUtil.id(value).toString()); + out.endArray(); } }