Update text on the tribe selection screen when respawning and added the option to announce when a player joins a tribe

This commit is contained in:
Sollace 2023-01-27 23:48:44 +00:00
parent f17a682d8c
commit 485c9e764a
8 changed files with 31 additions and 16 deletions

View file

@ -5,6 +5,7 @@ import net.minecraft.world.GameRules.BooleanRule;
public interface UGameRules { public interface UGameRules {
GameRules.Key<BooleanRule> SWAP_TRIBE_ON_DEATH = GameRules.register("swapTribeOnDeath", GameRules.Category.SPAWNING, BooleanRule.create(false)); GameRules.Key<BooleanRule> SWAP_TRIBE_ON_DEATH = GameRules.register("swapTribeOnDeath", GameRules.Category.SPAWNING, BooleanRule.create(false));
GameRules.Key<BooleanRule> ANNOUNCE_TRIBE_JOINS = GameRules.register("announceTribeJoins", GameRules.Category.SPAWNING, BooleanRule.create(false));
static void bootstrap() { } static void bootstrap() { }
} }

View file

@ -20,11 +20,16 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
final Set<Race> allowedRaces; final Set<Race> allowedRaces;
final Text journeyText;
final Text choiceText;
private boolean finished; private boolean finished;
public TribeSelectionScreen(Set<Race> allowedRaces) { public TribeSelectionScreen(Set<Race> allowedRaces, String baseString) {
super(Text.translatable("gui.unicopia.tribe_selection")); super(Text.translatable(baseString));
this.allowedRaces = allowedRaces; this.allowedRaces = allowedRaces;
this.journeyText = Text.translatable(baseString + ".journey");
this.choiceText = Text.translatable(baseString + ".choice");
} }
@Override @Override
@ -39,11 +44,11 @@ public class TribeSelectionScreen extends GameGui implements HidesHud {
top += height / 8; top += height / 8;
TextBlock block = addDrawable(new TextBlock(left, top += 10, pageWidth)); 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; top += block.getBounds().height;
block = addDrawable(new TextBlock(left, top += 7, pageWidth)); 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 += block.getBounds().height;
top += 30; top += 30;

View file

@ -636,7 +636,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put); oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put);
} else { } else {
if (forcedSwap) { 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 { } else {
oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put); oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put);
} }

View file

@ -7,7 +7,6 @@ import com.sollace.fabwork.api.packets.*;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
public interface Channel { public interface Channel {
C2SPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(Unicopia.id("player_ability"), MsgPlayerAbility::read); C2SPacketType<MsgPlayerAbility<?>> CLIENT_PLAYER_ABILITY = SimpleNetworking.clientToServer(Unicopia.id("player_ability"), MsgPlayerAbility::read);
@ -40,7 +39,7 @@ public interface Channel {
race = Race.UNSET; race = Race.UNSET;
} }
if (race.isUnset()) { 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 { } else {
pony.setSpecies(race); pony.setSpecies(race);
Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString()); Unicopia.LOGGER.info("Setting {}'s race to {} due to host setting", handler.player.getDisplayName().getString(), Race.REGISTRY.getId(race).toString());

View file

@ -1,13 +1,13 @@
package com.minelittlepony.unicopia.network; package com.minelittlepony.unicopia.network;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.WorldTribeManager;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.sollace.fabwork.api.packets.HandledPacket; import com.sollace.fabwork.api.packets.HandledPacket;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.*;
/** /**
* Sent to the server when a client wants to request a species change. * 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()); player.setSpecies(newRace.isPermitted(sender) ? newRace : WorldTribeManager.forWorld((ServerWorld)player.asWorld()).getDefaultRace());
if (force) { 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(); player.onSpawn();
} }
} }

View file

@ -8,19 +8,18 @@ import com.sollace.fabwork.api.packets.Packet;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.text.Text;
public record MsgTribeSelect (Set<Race> availableRaces, Text serverMessage) implements Packet<PlayerEntity> { public record MsgTribeSelect (Set<Race> availableRaces, String serverMessage) implements Packet<PlayerEntity> {
public MsgTribeSelect(PacketByteBuf buffer) { public MsgTribeSelect(PacketByteBuf buffer) {
this( this(
buffer.readCollection(HashSet::new, buf -> buf.readRegistryValue(Race.REGISTRY)), buffer.readCollection(HashSet::new, buf -> buf.readRegistryValue(Race.REGISTRY)),
buffer.readText() buffer.readString()
); );
} }
@Override @Override
public void toBuffer(PacketByteBuf buffer) { public void toBuffer(PacketByteBuf buffer) {
buffer.writeCollection(availableRaces, (buf, race) -> buf.writeRegistryValue(Race.REGISTRY, race)); buffer.writeCollection(availableRaces, (buf, race) -> buf.writeRegistryValue(Race.REGISTRY, race));
buffer.writeText(serverMessage); buffer.writeString(serverMessage);
} }
} }

View file

@ -36,7 +36,7 @@ public class ClientNetworkHandlerImpl {
} }
private void handleTribeScreen(PlayerEntity sender, MsgTribeSelect packet) { private void handleTribeScreen(PlayerEntity sender, MsgTribeSelect packet) {
client.setScreen(new TribeSelectionScreen(packet.availableRaces())); client.setScreen(new TribeSelectionScreen(packet.availableRaces(), packet.serverMessage()));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -309,10 +309,12 @@
"gui.unicopia": "Unicopia...", "gui.unicopia": "Unicopia...",
"gui.unicopia.page_num": "%d of %d", "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": "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.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.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.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.", "gui.unicopia.tribe_selection.preference": "Your current preferred tribe is set to %s.",