diff --git a/changelog.md b/changelog.md index d0b0f48..86a1b1b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +------------------------------------------------------ +Version 1.5.1-mc1.20.1 +------------------------------------------------------ +**Fixes** +- Actions for the starting state now run as expected when a dialogue is started + ------------------------------------------------------ Version 1.5.0-mc1.20.1 ------------------------------------------------------ diff --git a/gradle.properties b/gradle.properties index 358344f..0aa1a52 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx2G java_version=17 # Mod Properties - mod_version = 1.5.0-mc1.20.1 + mod_version = 1.5.1-mc1.20.1 maven_group = org.ladysnake archives_base_name = blabber diff --git a/src/main/java/org/ladysnake/blabber/impl/common/PlayerDialogueTracker.java b/src/main/java/org/ladysnake/blabber/impl/common/PlayerDialogueTracker.java index da7a4f4..9b037f1 100644 --- a/src/main/java/org/ladysnake/blabber/impl/common/PlayerDialogueTracker.java +++ b/src/main/java/org/ladysnake/blabber/impl/common/PlayerDialogueTracker.java @@ -63,15 +63,16 @@ public static PlayerDialogueTracker get(PlayerEntity player) { public void startDialogue(Identifier id, @Nullable Entity interlocutor) throws CommandSyntaxException { DialogueTemplate template = DialogueRegistry.getOrEmpty(id) .orElseThrow(() -> new IllegalArgumentException("Unknown dialogue " + id)); - this.startDialogue0( + DialogueStateMachine currentDialogue = this.startDialogue0( id, template, template.start(), interlocutor ); + currentDialogue.getStartAction().ifPresent(a -> a.action().handle((ServerPlayerEntity) this.player, interlocutor)); } - private void startDialogue0(Identifier id, DialogueTemplate template, @Nullable String start, @Nullable Entity interlocutor) throws CommandSyntaxException { + private DialogueStateMachine startDialogue0(Identifier id, DialogueTemplate template, @Nullable String start, @Nullable Entity interlocutor) throws CommandSyntaxException { ServerPlayerEntity serverPlayer = ((ServerPlayerEntity) this.player); this.interlocutor = interlocutor; try { @@ -79,6 +80,7 @@ private void startDialogue0(Identifier id, DialogueTemplate template, @Nullable this.currentDialogue = new DialogueStateMachine(id, parsedTemplate, start); this.updateConditions(serverPlayer, this.currentDialogue); this.openDialogueScreen(); + return this.currentDialogue; } catch (CommandSyntaxException e) { this.interlocutor = null; throw e; @@ -109,7 +111,7 @@ public void updateDialogue() { this.endDialogue(); DialogueRegistry.getOrEmpty(oldDialogue.getId()) - .ifPresent(template -> this.tryStartDialogue( + .ifPresent(template -> this.tryResumeDialogue( oldDialogue.getId(), template, oldDialogue.getCurrentStateKey(), @@ -157,7 +159,7 @@ public void serverTick() { } else { interlocutor = null; } - tryStartDialogue(saved.dialogueId(), saved.template(), saved.selectedState(), interlocutor); + tryResumeDialogue(saved.dialogueId(), saved.template(), saved.selectedState(), interlocutor); } this.resumptionAttempts = 0; this.deserializedState = null; @@ -185,11 +187,11 @@ public void serverTick() { } } - private void tryStartDialogue(Identifier id, DialogueTemplate template, String selectedState, Entity interlocutor) { + private void tryResumeDialogue(Identifier id, DialogueTemplate template, String selectedState, Entity interlocutor) { try { this.startDialogue0(id, template, selectedState, interlocutor); } catch (CommandSyntaxException e) { - Blabber.LOGGER.error("(Blabber) Failed to load dialogue template " + id, e); + Blabber.LOGGER.error("(Blabber) Failed to load dialogue template {}", id, e); } } diff --git a/src/main/java/org/ladysnake/blabber/impl/common/machine/DialogueStateMachine.java b/src/main/java/org/ladysnake/blabber/impl/common/machine/DialogueStateMachine.java index 70aca76..6f971f2 100644 --- a/src/main/java/org/ladysnake/blabber/impl/common/machine/DialogueStateMachine.java +++ b/src/main/java/org/ladysnake/blabber/impl/common/machine/DialogueStateMachine.java @@ -179,6 +179,10 @@ public boolean isAvailable(int choice) { return this.conditionalChoices.getOrDefault(this.currentStateKey, Int2BooleanMaps.EMPTY_MAP).getOrDefault(choice, true); } + public Optional> getStartAction() { + return this.getStates().get(this.template.start()).action(); + } + /** * @throws IllegalStateException if making an invalid choice */