Skip to content

Commit

Permalink
only load actions for action order that are available
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Feb 15, 2024
1 parent 75516db commit fb2f94a
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/main/java/de/teamlapen/vampirism/client/ClientConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<IAction<?>> {
private static final class IActionListTypeAdapter extends TypeAdapter<List<IAction<?>>> {

@Override
public @NotNull IAction<?> read(@NotNull JsonReader in) throws IOException {
return RegUtil.getAction(new ResourceLocation(in.nextString()));
public @NotNull List<IAction<?>> read(@NotNull JsonReader in) throws IOException {
List<IAction<?>> 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<IAction<?>> 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();
}
}

Expand Down

0 comments on commit fb2f94a

Please sign in to comment.