From 485c9e764a8dacf2b505655619b7219cd285cbf4 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 27 Jan 2023 23:48:44 +0000 Subject: [PATCH] Update text on the tribe selection screen when respawning and added the option to announce when a player joins a tribe --- .../com/minelittlepony/unicopia/UGameRules.java | 1 + .../unicopia/client/gui/TribeSelectionScreen.java | 13 +++++++++---- .../minelittlepony/unicopia/entity/player/Pony.java | 2 +- .../minelittlepony/unicopia/network/Channel.java | 3 +-- .../unicopia/network/MsgRequestSpeciesChange.java | 13 +++++++++++-- .../unicopia/network/MsgTribeSelect.java | 7 +++---- .../network/handler/ClientNetworkHandlerImpl.java | 2 +- src/main/resources/assets/unicopia/lang/en_us.json | 6 ++++-- 8 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/UGameRules.java b/src/main/java/com/minelittlepony/unicopia/UGameRules.java index a42b9b76..aa06c2dc 100644 --- a/src/main/java/com/minelittlepony/unicopia/UGameRules.java +++ b/src/main/java/com/minelittlepony/unicopia/UGameRules.java @@ -5,6 +5,7 @@ import net.minecraft.world.GameRules.BooleanRule; public interface UGameRules { GameRules.Key SWAP_TRIBE_ON_DEATH = GameRules.register("swapTribeOnDeath", GameRules.Category.SPAWNING, BooleanRule.create(false)); + GameRules.Key ANNOUNCE_TRIBE_JOINS = GameRules.register("announceTribeJoins", GameRules.Category.SPAWNING, BooleanRule.create(false)); static void bootstrap() { } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/TribeSelectionScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/TribeSelectionScreen.java index 19a465df..55c44635 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/TribeSelectionScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/TribeSelectionScreen.java @@ -20,11 +20,16 @@ public class TribeSelectionScreen extends GameGui implements HidesHud { final Set allowedRaces; + final Text journeyText; + final Text choiceText; + private boolean finished; - public TribeSelectionScreen(Set allowedRaces) { - super(Text.translatable("gui.unicopia.tribe_selection")); + public TribeSelectionScreen(Set allowedRaces, String baseString) { + super(Text.translatable(baseString)); this.allowedRaces = allowedRaces; + this.journeyText = Text.translatable(baseString + ".journey"); + this.choiceText = Text.translatable(baseString + ".choice"); } @Override @@ -39,11 +44,11 @@ public class TribeSelectionScreen extends GameGui implements HidesHud { top += height / 8; TextBlock block = addDrawable(new TextBlock(left, top += 10, pageWidth)); - block.getStyle().setText(Text.translatable("gui.unicopia.tribe_selection.welcome.journey")); + block.getStyle().setText(journeyText); top += block.getBounds().height; block = addDrawable(new TextBlock(left, top += 7, pageWidth)); - block.getStyle().setText(Text.translatable("gui.unicopia.tribe_selection.welcome.choice")); + block.getStyle().setText(choiceText); top += block.getBounds().height; top += 30; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 52473919..18a321dc 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -636,7 +636,7 @@ public class Pony extends Living implements Copyable, Update oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put); } else { if (forcedSwap) { - Channel.SERVER_SELECT_TRIBE.sendToPlayer(new MsgTribeSelect(Race.allPermitted(entity), Text.translatable("gui.unicopia.tribe_selection.respawn")), (ServerPlayerEntity)entity); + Channel.SERVER_SELECT_TRIBE.sendToPlayer(new MsgTribeSelect(Race.allPermitted(entity), "gui.unicopia.tribe_selection.respawn"), (ServerPlayerEntity)entity); } else { oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put); } diff --git a/src/main/java/com/minelittlepony/unicopia/network/Channel.java b/src/main/java/com/minelittlepony/unicopia/network/Channel.java index d49f3f0e..3340b0bf 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/Channel.java +++ b/src/main/java/com/minelittlepony/unicopia/network/Channel.java @@ -7,7 +7,6 @@ import com.sollace.fabwork.api.packets.*; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.Text; public interface Channel { C2SPacketType> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(Unicopia.id("player_ability"), MsgPlayerAbility::read); @@ -40,7 +39,7 @@ public interface Channel { race = Race.UNSET; } if (race.isUnset()) { - sender.sendPacket(SERVER_SELECT_TRIBE.id(), new MsgTribeSelect(Race.allPermitted(handler.player), Text.translatable("gui.unicopia.tribe_selection.journey")).toBuffer()); + sender.sendPacket(SERVER_SELECT_TRIBE.id(), new MsgTribeSelect(Race.allPermitted(handler.player), "gui.unicopia.tribe_selection.welcome").toBuffer()); } else { pony.setSpecies(race); Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString()); diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java index 2a410830..239503b0 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java @@ -1,13 +1,13 @@ package com.minelittlepony.unicopia.network; -import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.WorldTribeManager; +import com.minelittlepony.unicopia.*; import com.minelittlepony.unicopia.entity.player.Pony; import com.sollace.fabwork.api.packets.HandledPacket; import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.*; /** * Sent to the server when a client wants to request a species change. @@ -37,6 +37,15 @@ public record MsgRequestSpeciesChange ( player.setSpecies(newRace.isPermitted(sender) ? newRace : WorldTribeManager.forWorld((ServerWorld)player.asWorld()).getDefaultRace()); if (force) { + if (sender.world.getGameRules().getBoolean(UGameRules.ANNOUNCE_TRIBE_JOINS)) { + Text message = Text.translatable("respawn.reason.joined_new_tribe", + sender.getDisplayName(), + player.getActualSpecies().getDisplayName(), player.getActualSpecies().getAltDisplayName()); + sender.world.getPlayers().forEach(p -> { + ((ServerPlayerEntity)p).sendMessageToClient(message, false); + }); + } + player.onSpawn(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgTribeSelect.java b/src/main/java/com/minelittlepony/unicopia/network/MsgTribeSelect.java index 25128d8b..113ad846 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgTribeSelect.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgTribeSelect.java @@ -8,19 +8,18 @@ import com.sollace.fabwork.api.packets.Packet; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.PacketByteBuf; -import net.minecraft.text.Text; -public record MsgTribeSelect (Set availableRaces, Text serverMessage) implements Packet { +public record MsgTribeSelect (Set availableRaces, String serverMessage) implements Packet { public MsgTribeSelect(PacketByteBuf buffer) { this( buffer.readCollection(HashSet::new, buf -> buf.readRegistryValue(Race.REGISTRY)), - buffer.readText() + buffer.readString() ); } @Override public void toBuffer(PacketByteBuf buffer) { buffer.writeCollection(availableRaces, (buf, race) -> buf.writeRegistryValue(Race.REGISTRY, race)); - buffer.writeText(serverMessage); + buffer.writeString(serverMessage); } } diff --git a/src/main/java/com/minelittlepony/unicopia/network/handler/ClientNetworkHandlerImpl.java b/src/main/java/com/minelittlepony/unicopia/network/handler/ClientNetworkHandlerImpl.java index 585fe663..691479ac 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/handler/ClientNetworkHandlerImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/network/handler/ClientNetworkHandlerImpl.java @@ -36,7 +36,7 @@ public class ClientNetworkHandlerImpl { } private void handleTribeScreen(PlayerEntity sender, MsgTribeSelect packet) { - client.setScreen(new TribeSelectionScreen(packet.availableRaces())); + client.setScreen(new TribeSelectionScreen(packet.availableRaces(), packet.serverMessage())); } @SuppressWarnings("unchecked") diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index aa6693f4..44da483f 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -309,10 +309,12 @@ "gui.unicopia": "Unicopia...", "gui.unicopia.page_num": "%d of %d", - "gui.unicopia.tribe_selection": "Select Your Tribe", + "respawn.reason.joined_new_tribe": "%1$s was reborn as a %2$s", + "gui.unicopia.tribe_selection.respawn": "You have died.", "gui.unicopia.tribe_selection.respawn.journey": "But the end is not all, for at the end of every end is another beginning.", - "gui.unicopia.tribe_selection.welcome": "Welcome to Equestria!", + "gui.unicopia.tribe_selection.respawn.choice": "Choose wisely, for the choice you make now will change the world around you and the paths you may take.", + "gui.unicopia.tribe_selection.welcome": "elect Your Tribe", "gui.unicopia.tribe_selection.welcome.journey": "A journey into magic and adventure awaits, traveller! But before you go, you must select your path.", "gui.unicopia.tribe_selection.welcome.choice": "Choose wisely, for the choice you make now will change the world around you and the paths you may take.", "gui.unicopia.tribe_selection.preference": "Your current preferred tribe is set to %s.",