diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 05b2b40..0aac695 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: with: cache: gradle distribution: microsoft - java-version: 17 + java-version: 21 - name: Build with Gradle run: gradle build - name: Upload Artifacts diff --git a/build.gradle b/build.gradle index 0f16e2a..7ab8cd1 100644 --- a/build.gradle +++ b/build.gradle @@ -40,12 +40,12 @@ processResources { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } tasks.withType(JavaCompile) { - options.release = 17 + options.release = 21 options.encoding = "UTF-8" } diff --git a/gradle.properties b/gradle.properties index f6ac076..db3fe5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,9 +5,9 @@ mod_version = 1.0.0 org.gradle.jvmargs = -Xmx1G # Versions -minecraft_version = 1.20.4 -yarn_mappings = 1.20.4+build.3 +minecraft_version = 1.21.3 +yarn_mappings = 1.21.3+build.2 loader_version = 0.16.9 -fabric_version = 0.97.2+1.20.4 +fabric_version = 0.109.0+1.21.3 -plasmid_version = 0.5.102-SNAPSHOT+1.20.4 +plasmid_version = 0.6.0+1.21.3 diff --git a/src/main/java/io/github/haykam821/downpour/Main.java b/src/main/java/io/github/haykam821/downpour/Main.java index b9e4758..19c1db9 100644 --- a/src/main/java/io/github/haykam821/downpour/Main.java +++ b/src/main/java/io/github/haykam821/downpour/Main.java @@ -4,23 +4,27 @@ import io.github.haykam821.downpour.game.phase.DownpourWaitingPhase; import net.fabricmc.api.ModInitializer; import net.minecraft.util.Identifier; -import xyz.nucleoid.plasmid.game.GameType; -import xyz.nucleoid.plasmid.game.stats.StatisticKey; +import xyz.nucleoid.plasmid.api.game.GameType; +import xyz.nucleoid.plasmid.api.game.stats.StatisticKey; public class Main implements ModInitializer { - public static final String MOD_ID = "downpour"; + private static final String MOD_ID = "downpour"; - private static final Identifier DOWNPOUR_ID = new Identifier(MOD_ID, "downpour"); + private static final Identifier DOWNPOUR_ID = Main.identifier("downpour"); public static final GameType DOWNPOUR_TYPE = GameType.register(DOWNPOUR_ID, DownpourConfig.CODEC, DownpourWaitingPhase::open); - private static final Identifier ROUNDS_SURVIVED_ID = new Identifier(MOD_ID, "rounds_survived"); + private static final Identifier ROUNDS_SURVIVED_ID = Main.identifier("rounds_survived"); public static final StatisticKey ROUNDS_SURVIVED = StatisticKey.intKey(ROUNDS_SURVIVED_ID); - private static final Identifier PLAYERS_PUNCHED_ID = new Identifier(MOD_ID, "players_punched"); + private static final Identifier PLAYERS_PUNCHED_ID = Main.identifier("players_punched"); public static final StatisticKey PLAYERS_PUNCHED = StatisticKey.intKey(PLAYERS_PUNCHED_ID); @Override public void onInitialize() { return; } + + public static Identifier identifier(String path) { + return Identifier.of(MOD_ID, path); + } } \ No newline at end of file diff --git a/src/main/java/io/github/haykam821/downpour/game/DownpourConfig.java b/src/main/java/io/github/haykam821/downpour/game/DownpourConfig.java index 17b31ed..8e8dc40 100644 --- a/src/main/java/io/github/haykam821/downpour/game/DownpourConfig.java +++ b/src/main/java/io/github/haykam821/downpour/game/DownpourConfig.java @@ -3,6 +3,7 @@ import java.util.Optional; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.haykam821.downpour.game.map.DownpourMapConfig; @@ -11,15 +12,15 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.intprovider.ConstantIntProvider; import net.minecraft.util.math.intprovider.IntProvider; -import xyz.nucleoid.plasmid.game.GameSpace; -import xyz.nucleoid.plasmid.game.common.config.PlayerConfig; -import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle; +import xyz.nucleoid.plasmid.api.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig; +import xyz.nucleoid.plasmid.api.game.stats.GameStatisticBundle; public class DownpourConfig { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> { return instance.group( DownpourMapConfig.CODEC.fieldOf("map").forGetter(DownpourConfig::getMapConfig), - PlayerConfig.CODEC.fieldOf("players").forGetter(DownpourConfig::getPlayerConfig), + WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(DownpourConfig::getPlayerConfig), IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(DownpourConfig::getTicksUntilClose), SoundEvent.CODEC.optionalFieldOf("lock_sound", SoundEvents.BLOCK_NOTE_BLOCK_SNARE.value()).forGetter(DownpourConfig::getLockSound), SoundEvent.CODEC.optionalFieldOf("unlock_sound", SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER).forGetter(DownpourConfig::getUnlockSound), @@ -31,7 +32,7 @@ public class DownpourConfig { }); private final DownpourMapConfig mapConfig; - private final PlayerConfig playerConfig; + private final WaitingLobbyConfig playerConfig; private final IntProvider ticksUntilClose; private final SoundEvent lockSound; private final SoundEvent unlockSound; @@ -40,7 +41,7 @@ public class DownpourConfig { private final int noKnockbackRounds; private final Optional statisticBundleNamespace; - public DownpourConfig(DownpourMapConfig mapConfig, PlayerConfig playerConfig, IntProvider ticksUntilClose, SoundEvent lockSound, SoundEvent unlockSound, int lockTime, int unlockTime, int noKnockbackRounds, Optional statisticBundleNamespace) { + public DownpourConfig(DownpourMapConfig mapConfig, WaitingLobbyConfig playerConfig, IntProvider ticksUntilClose, SoundEvent lockSound, SoundEvent unlockSound, int lockTime, int unlockTime, int noKnockbackRounds, Optional statisticBundleNamespace) { this.mapConfig = mapConfig; this.playerConfig = playerConfig; this.ticksUntilClose = ticksUntilClose; @@ -56,7 +57,7 @@ public DownpourMapConfig getMapConfig() { return this.mapConfig; } - public PlayerConfig getPlayerConfig() { + public WaitingLobbyConfig getPlayerConfig() { return this.playerConfig; } diff --git a/src/main/java/io/github/haykam821/downpour/game/DownpourTimerBar.java b/src/main/java/io/github/haykam821/downpour/game/DownpourTimerBar.java index 8d131f9..1292ce6 100644 --- a/src/main/java/io/github/haykam821/downpour/game/DownpourTimerBar.java +++ b/src/main/java/io/github/haykam821/downpour/game/DownpourTimerBar.java @@ -4,8 +4,8 @@ import net.minecraft.entity.boss.BossBar; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.game.common.widget.BossBarWidget; +import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets; +import xyz.nucleoid.plasmid.api.game.common.widget.BossBarWidget; public class DownpourTimerBar { private static final Text TITLE = Text.translatable("gameType.downpour.downpour").formatted(Formatting.AQUA); diff --git a/src/main/java/io/github/haykam821/downpour/game/map/DownpourMap.java b/src/main/java/io/github/haykam821/downpour/game/map/DownpourMap.java index 1bfbbdf..3e39c57 100644 --- a/src/main/java/io/github/haykam821/downpour/game/map/DownpourMap.java +++ b/src/main/java/io/github/haykam821/downpour/game/map/DownpourMap.java @@ -4,7 +4,7 @@ import net.minecraft.world.gen.chunk.ChunkGenerator; import xyz.nucleoid.map_templates.BlockBounds; import xyz.nucleoid.map_templates.MapTemplate; -import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator; +import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator; public class DownpourMap { private final MapTemplate template; diff --git a/src/main/java/io/github/haykam821/downpour/game/phase/DownpourActivePhase.java b/src/main/java/io/github/haykam821/downpour/game/phase/DownpourActivePhase.java index 4a2c4ea..ea9885f 100644 --- a/src/main/java/io/github/haykam821/downpour/game/phase/DownpourActivePhase.java +++ b/src/main/java/io/github/haykam821/downpour/game/phase/DownpourActivePhase.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import io.github.haykam821.downpour.Main; @@ -18,7 +19,6 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.hit.EntityHitResult; @@ -26,19 +26,21 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; -import xyz.nucleoid.plasmid.game.GameActivity; -import xyz.nucleoid.plasmid.game.GameCloseReason; -import xyz.nucleoid.plasmid.game.GameSpace; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.game.event.GameActivityEvents; -import xyz.nucleoid.plasmid.game.event.GamePlayerEvents; -import xyz.nucleoid.plasmid.game.player.PlayerOffer; -import xyz.nucleoid.plasmid.game.player.PlayerOfferResult; -import xyz.nucleoid.plasmid.game.rule.GameRuleType; -import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle; -import xyz.nucleoid.plasmid.game.stats.StatisticKey; -import xyz.nucleoid.plasmid.game.stats.StatisticKeys; -import xyz.nucleoid.plasmid.util.PlayerRef; +import xyz.nucleoid.plasmid.api.game.GameActivity; +import xyz.nucleoid.plasmid.api.game.GameCloseReason; +import xyz.nucleoid.plasmid.api.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets; +import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents; +import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents; +import xyz.nucleoid.plasmid.api.game.player.JoinAcceptor; +import xyz.nucleoid.plasmid.api.game.player.JoinAcceptorResult; +import xyz.nucleoid.plasmid.api.game.player.JoinOffer; +import xyz.nucleoid.plasmid.api.game.rule.GameRuleType; +import xyz.nucleoid.plasmid.api.game.stats.GameStatisticBundle; +import xyz.nucleoid.plasmid.api.game.stats.StatisticKey; +import xyz.nucleoid.plasmid.api.game.stats.StatisticKeys; +import xyz.nucleoid.plasmid.api.util.PlayerRef; +import xyz.nucleoid.stimuli.event.EventResult; import xyz.nucleoid.stimuli.event.player.PlayerAttackEntityEvent; import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; @@ -85,7 +87,7 @@ public static void open(GameSpace gameSpace, ServerWorld world, DownpourMap map, gameSpace.setActivity(activity -> { GlobalWidgets widgets = GlobalWidgets.addTo(activity); - List players = gameSpace.getPlayers().stream().map(PlayerRef::of).collect(Collectors.toList()); + List players = gameSpace.getPlayers().participants().stream().map(PlayerRef::of).collect(Collectors.toList()); Collections.shuffle(players); DownpourActivePhase phase = new DownpourActivePhase(gameSpace, world, map, config, players, widgets); @@ -95,7 +97,8 @@ public static void open(GameSpace gameSpace, ServerWorld world, DownpourMap map, // Listeners activity.listen(GameActivityEvents.ENABLE, phase::enable); activity.listen(GameActivityEvents.TICK, phase::tick); - activity.listen(GamePlayerEvents.OFFER, phase::offerPlayer); + activity.listen(GamePlayerEvents.ACCEPT, phase::onAcceptPlayers); + activity.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators); activity.listen(GamePlayerEvents.REMOVE, phase::removePlayer); activity.listen(PlayerAttackEntityEvent.EVENT, phase::onPlayerAttackEntity); activity.listen(PlayerDamageEvent.EVENT, phase::onPlayerDamage); @@ -137,6 +140,11 @@ private void enable() { index++; } + + for (ServerPlayerEntity player : this.gameSpace.getPlayers().spectators()) { + DownpourActivePhase.spawn(this.world, this.map.getBounds().center(), 0, player); + this.setSpectator(player); + } } private void createShelter() { @@ -268,10 +276,10 @@ private void setSpectator(ServerPlayerEntity player) { player.changeGameMode(GameMode.SPECTATOR); } - private PlayerOfferResult offerPlayer(PlayerOffer offer) { - return offer.accept(this.world, this.map.getBounds().center()).and(() -> { - this.updateRoundsExperienceLevel(offer.player()); - this.setSpectator(offer.player()); + private JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) { + return acceptor.teleport(this.world, this.map.getBounds().center()).thenRunForEach(player -> { + this.updateRoundsExperienceLevel(player); + this.setSpectator(player); }); } @@ -313,7 +321,7 @@ public void applyPlayerFinishStatistics(ServerPlayerEntity player, StatisticKey< } } - private ActionResult onPlayerAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) { + private EventResult onPlayerAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) { if (!this.isGameEnding() && attacker != attacked && this.players.contains(PlayerRef.of(attacker)) && !this.singleplayer && this.statistics != null) { ServerPlayerEntity attackedPlayer = (ServerPlayerEntity) attacked; if (this.players.contains(PlayerRef.of(attackedPlayer))) { @@ -321,23 +329,23 @@ private ActionResult onPlayerAttackEntity(ServerPlayerEntity attacker, Hand hand } } - return ActionResult.PASS; + return EventResult.PASS; } - private ActionResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) { - return this.rounds >= this.config.getNoKnockbackRounds() ? ActionResult.SUCCESS : ActionResult.FAIL; + private EventResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) { + return this.rounds >= this.config.getNoKnockbackRounds() ? EventResult.ALLOW : EventResult.DENY; } - private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { + private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { if (!this.eliminate(player, true)) { DownpourActivePhase.spawnAtCenter(this.world, this.map, player); } - return ActionResult.FAIL; + return EventResult.DENY; } public static void spawn(ServerWorld world, Vec3d pos, float yaw, ServerPlayerEntity player) { player.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, StatusEffectInstance.INFINITE, 127, true, false)); - player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), yaw, 0); + player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), yaw, 0, true); } public static void spawnAtCenter(ServerWorld world, DownpourMap map, ServerPlayerEntity player) { diff --git a/src/main/java/io/github/haykam821/downpour/game/phase/DownpourWaitingPhase.java b/src/main/java/io/github/haykam821/downpour/game/phase/DownpourWaitingPhase.java index 19197cc..1244f0a 100644 --- a/src/main/java/io/github/haykam821/downpour/game/phase/DownpourWaitingPhase.java +++ b/src/main/java/io/github/haykam821/downpour/game/phase/DownpourWaitingPhase.java @@ -6,19 +6,20 @@ import net.minecraft.entity.damage.DamageSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ActionResult; import net.minecraft.world.GameMode; import xyz.nucleoid.fantasy.RuntimeWorldConfig; -import xyz.nucleoid.plasmid.game.GameOpenContext; -import xyz.nucleoid.plasmid.game.GameOpenProcedure; -import xyz.nucleoid.plasmid.game.GameResult; -import xyz.nucleoid.plasmid.game.GameSpace; -import xyz.nucleoid.plasmid.game.common.GameWaitingLobby; -import xyz.nucleoid.plasmid.game.event.GameActivityEvents; -import xyz.nucleoid.plasmid.game.event.GamePlayerEvents; -import xyz.nucleoid.plasmid.game.player.PlayerOffer; -import xyz.nucleoid.plasmid.game.player.PlayerOfferResult; -import xyz.nucleoid.plasmid.game.rule.GameRuleType; +import xyz.nucleoid.plasmid.api.game.GameOpenContext; +import xyz.nucleoid.plasmid.api.game.GameOpenProcedure; +import xyz.nucleoid.plasmid.api.game.GameResult; +import xyz.nucleoid.plasmid.api.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.common.GameWaitingLobby; +import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents; +import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents; +import xyz.nucleoid.plasmid.api.game.player.JoinAcceptor; +import xyz.nucleoid.plasmid.api.game.player.JoinAcceptorResult; +import xyz.nucleoid.plasmid.api.game.player.JoinOffer; +import xyz.nucleoid.plasmid.api.game.rule.GameRuleType; +import xyz.nucleoid.stimuli.event.EventResult; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; public class DownpourWaitingPhase { @@ -50,14 +51,15 @@ public static GameOpenProcedure open(GameOpenContext context) { // Listeners activity.listen(PlayerDeathEvent.EVENT, phase::onPlayerDeath); - activity.listen(GamePlayerEvents.OFFER, phase::offerPlayer); + activity.listen(GamePlayerEvents.ACCEPT, phase::onAcceptPlayers); + activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept); activity.listen(GameActivityEvents.REQUEST_START, phase::requestStart); }); } - private PlayerOfferResult offerPlayer(PlayerOffer offer) { - return offer.accept(this.world, DownpourActivePhase.getCenterSpawnPos(this.map)).and(() -> { - offer.player().changeGameMode(GameMode.ADVENTURE); + private JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) { + return acceptor.teleport(this.world, DownpourActivePhase.getCenterSpawnPos(this.map)).thenRunForEach(player -> { + player.changeGameMode(GameMode.ADVENTURE); }); } @@ -66,8 +68,8 @@ private GameResult requestStart() { return GameResult.ok(); } - private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { + private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { DownpourActivePhase.spawnAtCenter(this.world, this.map, player); - return ActionResult.FAIL; + return EventResult.DENY; } } \ No newline at end of file diff --git a/src/main/resources/data/downpour/games/standard_downpour.json b/src/main/resources/data/downpour/plasmid/game/standard_downpour.json similarity index 100% rename from src/main/resources/data/downpour/games/standard_downpour.json rename to src/main/resources/data/downpour/plasmid/game/standard_downpour.json diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0132c8d..b463278 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -20,7 +20,7 @@ "icon": "assets/downpour/icon.png", "depends": { "fabricloader": ">=0.4.0", - "java": ">=17", - "plasmid": ">=0.5.0" + "java": ">=21", + "plasmid": ">=0.6.0" } }