diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18e1b13..0aac695 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,24 +6,18 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Cache - uses: actions/cache@v2 - with: - path: | - ~/.gradle/loom-cache - ~/.gradle/caches - key: gradle-${{hashFiles('**/*.gradle*')}} - restore-keys: gradle- - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Java - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: - java-version: 17 + cache: gradle + distribution: microsoft + java-version: 21 - name: Build with Gradle run: gradle build - name: Upload Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: artifacts path: build/libs \ No newline at end of file diff --git a/build.gradle b/build.gradle index 40e2cac..756537c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,8 @@ plugins { - id "fabric-loom" version "1.5.7" + id "fabric-loom" version "1.9.2" id "maven-publish" } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group @@ -46,7 +43,13 @@ processResources { } } +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + tasks.withType(JavaCompile) { + options.release = 21 options.encoding = "UTF-8" } diff --git a/gradle.properties b/gradle.properties index 8b82c26..50f5087 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 -loader_version = 0.15.6 -fabric_version = 0.96.0+1.20.4 +minecraft_version = 1.21.3 +yarn_mappings = 1.21.3+build.2 +loader_version = 0.16.9 +fabric_version = 0.110.0+1.21.3 -plasmid_version = 0.5.102-SNAPSHOT+1.20.4 \ No newline at end of file +plasmid_version = 0.6.1+1.21.3 \ No newline at end of file diff --git a/src/main/java/io/github/haykam821/deathswap/Main.java b/src/main/java/io/github/haykam821/deathswap/Main.java index 0f991a0..8c94e06 100644 --- a/src/main/java/io/github/haykam821/deathswap/Main.java +++ b/src/main/java/io/github/haykam821/deathswap/Main.java @@ -4,25 +4,31 @@ import io.github.haykam821.deathswap.game.DeathSwapConfig; import io.github.haykam821.deathswap.game.phase.DeathSwapWaitingPhase; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.util.Identifier; -import xyz.nucleoid.plasmid.game.GameType; +import xyz.nucleoid.plasmid.api.game.GameType; public class Main implements ModInitializer { - public static final String MOD_ID = "deathswap"; + private static final String MOD_ID = "deathswap"; - private static final Identifier BARRIER_AIR_ID = new Identifier(MOD_ID, "barrier_air"); - public static final Block BARRIER_AIR = new BarrierAirBlock(FabricBlockSettings.copyOf(Blocks.AIR).strength(-1, 3600000)); + private static final Identifier BARRIER_AIR_ID = Main.identifier("barrier_air"); + private static final RegistryKey BARRIER_AIR_KEY = RegistryKey.of(RegistryKeys.BLOCK, BARRIER_AIR_ID); + public static final Block BARRIER_AIR = new BarrierAirBlock(Block.Settings.copy(Blocks.AIR).strength(-1, 3600000).registryKey(BARRIER_AIR_KEY)); - private static final Identifier DEATH_SWAP_ID = new Identifier(MOD_ID, "death_swap"); + private static final Identifier DEATH_SWAP_ID = Main.identifier("death_swap"); public static final GameType DEATH_SWAP_TYPE = GameType.register(DEATH_SWAP_ID, DeathSwapConfig.CODEC, DeathSwapWaitingPhase::open); @Override public void onInitialize() { - Registry.register(Registries.BLOCK, BARRIER_AIR_ID, BARRIER_AIR); + Registry.register(Registries.BLOCK, BARRIER_AIR_KEY, BARRIER_AIR); + } + + public static Identifier identifier(String path) { + return Identifier.of(MOD_ID, path); } } diff --git a/src/main/java/io/github/haykam821/deathswap/block/BarrierAirBlock.java b/src/main/java/io/github/haykam821/deathswap/block/BarrierAirBlock.java index cb8bdaa..fce5339 100644 --- a/src/main/java/io/github/haykam821/deathswap/block/BarrierAirBlock.java +++ b/src/main/java/io/github/haykam821/deathswap/block/BarrierAirBlock.java @@ -7,6 +7,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import xyz.nucleoid.packettweaker.PacketContext; public class BarrierAirBlock extends AirBlock implements PolymerBlock { public static final MapCodec CODEC = Block.createCodec(BarrierAirBlock::new); @@ -21,7 +22,7 @@ public MapCodec getCodec() { } @Override - public Block getPolymerBlock(BlockState state) { - return Blocks.BARRIER; + public BlockState getPolymerBlockState(BlockState state, PacketContext context) { + return Blocks.BARRIER.getDefaultState(); } } diff --git a/src/main/java/io/github/haykam821/deathswap/game/DeathSwapConfig.java b/src/main/java/io/github/haykam821/deathswap/game/DeathSwapConfig.java index 5364a04..46caed7 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/DeathSwapConfig.java +++ b/src/main/java/io/github/haykam821/deathswap/game/DeathSwapConfig.java @@ -1,18 +1,19 @@ package io.github.haykam821.deathswap.game; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.haykam821.deathswap.game.map.DeathSwapMapConfig; import net.minecraft.SharedConstants; import net.minecraft.util.math.intprovider.ConstantIntProvider; import net.minecraft.util.math.intprovider.IntProvider; -import xyz.nucleoid.plasmid.game.common.config.PlayerConfig; +import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig; public class DeathSwapConfig { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> { return instance.group( - PlayerConfig.CODEC.fieldOf("players").forGetter(DeathSwapConfig::getPlayerConfig), + WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(DeathSwapConfig::getPlayerConfig), DeathSwapMapConfig.CODEC.fieldOf("map").forGetter(DeathSwapConfig::getMapConfig), IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 10)).forGetter(DeathSwapConfig::getTicksUntilClose), Codec.INT.optionalFieldOf("initial_swap_ticks", SharedConstants.TICKS_PER_MINUTE * 5).forGetter(DeathSwapConfig::getInitialSwapTicks), @@ -22,7 +23,7 @@ public class DeathSwapConfig { ).apply(instance, DeathSwapConfig::new); }); - private final PlayerConfig playerConfig; + private final WaitingLobbyConfig playerConfig; private final DeathSwapMapConfig mapConfig; private final IntProvider ticksUntilClose; private final int initialSwapTicks; @@ -30,7 +31,7 @@ public class DeathSwapConfig { private final int swapWarningTicks; private final int swapEliminationCollectionTicks; - public DeathSwapConfig(PlayerConfig playerConfig, DeathSwapMapConfig mapConfig, IntProvider ticksUntilClose, int initialSwapTicks, int swapTicks, int swapWarningTicks, int swapEliminationCollectionTicks) { + public DeathSwapConfig(WaitingLobbyConfig playerConfig, DeathSwapMapConfig mapConfig, IntProvider ticksUntilClose, int initialSwapTicks, int swapTicks, int swapWarningTicks, int swapEliminationCollectionTicks) { this.playerConfig = playerConfig; this.mapConfig = mapConfig; this.ticksUntilClose = ticksUntilClose; @@ -40,7 +41,7 @@ public DeathSwapConfig(PlayerConfig playerConfig, DeathSwapMapConfig mapConfig, this.swapEliminationCollectionTicks = swapEliminationCollectionTicks; } - public PlayerConfig getPlayerConfig() { + public WaitingLobbyConfig getPlayerConfig() { return this.playerConfig; } diff --git a/src/main/java/io/github/haykam821/deathswap/game/DeathSwapTimer.java b/src/main/java/io/github/haykam821/deathswap/game/DeathSwapTimer.java index 981b778..4464d78 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/DeathSwapTimer.java +++ b/src/main/java/io/github/haykam821/deathswap/game/DeathSwapTimer.java @@ -14,8 +14,8 @@ import net.minecraft.server.network.ServerPlayerEntity; 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 DeathSwapTimer { private static final BossBar.Style STYLE = BossBar.Style.PROGRESS; diff --git a/src/main/java/io/github/haykam821/deathswap/game/EliminationCollector.java b/src/main/java/io/github/haykam821/deathswap/game/EliminationCollector.java index faa7c77..5ea0f47 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/EliminationCollector.java +++ b/src/main/java/io/github/haykam821/deathswap/game/EliminationCollector.java @@ -9,8 +9,8 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import xyz.nucleoid.plasmid.game.player.PlayerIterable; -import xyz.nucleoid.plasmid.util.PlayerRef; +import xyz.nucleoid.plasmid.api.game.player.PlayerIterable; +import xyz.nucleoid.plasmid.api.util.PlayerRef; public class EliminationCollector { private static final int FADE_IN_TICKS = 20; diff --git a/src/main/java/io/github/haykam821/deathswap/game/SwapData.java b/src/main/java/io/github/haykam821/deathswap/game/SwapData.java index 0ec1a3a..38b746a 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/SwapData.java +++ b/src/main/java/io/github/haykam821/deathswap/game/SwapData.java @@ -3,13 +3,15 @@ import java.util.List; import net.minecraft.entity.Entity; +import net.minecraft.network.packet.s2c.play.PositionFlag; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.Vec3d; -public record SwapData(Vec3d pos, Entity vehicle, List passengers) { +public record SwapData(ServerWorld world, Vec3d pos, Entity vehicle, List passengers) { public void apply(ServerPlayerEntity player) { player.stopRiding(); - player.teleport(this.pos.getX(), this.pos.getY(), this.pos.getZ()); + player.teleport(world, this.pos.getX(), this.pos.getY(), this.pos.getZ(), PositionFlag.ROT, 0, 0, false); if (this.vehicle != null) { player.startRiding(this.vehicle, true); @@ -21,6 +23,6 @@ public void apply(ServerPlayerEntity player) { } public static SwapData from(ServerPlayerEntity player) { - return new SwapData(player.getPos(), player.getVehicle(), player.getPassengerList()); + return new SwapData(player.getServerWorld(), player.getPos(), player.getVehicle(), player.getPassengerList()); } } diff --git a/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapChunkGenerator.java b/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapChunkGenerator.java index 738bb70..860914b 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapChunkGenerator.java +++ b/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapChunkGenerator.java @@ -1,7 +1,6 @@ package io.github.haykam821.deathswap.game.map; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; import net.minecraft.block.BlockState; import net.minecraft.server.MinecraftServer; @@ -15,7 +14,6 @@ import net.minecraft.world.biome.source.BiomeAccess; import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.GenerationStep.Carver; import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.gen.chunk.Blender; import net.minecraft.world.gen.chunk.ChunkGenerator; @@ -24,7 +22,7 @@ import net.minecraft.world.gen.chunk.VerticalBlockSample; import net.minecraft.world.gen.noise.NoiseConfig; import xyz.nucleoid.fantasy.util.ChunkGeneratorSettingsProvider; -import xyz.nucleoid.plasmid.game.world.generator.GameChunkGenerator; +import xyz.nucleoid.plasmid.api.game.world.generator.GameChunkGenerator; public final class DeathSwapChunkGenerator extends GameChunkGenerator implements ChunkGeneratorSettingsProvider { private final DeathSwapMapConfig mapConfig; @@ -55,11 +53,11 @@ private boolean isChunkWithinArea(Chunk chunk) { } @Override - public CompletableFuture populateBiomes(Executor executor, NoiseConfig noiseConfig, Blender blender, StructureAccessor structures, Chunk chunk) { + public CompletableFuture populateBiomes(NoiseConfig noiseConfig, Blender blender, StructureAccessor structures, Chunk chunk) { if (this.isChunkWithinArea(chunk)) { - return this.chunkGenerator.populateBiomes(executor, noiseConfig, blender, structures, chunk); + return this.chunkGenerator.populateBiomes(noiseConfig, blender, structures, chunk); } else { - return super.populateBiomes(executor, noiseConfig, blender, structures, chunk); + return super.populateBiomes(noiseConfig, blender, structures, chunk); } } @@ -77,11 +75,11 @@ public void populateEntities(ChunkRegion region) { } @Override - public CompletableFuture populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig, StructureAccessor structures, Chunk chunk) { + public CompletableFuture populateNoise(Blender blender, NoiseConfig noiseConfig, StructureAccessor structures, Chunk chunk) { if (this.isChunkWithinArea(chunk)) { - return this.chunkGenerator.populateNoise(executor, blender, noiseConfig, structures, chunk); + return this.chunkGenerator.populateNoise(blender, noiseConfig, structures, chunk); } - return super.populateNoise(executor, blender, noiseConfig, structures, chunk); + return super.populateNoise(blender, noiseConfig, structures, chunk); } @Override @@ -117,7 +115,7 @@ private void generateWalls(int chunkX, int chunkZ, BlockPos originPos, Chunk chu BlockPos.Mutable pos = new BlockPos.Mutable(); int bottomY = chunk.getBottomY(); - int topY = chunk.getTopY() - 1; + int topY = chunk.getTopYInclusive(); // Top for (int x = 0; x < 16; x++) { @@ -177,9 +175,9 @@ private BlockState getBarrierState(Random random, BlockPos pos) { } @Override - public void carve(ChunkRegion region, long seed, NoiseConfig noiseConfig, BiomeAccess access, StructureAccessor structures, Chunk chunk, Carver carver) { + public void carve(ChunkRegion region, long seed, NoiseConfig noiseConfig, BiomeAccess access, StructureAccessor structures, Chunk chunk) { if (this.isChunkWithinArea(chunk)) { - this.chunkGenerator.carve(region, seed, noiseConfig, access, structures, chunk, carver); + this.chunkGenerator.carve(region, seed, noiseConfig, access, structures, chunk); } } diff --git a/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapMap.java b/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapMap.java index 63974f1..c4064ef 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapMap.java +++ b/src/main/java/io/github/haykam821/deathswap/game/map/DeathSwapMap.java @@ -35,7 +35,7 @@ public BlockBox getBox() { public int getSurfaceY(ServerWorld world, int x, int z) { int bottomY = world.getBottomY(); - int maxY = Math.min(world.getTopY(), bottomY + world.getLogicalHeight()) - 1; + int maxY = Math.min(world.getTopYInclusive(), bottomY + world.getLogicalHeight() - 1); BlockPos.Mutable pos = new BlockPos.Mutable(x, maxY, z); Chunk chunk = world.getChunk(pos); diff --git a/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapActivePhase.java b/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapActivePhase.java index 55093bf..28d1e89 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapActivePhase.java +++ b/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapActivePhase.java @@ -15,24 +15,25 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; import net.minecraft.world.GameRules; -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.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.stimuli.event.EventResult; import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; -public class DeathSwapActivePhase implements GameActivityEvents.Enable, GameActivityEvents.Tick, GamePlayerEvents.Offer, PlayerDamageEvent, PlayerDeathEvent, GamePlayerEvents.Remove { +public class DeathSwapActivePhase implements GameActivityEvents.Enable, GameActivityEvents.Tick, GamePlayerEvents.Accept, PlayerDamageEvent, PlayerDeathEvent, GamePlayerEvents.Remove { private final GameSpace gameSpace; private final ServerWorld world; private final DeathSwapMap map; @@ -56,7 +57,7 @@ public DeathSwapActivePhase(GameSpace gameSpace, ServerWorld world, GlobalWidget public static void open(GameSpace gameSpace, ServerWorld world, DeathSwapMap map, DeathSwapConfig config) { gameSpace.setActivity(activity -> { GlobalWidgets widgets = GlobalWidgets.addTo(activity); - Set players = Sets.newHashSet(gameSpace.getPlayers()); + Set players = Sets.newHashSet(gameSpace.getPlayers().participants()); DeathSwapActivePhase phase = new DeathSwapActivePhase(gameSpace, world, widgets, map, config, players); // Rules @@ -70,7 +71,8 @@ public static void open(GameSpace gameSpace, ServerWorld world, DeathSwapMap map // Listeners activity.listen(GameActivityEvents.ENABLE, phase); activity.listen(GameActivityEvents.TICK, phase); - activity.listen(GamePlayerEvents.OFFER, phase); + activity.listen(GamePlayerEvents.ACCEPT, phase); + activity.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators); activity.listen(PlayerDamageEvent.EVENT, phase); activity.listen(PlayerDeathEvent.EVENT, phase); activity.listen(GamePlayerEvents.REMOVE, phase); @@ -86,6 +88,11 @@ public void onEnable() { player.changeGameMode(GameMode.SURVIVAL); DeathSwapActivePhase.spawn(this.world, this.map, this.config.getMapConfig(), player); } + + for (ServerPlayerEntity player : this.gameSpace.getPlayers().spectators()) { + this.setSpectator(player); + DeathSwapActivePhase.spawnAtCenter(this.world, this.map, this.config.getMapConfig(), player); + } } @Override @@ -126,10 +133,10 @@ public void onTick() { } @Override - public PlayerOfferResult onOfferPlayer(PlayerOffer offer) { - return offer.accept(this.world, DeathSwapActivePhase.getCenterPos(this.world, this.map, this.config.getMapConfig())).and(() -> { - offer.player().setBodyYaw(DeathSwapActivePhase.getSpawnYaw(world)); - this.setSpectator(offer.player()); + public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) { + return acceptor.teleport(this.world, DeathSwapActivePhase.getCenterPos(this.world, this.map, this.config.getMapConfig())).thenRunForEach(player -> { + player.setBodyYaw(DeathSwapActivePhase.getSpawnYaw(world)); + this.setSpectator(player); }); } @@ -139,15 +146,15 @@ public void onRemovePlayer(ServerPlayerEntity player) { } @Override - public ActionResult onDamage(ServerPlayerEntity player, DamageSource source, float amount) { - return this.isGameEnding() ? ActionResult.FAIL : ActionResult.PASS; + public EventResult onDamage(ServerPlayerEntity player, DamageSource source, float amount) { + return this.isGameEnding() ? EventResult.DENY : EventResult.PASS; } @Override - public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) { + public EventResult onDeath(ServerPlayerEntity player, DamageSource source) { if (this.isGameEnding()) { DeathSwapActivePhase.spawn(this.world, this.map, this.config.getMapConfig(), player); - return ActionResult.FAIL; + return EventResult.DENY; } if (this.players.contains(player) && this.world.getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES)) { @@ -156,7 +163,7 @@ public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) { } this.eliminate(player, true); - return ActionResult.FAIL; + return EventResult.DENY; } // Getters @@ -235,7 +242,7 @@ public static void spawn(ServerWorld world, DeathSwapMap map, DeathSwapMapConfig int surfaceY = map.getSurfaceY(world, x, z); float yaw = DeathSwapActivePhase.getSpawnYaw(world); - player.teleport(world, x + 0.5, surfaceY, z + 0.5, yaw, 0); + player.teleport(world, x + 0.5, surfaceY, z + 0.5, Set.of(), yaw, 0, true); } public static Vec3d getCenterPos(ServerWorld world, DeathSwapMap map, DeathSwapMapConfig mapConfig) { @@ -251,6 +258,6 @@ public static void spawnAtCenter(ServerWorld world, DeathSwapMap map, DeathSwapM Vec3d pos = DeathSwapActivePhase.getCenterPos(world, map, mapConfig); float yaw = DeathSwapActivePhase.getSpawnYaw(world); - 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); } } diff --git a/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapWaitingPhase.java b/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapWaitingPhase.java index 268d753..897c803 100644 --- a/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapWaitingPhase.java +++ b/src/main/java/io/github/haykam821/deathswap/game/phase/DeathSwapWaitingPhase.java @@ -7,7 +7,6 @@ import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.random.RandomSeed; @@ -16,21 +15,23 @@ import net.minecraft.world.GameRules; import net.minecraft.world.dimension.DimensionType; 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.PlayerAttackEntityEvent; import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; -public class DeathSwapWaitingPhase implements PlayerAttackEntityEvent, GamePlayerEvents.Offer, PlayerDamageEvent, PlayerDeathEvent, GameActivityEvents.RequestStart { +public class DeathSwapWaitingPhase implements PlayerAttackEntityEvent, GamePlayerEvents.Accept, PlayerDamageEvent, PlayerDeathEvent, GameActivityEvents.RequestStart { private final GameSpace gameSpace; private final ServerWorld world; private final DeathSwapMap map; @@ -72,7 +73,8 @@ public static GameOpenProcedure open(GameOpenContext context) { // Listeners activity.listen(PlayerAttackEntityEvent.EVENT, phase); - activity.listen(GamePlayerEvents.OFFER, phase); + activity.listen(GamePlayerEvents.ACCEPT, phase); + activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept); activity.listen(PlayerDamageEvent.EVENT, phase); activity.listen(PlayerDeathEvent.EVENT, phase); activity.listen(GameActivityEvents.REQUEST_START, phase); @@ -81,30 +83,30 @@ public static GameOpenProcedure open(GameOpenContext context) { // Listeners @Override - public ActionResult onAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) { - return ActionResult.FAIL; + public EventResult onAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) { + return EventResult.DENY; } @Override - public PlayerOfferResult onOfferPlayer(PlayerOffer offer) { - return offer.accept(this.world, DeathSwapActivePhase.getCenterPos(this.world, this.map, this.config.getMapConfig())).and(() -> { - offer.player().setBodyYaw(DeathSwapActivePhase.getSpawnYaw(world)); - offer.player().changeGameMode(GameMode.ADVENTURE); + public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) { + return acceptor.teleport(this.world, DeathSwapActivePhase.getCenterPos(this.world, this.map, this.config.getMapConfig())).thenRunForEach(player -> { + player.setBodyYaw(DeathSwapActivePhase.getSpawnYaw(world)); + player.changeGameMode(GameMode.ADVENTURE); }); } @Override - public ActionResult onDamage(ServerPlayerEntity player, DamageSource source, float amount) { - return ActionResult.FAIL; + public EventResult onDamage(ServerPlayerEntity player, DamageSource source, float amount) { + return EventResult.DENY; } @Override - public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) { + public EventResult onDeath(ServerPlayerEntity player, DamageSource source) { // Respawn player DeathSwapActivePhase.spawnAtCenter(this.world, this.map, this.config.getMapConfig(), player); player.setHealth(player.getMaxHealth()); - return ActionResult.FAIL; + return EventResult.DENY; } @Override diff --git a/src/main/resources/data/deathswap/games/amplified_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/amplified_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/amplified_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/amplified_death_swap.json diff --git a/src/main/resources/data/deathswap/games/death_swap.json b/src/main/resources/data/deathswap/plasmid/game/death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/death_swap.json diff --git a/src/main/resources/data/deathswap/games/end_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/end_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/end_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/end_death_swap.json diff --git a/src/main/resources/data/deathswap/games/nether_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/nether_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/nether_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/nether_death_swap.json diff --git a/src/main/resources/data/deathswap/games/tiny_amplified_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/tiny_amplified_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/tiny_amplified_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/tiny_amplified_death_swap.json diff --git a/src/main/resources/data/deathswap/games/tiny_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/tiny_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/tiny_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/tiny_death_swap.json diff --git a/src/main/resources/data/deathswap/games/tiny_end_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/tiny_end_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/tiny_end_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/tiny_end_death_swap.json diff --git a/src/main/resources/data/deathswap/games/tiny_nether_death_swap.json b/src/main/resources/data/deathswap/plasmid/game/tiny_nether_death_swap.json similarity index 100% rename from src/main/resources/data/deathswap/games/tiny_nether_death_swap.json rename to src/main/resources/data/deathswap/plasmid/game/tiny_nether_death_swap.json diff --git a/src/main/resources/data/minecraft/tags/blocks/dragon_immune.json b/src/main/resources/data/minecraft/tags/block/blocks_wind_charge_explosions.json similarity index 100% rename from src/main/resources/data/minecraft/tags/blocks/dragon_immune.json rename to src/main/resources/data/minecraft/tags/block/blocks_wind_charge_explosions.json diff --git a/src/main/resources/data/minecraft/tags/blocks/wither_immune.json b/src/main/resources/data/minecraft/tags/block/dragon_immune.json similarity index 100% rename from src/main/resources/data/minecraft/tags/blocks/wither_immune.json rename to src/main/resources/data/minecraft/tags/block/dragon_immune.json diff --git a/src/main/resources/data/minecraft/tags/block/wither_immune.json b/src/main/resources/data/minecraft/tags/block/wither_immune.json new file mode 100644 index 0000000..cadd66f --- /dev/null +++ b/src/main/resources/data/minecraft/tags/block/wither_immune.json @@ -0,0 +1,5 @@ +{ + "values": [ + "deathswap:barrier_air" + ] +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 971fdf6..df4faf1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,6 +21,7 @@ "icon": "assets/deathswap/icon.png", "depends": { "fabricloader": ">=0.4.0", - "plasmid": ">=0.5.0" + "java": ">=21", + "plasmid": ">=0.6.0" } }