Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/staging/0.6' into 1.21
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	src/main/java/xyz/nucleoid/plasmid/game/GameSpaceMetadata.java
#	src/main/java/xyz/nucleoid/plasmid/game/manager/GameSpaceManager.java
#	src/main/java/xyz/nucleoid/plasmid/game/portal/game/ConcurrentGamePortalBackend.java
#	src/main/java/xyz/nucleoid/plasmid/game/portal/game/NewGamePortalBackend.java
#	src/main/java/xyz/nucleoid/plasmid/game/portal/game/SingleGamePortalBackend.java
  • Loading branch information
Patbox committed May 31, 2024
2 parents e7cc9bb + 71e88c2 commit f8373bc
Show file tree
Hide file tree
Showing 29 changed files with 304 additions and 397 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ loader_version=0.15.1
fabric_version=0.89.2+1.20.2

# Mod Properties
mod_version=0.5
mod_version=0.6
maven_group=xyz.nucleoid
archives_base_name=plasmid
11 changes: 6 additions & 5 deletions src/main/java/xyz/nucleoid/plasmid/Plasmid.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.fabricmc.fabric.api.event.registry.DynamicRegistries;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
Expand All @@ -15,14 +16,14 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.nucleoid.plasmid.command.*;
import xyz.nucleoid.plasmid.event.GameEvents;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.game.composite.RandomGame;
import xyz.nucleoid.plasmid.game.composite.RandomGameConfig;
import xyz.nucleoid.plasmid.game.config.GameConfig;
import xyz.nucleoid.plasmid.game.config.GameConfigs;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.manager.GameSpaceManager;
Expand All @@ -32,8 +33,8 @@
import xyz.nucleoid.plasmid.game.portal.game.ConcurrentGamePortalConfig;
import xyz.nucleoid.plasmid.game.portal.game.LegacyOnDemandPortalConfig;
import xyz.nucleoid.plasmid.game.portal.game.NewGamePortalConfig;
import xyz.nucleoid.plasmid.game.portal.menu.*;
import xyz.nucleoid.plasmid.game.portal.game.SingleGamePortalConfig;
import xyz.nucleoid.plasmid.game.portal.menu.*;
import xyz.nucleoid.plasmid.game.world.generator.GameChunkGenerator;
import xyz.nucleoid.plasmid.util.compatibility.TrinketsCompatibility;

Expand All @@ -44,8 +45,9 @@ public final class Plasmid implements ModInitializer {

@Override
public void onInitialize() {
Registry.register(Registries.CHUNK_GENERATOR, new Identifier(ID, "game"), GameChunkGenerator.CODEC);
DynamicRegistries.register(GameConfigs.REGISTRY_KEY, GameConfig.DIRECT_CODEC);

Registry.register(Registries.CHUNK_GENERATOR, new Identifier(ID, "game"), GameChunkGenerator.CODEC);

GamePortalConfig.register(new Identifier(ID, "single_game"), SingleGamePortalConfig.CODEC);
GamePortalConfig.register(new Identifier(ID, "new_game"), NewGamePortalConfig.CODEC);
Expand All @@ -69,8 +71,7 @@ public void onInitialize() {
}

private void loadData(DynamicRegistryManager registryManager, ResourceManager manager) {
GameConfigs.reload(registryManager, manager);
GamePortalManager.INSTANCE.reload(manager);
GamePortalManager.INSTANCE.reload(registryManager, manager);
}

private void registerCallbacks() {
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/xyz/nucleoid/plasmid/command/GameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtOps;
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
Expand Down Expand Up @@ -100,7 +101,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(literal("joinall")
.requires(source -> source.hasPermissionLevel(2))
.executes(GameCommand::joinAllGame)
.then(GameConfigArgument.argument("game_config")
.then(GameSpaceArgument.argument("game_space")
.executes(GameCommand::joinAllQualifiedGame)
)
)
Expand All @@ -121,7 +122,7 @@ private static int openGame(CommandContext<ServerCommandSource> context) throws
protected static int openGame(CommandContext<ServerCommandSource> context, boolean test) throws CommandSyntaxException {
try {
var game = GameConfigArgument.get(context, "game_config");
return openGame(context, game.getSecond(), test);
return openGame(context, game, test);
} catch (CommandSyntaxException e) {
throw e;
} catch (Exception e) {
Expand All @@ -138,13 +139,13 @@ private static int openAnonymousGame(CommandContext<ServerCommandSource> context
protected static int openAnonymousGame(CommandContext<ServerCommandSource> context, boolean test) throws CommandSyntaxException {
try {
var configNbt = NbtCompoundArgumentType.getNbtCompound(context, "game_config_nbt");
var result = GameConfig.CODEC.parse(RegistryOps.of(NbtOps.INSTANCE, context.getSource().getRegistryManager()), configNbt);
var result = GameConfig.DIRECT_CODEC.parse(RegistryOps.of(NbtOps.INSTANCE, context.getSource().getRegistryManager()), configNbt);
if (result.error().isPresent()) {
throw MALFORMED_CONFIG.create(result.error().get());
}

var game = result.result().get();
return openGame(context, game, test);
return openGame(context, RegistryEntry.of(game), test);
} catch (CommandSyntaxException e) {
throw e;
} catch (Exception e) {
Expand All @@ -154,7 +155,7 @@ protected static int openAnonymousGame(CommandContext<ServerCommandSource> conte
}
}

private static int openGame(CommandContext<ServerCommandSource> context, GameConfig<?> config, boolean test) {
private static int openGame(CommandContext<ServerCommandSource> context, RegistryEntry<GameConfig<?>> config, boolean test) {
var source = context.getSource();
var server = source.getServer();

Expand Down Expand Up @@ -414,19 +415,21 @@ private static int stopGameConfirmed(CommandContext<ServerCommandSource> context
}

private static int listGames(CommandContext<ServerCommandSource> context) {
var registry = context.getSource().getRegistryManager().get(GameConfigs.REGISTRY_KEY);
var source = context.getSource();
source.sendFeedback(() -> GameTexts.Command.gameList().formatted(Formatting.BOLD), false);

for (var id : GameConfigs.getKeys()) {
registry.streamEntries().forEach(game -> {
var id = game.registryKey().getValue();
source.sendFeedback(() -> {
String command = "/game open " + id;

var link = GameConfigs.get(id).name().copy()
var link = GameConfig.name(game).copy()
.setStyle(GameTexts.commandLinkStyle(command));

return GameTexts.Command.listEntry(link);
}, false);
}
});

return Command.SINGLE_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.mojang.datafixers.util.Pair;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.IdentifierArgumentType;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
Expand All @@ -15,6 +18,7 @@
import xyz.nucleoid.plasmid.game.config.GameConfigs;

import java.util.Locale;
import java.util.Optional;
import java.util.function.Function;

public final class GameConfigArgument {
Expand All @@ -25,24 +29,21 @@ public final class GameConfigArgument {
public static RequiredArgumentBuilder<ServerCommandSource, Identifier> argument(String name) {
return CommandManager.argument(name, IdentifierArgumentType.identifier())
.suggests((ctx, builder) -> {
Iterable<Identifier> candidates = GameConfigs.getKeys().stream()::iterator;
var registry = ctx.getSource().getRegistryManager().get(GameConfigs.REGISTRY_KEY);
var remaining = builder.getRemaining().toLowerCase(Locale.ROOT);

CommandSource.forEachMatching(candidates, remaining, Function.identity(), id -> {
builder.suggest(id.toString(), GameConfigs.get(id).name());
CommandSource.forEachMatching(registry.getKeys(), remaining, RegistryKey::getValue, key -> {
registry.getEntry(key).ifPresent(entry -> {
builder.suggest(key.getValue().toString(), GameConfig.name(entry));
});
});
return builder.buildFuture();
});
}

public static Pair<Identifier, GameConfig<?>> get(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
var identifier = IdentifierArgumentType.getIdentifier(context, name);

var config = GameConfigs.get(identifier);
if (config == null) {
throw GAME_NOT_FOUND.create(identifier);
}

return new Pair<>(identifier, config);
public static RegistryEntry.Reference<GameConfig<?>> get(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
var key = RegistryKey.of(GameConfigs.REGISTRY_KEY, IdentifierArgumentType.getIdentifier(context, name));
var registry = context.getSource().getRegistryManager().get(GameConfigs.REGISTRY_KEY);
return registry.getEntry(key).orElseThrow(() -> GAME_NOT_FOUND.create(key.getValue()));
}
}
7 changes: 4 additions & 3 deletions src/main/java/xyz/nucleoid/plasmid/command/ui/GameJoinUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.math.MathHelper;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.config.GameConfig;
import xyz.nucleoid.plasmid.game.manager.GameSpaceManager;
import xyz.nucleoid.plasmid.game.manager.ManagedGameSpace;
import xyz.nucleoid.plasmid.game.player.GamePlayerJoiner;
Expand Down Expand Up @@ -113,10 +114,10 @@ private void changePage(int change) {

private GuiElementBuilder createIconFor(GameSpace gameSpace) {
var sourceConfig = gameSpace.getMetadata().sourceConfig();
var element = GuiElementBuilder.from(sourceConfig.icon().copy()).hideFlags()
.setName(sourceConfig.name().copy());
var element = GuiElementBuilder.from(sourceConfig.value().icon().copy()).hideFlags()
.setName(GameConfig.name(sourceConfig).copy());

for (var line : sourceConfig.description()) {
for (var line : sourceConfig.value().description()) {
var text = line.copy();

if (line.getStyle().getColor() == null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xyz/nucleoid/plasmid/event/GameEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.plasmid.game.GameActivity;
Expand Down Expand Up @@ -75,7 +76,7 @@ public interface GameSpaceOpened {
* @param game The game and its configuration
* @param gameSpace The {@link GameSpace} the game is running in.
*/
void onGameSpaceOpened(GameConfig<?> game, GameSpace gameSpace);
void onGameSpaceOpened(RegistryEntry<GameConfig<?>> game, GameSpace gameSpace);
}

public interface CreateActivity {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.plasmid.game;

import net.minecraft.registry.entry.RegistryEntry;
import xyz.nucleoid.plasmid.game.config.GameConfig;

/**
Expand All @@ -8,23 +9,23 @@
* @see GameOpenContext
*/
public interface GameOpenProcedure {
static GameOpenProcedure withOverride(GameOpenProcedure procedure, GameConfig<?> game) {
static GameOpenProcedure withOverride(GameOpenProcedure procedure, RegistryEntry<GameConfig<?>> game) {
return new GameOpenProcedure() {
@Override
public void apply(GameSpace context) {
procedure.apply(context);
}

@Override
public GameConfig<?> configOverride() {
public RegistryEntry<GameConfig<?>> configOverride() {
return game;
}
};
}

void apply(GameSpace gameSpace);

default GameConfig<?> configOverride() {
default RegistryEntry<GameConfig<?>> configOverride() {
return null;
}
}
15 changes: 7 additions & 8 deletions src/main/java/xyz/nucleoid/plasmid/game/GameSpaceMetadata.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.plasmid.game;

import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.config.GameConfig;

Expand All @@ -12,18 +13,17 @@
public record GameSpaceMetadata(
UUID id,
Identifier userId,
GameConfig<?> sourceConfig,
GameConfig<?> originalSourceConfig
RegistryEntry<GameConfig<?>> sourceConfig,
RegistryEntry<GameConfig<?>> originalSourceConfig
) {


public GameSpaceMetadata(
UUID id,
Identifier userId,
GameConfig<?> sourceConfig
RegistryEntry<GameConfig<?>> sourceConfig
) {
this(id, userId, sourceConfig, sourceConfig);
}

/**
* @return the globally unique ID for this {@link GameSpace}
*/
Expand All @@ -46,12 +46,11 @@ public Identifier userId() {
/**
* @return the {@link GameConfig} that was responsible for creating this {@link GameSpace}
*/
@Override
public GameConfig<?> sourceConfig() {
public RegistryEntry<GameConfig<?>> sourceConfig() {
return this.sourceConfig;
}

public boolean isSourceConfig(GameConfig<?> gameConfig) {
public boolean isSourceConfig(RegistryEntry<GameConfig<?>> gameConfig) {
return this.sourceConfig == gameConfig || this.originalSourceConfig == gameConfig;
}
}
11 changes: 6 additions & 5 deletions src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.*;
import net.minecraft.util.Formatting;
import xyz.nucleoid.plasmid.game.config.GameConfig;

/**
* Utility class containing various functions that supply {@link Text} instances.
Expand Down Expand Up @@ -32,21 +33,21 @@ public static Style commandLinkStyle(String command, Text hoverText) {

public static final class Broadcast {
public static MutableText gameOpened(ServerCommandSource source, GameSpace gameSpace) {
var gameName = gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.GRAY);
var gameName = GameConfig.name(gameSpace.getMetadata().sourceConfig()).copy().formatted(Formatting.GRAY);

return Text.translatable("text.plasmid.game.open.opened", source.getDisplayName(), gameName)
.append(GameTexts.Join.link(gameSpace));
}

public static MutableText gameOpenedTesting(ServerCommandSource source, GameSpace gameSpace) {
var gameName = gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.GRAY);
var gameName = GameConfig.name(gameSpace.getMetadata().sourceConfig()).copy().formatted(Formatting.GRAY);

return Text.translatable("text.plasmid.game.open.opened.testing", source.getDisplayName(), gameName)
.append(GameTexts.Join.link(gameSpace));
}

public static MutableText propose(ServerCommandSource source, GameSpace gameSpace) {
var gameName = gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.GRAY);
var gameName = GameConfig.name(gameSpace.getMetadata().sourceConfig()).copy().formatted(Formatting.GRAY);

return Text.translatable("text.plasmid.game.propose", source.getDisplayName(), gameName)
.append(GameTexts.Join.link(gameSpace));
Expand All @@ -59,7 +60,7 @@ public static MutableText gameOpenError() {

public static final class Command {
public static MutableText located(ServerPlayerEntity player, GameSpace gameSpace) {
var gameName = gameSpace.getMetadata().sourceConfig().name().copy().formatted(Formatting.GRAY);
var gameName = GameConfig.name(gameSpace.getMetadata().sourceConfig()).copy().formatted(Formatting.GRAY);

return Text.translatable("text.plasmid.game.locate.located", player.getDisplayName(), gameName)
.append(GameTexts.Join.link(gameSpace));
Expand Down Expand Up @@ -112,7 +113,7 @@ public static MutableText success(ServerPlayerEntity player) {
}

public static MutableText link(GameSpace gameSpace) {
var hover = Text.translatable("text.plasmid.join_link_hover", gameSpace.getMetadata().sourceConfig().name());
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import xyz.nucleoid.plasmid.game.common.config.PlayerConfig;
import xyz.nucleoid.plasmid.game.common.widget.BossBarWidget;
import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget;
import xyz.nucleoid.plasmid.game.config.GameConfig;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.manager.GameSpaceManager;
Expand Down Expand Up @@ -92,8 +93,8 @@ public static GameWaitingLobby addTo(GameActivity activity, PlayerConfig playerC
activity.listen(GamePlayerEvents.REMOVE, lobby::onRemovePlayer);


lobby.setSidebarLines(sourceConfig.description());
var title = sourceConfig.shortName().copy();
lobby.setSidebarLines(sourceConfig.value().description());
var title = GameConfig.shortName(sourceConfig).copy();

if (title.getStyle().getColor() == null) {
title.setStyle(title.getStyle().withColor(Formatting.GOLD));
Expand Down
Loading

0 comments on commit f8373bc

Please sign in to comment.