diff --git a/build.gradle b/build.gradle index 4d7f8c64..c7d537fd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ plugins { - id 'fabric-loom' version '1.4.+' + id 'fabric-loom' version '1.6.+' id 'maven-publish' id "com.modrinth.minotaur" version "2.+" } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name group = project.maven_group @@ -84,30 +84,29 @@ dependencies { modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modApi include('xyz.nucleoid:server-translations-api:2.2.0+1.20.3-rc1') - modApi include('xyz.nucleoid:packet-tweaker:0.5.0+1.20.2-rc1') - modApi include('xyz.nucleoid:fantasy:0.5.0+1.20.4') + modApi include('xyz.nucleoid:server-translations-api:2.3.0+1.20.5-rc2') + modApi include('xyz.nucleoid:packet-tweaker:0.5.1+1.20.6') + modApi include('xyz.nucleoid:fantasy:0.6.0+1.20.6') modApi include('xyz.nucleoid:more-codecs:0.3.3+1.20.2') - modApi include('xyz.nucleoid:stimuli:0.4.10+1.20.4') + modApi include('xyz.nucleoid:stimuli:0.4.11+1.20.6') modApi include('xyz.nucleoid:map-templates:0.1.9+1.20.4') modApi include('xyz.nucleoid:substrate:0.2.2+1.20.1') - modApi 'eu.pb4:polymer-core:0.7.5+1.20.4' - modApi 'eu.pb4:polymer-resource-pack:0.7.5+1.20.4' - modApi 'eu.pb4:polymer-blocks:0.7.5+1.20.4' - modApi 'eu.pb4:polymer-virtual-entity:0.7.5+1.20.4' - modApi include('eu.pb4:hologram-api:0.2.5+1.20.2') - modApi include('eu.pb4:sgui:1.4.1+1.20.4') - modApi include('eu.pb4:sidebar-api:0.3.0+1.20.3') - modApi include("eu.pb4:placeholder-api:2.3.0+1.20.3") - modApi include("eu.pb4:map-canvas-api:0.2.2+1.19.4") - modApi include("eu.pb4:player-data-api:0.4.0+1.20.3") - modApi include("eu.pb4:predicate-api:0.3.0+1.20.2") + modApi 'eu.pb4:polymer-core:0.8.2+1.20.6' + modApi 'eu.pb4:polymer-resource-pack:0.8.2+1.20.6' + modApi 'eu.pb4:polymer-blocks:0.8.2+1.20.6' + modApi 'eu.pb4:polymer-virtual-entity:0.8.2+1.20.6' + modApi include('eu.pb4:sgui:1.5.1+1.20.5') + modApi include('eu.pb4:sidebar-api:0.4.0+1.20.5') + modApi include("eu.pb4:placeholder-api:2.4.0-pre.1+1.20.5") + modApi include("eu.pb4:map-canvas-api:0.3.0+1.20.6") + modApi include("eu.pb4:player-data-api:0.5.0+1.20.5") + modApi include("eu.pb4:predicate-api:0.4.0+1.20.5") modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT") modCompileOnly('xyz.nucleoid:disguiselib-fabric:1.3.2') modCompileOnly('maven.modrinth:afkdisplay:1.1.0') - modCompileOnly('eu.pb4:polymer-autohost:0.7.4+1.20.4') + modCompileOnly('eu.pb4:polymer-autohost:0.8.2+1.20.6') modCompileOnly("dev.emi:trinkets:3.7.1") testmodImplementation sourceSets.main.output @@ -123,7 +122,7 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index 272ed337..59f55f52 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,12 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 -loader_version=0.15.1 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +loader_version=0.15.10 #Fabric api -fabric_version=0.89.2+1.20.2 +fabric_version=0.99.0+1.20.6 # Mod Properties mod_version=0.6 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586a..48c0a02c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/xyz/nucleoid/plasmid/Plasmid.java b/src/main/java/xyz/nucleoid/plasmid/Plasmid.java index 077ba781..b3be6170 100644 --- a/src/main/java/xyz/nucleoid/plasmid/Plasmid.java +++ b/src/main/java/xyz/nucleoid/plasmid/Plasmid.java @@ -47,7 +47,7 @@ public final class Plasmid implements ModInitializer { public void onInitialize() { DynamicRegistries.register(GameConfigs.REGISTRY_KEY, GameConfig.DIRECT_CODEC); - Registry.register(Registries.CHUNK_GENERATOR, new Identifier(ID, "game"), GameChunkGenerator.CODEC); + Registry.register(Registries.CHUNK_GENERATOR, new Identifier(ID, "config"), GameChunkGenerator.CODEC); GamePortalConfig.register(new Identifier(ID, "single_game"), SingleGamePortalConfig.CODEC); GamePortalConfig.register(new Identifier(ID, "new_game"), NewGamePortalConfig.CODEC); @@ -57,7 +57,7 @@ public void onInitialize() { GamePortalConfig.register(new Identifier(ID, "menu"), MenuPortalConfig.CODEC); GamePortalConfig.register(new Identifier(ID, "advanced_menu"), AdvancedMenuPortalConfig.CODEC); - MenuEntryConfig.register(new Identifier(ID, "game"), GameMenuEntryConfig.CODEC); + MenuEntryConfig.register(new Identifier(ID, "config"), GameMenuEntryConfig.CODEC); MenuEntryConfig.register(new Identifier(ID, "portal"), PortalEntryConfig.CODEC); MenuEntryConfig.register(new Identifier(ID, "portal_gui"), PortalGuiEntryConfig.CODEC); @@ -106,7 +106,7 @@ private void registerCallbacks() { try { game.getBehavior().propagatingInvoker(GameActivityEvents.TICK).onTick(); } catch (Throwable t) { - game.closeWithError("An unexpected error occurred while ticking the game"); + game.closeWithError("An unexpected error occurred while ticking the config"); } } }); diff --git a/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java b/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java index 5d06c5e0..8e4a77a1 100644 --- a/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java +++ b/src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java @@ -57,7 +57,7 @@ public final class GameCommand { // @formatter:off public static void register(CommandDispatcher dispatcher) { dispatcher.register( - literal("game") + literal("config") .then(literal("open") .requires(source -> source.hasPermissionLevel(2)) .then(GameConfigArgument.argument("game_config") @@ -209,7 +209,7 @@ private static void onOpenSuccess(ServerCommandSource source, GameSpace gameSpac } private static void onOpenError(ServerCommandSource source, Throwable throwable) { - Plasmid.LOGGER.error("Failed to start game", throwable); + Plasmid.LOGGER.error("Failed to start config", throwable); var gameOpenException = GameOpenException.unwrap(throwable); @@ -405,7 +405,7 @@ private static int stopGameConfirmed(CommandContext context var message = GameTexts.Stop.stoppedBy(source); playerSet.sendMessage(message.formatted(Formatting.GRAY)); } catch (Throwable throwable) { - Plasmid.LOGGER.error("Failed to stop game", throwable); + Plasmid.LOGGER.error("Failed to stop config", throwable); playerSet.sendMessage(GameTexts.Stop.genericError().formatted(Formatting.RED)); } @@ -422,7 +422,7 @@ private static int listGames(CommandContext context) { registry.streamEntries().forEach(game -> { var id = game.registryKey().getValue(); source.sendFeedback(() -> { - String command = "/game open " + id; + String command = "/config open " + id; var link = GameConfig.name(game).copy() .setStyle(GameTexts.commandLinkStyle(command)); diff --git a/src/main/java/xyz/nucleoid/plasmid/command/GamePortalCommand.java b/src/main/java/xyz/nucleoid/plasmid/command/GamePortalCommand.java index 4212679f..5c8d7017 100644 --- a/src/main/java/xyz/nucleoid/plasmid/command/GamePortalCommand.java +++ b/src/main/java/xyz/nucleoid/plasmid/command/GamePortalCommand.java @@ -28,7 +28,7 @@ public final class GamePortalCommand { // @formatter:off public static void register(CommandDispatcher dispatcher) { dispatcher.register( - literal("game") + literal("config") .then(literal("portal") .then(literal("connect") .requires(source -> source.hasPermissionLevel(3)) diff --git a/src/main/java/xyz/nucleoid/plasmid/command/GameTestCommand.java b/src/main/java/xyz/nucleoid/plasmid/command/GameTestCommand.java index b2291a07..9cf65e6f 100644 --- a/src/main/java/xyz/nucleoid/plasmid/command/GameTestCommand.java +++ b/src/main/java/xyz/nucleoid/plasmid/command/GameTestCommand.java @@ -14,7 +14,7 @@ public final class GameTestCommand { // @formatter:off public static void register(CommandDispatcher dispatcher) { dispatcher.register( - literal("game") + literal("config") .then(literal("test") .requires(source -> source.hasPermissionLevel(2)) .then(GameConfigArgument.argument("game_config") diff --git a/src/main/java/xyz/nucleoid/plasmid/command/ui/GameJoinUi.java b/src/main/java/xyz/nucleoid/plasmid/command/ui/GameJoinUi.java index 98b42fab..31376b7e 100644 --- a/src/main/java/xyz/nucleoid/plasmid/command/ui/GameJoinUi.java +++ b/src/main/java/xyz/nucleoid/plasmid/command/ui/GameJoinUi.java @@ -114,7 +114,7 @@ private void changePage(int change) { private GuiElementBuilder createIconFor(GameSpace gameSpace) { var sourceConfig = gameSpace.getMetadata().sourceConfig(); - var element = GuiElementBuilder.from(sourceConfig.value().icon().copy()).hideFlags() + var element = GuiElementBuilder.from(sourceConfig.value().icon().copy()).hideDefaultTooltip() .setName(GameConfig.name(sourceConfig).copy()); for (var line : sourceConfig.value().description()) { @@ -133,7 +133,7 @@ private GuiElementBuilder createIconFor(GameSpace gameSpace) { Text.literal(gameSpace.getPlayers().size() + "").formatted(Formatting.YELLOW)).formatted(Formatting.GOLD)) ); - element.hideFlags(); + element.hideDefaultTooltip(); element.setCallback((a, b, c, d) -> tryJoinGame(this.getPlayer(), gameSpace)); return element; diff --git a/src/main/java/xyz/nucleoid/plasmid/event/GameEvents.java b/src/main/java/xyz/nucleoid/plasmid/event/GameEvents.java index 419b83a7..0860c662 100644 --- a/src/main/java/xyz/nucleoid/plasmid/event/GameEvents.java +++ b/src/main/java/xyz/nucleoid/plasmid/event/GameEvents.java @@ -73,15 +73,15 @@ private GameEvents() { public interface GameSpaceOpened { /** - * @param game The game and its configuration - * @param gameSpace The {@link GameSpace} the game is running in. + * @param game The config and its configuration + * @param gameSpace The {@link GameSpace} the config is running in. */ void onGameSpaceOpened(RegistryEntry> game, GameSpace gameSpace); } public interface CreateActivity { /** - * Called when the {@link GameActivity} of a {@link GameSpace} is being created (eg. when going from waiting lobby -> active game) + * Called when the {@link GameActivity} of a {@link GameSpace} is being created (eg. when going from waiting lobby -> active config) * Note: This event can be called multiple times on the same {@link GameSpace} * * @param gameSpace The {@link GameSpace} that is having its {@link GameActivity} changed. @@ -92,7 +92,7 @@ public interface CreateActivity { public interface DestroyActivity { /** - * Called when the {@link GameActivity} of a {@link GameSpace} is being destroyed (eg. when going from waiting lobby -> active game) + * Called when the {@link GameActivity} of a {@link GameSpace} is being destroyed (eg. when going from waiting lobby -> active config) * Note: This event can be called multiple times on the same {@link GameSpace} * * @param gameSpace The {@link GameSpace} that is having its {@link GameActivity} changed. @@ -103,7 +103,7 @@ public interface DestroyActivity { public interface RequestStart { /** - * @param gameSpace The {@link GameSpace} the game is in + * @param gameSpace The {@link GameSpace} the config is in * @param result The current {@link GameResult} of the request that may have been overridden by other listener, and may also be a failure * @return null if you don't want to override the result, or a {@link GameResult} if you want to override it. */ @@ -122,7 +122,7 @@ public interface CollectPlayersForJoin { * * @param gameSpace the {@link GameSpace} being joined * @param player the initial player who tried to join a {@link GameSpace} - * @param additional a set of additional players who should join the game + * @param additional a set of additional players who should join the config */ void collectPlayersForJoin(GameSpace gameSpace, ServerPlayerEntity player, Set additional); } @@ -130,7 +130,7 @@ public interface CollectPlayersForJoin { public interface PlayerJoin { /** - * @param gameSpace The {@link GameSpace} the game is running in. + * @param gameSpace The {@link GameSpace} the config is running in. * @param player the initial player who tried to join a {@link GameSpace} */ void onPlayerJoin(GameSpace gameSpace, ServerPlayerEntity player); @@ -138,7 +138,7 @@ public interface PlayerJoin { public interface PlayerLeft { /** - * @param gameSpace The {@link GameSpace} the game is running in. + * @param gameSpace The {@link GameSpace} the config is running in. * @param player the initial player who tried to join a {@link GameSpace} */ void onPlayerLeft(GameSpace gameSpace, ServerPlayerEntity player); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameCloseReason.java b/src/main/java/xyz/nucleoid/plasmid/game/GameCloseReason.java index 75278737..be94aab3 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameCloseReason.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameCloseReason.java @@ -1,26 +1,26 @@ package xyz.nucleoid.plasmid.game; /** - * Represents a reason for a game to close. + * Represents a reason for a config to close. * - *

To close a game, see {@link GameSpace#close}. - *

To listen for game closure, see {@link xyz.nucleoid.plasmid.event.GameEvents#CLOSING}. + *

To close a config, see {@link GameSpace#close}. + *

To listen for config closure, see {@link xyz.nucleoid.plasmid.event.GameEvents#CLOSING}. */ public enum GameCloseReason { /** - * Used when a game ends normally. + * Used when a config ends normally. */ FINISHED, /** - * Used when the server closes or a player manually runs a command to close the game. + * Used when the server closes or a player manually runs a command to close the config. */ CANCELED, /** - * Used when the game space is unloaded or the game's last player leaves, making the game no longer useful. + * Used when the config space is unloaded or the config's last player leaves, making the config no longer useful. */ GARBAGE_COLLECTED, /** - * Used when an exception is thrown that requires the game to close. + * Used when an exception is thrown that requires the config to close. */ ERRORED, /** diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameOpenContext.java b/src/main/java/xyz/nucleoid/plasmid/game/GameOpenContext.java index 89e27c25..a0ca8d0c 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameOpenContext.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameOpenContext.java @@ -12,22 +12,22 @@ import java.util.function.Consumer; /** - * This object is passed to game constructors, holding all relevant information needed to construct the game as well as + * This object is passed to config constructors, holding all relevant information needed to construct the config as well as * providing the access through which to create a {@link GameSpace}. * - * @param the config type passed for this game + * @param the config type passed for this config * @see GameOpenProcedure * @see GameType.Open */ public record GameOpenContext(MinecraftServer server, GameConfig game) { /** - * Creates a {@link GameOpenProcedure} that opens a game given the {@code setup} function. + * Creates a {@link GameOpenProcedure} that opens a config given the {@code setup} function. *

* This setup function should set any rules or event listeners on the given {@link GameActivity} needed for it to * function. The setup function furthermore runs on-thread and should not run any slow operations. * * @param setup the setup function for the newly constructed {@link GameActivity} - * @return a {@link GameOpenProcedure} which should be returned by a game constructor + * @return a {@link GameOpenProcedure} which should be returned by a config constructor * @see GameActivity * @see GameActivity#listen(StimulusEvent, Object) * @see GameActivity#setRule(GameRuleType, ActionResult) @@ -37,14 +37,14 @@ public GameOpenProcedure open(Consumer setup) { } /** - * Creates a {@link GameOpenProcedure} that opens a game given the {@code setup} function and creates a world. + * Creates a {@link GameOpenProcedure} that opens a config given the {@code setup} function and creates a world. *

* This setup function should set any rules or event listeners on the given {@link GameActivity} needed for it to * function. The setup function furthermore runs on-thread and should not run any slow operations. * * @param setup the setup function for the newly constructed {@link GameActivity} * @param worldConfig the configuration describing how the added world should be constructed - * @return a {@link GameOpenProcedure} which should be returned by a game constructor + * @return a {@link GameOpenProcedure} which should be returned by a config constructor * @see GameActivity * @see GameActivity#listen(StimulusEvent, Object) * @see GameActivity#setRule(GameRuleType, ActionResult) @@ -57,7 +57,7 @@ public GameOpenProcedure openWithWorld(RuntimeWorldConfig worldConfig, BiConsume } /** - * @return the configuration that this game was opened with + * @return the configuration that this config was opened with */ public C config() { return this.game.config(); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameResources.java b/src/main/java/xyz/nucleoid/plasmid/game/GameResources.java index 78775510..5bf3b7b0 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameResources.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameResources.java @@ -19,7 +19,7 @@ public synchronized void close() { try { resource.close(); } catch (Exception e) { - Plasmid.LOGGER.warn("Failed to close resource for game", e); + Plasmid.LOGGER.warn("Failed to close resource for config", e); } } this.resources.clear(); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameSpace.java b/src/main/java/xyz/nucleoid/plasmid/game/GameSpace.java index 24474036..0dbcd43e 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameSpace.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameSpace.java @@ -13,12 +13,12 @@ import java.util.function.Consumer; /** - * Represents an instance of a game, and the "space" within which it occurs. + * Represents an instance of a config, and the "space" within which it occurs. *

* The {@link GameSpace} controls all of its attached {@link ServerWorld} objects, all joined players, and all the - * behavior that takes place within the game. + * behavior that takes place within the config. *

- * Behavior should be controlled by game implementations through the use of {@link GameActivity} instances. + * Behavior should be controlled by config implementations through the use of {@link GameActivity} instances. * * @see GameType * @see GameActivity @@ -50,11 +50,11 @@ public interface GameSpace { void setActivity(Consumer builder); /** - * Submits a request to the currently active {@link GameActivity} for this game to be started. - * What a start request means is dependent on the game implementation, and a game does not necessarily need to - * respond to this event unless they wish to respond to the {@code /game start} command. + * Submits a request to the currently active {@link GameActivity} for this config to be started. + * What a start request means is dependent on the config implementation, and a config does not necessarily need to + * respond to this event unless they wish to respond to the {@code /config start} command. * - * @return a {@link GameResult} describing whether this game was successfully started, or an error if not + * @return a {@link GameResult} describing whether this config was successfully started, or an error if not * @see GameActivityEvents#REQUEST_START */ GameResult requestStart(); @@ -68,7 +68,7 @@ public interface GameSpace { *

  • {@link GamePlayerEvents#REMOVE} for every player in this {@link GameSpace}
  • *
  • {@link GameActivityEvents#DESTROY}
  • * - * @param reason the reason for this game closing + * @param reason the reason for this config closing */ void close(GameCloseReason reason); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameSpaceMetadata.java b/src/main/java/xyz/nucleoid/plasmid/game/GameSpaceMetadata.java index 6e0b234f..9deded70 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameSpaceMetadata.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameSpaceMetadata.java @@ -8,7 +8,7 @@ /** * Represents the static metadata to a {@link GameSpace} relating to how it should be referenced (by IDs) and which - * game configuration is responsible for constructing it. + * config configuration is responsible for constructing it. */ public record GameSpaceMetadata( UUID id, diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameSpacePlayers.java b/src/main/java/xyz/nucleoid/plasmid/game/GameSpacePlayers.java index 6f6b0697..9081ddb1 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameSpacePlayers.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameSpacePlayers.java @@ -16,12 +16,12 @@ */ public interface GameSpacePlayers extends PlayerSet { /** - * Screens a group of players and returns whether the collective group should be allowed into the game. + * Screens a group of players and returns whether the collective group should be allowed into the config. *

    * This logic is controlled through the active {@link GameActivity} through {@link GamePlayerEvents#SCREEN_JOINS}. * * @param players the group of players trying to join - * @return a {@link GameResult} describing whether this group can join this game, or an error if not + * @return a {@link GameResult} describing whether this group can join this config, or an error if not * @see GamePlayerEvents#SCREEN_JOINS * @see GameSpacePlayers#offer(ServerPlayerEntity) * @see xyz.nucleoid.plasmid.game.player.GamePlayerJoiner @@ -29,13 +29,13 @@ public interface GameSpacePlayers extends PlayerSet { GameResult screenJoins(Collection players); /** - * Offers an individual player to join this game. If accepted, they will be teleported into the game, and if not + * Offers an individual player to join this config. If accepted, they will be teleported into the config, and if not * an error {@link GameResult} will be returned. *

    * This logic is controlled through the active {@link GameActivity} through {@link GamePlayerEvents#OFFER}. * * @param player the player trying to join - * @return a {@link GameResult} describing whether this player joined the game, or an error if not + * @return a {@link GameResult} describing whether this player joined the config, or an error if not * @see GamePlayerEvents#OFFER * @see xyz.nucleoid.plasmid.game.player.GamePlayerJoiner */ diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java b/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java index d6eb1b56..26da799b 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java @@ -9,7 +9,7 @@ /** * Utility class containing various functions that supply {@link Text} instances. *

    - * This provides a common path for Plasmid and game implementations to share common messages. + * This provides a common path for Plasmid and config implementations to share common messages. */ public final class GameTexts { public static MutableText commandLink(String text, String command) { @@ -116,7 +116,7 @@ public static MutableText link(GameSpace gameSpace) { var hover = Text.translatable("text.plasmid.join_link_hover", GameConfig.name(gameSpace.getMetadata().sourceConfig())); return Text.translatable("text.plasmid.game.open.join") - .setStyle(commandLinkStyle("/game join " + gameSpace.getMetadata().userId(), hover)); + .setStyle(commandLinkStyle("/config join " + gameSpace.getMetadata().userId(), hover)); } public static MutableText partyJoinError(int errorCount) { @@ -148,7 +148,7 @@ public static MutableText inOtherGame() { "text.plasmid.join_result.in_other_game", commandLink( Text.translatable("text.plasmid.join_result.in_other_game.leave_this_game"), - "/game leave" + "/config leave" ) ); } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/GameType.java b/src/main/java/xyz/nucleoid/plasmid/game/GameType.java index d972e912..9003f389 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/GameType.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/GameType.java @@ -11,10 +11,10 @@ import java.util.function.Consumer; /** - * Represents a specific "type" of game. A {@link GameType} is simply responsible for taking a configuration object - * and setting up game state. + * Represents a specific "type" of config. A {@link GameType} is simply responsible for taking a configuration object + * and setting up config state. *

    - * A {@link GameType} cannot be directly interacted with from inside the game, but is instead referenced through game + * A {@link GameType} cannot be directly interacted with from inside the config, but is instead referenced through config * configurations which are stored in a datapack. * * @param the type of config that should be loaded @@ -34,11 +34,11 @@ private GameType(Identifier id, Codec configCodec, Open open) { } /** - * Registers a new {@link GameType} with the given id, codec to parse a config, and function to set up the game. + * Registers a new {@link GameType} with the given id, codec to parse a config, and function to set up the config. * - * @param identifier a unique identifier to register this game type with + * @param identifier a unique identifier to register this config type with * @param configCodec a {@link Codec} that can deserialize - * @param open a function that describes how the game should be set up, given a configuration + * @param open a function that describes how the config should be set up, given a configuration * @param the type of config that should be loadedS * @return the registered {@link GameType} instance * @see Codec @@ -77,13 +77,13 @@ public static GameType get(Identifier identifier) { public interface Open { /** - * Given a game configuration, returns a {@link GameOpenProcedure} describing how this game should be opened. + * Given a config configuration, returns a {@link GameOpenProcedure} describing how this config should be opened. *

    * This code runs off-thread, so all blocking or slow operations should run here. Logic interacting with the - * game should be run in the {@link GameActivity} setup function (see {@link GameOpenContext#open(Consumer)}). + * config should be run in the {@link GameActivity} setup function (see {@link GameOpenContext#open(Consumer)}). * * @param context the context with which to construct a {@link GameOpenContext} and access configuration - * @return a {@link GameOpenContext} describing how the game should be opened + * @return a {@link GameOpenContext} describing how the config should be opened */ GameOpenProcedure open(GameOpenContext context); } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/common/GameResourcePack.java b/src/main/java/xyz/nucleoid/plasmid/game/common/GameResourcePack.java index 6e355d98..b0179a42 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/common/GameResourcePack.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/common/GameResourcePack.java @@ -96,7 +96,7 @@ public void addTo(GameActivity activity) { } private void sendTo(ServerPlayerEntity player) { - player.networkHandler.sendPacket(new ResourcePackSendS2CPacket(this.uuid, this.url, this.hash, this.required, this.prompt)); + player.networkHandler.sendPacket(new ResourcePackSendS2CPacket(this.uuid, this.url, this.hash, this.required, Optional.ofNullable(this.prompt))); } private void unload(ServerPlayerEntity player) { diff --git a/src/main/java/xyz/nucleoid/plasmid/game/common/GameWaitingLobby.java b/src/main/java/xyz/nucleoid/plasmid/game/common/GameWaitingLobby.java index e15a2f48..40e4f92c 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/common/GameWaitingLobby.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/common/GameWaitingLobby.java @@ -33,7 +33,7 @@ /** * A very simple waiting lobby implementation that games can easily apply to their {@link GameActivity}. *

    - * This implements both control for minimum/maximum players as well as a countdown for game start, and additionally + * This implements both control for minimum/maximum players as well as a countdown for config start, and additionally * sets some basic rules which prevent players from damaging the map or each other. * * @see GameWaitingLobby#addTo(GameActivity, PlayerConfig) @@ -317,7 +317,7 @@ private boolean isActiveFull() { return true; } - // if there are no players outside of a game on the server + // if there are no players outside of a config on the server for (var world : server.getWorlds()) { if (hasActivePlayer(world) && !GameSpaceManager.get().hasGame(world)) { return false; diff --git a/src/main/java/xyz/nucleoid/plasmid/game/common/OldCombat.java b/src/main/java/xyz/nucleoid/plasmid/game/common/OldCombat.java index de4a14af..fa14155b 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/common/OldCombat.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/common/OldCombat.java @@ -1,10 +1,13 @@ package xyz.nucleoid.plasmid.game.common; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.AttributeModifierSlot; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.attribute.EntityAttribute; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.item.*; +import net.minecraft.registry.entry.RegistryEntry; import java.util.UUID; @@ -14,8 +17,8 @@ * This works by modifying the damage and attack speed attributes to match their 1.8 levels. */ public final class OldCombat { - private static final EntityAttribute DAMAGE_ATTRIBUTE = EntityAttributes.GENERIC_ATTACK_DAMAGE; - private static final EntityAttribute SPEED_ATTRIBUTE = EntityAttributes.GENERIC_ATTACK_SPEED; + private static final RegistryEntry DAMAGE_ATTRIBUTE = EntityAttributes.GENERIC_ATTACK_DAMAGE; + private static final RegistryEntry SPEED_ATTRIBUTE = EntityAttributes.GENERIC_ATTACK_SPEED; private static final UUID DAMAGE_ID = Item.ATTACK_DAMAGE_MODIFIER_ID; private static final UUID SPEED_ID = Item.ATTACK_SPEED_MODIFIER_ID; @@ -34,30 +37,31 @@ public static ItemStack applyTo(ItemStack stack) { var material = ((ToolItem) item).getMaterial(); - var defaultModifiers = item.getAttributeModifiers(EquipmentSlot.MAINHAND); + var defaultModifiers = item.getAttributeModifiers(); - if (defaultModifiers.containsKey(SPEED_ATTRIBUTE)) { + { EntityAttributeModifier modifier = createSpeedModifier(); - stack.addAttributeModifier(SPEED_ATTRIBUTE, modifier, EquipmentSlot.MAINHAND); + defaultModifiers = defaultModifiers.with(SPEED_ATTRIBUTE, modifier, AttributeModifierSlot.MAINHAND); } - if (defaultModifiers.containsKey(DAMAGE_ATTRIBUTE)) { + { float attackDamage = material.getAttackDamage(); int baseDamage = getBaseDamage(stack); EntityAttributeModifier modifier = createDamageModifier(attackDamage + baseDamage); - stack.addAttributeModifier(DAMAGE_ATTRIBUTE, modifier, EquipmentSlot.MAINHAND); - } + defaultModifiers = defaultModifiers.with(DAMAGE_ATTRIBUTE, modifier, AttributeModifierSlot.MAINHAND); + } + stack.set(DataComponentTypes.ATTRIBUTE_MODIFIERS, defaultModifiers); return stack; } private static EntityAttributeModifier createSpeedModifier() { - return new EntityAttributeModifier(SPEED_ID, "Weapon modifier", 10000.0F, EntityAttributeModifier.Operation.ADDITION); + return new EntityAttributeModifier(SPEED_ID, "Weapon modifier", 10000.0F, EntityAttributeModifier.Operation.ADD_VALUE); } private static EntityAttributeModifier createDamageModifier(double damage) { - return new EntityAttributeModifier(DAMAGE_ID, "Weapon modifier", damage, EntityAttributeModifier.Operation.ADDITION); + return new EntityAttributeModifier(DAMAGE_ID, "Weapon modifier", damage, EntityAttributeModifier.Operation.ADD_VALUE); } private static int getBaseDamage(ItemStack stack) { diff --git a/src/main/java/xyz/nucleoid/plasmid/game/common/config/PlayerConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/common/config/PlayerConfig.java index 9e749598..bdbd168c 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/common/config/PlayerConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/common/config/PlayerConfig.java @@ -9,7 +9,7 @@ /** * A standard configuration type that contains various data used by a {@link GameWaitingLobby}. *

    - * This involves values such as how many players are required in the game, or how many there can be at a maximum, as + * This involves values such as how many players are required in the config, or how many there can be at a maximum, as * well as how long players should wait in the waiting lobby given there being a sufficient number of players. * * @see GameWaitingLobby diff --git a/src/main/java/xyz/nucleoid/plasmid/game/common/team/GameTeamConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/common/team/GameTeamConfig.java index 46784fb0..63a15ffb 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/common/team/GameTeamConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/common/team/GameTeamConfig.java @@ -4,6 +4,8 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.component.type.FireworkExplosionComponent; +import net.minecraft.component.type.FireworksComponent; import net.minecraft.item.FireworkRocketItem; import net.minecraft.item.ItemStack; import net.minecraft.scoreboard.AbstractTeam; @@ -71,7 +73,7 @@ public static Builder builder(GameTeamConfig config) { return new Builder(config); } - public ItemStack createFirework(int flight, FireworkRocketItem.Type type) { + public ItemStack createFirework(int flight, FireworkExplosionComponent.Type type) { var color = this.fireworkColor().getRgb(); return ItemStackBuilder.firework(color, flight, type).build(); } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/common/team/TeamSelectionLobby.java b/src/main/java/xyz/nucleoid/plasmid/game/common/team/TeamSelectionLobby.java index 491c58ea..dd37d05a 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/common/team/TeamSelectionLobby.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/common/team/TeamSelectionLobby.java @@ -1,9 +1,12 @@ package xyz.nucleoid.plasmid.game.common.team; +import com.mojang.serialization.Codec; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Reference2IntMap; import it.unimi.dsi.fastutil.objects.Reference2IntMaps; import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.registry.tag.ItemTags; import net.minecraft.server.network.ServerPlayerEntity; @@ -24,7 +27,7 @@ import java.util.stream.Collectors; /** - * A very simple team selection lobby implementation that allows players to select a team while waiting to start a game. + * A very simple team selection lobby implementation that allows players to select a team while waiting to start a config. *

    * This makes use of {@link TeamAllocator} in order to assign players teams fairly and take into account maximum team * sizes as well as team preferences. @@ -81,9 +84,9 @@ private void onAddPlayer(ServerPlayerEntity player) { .formatted(Formatting.BOLD, config.chatFormatting()); var stack = new ItemStack(ColoredBlocks.wool(config.blockDyeColor())); - stack.setCustomName(name); + stack.set(DataComponentTypes.ITEM_NAME, name); - stack.getOrCreateNbt().putString(TEAM_KEY, team.key().id()); + stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.with(Codec.STRING.fieldOf(TEAM_KEY), team.key().id()).getOrThrow()); player.getInventory().setStack(index++, stack); } @@ -93,8 +96,8 @@ private TypedActionResult onUseItem(ServerPlayerEntity player, Hand h var stack = player.getStackInHand(hand); if (stack.isIn(ItemTags.WOOL)) { - var tag = stack.getOrCreateNbt(); - var key = new GameTeamKey(tag.getString(TEAM_KEY)); + var key = new GameTeamKey(stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT) + .get(Codec.STRING.fieldOf(TEAM_KEY)).getOrThrow()); var team = this.teams.byKey(key); if (team != null) { diff --git a/src/main/java/xyz/nucleoid/plasmid/game/config/GameConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/config/GameConfig.java index 13ad81bc..729622c4 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/config/GameConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/config/GameConfig.java @@ -50,7 +50,7 @@ public static String sourceName(RegistryEntry> config) { } /** - * @return the name for this game config, defaulted to the game type name if none is specified + * @return the name for this config config, defaulted to the config type name if none is specified */ public static Text name(final RegistryEntry> config) { var name = config.value().name; @@ -58,7 +58,7 @@ public static Text name(final RegistryEntry> config) { return name; } - var translationKey = config.getKey().map(key -> Util.createTranslationKey("game", key.getValue())) + var translationKey = config.getKey().map(key -> Util.createTranslationKey("config", key.getValue())) .filter(GameConfig::hasTranslationFor); if (translationKey.isPresent()) { return Text.translatable(translationKey.get()); @@ -78,7 +78,7 @@ public static Text shortName(final RegistryEntry> config) { } /** - * @return provided description of game, defaults to empty list + * @return provided description of config, defaults to empty list */ @Override public List description() { @@ -89,7 +89,7 @@ public List description() { } /** - * @return game configs icon, defaults to grass block + * @return config configs icon, defaults to grass block */ @Override public ItemStack icon() { diff --git a/src/main/java/xyz/nucleoid/plasmid/game/event/GameActivityEvents.java b/src/main/java/xyz/nucleoid/plasmid/game/event/GameActivityEvents.java index a4358437..77641983 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/event/GameActivityEvents.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/event/GameActivityEvents.java @@ -17,7 +17,7 @@ public final class GameActivityEvents { /** * Called when a {@link GameActivity} is set on a {@link GameSpace} through {@link GameSpace#setActivity(Consumer)}. *

    - * This event should be used for any start logic needed to be done by a game. + * This event should be used for any start logic needed to be done by a config. *

    * This event is called after {@link GameActivityEvents#CREATE} as well as after {@link GamePlayerEvents#ADD} which * will have been called for all players in this {@link GameSpace}. @@ -36,7 +36,7 @@ public final class GameActivityEvents { * Called when a {@link GameActivity} should be disabled. This happens when a {@link GameActivity} is replaced by * another on a {@link GameSpace} or when a {@link GameSpace} is closed. *

    - * This event should be used for any closing logic needed to be done by a game. + * This event should be used for any closing logic needed to be done by a config. *

    * This event is called before {@link GameActivityEvents#DESTROY} as well as before {@link GamePlayerEvents#REMOVE} * which will still be called for all players in this {@link GameSpace}. @@ -74,7 +74,7 @@ public final class GameActivityEvents { * Called when a {@link GameActivity} is finally destroyed. This can happen as a result of the {@link GameActivity} * being replaced or the {@link GameSpace} closing. *

    - * This event should be used for any final tear-down logic needed to be done by a game. + * This event should be used for any final tear-down logic needed to be done by a config. *

    * This event is called after {@link GameActivityEvents#DISABLE} as well as after {@link GamePlayerEvents#REMOVE} * which will have been called for all players in this {@link GameSpace}. @@ -103,7 +103,7 @@ public final class GameActivityEvents { }); /** - * Called when the {@code /game start} command is run by a player. + * Called when the {@code /config start} command is run by a player. *

    * This event should be used to run actual starting logic as well as to return any errors if starting is not * currently possible. diff --git a/src/main/java/xyz/nucleoid/plasmid/game/event/GamePlayerEvents.java b/src/main/java/xyz/nucleoid/plasmid/game/event/GamePlayerEvents.java index 09789900..ec45bd85 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/event/GamePlayerEvents.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/event/GamePlayerEvents.java @@ -44,7 +44,7 @@ public final class GamePlayerEvents { /** * Called when a {@link ServerPlayerEntity} is removed from a {@link GameActivity}. This involves all cases where a * {@link ServerPlayerEntity} should be no longer be tracked by a {@link GameActivity}, and is NOT limited to a - * player specifically leaving the game. + * player specifically leaving the config. *

    * This will be fired when: *

  • A {@link ServerPlayerEntity} intentionally leaves this {@link GameSpace}
  • @@ -96,10 +96,10 @@ public final class GamePlayerEvents { }); /** - * Called when a group of players try to join this game. This should be used to reject multiple players as a group, - * such as when a party tries to join but has too many players to fit into the game. + * Called when a group of players try to join this config. This should be used to reject multiple players as a group, + * such as when a party tries to join but has too many players to fit into the config. *

    - * This is called before {@link GamePlayerEvents#OFFER} which handles specifically bringing a player into the game. + * This is called before {@link GamePlayerEvents#OFFER} which handles specifically bringing a player into the config. * * @see GamePlayerEvents#OFFER */ @@ -119,7 +119,7 @@ public final class GamePlayerEvents { }); /** - * Called when a single {@link ServerPlayerEntity} tries to join this game. This event is responsible for bringing + * Called when a single {@link ServerPlayerEntity} tries to join this config. This event is responsible for bringing * the player into the {@link GameSpace} world in the correct location. *

    * Games must respond to this event in order for a player to be able to join by returning either @@ -147,7 +147,7 @@ public final class GamePlayerEvents { /** * Called when display name of {@link ServerPlayerEntity} is created. - * Can be used to manipulate it in game. + * Can be used to manipulate it in config. */ public static final StimulusEvent DISPLAY_NAME = StimulusEvent.create(Name.class, ctx -> (player, current, vanillaText) -> { try { diff --git a/src/main/java/xyz/nucleoid/plasmid/game/manager/GameSpaceManager.java b/src/main/java/xyz/nucleoid/plasmid/game/manager/GameSpaceManager.java index 2dfb3d32..090c3490 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/manager/GameSpaceManager.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/manager/GameSpaceManager.java @@ -93,7 +93,7 @@ public CompletableFuture open(RegistryEntry> con ); } - private ManagedGameSpace addGameSpace(RegistryEntry> config, RegistryEntry> source, GameOpenProcedure procedure) { + private ManagedGameSpace addGameSpace(RegistryEntry> config, RegistryEntry> sourceConfig, GameOpenProcedure procedure) { if (this.server == null) { throw new RuntimeException("Not initialized yet!"); } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java b/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java index b9f1130e..21fdc814 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/manager/ManagedGameSpace.java @@ -68,8 +68,8 @@ public void setActivity(Consumer builder) { return activity; }); } catch (Throwable throwable) { - Plasmid.LOGGER.error("An unexpected error occurred while setting game activity", throwable); - this.closeWithError("An unexpected error occurred while setting game activity"); + Plasmid.LOGGER.error("An unexpected error occurred while setting config activity", throwable); + this.closeWithError("An unexpected error occurred while setting config activity"); } } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/player/PlayerIterable.java b/src/main/java/xyz/nucleoid/plasmid/game/player/PlayerIterable.java index 7c84a4de..3bbdf0ff 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/player/PlayerIterable.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/player/PlayerIterable.java @@ -86,7 +86,7 @@ default void playSound(SoundEvent sound) { @Override default void playSound(SoundEvent sound, SoundCategory category, float volume, float pitch) { for (var player : this) { - player.playSound(sound, category, volume, pitch); + player.playSoundToPlayer(sound, category, volume, pitch); } } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/player/isolation/IsolatingPlayerTeleporter.java b/src/main/java/xyz/nucleoid/plasmid/game/player/isolation/IsolatingPlayerTeleporter.java index f4e28b96..bb27f343 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/player/isolation/IsolatingPlayerTeleporter.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/player/isolation/IsolatingPlayerTeleporter.java @@ -13,9 +13,9 @@ /** * Teleports payer in and out of a {@link GameSpace}. This involves ensuring that the player does not bring anything - * into the game space as well as to not bring anything out of the game space. + * into the config space as well as to not bring anything out of the config space. *

    - * The player's NBT must be saved on entry to a game space, and it must not be saved when exiting and instead restored. + * The player's NBT must be saved on entry to a config space, and it must not be saved when exiting and instead restored. *

    * This class is also responsible for resetting player state and sending packets such that the player is fully refreshed * after teleporting and no weird issues can arise from invalid state passing through dimensions. @@ -100,7 +100,7 @@ private void teleport(ServerPlayerEntity player, Function consumer) {} - @Deprecated(forRemoval = true) - @Nullable - default GuiProvider getGuiProvider() { - return null; - } - interface Factory { GamePortalBackend create(MinecraftServer server, Identifier id); } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/GamePortalManager.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/GamePortalManager.java index 87dc4dc9..71ade898 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/GamePortalManager.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/GamePortalManager.java @@ -93,13 +93,13 @@ private Map loadConfigs(DynamicRegistryManager reg }); result.error().ifPresent(error -> { - Plasmid.LOGGER.error("Failed to parse game portal at {}: {}", path, error.toString()); + Plasmid.LOGGER.error("Failed to parse config portal at {}: {}", path, error.toString()); }); } } catch (IOException e) { - Plasmid.LOGGER.error("Failed to read game portal at {}", path, e); + Plasmid.LOGGER.error("Failed to read config portal at {}", path, e); } catch (JsonParseException e) { - Plasmid.LOGGER.error("Failed to parse game portal JSON at {}: {}", path, e); + Plasmid.LOGGER.error("Failed to parse config portal JSON at {}: {}", path, e); } }); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/ConcurrentGamePortalConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/ConcurrentGamePortalConfig.java index b168136b..298d973a 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/ConcurrentGamePortalConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/ConcurrentGamePortalConfig.java @@ -12,7 +12,7 @@ public record ConcurrentGamePortalConfig(RegistryEntry> game, CustomValuesConfig custom) implements GamePortalConfig { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group( - GameConfig.CODEC.fieldOf("game").forGetter(c -> c.game), + GameConfig.CODEC.fieldOf("config").forGetter(c -> c.game), CustomValuesConfig.CODEC.optionalFieldOf("custom", CustomValuesConfig.empty()).forGetter(c -> c.custom) ).apply(i, ConcurrentGamePortalConfig::new)); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/GameConfigGamePortalBackend.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/GameConfigGamePortalBackend.java index a2d90e7d..37ba81cf 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/GameConfigGamePortalBackend.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/GameConfigGamePortalBackend.java @@ -2,10 +2,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import xyz.nucleoid.plasmid.game.GameSpace; +import xyz.nucleoid.plasmid.game.config.GameConfig; import xyz.nucleoid.plasmid.game.config.GameConfigs; import xyz.nucleoid.plasmid.game.manager.GameSpaceManager; import xyz.nucleoid.plasmid.game.portal.GamePortalBackend; @@ -15,11 +17,11 @@ import java.util.function.Consumer; public interface GameConfigGamePortalBackend extends GamePortalBackend { - Identifier gameId(); + RegistryEntry> config(); @Override default void provideGameSpaces(Consumer consumer) { - var gameConfig = GameConfigs.get(this.gameId()); + var gameConfig = this.config(); for (var gameSpace : GameSpaceManager.get().getOpenGameSpaces()) { if (gameSpace.getMetadata().isSourceConfig(gameConfig)) { consumer.accept(gameSpace); @@ -30,7 +32,7 @@ default void provideGameSpaces(Consumer consumer) { @Override default int getPlayerCount() { int count = 0; - var gameConfig = GameConfigs.get(this.gameId()); + var gameConfig = this.config(); for (var gameSpace : GameSpaceManager.get().getOpenGameSpaces()) { if (gameSpace.getMetadata().isSourceConfig(gameConfig)) { count += gameSpace.getPlayers().size(); @@ -41,9 +43,9 @@ default int getPlayerCount() { @Override default List getDescription() { - var config = GameConfigs.get(this.gameId()); - if (config != null) { - return config.description(); + var config = this.config(); + if (config != null && config.hasKeyAndValue()) { + return config.value().description(); } return Collections.emptyList(); @@ -51,22 +53,18 @@ default List getDescription() { @Override default ItemStack getIcon() { - var config = GameConfigs.get(this.gameId()); - if (config != null) { - return config.icon(); + var config = this.config(); + if (config != null && config.hasKeyAndValue()) { + return config.value().icon(); } + return Items.BARRIER.getDefaultStack(); } @Override default Text getName() { - var config = GameConfigs.get(this.gameId()); - if (config != null) { - return config.name(); - } else { - return Text.literal(this.gameId().toString()).formatted(Formatting.RED); - } + return GameConfig.name(this.config()); } @Override diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/LegacyOnDemandPortalConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/LegacyOnDemandPortalConfig.java index 10d061d9..85b21888 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/LegacyOnDemandPortalConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/LegacyOnDemandPortalConfig.java @@ -12,7 +12,7 @@ public record LegacyOnDemandPortalConfig(RegistryEntry> game, CustomValuesConfig custom) implements GamePortalConfig { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group( - GameConfig.CODEC.fieldOf("game").forGetter(c -> c.game), + GameConfig.CODEC.fieldOf("config").forGetter(c -> c.game), CustomValuesConfig.CODEC.optionalFieldOf("custom", CustomValuesConfig.empty()).forGetter(c -> c.custom) ).apply(i, LegacyOnDemandPortalConfig::new)); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalBackend.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalBackend.java index ae9defa2..752ed3d5 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalBackend.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalBackend.java @@ -10,40 +10,13 @@ import xyz.nucleoid.plasmid.game.manager.GameSpaceManager; import xyz.nucleoid.plasmid.game.manager.ManagedGameSpace; import xyz.nucleoid.plasmid.game.player.GamePlayerJoiner; -import xyz.nucleoid.plasmid.game.portal.GamePortalBackend; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.function.Function; -public record NewGamePortalBackend(RegistryEntry> game) implements GameConfigGamePortalBackend { - @Override - public void provideGameSpaces(Consumer consumer) { - for (var gameSpace : GameSpaceManager.get().getOpenGameSpaces()) { - if (gameSpace.getMetadata().sourceConfig().equals(this.game)) { - consumer.accept(gameSpace); - } - } - } - - @Override - public int getPlayerCount() { - int count = 0; - for (var gameSpace : GameSpaceManager.get().getOpenGameSpaces()) { - if (gameSpace.getMetadata().sourceConfig().equals(this.game)) { - count += gameSpace.getPlayers().size(); - } - } - return count; - } - - @Override - public ActionType getActionType() { - return ActionType.PLAY; - } - -public record NewGamePortalBackend(Identifier gameId) implements GameConfigGamePortalBackend { +public record NewGamePortalBackend(RegistryEntry> config) implements GameConfigGamePortalBackend { @Override public void applyTo(ServerPlayerEntity player) { CompletableFuture.supplyAsync(() -> this.openGame(player.server)) @@ -62,22 +35,7 @@ public void applyTo(ServerPlayerEntity player) { }, player.server); } - @Override - public Text getName() { - return GameConfig.name(this.game); - } - - @Override - public List getDescription() { - return this.game.value().description(); - } - - @Override - public ItemStack getIcon() { - return this.game.value().icon(); - } - private CompletableFuture openGame(MinecraftServer server) { - return GameSpaceManager.get().open(this.game); + return GameSpaceManager.get().open(this.config); } } diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalConfig.java index 047c515d..5026172a 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalConfig.java @@ -12,7 +12,7 @@ public record NewGamePortalConfig(RegistryEntry> game, CustomValuesConfig custom) implements GamePortalConfig { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group( - GameConfig.CODEC.fieldOf("game").forGetter(c -> c.game), + GameConfig.CODEC.fieldOf("config").forGetter(c -> c.game), CustomValuesConfig.CODEC.optionalFieldOf("custom", CustomValuesConfig.empty()).forGetter(c -> c.custom) ).apply(i, NewGamePortalConfig::new)); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/SingleGamePortalConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/SingleGamePortalConfig.java index a3563d10..599ea625 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/game/SingleGamePortalConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/game/SingleGamePortalConfig.java @@ -12,7 +12,7 @@ public record SingleGamePortalConfig(RegistryEntry> game, CustomValuesConfig custom) implements GamePortalConfig { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group( - GameConfig.CODEC.fieldOf("game").forGetter(c -> c.game), + GameConfig.CODEC.fieldOf("config").forGetter(c -> c.game), CustomValuesConfig.CODEC.optionalFieldOf("custom", CustomValuesConfig.empty()).forGetter(c -> c.custom) ).apply(i, SingleGamePortalConfig::new)); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/AdvancedMenuPortalBackend.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/AdvancedMenuPortalBackend.java index 1e4d1629..79e50453 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/AdvancedMenuPortalBackend.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/AdvancedMenuPortalBackend.java @@ -85,11 +85,6 @@ private List getGuiElements() { return elements; } - @Override - public GuiProvider getGuiProvider() { - return this::getGuiElements; - } - private List getEntries() { if (this.entries == null) { this.entries = new ArrayList(this.entryConfigs.size()); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/GameMenuEntryConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/GameMenuEntryConfig.java index 37e98505..4c1fc547 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/GameMenuEntryConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/GameMenuEntryConfig.java @@ -20,7 +20,7 @@ public record GameMenuEntryConfig( Optional icon ) implements MenuEntryConfig { public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group( - GameConfig.CODEC.fieldOf("game").forGetter(GameMenuEntryConfig::game), + GameConfig.CODEC.fieldOf("config").forGetter(GameMenuEntryConfig::game), PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(GameMenuEntryConfig::name), MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(GameMenuEntryConfig::description), MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(GameMenuEntryConfig::icon) diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalBackend.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalBackend.java index 9d96b1b1..7da5c8ba 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalBackend.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalBackend.java @@ -77,11 +77,6 @@ private List getGuiElements() { return elements; } - @Override - public GuiProvider getGuiProvider() { - return this::getGuiElements; - } - private List buildGames(List configs) { var games = new ArrayList(configs.size()); for (var configEntry : configs) { diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalConfig.java index 22d9a8c5..50f163aa 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/MenuPortalConfig.java @@ -61,7 +61,7 @@ public record Entry(RegistryEntry> game, Optional icon) { static final Codec CODEC_OBJECT = RecordCodecBuilder.create(i -> i.group( - GameConfig.CODEC.fieldOf("game").forGetter(entry -> entry.game), + GameConfig.CODEC.fieldOf("config").forGetter(entry -> entry.game), PlasmidCodecs.TEXT.optionalFieldOf("name").forGetter(Entry::name), MoreCodecs.listOrUnit(PlasmidCodecs.TEXT).optionalFieldOf("description").forGetter(Entry::description), MoreCodecs.ITEM_STACK.optionalFieldOf("icon").forGetter(Entry::icon) diff --git a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/PortalGuiEntryConfig.java b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/PortalGuiEntryConfig.java index e18b6e2d..3dff1b95 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/PortalGuiEntryConfig.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/portal/menu/PortalGuiEntryConfig.java @@ -35,16 +35,7 @@ public MenuEntry createEntry() { var portal = GamePortalManager.INSTANCE.byId(this.portal); if (portal != null) { - var provider = portal.getGuiProvider(); - if (provider != null) { - return new PortalGuiEntry( - portal, - provider, - this.name.orElse(portal.getName()), - this.description.orElse(portal.getDescription()), - this.icon.orElse(portal.getIcon()) - ); - } + } return new InvalidMenuEntry(this.name); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/stats/StatisticKeys.java b/src/main/java/xyz/nucleoid/plasmid/game/stats/StatisticKeys.java index 6af8e57b..8f256e2f 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/stats/StatisticKeys.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/stats/StatisticKeys.java @@ -10,7 +10,7 @@ */ public final class StatisticKeys { // Games - // These are hidden as typically the value for a given game will be 0 or 1 + // These are hidden as typically the value for a given config will be 0 or 1 public static final StatisticKey GAMES_PLAYED = StatisticKey.hiddenIntKey(id("games_played"), StatisticKey.StorageType.TOTAL); public static final StatisticKey GAMES_WON = StatisticKey.hiddenIntKey(id("games_won"), StatisticKey.StorageType.TOTAL); public static final StatisticKey GAMES_LOST = StatisticKey.hiddenIntKey(id("games_lost"), StatisticKey.StorageType.TOTAL); diff --git a/src/main/java/xyz/nucleoid/plasmid/game/world/GameSpaceWorlds.java b/src/main/java/xyz/nucleoid/plasmid/game/world/GameSpaceWorlds.java index 016cf973..9068622b 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/world/GameSpaceWorlds.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/world/GameSpaceWorlds.java @@ -13,7 +13,7 @@ public interface GameSpaceWorlds extends Iterable { /** * Creates and adds a temporary world to be associated with this {@link GameSpace}. - * When the game is closed, the world will be deleted. + * When the config is closed, the world will be deleted. * * @param worldConfig a config describing how the new world should be created * @return the created world instance diff --git a/src/main/java/xyz/nucleoid/plasmid/game/world/generator/GameChunkGenerator.java b/src/main/java/xyz/nucleoid/plasmid/game/world/generator/GameChunkGenerator.java index c6df21e1..4842d03e 100644 --- a/src/main/java/xyz/nucleoid/plasmid/game/world/generator/GameChunkGenerator.java +++ b/src/main/java/xyz/nucleoid/plasmid/game/world/generator/GameChunkGenerator.java @@ -1,11 +1,10 @@ package xyz.nucleoid.plasmid.game.world.generator; import com.mojang.datafixers.util.Pair; -import com.mojang.serialization.Codec; -import com.mojang.serialization.DataResult; -import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.*; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryOps; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ChunkRegion; @@ -29,18 +28,25 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; +import java.util.stream.Stream; public abstract class GameChunkGenerator extends ChunkGenerator { - public static final Codec CODEC = new Codec<>() { + public static final MapCodec CODEC = new MapCodec<>() { @Override - public DataResult> decode(DynamicOps ops, T input) { - return Biome.REGISTRY_CODEC.decode(ops, ops.createString(BiomeKeys.THE_VOID.getValue().toString())) - .map(pair -> pair.mapFirst(VoidChunkGenerator::new)); + public Stream keys(DynamicOps ops) { + return Stream.empty(); } @Override - public DataResult encode(ChunkGenerator input, DynamicOps ops, T prefix) { - return DataResult.success(prefix); + public DataResult decode(DynamicOps ops, MapLike input) { + return DataResult.success(new VoidChunkGenerator( + ((RegistryOps) ops).getEntryLookup(RegistryKeys.BIOME).get().getOrThrow(BiomeKeys.THE_VOID) + )); + } + + @Override + public RecordBuilder encode(ChunkGenerator input, DynamicOps ops, RecordBuilder prefix) { + return prefix; } }; @@ -108,7 +114,7 @@ public int getWorldHeight() { } @Override - protected final Codec getCodec() { + protected final MapCodec getCodec() { return CODEC; } diff --git a/src/main/java/xyz/nucleoid/plasmid/mixin/game/portal/EntityMixin.java b/src/main/java/xyz/nucleoid/plasmid/mixin/game/portal/EntityMixin.java index c3551535..a2908206 100644 --- a/src/main/java/xyz/nucleoid/plasmid/mixin/game/portal/EntityMixin.java +++ b/src/main/java/xyz/nucleoid/plasmid/mixin/game/portal/EntityMixin.java @@ -1,6 +1,5 @@ package xyz.nucleoid.plasmid.mixin.game.portal; -import eu.pb4.holograms.api.holograms.AbstractHologram; import eu.pb4.polymer.virtualentity.api.ElementHolder; import eu.pb4.polymer.virtualentity.api.attachment.EntityAttachment; import eu.pb4.polymer.virtualentity.api.elements.TextDisplayElement; diff --git a/src/main/java/xyz/nucleoid/plasmid/mixin/game/space/PlayerManagerMixin.java b/src/main/java/xyz/nucleoid/plasmid/mixin/game/space/PlayerManagerMixin.java index a2cc789c..345b05db 100644 --- a/src/main/java/xyz/nucleoid/plasmid/mixin/game/space/PlayerManagerMixin.java +++ b/src/main/java/xyz/nucleoid/plasmid/mixin/game/space/PlayerManagerMixin.java @@ -118,7 +118,7 @@ private void respawnPlayer( playerData = userData; player.readNbt(userData); } else { - playerData = this.saveHandler.loadPlayerData(player); + playerData = this.saveHandler.loadPlayerData(player).orElse(null); } var dimension = playerData != null ? this.getDimensionFromData(playerData) : null; @@ -130,7 +130,7 @@ private void respawnPlayer( player.setServerWorld(world); - player.setGameMode(playerData); + player.readGameModeNbt(playerData); } @Unique diff --git a/src/main/java/xyz/nucleoid/plasmid/shop/ShopEntry.java b/src/main/java/xyz/nucleoid/plasmid/shop/ShopEntry.java index b4eb8cb5..a01fcf4b 100644 --- a/src/main/java/xyz/nucleoid/plasmid/shop/ShopEntry.java +++ b/src/main/java/xyz/nucleoid/plasmid/shop/ShopEntry.java @@ -2,6 +2,7 @@ import eu.pb4.sgui.api.elements.GuiElementInterface; import eu.pb4.sgui.api.gui.GuiInterface; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; @@ -51,7 +52,7 @@ private ItemStack defaultIconBuilder(ServerPlayerEntity player, ShopEntry entry) name.append(costText); } - icon.setCustomName(name); + icon.set(DataComponentTypes.ITEM_NAME, name); return icon; } @@ -75,7 +76,7 @@ public static ShopEntry buyItem(ItemStack stack) { var count = Text.literal(stack.getCount() + "x "); var name = icon.getName().copy().formatted(Formatting.BOLD); - icon.setCustomName(count.append(name)); + icon.set(DataComponentTypes.ITEM_NAME, count.append(name)); return new ShopEntry(icon).onBuy((player) -> player.getInventory().offerOrDrop(stack.copy())); } @@ -85,7 +86,7 @@ public static ShopEntry buyItem(ItemStack stack, Cost cost) { var count = Text.literal(stack.getCount() + "x "); var name = icon.getName().copy().formatted(Formatting.BOLD); - icon.setCustomName(count.append(name)); + icon.set(DataComponentTypes.ITEM_NAME, count.append(name)); return new ShopEntry(icon).onBuy((player) -> player.getInventory().offerOrDrop(stack.copy())).withCost(cost); } @@ -173,7 +174,7 @@ public ClickCallback getGuiCallback() { sound = SoundEvents.ENTITY_VILLAGER_NO; } - gui.getPlayer().playSound(sound, SoundCategory.MASTER, 1.0F, 1.0F); + gui.getPlayer().playSoundToPlayer(sound, SoundCategory.MASTER, 1.0F, 1.0F); }; } } diff --git a/src/main/java/xyz/nucleoid/plasmid/storage/ServerStorageManager.java b/src/main/java/xyz/nucleoid/plasmid/storage/ServerStorageManager.java index 4711137d..6a7aa7fa 100644 --- a/src/main/java/xyz/nucleoid/plasmid/storage/ServerStorageManager.java +++ b/src/main/java/xyz/nucleoid/plasmid/storage/ServerStorageManager.java @@ -3,6 +3,7 @@ import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Identifier; import net.minecraft.world.PersistentState; @@ -17,7 +18,7 @@ public final class ServerStorageManager extends PersistentState { public static ServerStorageManager get(ServerWorld world) { var type = new PersistentState.Type<>( - ServerStorageManager::new, + ServerStorageManager::new, ServerStorageManager::readNbt, null ); @@ -30,7 +31,7 @@ public static boolean isLoaded() { } @Override - public NbtCompound writeNbt(NbtCompound nbt) { + public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) { var storageList = new NbtList(); ServerStorage.STORAGES.forEach((key, value) -> { var storageTag = value.toTag(); @@ -41,7 +42,7 @@ public NbtCompound writeNbt(NbtCompound nbt) { return nbt; } - private static ServerStorageManager readNbt(NbtCompound nbt) { + private static ServerStorageManager readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) { loaded = true; var storageTags = nbt.getList("storages", NbtType.COMPOUND); diff --git a/src/main/java/xyz/nucleoid/plasmid/util/Guis.java b/src/main/java/xyz/nucleoid/plasmid/util/Guis.java index 77cece58..1ecea6c0 100644 --- a/src/main/java/xyz/nucleoid/plasmid/util/Guis.java +++ b/src/main/java/xyz/nucleoid/plasmid/util/Guis.java @@ -17,18 +17,6 @@ import java.util.Collection; public final class Guis { - private static final ItemStack[] NUMBERS = new ItemStack[] { - createBanner("{BlockEntityTag:{Patterns:[{Pattern:bs,Color:0},{Pattern:ls,Color:0},{Pattern:ts,Color:0},{Pattern:rs,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:cs,Color:0},{Pattern:tl,Color:0},{Pattern:cbo,Color:7},{Pattern:bs,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:ts,Color:0},{Pattern:mr,Color:7},{Pattern:bs,Color:0},{Pattern:dls,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:bs,Color:0},{Pattern:ms,Color:0},{Pattern:ts,Color:0},{Pattern:cbo,Color:7},{Pattern:rs,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:ls,Color:0},{Pattern:hhb,Color:7},{Pattern:rs,Color:0},{Pattern:ms,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:bs,Color:0},{Pattern:mr,Color:7},{Pattern:ts,Color:0},{Pattern:drs,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:bs,Color:0},{Pattern:rs,Color:0},{Pattern:hh,Color:7},{Pattern:ms,Color:0},{Pattern:ts,Color:0},{Pattern:ls,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:dls,Color:0},{Pattern:ts,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:dls,Color:0},{Pattern:ts,Color:0},{Pattern:bo,Color:7}]}}"), - createBanner("{BlockEntityTag:{Patterns:[{Pattern:ls,Color:0},{Pattern:hhb,Color:7},{Pattern:ms,Color:0},{Pattern:ts,Color:0},{Pattern:rs,Color:0},{Pattern:bs,Color:0},{Pattern:bo,Color:7}]}}") - }; private Guis() { } @@ -79,7 +67,8 @@ private static void buildSelector(SlotHolder holder, GuiElementInterface... elem } public static ItemStack getNumericBanner(@Range(from = 0, to = 9) int value) { - return NUMBERS[Math.abs(value) % 10]; + //return NUMBERS[Math.abs(value) % 10]; + return ItemStack.EMPTY; } private static ScreenHandlerType selectScreenType(int rowCount) { @@ -92,15 +81,4 @@ private static ScreenHandlerType selectScreenType(int rowCount) { default -> ScreenHandlerType.GENERIC_9X6; }; } - - private static ItemStack createBanner(String nbt) { - ItemStack stack = Items.GRAY_BANNER.getDefaultStack(); - try { - stack.setNbt(StringNbtReader.parse(nbt)); - stack.setCustomName(ScreenTexts.EMPTY); - stack.addHideFlag(ItemStack.TooltipSection.ADDITIONAL); - } catch (Exception e) {} - - return stack; - } } diff --git a/src/main/java/xyz/nucleoid/plasmid/util/ItemStackBuilder.java b/src/main/java/xyz/nucleoid/plasmid/util/ItemStackBuilder.java index c5c471c8..b3dc7b65 100644 --- a/src/main/java/xyz/nucleoid/plasmid/util/ItemStackBuilder.java +++ b/src/main/java/xyz/nucleoid/plasmid/util/ItemStackBuilder.java @@ -1,7 +1,11 @@ package xyz.nucleoid.plasmid.util; +import it.unimi.dsi.fastutil.ints.IntList; import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.block.Block; +import net.minecraft.component.DataComponentType; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.*; import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.attribute.EntityAttribute; @@ -10,8 +14,13 @@ import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtString; import net.minecraft.registry.Registries; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.TagKey; import net.minecraft.text.Text; +import net.minecraft.util.Unit; +import org.jetbrains.annotations.Nullable; + +import java.util.List; public final class ItemStackBuilder { private final ItemStack stack; @@ -28,22 +37,12 @@ public static ItemStackBuilder of(ItemStack stack) { return new ItemStackBuilder(stack.copy()); } - public static ItemStackBuilder firework(int color, int flight, FireworkRocketItem.Type type) { + public static ItemStackBuilder firework(int color, int flight, FireworkExplosionComponent.Type type) { var rocket = new ItemStack(Items.FIREWORK_ROCKET, 1); - var star = new ItemStack(Items.FIREWORK_STAR); - var explosion = star.getOrCreateSubNbt("Explosion"); - - explosion.putIntArray("Colors", new int[] { color }); - explosion.putByte("Type", (byte) type.getId()); - - var fireworks = rocket.getOrCreateSubNbt("Fireworks"); - - var explosions = new NbtList(); - explosions.add(explosion); - fireworks.put("Explosions", explosions); - - fireworks.putByte("Flight", (byte) flight); + rocket.set(DataComponentTypes.FIREWORKS, new FireworksComponent(flight, List.of( + new FireworkExplosionComponent(type, IntList.of(color), IntList.of(), false, false) + ))); return new ItemStackBuilder(rocket); } @@ -58,91 +57,39 @@ public ItemStackBuilder addEnchantment(Enchantment enchantment, int level) { return this; } - public ItemStackBuilder addCanDestroy(Block block) { - var blockId = Registries.BLOCK.getId(block); - return this.addCanDestroy(blockId.toString()); - } - - public ItemStackBuilder addCanDestroy(TagKey block) { - return this.addCanDestroy("#" + block.id()); - } - - public ItemStackBuilder addCanPlaceOn(Block block) { - var blockId = Registries.BLOCK.getId(block); - return this.addCanPlaceOn(blockId.toString()); - } - - public ItemStackBuilder addCanPlaceOn(TagKey block) { - return this.addCanPlaceOn("#" + block.id()); - } - - private ItemStackBuilder addCanDestroy(String predicate) { - return this.addPredicate("CanDestroy", predicate); - } - - private ItemStackBuilder addCanPlaceOn(String predicate) { - return this.addPredicate("CanPlaceOn", predicate); - } - - private ItemStackBuilder addPredicate(String key, String predicate) { - var tag = this.stack.getOrCreateNbt(); - - NbtList predicateList; - - if (tag.contains(key, NbtType.LIST)) { - predicateList = tag.getList(key, NbtType.STRING); - } else { - predicateList = new NbtList(); - tag.put(key, predicateList); - } - - predicateList.add(NbtString.of(predicate)); - + public ItemStackBuilder set(DataComponentType type, @Nullable T value) { + this.stack.set(type,value); return this; } public ItemStackBuilder setUnbreakable() { - var tag = this.stack.getOrCreateNbt(); - tag.putBoolean("Unbreakable", true); + this.stack.set(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)); return this; } public ItemStackBuilder setDyeColor(int color) { - var item = this.stack.getItem(); - if (item instanceof DyeableItem dyeable) { - dyeable.setColor(this.stack, color); - } + this.stack.set(DataComponentTypes.DYED_COLOR, new DyedColorComponent(color, true)); return this; } public ItemStackBuilder setName(Text text) { - this.stack.setCustomName(text); + this.stack.set(DataComponentTypes.ITEM_NAME, text); return this; } public ItemStackBuilder addLore(Text text) { - var display = this.stack.getOrCreateSubNbt("display"); - - NbtList loreList; - if (display.contains("Lore", 9)) { - loreList = display.getList("Lore", 8); - } else { - loreList = new NbtList(); - display.put("Lore", loreList); - } - - loreList.add(NbtString.of(Text.Serialization.toJsonString(text))); - + this.stack.apply(DataComponentTypes.LORE, LoreComponent.DEFAULT, x -> x.with(text)); return this; } - public ItemStackBuilder addModifier(EntityAttribute attribute, EntityAttributeModifier modifier, EquipmentSlot slot) { - this.stack.addAttributeModifier(attribute, modifier, slot); + public ItemStackBuilder addModifier(RegistryEntry attribute, EntityAttributeModifier modifier, AttributeModifierSlot slot) { + this.stack.apply(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent.DEFAULT, + x -> x.with(attribute, modifier, slot)); return this; } public ItemStackBuilder setRepairCost(int repairCost) { - this.stack.setRepairCost(repairCost); + this.stack.set(DataComponentTypes.REPAIR_COST, repairCost); return this; } @@ -151,22 +98,6 @@ public ItemStackBuilder setDamage(int damage) { return this; } - public ItemStackBuilder hideFlags() { - this.stack.getOrCreateNbt().putByte("HideFlags", (byte) 127); - return this; - } - - public ItemStackBuilder hideFlag(ItemStack.TooltipSection section) { - this.stack.getOrCreateNbt().putByte("HideFlags", (byte) (this.stack.getOrCreateNbt().getByte("HideFlags") | section.getFlag()) ); - return this; - } - - public ItemStackBuilder hideFlags(byte value) { - this.stack.getOrCreateNbt().putByte("HideFlags", value); - return this; - } - - public ItemStack build() { return this.stack.copy(); }