From f571baf772873e870f1f2efefb22d3a282c75c65 Mon Sep 17 00:00:00 2001 From: Hugman Date: Sun, 13 Aug 2023 18:37:32 +0200 Subject: [PATCH 1/7] Add Detailed Game Entry for menus --- .../xyz/nucleoid/extras/NucleoidExtras.java | 2 + .../game_portal/entry/DetailedGameEntry.java | 112 ++++++++++++++++++ .../entry/DetailedGameEntryConfig.java | 59 +++++++++ .../game_portal/entry/ExtraMenuEntries.java | 10 ++ .../data/nucleoid_extras/lang/en_us.json | 2 + 5 files changed, 185 insertions(+) create mode 100644 src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java create mode 100644 src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java create mode 100644 src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java diff --git a/src/main/java/xyz/nucleoid/extras/NucleoidExtras.java b/src/main/java/xyz/nucleoid/extras/NucleoidExtras.java index 4c8ea76..93c3aad 100644 --- a/src/main/java/xyz/nucleoid/extras/NucleoidExtras.java +++ b/src/main/java/xyz/nucleoid/extras/NucleoidExtras.java @@ -13,6 +13,7 @@ import xyz.nucleoid.extras.error.ExtrasErrorReporter; import xyz.nucleoid.extras.game_portal.ExtrasGamePortals; import xyz.nucleoid.extras.game_portal.ServerChangePortalBackend; +import xyz.nucleoid.extras.game_portal.entry.ExtraMenuEntries; import xyz.nucleoid.extras.integrations.NucleoidIntegrations; import xyz.nucleoid.extras.integrations.http.NucleoidHttpClient; import xyz.nucleoid.extras.lobby.*; @@ -43,6 +44,7 @@ public void onInitialize() { ExtrasErrorReporter.register(); ExtraPlaceholders.register(); ExtrasGamePortals.register(); + ExtraMenuEntries.register(); ExtraCommands.register(); PlayerDataApi.register(PlayerLobbyState.STORAGE); diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java new file mode 100644 index 0000000..b1da5a3 --- /dev/null +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java @@ -0,0 +1,112 @@ +package xyz.nucleoid.extras.game_portal.entry; + +import eu.pb4.sgui.api.elements.GuiElement; +import eu.pb4.sgui.api.elements.GuiElementBuilder; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import xyz.nucleoid.plasmid.game.GameSpace; +import xyz.nucleoid.plasmid.game.portal.GamePortal; +import xyz.nucleoid.plasmid.game.portal.GamePortalBackend; +import xyz.nucleoid.plasmid.game.portal.game.ConcurrentGamePortalBackend; +import xyz.nucleoid.plasmid.game.portal.menu.MenuEntry; + +import java.util.List; +import java.util.function.Consumer; + +public record DetailedGameEntry( + ConcurrentGamePortalBackend game, + GamePortal detailPortal, + Text name, + List description, + ItemStack icon +) implements MenuEntry { + @Override + public void click(ServerPlayerEntity player) { + this.game.applyTo(player); + } + + public void secondaryClick(ServerPlayerEntity player) { + this.detailPortal.requestJoin(player); + } + + @Override + public int getPlayerCount() { + return this.game.getPlayerCount(); + } + + @Override + public void provideGameSpaces(Consumer consumer) { + game.provideGameSpaces(consumer); + } + + @Override + public GamePortalBackend.ActionType getActionType() { + return this.game.getActionType(); + } + + public GuiElement createGuiElement() { + var element = GuiElementBuilder.from(this.icon().copy()).hideFlags() + .setName(Text.empty().append(this.name())); + + for (var line : this.description()) { + var text = line.copy(); + + if (line.getStyle().getColor() == null) { + text.setStyle(line.getStyle().withFormatting(Formatting.GRAY)); + } + + element.addLoreLine(text); + } + + var playerCount = this.getPlayerCount(); + var spectatorCount = this.getSpectatorCount(); + boolean allowSpace = true; + + if (playerCount > -1) { + if (allowSpace) { + element.addLoreLine(ScreenTexts.EMPTY); + allowSpace = false; + } + element.addLoreLine(Text.empty() + .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) + .append(Text.translatable("text.plasmid.ui.game_join.players", + Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) + ); + } + + if (spectatorCount > -1) { + if (allowSpace) { + element.addLoreLine(ScreenTexts.EMPTY); + allowSpace = false; + } + + element.addLoreLine(Text.empty() + .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) + .append(Text.translatable("text.plasmid.ui.game_join.spectators", + Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) + ); + } + + var actionType = this.getActionType(); + + if (actionType != GamePortalBackend.ActionType.NONE) { + element.addLoreLine(Text.empty().append(Text.literal(" [ ").formatted(Formatting.GRAY)) + .append(actionType.text()) + .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x76ed6f))); + } + element.addLoreLine(Text.empty().append(Text.literal(" [ ").formatted(Formatting.GRAY)) + .append(Text.translatable("text.nucleoid_extras.ui.action.more")) + .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x5e8ad6))); + + element.setCallback((index, clickType, slotActionType, gui) -> { + if (clickType.isRight) this.secondaryClick(gui.getPlayer()); + else this.click(gui.getPlayer()); + }); + + return element.build(); + } +} diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java new file mode 100644 index 0000000..4e5f469 --- /dev/null +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java @@ -0,0 +1,59 @@ +package xyz.nucleoid.extras.game_portal.entry; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import xyz.nucleoid.codecs.MoreCodecs; +import xyz.nucleoid.plasmid.game.config.GameConfigs; +import xyz.nucleoid.plasmid.game.portal.GamePortalManager; +import xyz.nucleoid.plasmid.game.portal.game.ConcurrentGamePortalBackend; +import xyz.nucleoid.plasmid.game.portal.menu.*; +import xyz.nucleoid.plasmid.util.PlasmidCodecs; + +import java.util.List; +import java.util.Optional; + +public record DetailedGameEntryConfig( + Identifier game, + Identifier detailPortal, + Optional name, + Optional> description, + Optional icon +) implements MenuEntryConfig { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Identifier.CODEC.fieldOf("game").forGetter(DetailedGameEntryConfig::game), + Identifier.CODEC.fieldOf("detail_portal").forGetter(DetailedGameEntryConfig::detailPortal), + PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(DetailedGameEntryConfig::name), + MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(DetailedGameEntryConfig::description), + MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(DetailedGameEntryConfig::icon) + ).apply(instance, DetailedGameEntryConfig::new)); + + @Override + public MenuEntry createEntry() { + var game = new ConcurrentGamePortalBackend(this.game); + var gameConfig = GameConfigs.get(this.game); + var detailPortal = GamePortalManager.INSTANCE.byId(this.detailPortal); + + if (gameConfig == null) { + return new InvalidMenuEntry(game.getName()); + } + else if (detailPortal != null) { + return new DetailedGameEntry( + game, + detailPortal, + this.name.orElse(gameConfig.name()), + this.description.orElse(gameConfig.description()), + this.icon.orElse(gameConfig.icon()) + ); + } + + return new InvalidMenuEntry(this.name); + } + + @Override + public Codec codec() { + return CODEC; + } +} diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java new file mode 100644 index 0000000..fc2b2c0 --- /dev/null +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java @@ -0,0 +1,10 @@ +package xyz.nucleoid.extras.game_portal.entry; + +import xyz.nucleoid.extras.NucleoidExtras; +import xyz.nucleoid.plasmid.game.portal.menu.MenuEntryConfig; + +public class ExtraMenuEntries { + public static void register() { + MenuEntryConfig.register(NucleoidExtras.identifier("detailed_game"), DetailedGameEntryConfig.CODEC); + } +} diff --git a/src/main/resources/data/nucleoid_extras/lang/en_us.json b/src/main/resources/data/nucleoid_extras/lang/en_us.json index ebacd48..5a7180d 100644 --- a/src/main/resources/data/nucleoid_extras/lang/en_us.json +++ b/src/main/resources/data/nucleoid_extras/lang/en_us.json @@ -370,6 +370,8 @@ "text.nucleoid_extras.statistics.waiting": "Waiting for statistics data", "text.nucleoid_extras.seconds": "%s second(s)", + "text.nucleoid_extras.ui.action.more": "Right-Click for more...", + "advancements.nucleoid_extras.root.title": "Nucleoid", "advancements.nucleoid_extras.root.description": "Advancements for Nucleoid", "advancements.nucleoid_extras.first_tater.title": "My First Tater", From 6eb5b3839fade4d8fe7b3ab3161b29a0488c11ca Mon Sep 17 00:00:00 2001 From: Hugman Date: Mon, 14 Aug 2023 11:24:56 +0200 Subject: [PATCH 2/7] rename to option portal and make it support a main portal instead of a game id --- .../game_portal/entry/ExtraMenuEntries.java | 2 +- ...dGameEntry.java => OptionPortalEntry.java} | 13 +++---- ...nfig.java => OptionPortalEntryConfig.java} | 38 ++++++++----------- 3 files changed, 23 insertions(+), 30 deletions(-) rename src/main/java/xyz/nucleoid/extras/game_portal/entry/{DetailedGameEntry.java => OptionPortalEntry.java} (92%) rename src/main/java/xyz/nucleoid/extras/game_portal/entry/{DetailedGameEntryConfig.java => OptionPortalEntryConfig.java} (55%) diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java index fc2b2c0..25b102a 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java @@ -5,6 +5,6 @@ public class ExtraMenuEntries { public static void register() { - MenuEntryConfig.register(NucleoidExtras.identifier("detailed_game"), DetailedGameEntryConfig.CODEC); + MenuEntryConfig.register(NucleoidExtras.identifier("portal/option"), OptionPortalEntryConfig.CODEC); } } diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntry.java similarity index 92% rename from src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java rename to src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntry.java index b1da5a3..7660030 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntry.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntry.java @@ -11,14 +11,13 @@ import xyz.nucleoid.plasmid.game.GameSpace; import xyz.nucleoid.plasmid.game.portal.GamePortal; import xyz.nucleoid.plasmid.game.portal.GamePortalBackend; -import xyz.nucleoid.plasmid.game.portal.game.ConcurrentGamePortalBackend; import xyz.nucleoid.plasmid.game.portal.menu.MenuEntry; import java.util.List; import java.util.function.Consumer; -public record DetailedGameEntry( - ConcurrentGamePortalBackend game, +public record OptionPortalEntry( + GamePortal portal, GamePortal detailPortal, Text name, List description, @@ -26,7 +25,7 @@ public record DetailedGameEntry( ) implements MenuEntry { @Override public void click(ServerPlayerEntity player) { - this.game.applyTo(player); + this.portal.requestJoin(player); } public void secondaryClick(ServerPlayerEntity player) { @@ -35,17 +34,17 @@ public void secondaryClick(ServerPlayerEntity player) { @Override public int getPlayerCount() { - return this.game.getPlayerCount(); + return this.portal.getPlayerCount(); } @Override public void provideGameSpaces(Consumer consumer) { - game.provideGameSpaces(consumer); + portal.provideGameSpaces(consumer); } @Override public GamePortalBackend.ActionType getActionType() { - return this.game.getActionType(); + return this.portal.getBackend().getActionType(); } public GuiElement createGuiElement() { diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java similarity index 55% rename from src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java rename to src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java index 4e5f469..c40cfbd 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/DetailedGameEntryConfig.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java @@ -6,46 +6,40 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import xyz.nucleoid.codecs.MoreCodecs; -import xyz.nucleoid.plasmid.game.config.GameConfigs; import xyz.nucleoid.plasmid.game.portal.GamePortalManager; -import xyz.nucleoid.plasmid.game.portal.game.ConcurrentGamePortalBackend; import xyz.nucleoid.plasmid.game.portal.menu.*; import xyz.nucleoid.plasmid.util.PlasmidCodecs; import java.util.List; import java.util.Optional; -public record DetailedGameEntryConfig( - Identifier game, +public record OptionPortalEntryConfig( + Identifier portal, Identifier detailPortal, Optional name, Optional> description, Optional icon ) implements MenuEntryConfig { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Identifier.CODEC.fieldOf("game").forGetter(DetailedGameEntryConfig::game), - Identifier.CODEC.fieldOf("detail_portal").forGetter(DetailedGameEntryConfig::detailPortal), - PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(DetailedGameEntryConfig::name), - MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(DetailedGameEntryConfig::description), - MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(DetailedGameEntryConfig::icon) - ).apply(instance, DetailedGameEntryConfig::new)); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Identifier.CODEC.fieldOf("portal").forGetter(OptionPortalEntryConfig::portal), + Identifier.CODEC.fieldOf("detail_portal").forGetter(OptionPortalEntryConfig::detailPortal), + PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(OptionPortalEntryConfig::name), + MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(OptionPortalEntryConfig::description), + MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(OptionPortalEntryConfig::icon) + ).apply(instance, OptionPortalEntryConfig::new)); @Override public MenuEntry createEntry() { - var game = new ConcurrentGamePortalBackend(this.game); - var gameConfig = GameConfigs.get(this.game); + var portal = GamePortalManager.INSTANCE.byId(this.detailPortal); var detailPortal = GamePortalManager.INSTANCE.byId(this.detailPortal); - if (gameConfig == null) { - return new InvalidMenuEntry(game.getName()); - } - else if (detailPortal != null) { - return new DetailedGameEntry( - game, + if (portal != null && detailPortal != null) { + return new OptionPortalEntry( + portal, detailPortal, - this.name.orElse(gameConfig.name()), - this.description.orElse(gameConfig.description()), - this.icon.orElse(gameConfig.icon()) + this.name.orElse(portal.getName()), + this.description.orElse(portal.getDescription()), + this.icon.orElse(portal.getIcon()) ); } From b7800e0596e3927f5dbf566ff9fe7e3f35f5aa7b Mon Sep 17 00:00:00 2001 From: Hugman Date: Mon, 14 Aug 2023 17:11:49 +0200 Subject: [PATCH 3/7] Update OptionPortalEntryConfig.java --- .../extras/game_portal/entry/OptionPortalEntryConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java index c40cfbd..19ba404 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java @@ -30,7 +30,7 @@ public record OptionPortalEntryConfig( @Override public MenuEntry createEntry() { - var portal = GamePortalManager.INSTANCE.byId(this.detailPortal); + var portal = GamePortalManager.INSTANCE.byId(this.portal); var detailPortal = GamePortalManager.INSTANCE.byId(this.detailPortal); if (portal != null && detailPortal != null) { From 3e4bec5652e5567642a0137c6800c93e1f939cbc Mon Sep 17 00:00:00 2001 From: Hugman Date: Tue, 15 Aug 2023 15:22:55 +0200 Subject: [PATCH 4/7] Rename to quick portal --- .../game_portal/entry/ExtraMenuEntries.java | 2 +- ...PortalEntry.java => QuickPortalEntry.java} | 38 +++++++++---------- ...onfig.java => QuickPortalEntryConfig.java} | 26 ++++++------- 3 files changed, 33 insertions(+), 33 deletions(-) rename src/main/java/xyz/nucleoid/extras/game_portal/entry/{OptionPortalEntry.java => QuickPortalEntry.java} (71%) rename src/main/java/xyz/nucleoid/extras/game_portal/entry/{OptionPortalEntryConfig.java => QuickPortalEntryConfig.java} (63%) diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java index 25b102a..c23d754 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/ExtraMenuEntries.java @@ -5,6 +5,6 @@ public class ExtraMenuEntries { public static void register() { - MenuEntryConfig.register(NucleoidExtras.identifier("portal/option"), OptionPortalEntryConfig.CODEC); + MenuEntryConfig.register(NucleoidExtras.identifier("quick_portal"), QuickPortalEntryConfig.CODEC); } } diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntry.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java similarity index 71% rename from src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntry.java rename to src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java index 7660030..77866f9 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntry.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java @@ -16,20 +16,20 @@ import java.util.List; import java.util.function.Consumer; -public record OptionPortalEntry( - GamePortal portal, - GamePortal detailPortal, - Text name, - List description, - ItemStack icon +public record QuickPortalEntry( + GamePortal portal, + GamePortal quickPortal, + Text name, + List description, + ItemStack icon ) implements MenuEntry { @Override public void click(ServerPlayerEntity player) { - this.portal.requestJoin(player); + this.quickPortal.requestJoin(player); } public void secondaryClick(ServerPlayerEntity player) { - this.detailPortal.requestJoin(player); + this.portal.requestJoin(player); } @Override @@ -49,7 +49,7 @@ public GamePortalBackend.ActionType getActionType() { public GuiElement createGuiElement() { var element = GuiElementBuilder.from(this.icon().copy()).hideFlags() - .setName(Text.empty().append(this.name())); + .setName(Text.empty().append(this.name())); for (var line : this.description()) { var text = line.copy(); @@ -71,9 +71,9 @@ public GuiElement createGuiElement() { allowSpace = false; } element.addLoreLine(Text.empty() - .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) - .append(Text.translatable("text.plasmid.ui.game_join.players", - Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) + .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) + .append(Text.translatable("text.plasmid.ui.game_join.players", + Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) ); } @@ -84,9 +84,9 @@ public GuiElement createGuiElement() { } element.addLoreLine(Text.empty() - .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) - .append(Text.translatable("text.plasmid.ui.game_join.spectators", - Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) + .append(Text.literal("» ").formatted(Formatting.DARK_GRAY)) + .append(Text.translatable("text.plasmid.ui.game_join.spectators", + Text.literal(playerCount + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) ); } @@ -94,12 +94,12 @@ public GuiElement createGuiElement() { if (actionType != GamePortalBackend.ActionType.NONE) { element.addLoreLine(Text.empty().append(Text.literal(" [ ").formatted(Formatting.GRAY)) - .append(actionType.text()) - .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x76ed6f))); + .append(actionType.text()) + .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x76ed6f))); } element.addLoreLine(Text.empty().append(Text.literal(" [ ").formatted(Formatting.GRAY)) - .append(Text.translatable("text.nucleoid_extras.ui.action.more")) - .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x5e8ad6))); + .append(Text.translatable("text.nucleoid_extras.ui.action.more")) + .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x5e8ad6))); element.setCallback((index, clickType, slotActionType, gui) -> { if (clickType.isRight) this.secondaryClick(gui.getPlayer()); diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java similarity index 63% rename from src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java rename to src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java index 19ba404..e7fd66e 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/OptionPortalEntryConfig.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java @@ -13,30 +13,30 @@ import java.util.List; import java.util.Optional; -public record OptionPortalEntryConfig( +public record QuickPortalEntryConfig( Identifier portal, - Identifier detailPortal, + Identifier quickPortal, Optional name, Optional> description, Optional icon ) implements MenuEntryConfig { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Identifier.CODEC.fieldOf("portal").forGetter(OptionPortalEntryConfig::portal), - Identifier.CODEC.fieldOf("detail_portal").forGetter(OptionPortalEntryConfig::detailPortal), - PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(OptionPortalEntryConfig::name), - MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(OptionPortalEntryConfig::description), - MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(OptionPortalEntryConfig::icon) - ).apply(instance, OptionPortalEntryConfig::new)); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Identifier.CODEC.fieldOf("portal").forGetter(QuickPortalEntryConfig::portal), + Identifier.CODEC.fieldOf("quick_portal").forGetter(QuickPortalEntryConfig::quickPortal), + PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(QuickPortalEntryConfig::name), + MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(QuickPortalEntryConfig::description), + MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(QuickPortalEntryConfig::icon) + ).apply(instance, QuickPortalEntryConfig::new)); @Override public MenuEntry createEntry() { var portal = GamePortalManager.INSTANCE.byId(this.portal); - var detailPortal = GamePortalManager.INSTANCE.byId(this.detailPortal); + var quickPortal = GamePortalManager.INSTANCE.byId(this.quickPortal); - if (portal != null && detailPortal != null) { - return new OptionPortalEntry( + if (portal != null && quickPortal != null) { + return new QuickPortalEntry( portal, - detailPortal, + quickPortal, this.name.orElse(portal.getName()), this.description.orElse(portal.getDescription()), this.icon.orElse(portal.getIcon()) From e8e42586e07110754316b4c543f6a22ce999ca74 Mon Sep 17 00:00:00 2001 From: Hugman Date: Tue, 15 Aug 2023 16:24:56 +0200 Subject: [PATCH 5/7] Update QuickPortalEntry.java --- .../xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java index 77866f9..e07daa9 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java @@ -44,7 +44,7 @@ public void provideGameSpaces(Consumer consumer) { @Override public GamePortalBackend.ActionType getActionType() { - return this.portal.getBackend().getActionType(); + return this.quickPortal.getBackend().getActionType(); } public GuiElement createGuiElement() { From 4ba56f580bbbc992901e11eda822bccd3b912e27 Mon Sep 17 00:00:00 2001 From: Hugo Landrin Date: Wed, 16 Aug 2023 12:15:03 +0200 Subject: [PATCH 6/7] Update src/main/resources/data/nucleoid_extras/lang/en_us.json Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com> --- src/main/resources/data/nucleoid_extras/lang/en_us.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/data/nucleoid_extras/lang/en_us.json b/src/main/resources/data/nucleoid_extras/lang/en_us.json index 5a7180d..c8dda33 100644 --- a/src/main/resources/data/nucleoid_extras/lang/en_us.json +++ b/src/main/resources/data/nucleoid_extras/lang/en_us.json @@ -370,7 +370,7 @@ "text.nucleoid_extras.statistics.waiting": "Waiting for statistics data", "text.nucleoid_extras.seconds": "%s second(s)", - "text.nucleoid_extras.ui.action.more": "Right-Click for more...", + "text.nucleoid_extras.ui.action.more": "Right-click for more...", "advancements.nucleoid_extras.root.title": "Nucleoid", "advancements.nucleoid_extras.root.description": "Advancements for Nucleoid", From 86680bade27bfbb25c381b5c6c6802964d1c72e6 Mon Sep 17 00:00:00 2001 From: Hugman Date: Wed, 16 Aug 2023 12:28:39 +0200 Subject: [PATCH 7/7] Add custom message --- .../nucleoid/extras/game_portal/entry/QuickPortalEntry.java | 3 ++- .../extras/game_portal/entry/QuickPortalEntryConfig.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java index e07daa9..5ce16b8 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntry.java @@ -19,6 +19,7 @@ public record QuickPortalEntry( GamePortal portal, GamePortal quickPortal, + Text message, Text name, List description, ItemStack icon @@ -98,7 +99,7 @@ public GuiElement createGuiElement() { .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x76ed6f))); } element.addLoreLine(Text.empty().append(Text.literal(" [ ").formatted(Formatting.GRAY)) - .append(Text.translatable("text.nucleoid_extras.ui.action.more")) + .append(this.message().copy()) .append(Text.literal(" ]").formatted(Formatting.GRAY)).setStyle(Style.EMPTY.withColor(0x5e8ad6))); element.setCallback((index, clickType, slotActionType, gui) -> { diff --git a/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java index e7fd66e..db0d9cb 100644 --- a/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java +++ b/src/main/java/xyz/nucleoid/extras/game_portal/entry/QuickPortalEntryConfig.java @@ -16,6 +16,7 @@ public record QuickPortalEntryConfig( Identifier portal, Identifier quickPortal, + Text message, Optional name, Optional> description, Optional icon @@ -23,6 +24,7 @@ public record QuickPortalEntryConfig( public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Identifier.CODEC.fieldOf("portal").forGetter(QuickPortalEntryConfig::portal), Identifier.CODEC.fieldOf("quick_portal").forGetter(QuickPortalEntryConfig::quickPortal), + PlasmidCodecs.TEXT.fieldOf("message").orElse(Text.translatable("text.nucleoid_extras.ui.action.more")).forGetter(QuickPortalEntryConfig::message), PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(QuickPortalEntryConfig::name), MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(QuickPortalEntryConfig::description), MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(QuickPortalEntryConfig::icon) @@ -37,6 +39,7 @@ public MenuEntry createEntry() { return new QuickPortalEntry( portal, quickPortal, + this.message, this.name.orElse(portal.getName()), this.description.orElse(portal.getDescription()), this.icon.orElse(portal.getIcon())