Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 12, 2022
1 parent 7f937f0 commit a1b565c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 16 additions & 8 deletions src/testmod/java/io/github/ladysnake/babblings/Babblings.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@
public final class Babblings implements ModInitializer {
@Override
public void onInitialize() {
// The uuh testing server does not load dynamic registries so yes
RegistryEntryAddedCallback.event(BlabberRegistrar.ACTION_REGISTRY).register((rawId, id, object) -> {
if (id.equals(new Identifier("blabber:command"))) {
Gson gson = new Gson();
JsonElement remnantChoice = gson.fromJson(new InputStreamReader(Objects.requireNonNull(Babblings.class.getResourceAsStream("/data/babblings/blabber_dialogues/remnant_choice.json"))), JsonObject.class);
Registry.register(BlabberRegistrar.BUILTIN_DIALOGUES, new Identifier("babblings:remnant_choice_builtin"), DialogueTemplate.CODEC.parse(JsonOps.INSTANCE, remnantChoice).result().orElseThrow());
}
});
Identifier commandId = new Identifier("blabber:command");
if (BlabberRegistrar.ACTION_REGISTRY.containsId(commandId)) {
registerBuiltinDialogue();
} else {
RegistryEntryAddedCallback.event(BlabberRegistrar.ACTION_REGISTRY).register((rawId, id, object) -> {
if (id.equals(commandId)) {
registerBuiltinDialogue();
}
});
}
}

private void registerBuiltinDialogue() {
Gson gson = new Gson();
JsonElement remnantChoice = gson.fromJson(new InputStreamReader(Objects.requireNonNull(Babblings.class.getResourceAsStream("/data/babblings/blabber_dialogues/remnant_choice.json"))), JsonObject.class);
Registry.register(BlabberRegistrar.BUILTIN_DIALOGUES, new Identifier("babblings:remnant_choice_builtin"), DialogueTemplate.CODEC.parse(JsonOps.INSTANCE, remnantChoice).result().orElseThrow());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public void registryGetsPopulated(TestContext ctx) {
GameTestUtil.assertTrue("dialogue registry does not match expected state",
ctx.getWorld().getRegistryManager().get(BlabberRegistrar.DIALOGUE_REGISTRY_KEY).streamEntries().map(RegistryEntry.Reference::getKey).map(k -> k.orElseThrow().getValue()).sorted().toList().equals(List.of(
new Identifier("babblings:mountain_king"),
new Identifier("babblings:remnant_choice"))
new Identifier("babblings:remnant_choice"),
new Identifier("babblings:remnant_choice_builtin")
)
));
ctx.complete();
}
Expand Down

0 comments on commit a1b565c

Please sign in to comment.