From a1b565cc5d4852c70c6e0a40a53e6530f643415d Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sun, 12 Jun 2022 12:03:57 +0200 Subject: [PATCH] Fix tests --- .../github/ladysnake/babblings/Babblings.java | 24 ++++++++++++------- .../babblings/tests/BlabberTestSuite.java | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/testmod/java/io/github/ladysnake/babblings/Babblings.java b/src/testmod/java/io/github/ladysnake/babblings/Babblings.java index 07591ee8..44cea5c4 100644 --- a/src/testmod/java/io/github/ladysnake/babblings/Babblings.java +++ b/src/testmod/java/io/github/ladysnake/babblings/Babblings.java @@ -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()); } } diff --git a/src/testmod/java/io/github/ladysnake/babblings/tests/BlabberTestSuite.java b/src/testmod/java/io/github/ladysnake/babblings/tests/BlabberTestSuite.java index 4ccdb98a..422adf38 100644 --- a/src/testmod/java/io/github/ladysnake/babblings/tests/BlabberTestSuite.java +++ b/src/testmod/java/io/github/ladysnake/babblings/tests/BlabberTestSuite.java @@ -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(); }