Skip to content

Commit

Permalink
Merge tag '1.4.0' into 1.20.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	changelog.md
#	gradle.properties
#	gradle/libs.versions.toml
#	src/main/java/org/ladysnake/blabber/impl/client/BlabberClient.java
#	src/main/java/org/ladysnake/blabber/impl/common/model/DialogueState.java
#	src/main/java/org/ladysnake/blabber/impl/common/model/UnavailableAction.java
  • Loading branch information
SettingDust committed Jan 5, 2024
2 parents b8d15be + 75d22df commit af4546d
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 17 deletions.
31 changes: 31 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
------------------------------------------------------
Version 1.4.0-mc1.20.1
------------------------------------------------------

**Mod Interactions**
- REI no longer appears on the RPG dialogue screen variant

------------------------------------------------------
Version 1.3.1-mc1.20.1
------------------------------------------------------
**Fixes**
- Fixed the `/blabber` command failing to find dialogues added through regular datapacks

------------------------------------------------------
Version 1.3.0-mc1.20.1
------------------------------------------------------
**Additions**
- Added a new `DialogueActionV2` interface that lets mods act upon the interlocutor in a dialogue

------------------------------------------------------
Version 1.2.0-mc1.20.1
------------------------------------------------------
**Additions**
- Dialogues now support advanced text components, like entity selectors and scores
- You can now specify an *interlocutor* when starting a dialogue
- The interlocutor entity can be referred to in commands and texts using a new entity selector, `@interlocutor`
- It can also be referred to using a new loot condition, `blabber:interlocutor_properties`

**Changes**
- Dialogues can now be reloaded using the `/reload` command

------------------------------------------------------
Version 1.1.0-mc1.20.1
------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx2G
java_version=17

# Mod Properties
mod_version = 1.1.0-mc1.20.1
mod_version = 1.4.0-mc1.20.1
maven_group = org.ladysnake
archives_base_name = blabber

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/ladysnake/blabber/Blabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.blabber.api.DialogueActionV2;
import org.ladysnake.blabber.impl.common.BlabberCommand;
import org.ladysnake.blabber.impl.common.BlabberRegistrar;
import org.ladysnake.blabber.impl.common.CommandDialogueAction;
Expand Down Expand Up @@ -114,14 +115,25 @@ public static void registerAction(Identifier actionId, DialogueAction action) {
registerAction(actionId, Codec.unit(action));
}

/**
* Register a basic {@link DialogueAction} to handle dialogue choices.
*
* @param actionId the identifier used to reference the action in dialogue definition files
* @param action the action to run when triggered by a player
* @see #registerAction(Identifier, Codec)
*/
public static void registerAction(Identifier actionId, DialogueActionV2 action) {
registerAction(actionId, Codec.unit(action));
}

/**
* Register a configurable {@link DialogueAction} to handle dialogue choices.
*
* @param actionId the identifier used to reference the action in dialogue definition files
* @param codec a codec for deserializing dialogue actions using the given value
* @see #registerAction(Identifier, DialogueAction)
*/
public static void registerAction(Identifier actionId, Codec<? extends DialogueAction> codec) {
public static void registerAction(Identifier actionId, Codec<? extends DialogueActionV2> codec) {
Registry.register(BlabberRegistrar.ACTION_REGISTRY, actionId, codec);
}

Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/ladysnake/blabber/DialogueAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@
*/
package org.ladysnake.blabber;

import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.blabber.api.DialogueActionV2;

/**
* @see DialogueActionV2
* @see Blabber#registerAction(Identifier, DialogueAction)
*/
@FunctionalInterface
public interface DialogueAction {
public interface DialogueAction extends DialogueActionV2 {
/**
* Handles a dialogue action triggered by the given player.
*
* @param player the player executing the action
*/
void handle(ServerPlayerEntity player);

@Override
default void handle(ServerPlayerEntity player, @Nullable Entity interlocutor) {
this.handle(player);
}
}
40 changes: 40 additions & 0 deletions src/main/java/org/ladysnake/blabber/api/DialogueActionV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Blabber
* Copyright (C) 2022-2023 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package org.ladysnake.blabber.api;

import com.mojang.serialization.Codec;
import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

/**
* @see org.ladysnake.blabber.Blabber#registerAction(Identifier, DialogueActionV2)
* @see org.ladysnake.blabber.Blabber#registerAction(Identifier, Codec)
*/
@FunctionalInterface
public interface DialogueActionV2 {
/**
* Handles a dialogue action triggered by the given player.
*
* @param player the player executing the action
* @param interlocutor the entity with which the player is conversing, if any
* @see org.ladysnake.blabber.Blabber#startDialogue(ServerPlayerEntity, Identifier, Entity)
*/
void handle(ServerPlayerEntity player, @Nullable Entity interlocutor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

@ApiStatus.Experimental // half internal, expect some things to change
public class BlabberDialogueScreen extends HandledScreen<DialogueScreenHandler> {
public static final List<Identifier> DIALOGUE_ARROWS = IntStream.range(1, 6).mapToObj(i -> Blabber.id("container/dialogue/dialogue_arrow_" + i)).toList();
public static final List<Identifier> DIALOGUE_LOCKS = IntStream.range(1, 4).mapToObj(i -> Blabber.id("container/dialogue/dialogue_lock_" + i)).toList();
public static final List<Identifier> DIALOGUE_ARROWS = IntStream.range(1, 6).mapToObj(i -> Blabber.id("textures/gui/sprites/container/dialogue/dialogue_arrow_" + i + ".png")).toList();
public static final List<Identifier> DIALOGUE_LOCKS = IntStream.range(1, 4).mapToObj(i -> Blabber.id("textures/gui/sprites/container/dialogue/dialogue_lock_" + i + ".png")).toList();
public static final int DEFAULT_TITLE_GAP = 20;
public static final int DEFAULT_TEXT_MAX_WIDTH = 300;
public static final int DEFAULT_INSTRUCTIONS_BOTTOM_MARGIN = 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import org.ladysnake.blabber.Blabber;
import org.ladysnake.blabber.DialogueAction;
import org.ladysnake.blabber.api.DialogueActionV2;
import org.ladysnake.blabber.impl.common.machine.DialogueStateMachine;
import org.ladysnake.blabber.impl.common.packets.ChoiceAvailabilityPacket;
import org.ladysnake.blabber.impl.common.packets.DialogueListPacket;
Expand All @@ -58,8 +58,8 @@ public final class BlabberRegistrar implements EntityComponentInitializer {
return new DialogueScreenHandler(syncId, dialogue, interlocutor.orElse(null));
}));
public static final Identifier DIALOGUE_ACTION = Blabber.id("dialogue_action");
public static final RegistryKey<Registry<Codec<? extends DialogueAction>>> ACTION_REGISTRY_KEY = RegistryKey.ofRegistry(Blabber.id("dialogue_actions"));
public static final Registry<Codec<? extends DialogueAction>> ACTION_REGISTRY = FabricRegistryBuilder.from(
public static final RegistryKey<Registry<Codec<? extends DialogueActionV2>>> ACTION_REGISTRY_KEY = RegistryKey.ofRegistry(Blabber.id("dialogue_actions"));
public static final Registry<Codec<? extends DialogueActionV2>> ACTION_REGISTRY = FabricRegistryBuilder.from(
new SimpleRegistry<>(ACTION_REGISTRY_KEY, Lifecycle.stable(), false)
).buildAndRegister();
public static final SuggestionProvider<ServerCommandSource> ALL_DIALOGUES = SuggestionProviders.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.gson.JsonParseException;
import com.mojang.serialization.JsonOps;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys;
import net.fabricmc.fabric.api.resource.SimpleResourceReloadListener;
Expand All @@ -35,6 +36,7 @@
import net.minecraft.util.profiler.Profiler;
import org.ladysnake.blabber.Blabber;
import org.ladysnake.blabber.impl.common.model.DialogueTemplate;
import org.ladysnake.blabber.impl.common.packets.DialogueListPacket;
import org.ladysnake.blabber.impl.common.validation.DialogueLoadingException;
import org.ladysnake.blabber.impl.common.validation.DialogueValidator;
import org.ladysnake.blabber.impl.common.validation.ValidationResult;
Expand Down Expand Up @@ -107,7 +109,10 @@ public Collection<Identifier> getFabricDependencies() {
@Override
public void endDataPackReload(MinecraftServer server, LifecycledResourceManager resourceManager, boolean success) {
if (success) {
Set<Identifier> dialogueIds = DialogueRegistry.getIds();
DialogueListPacket idSyncPacket = new DialogueListPacket(dialogueIds);
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
ServerPlayNetworking.send(player, idSyncPacket);
PlayerDialogueTracker.get(player).updateDialogue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public ChoiceResult makeChoice(int choice) {

public boolean makeChoice(ServerPlayerEntity player, int choice) {
try { // Can't throw here, could cause trouble with a bad packet
ChoiceResult result = this.dialogue.choose(choice, action -> action.handle(player));
ChoiceResult result = this.dialogue.choose(choice, action -> action.handle(player, this.interlocutor));
if (result == ChoiceResult.END_DIALOGUE) {
PlayerDialogueTracker.get(player).endDialogue();
}

return true;
} catch (IllegalStateException e) {
Blabber.LOGGER.error("{} made invalid choice {} in {}#{}: {}", player.getEntityName(), choice, this.dialogue.getId(), this.getCurrentStateKey(), e.getMessage());
Blabber.LOGGER.error("{} made invalid choice {} in {}#{}: {}", player.getDisplayName(), choice, this.dialogue.getId(), this.getCurrentStateKey(), e.getMessage());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import com.mojang.serialization.Codec;
import net.minecraft.util.Identifier;
import org.ladysnake.blabber.DialogueAction;
import org.ladysnake.blabber.api.DialogueActionV2;

public record InstancedDialogueAction<A extends DialogueAction>(A action,
Codec<A> codec) {
public record InstancedDialogueAction<A extends DialogueActionV2>(A action,
Codec<A> codec) {
public static final Codec<InstancedDialogueAction<?>> CODEC = BlabberRegistrar.ACTION_REGISTRY.getCodec()
.dispatch("type", InstancedDialogueAction::codec, InstancedDialogueAction::xmap);

private static <A extends DialogueAction> Codec<InstancedDialogueAction<A>> xmap(Codec<A> c) {
private static <A extends DialogueActionV2> Codec<InstancedDialogueAction<A>> xmap(Codec<A> c) {
return c.xmap(a -> new InstancedDialogueAction<>(a, c), InstancedDialogueAction::action);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.blabber.Blabber;
import org.ladysnake.blabber.DialogueAction;
import org.ladysnake.blabber.api.DialogueActionV2;
import org.ladysnake.blabber.impl.common.InstancedDialogueAction;
import org.ladysnake.blabber.impl.common.model.ChoiceResult;
import org.ladysnake.blabber.impl.common.model.DialogueChoice;
Expand Down Expand Up @@ -167,7 +167,7 @@ public boolean isAvailable(int choice) {
/**
* @throws IllegalStateException if making an invalid choice
*/
public ChoiceResult choose(int choice, Consumer<DialogueAction> actionRunner) {
public ChoiceResult choose(int choice, Consumer<DialogueActionV2> actionRunner) {
if (choice == AvailableChoice.ESCAPE_HATCH.originalChoiceIndex() && IntStream.range(0, this.getCurrentState().choices().size()).noneMatch(this::isAvailable)) {
Blabber.LOGGER.warn("(Blabber) Escape hatch used on {}#{}", this.getId(), this.currentStateKey);
return ChoiceResult.END_DIALOGUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class BlabberOverlayDecider implements OverlayDecider {
@Override
public <R extends Screen> boolean isHandingScreen(Class<R> screen) {
return screen == BlabberDialogueScreen.class;
return BlabberDialogueScreen.class.isAssignableFrom(screen);
}

@Override
Expand Down

0 comments on commit af4546d

Please sign in to comment.