diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51e67fa..e55b9e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -30,7 +30,7 @@ jobs: - name: Build with Gradle run: ./gradlew build - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: artifacts path: build/libs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 66bcb69..7259f2c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -33,7 +33,7 @@ jobs: run: ./gradlew build - name: Upload GitHub release - uses: AButler/upload-release-assets@v2.0 + uses: AButler/upload-release-assets@v3.0 with: files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar' repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle b/build.gradle index 4b46188..1da70b0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'fabric-loom' version '1.1.+' + id 'fabric-loom' version '1.7.+' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -28,7 +28,7 @@ dependencies { 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 7d509c1..56925d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.1 -loader_version=0.14.21 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.1 +loader_version=0.16.9 # Dependencies -fabric_version=0.83.1+1.20.1 -plasmid_version=0.5+1.20.1-SNAPSHOT +fabric_version=0.110.2+1.21.4 +plasmid_version=0.6.2+1.21.4 # Mod Properties -mod_version=1.1.3 +mod_version=1.1.4 maven_group=xyz.nucleoid archives_base_name=farmy-feud diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..e1adfb4 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-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/xyz/nucleoid/farmyfeud/FarmyFeud.java b/src/main/java/xyz/nucleoid/farmyfeud/FarmyFeud.java index ca83a76..0e6bebd 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/FarmyFeud.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/FarmyFeud.java @@ -6,7 +6,7 @@ import org.apache.logging.log4j.Logger; import xyz.nucleoid.farmyfeud.game.FfConfig; import xyz.nucleoid.farmyfeud.game.FfWaiting; -import xyz.nucleoid.plasmid.game.GameType; +import xyz.nucleoid.plasmid.api.game.GameType; public final class FarmyFeud implements ModInitializer { public static final String ID = "farmy_feud"; @@ -15,7 +15,7 @@ public final class FarmyFeud implements ModInitializer { @Override public void onInitialize() { GameType.register( - new Identifier(FarmyFeud.ID, "farmy_feud"), + Identifier.of(FarmyFeud.ID, "farmy_feud"), FfConfig.CODEC, FfWaiting::open ); diff --git a/src/main/java/xyz/nucleoid/farmyfeud/entity/FarmSheepEntity.java b/src/main/java/xyz/nucleoid/farmyfeud/entity/FarmSheepEntity.java index 5c58612..1e3ce87 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/entity/FarmSheepEntity.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/entity/FarmSheepEntity.java @@ -25,7 +25,7 @@ import org.joml.Vector3f; import xyz.nucleoid.farmyfeud.game.active.FfActive; import xyz.nucleoid.map_templates.BlockBounds; -import xyz.nucleoid.plasmid.game.common.team.GameTeamKey; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey; import java.util.EnumSet; @@ -81,8 +81,8 @@ public boolean tryPickUp(long time, GameTeamKey team) { public void teleportWithPoof(double x, double y, double z) { if (this.getWorld() instanceof ServerWorld world) { - var colorComponents = this.getColor().getColorComponents(); - var particle = new DustParticleEffect(new Vector3f(colorComponents), 2f); + var colorComponents = this.getColor().getEntityColor(); + var particle = new DustParticleEffect(colorComponents, 2f); for (int i = 0; i < 20; i++) { double deltaX = this.random.nextGaussian() * 0.02; @@ -93,7 +93,7 @@ public void teleportWithPoof(double x, double y, double z) { } } - this.teleport(x, y, z); + this.teleport(x, y, z, false); } @Nullable @@ -120,7 +120,7 @@ protected void initGoals() { } @Override - protected void mobTick() { + protected void mobTick(ServerWorld world) { this.game.tickSheep(this); if (this.home != null) { @@ -137,13 +137,13 @@ protected void mobTick() { } @Override - public boolean damage(DamageSource source, float amount) { + public boolean damage(ServerWorld world, DamageSource source, float amount) { Entity vehicle = this.getVehicle(); if (vehicle != null && source.getSource() != null) { - return vehicle.damage(source, amount); + return vehicle.damage(world, source, amount); } - return super.damage(source, amount); + return super.damage(world, source, amount); } @Override diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/FfConfig.java b/src/main/java/xyz/nucleoid/farmyfeud/game/FfConfig.java index 8d0867c..ab4bfc4 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/FfConfig.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/FfConfig.java @@ -1,21 +1,23 @@ package xyz.nucleoid.farmyfeud.game; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.Identifier; -import xyz.nucleoid.plasmid.game.common.config.PlayerConfig; -import xyz.nucleoid.plasmid.game.common.team.GameTeam; +import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeam; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamList; import java.util.List; -public record FfConfig(Identifier map, PlayerConfig players, - List teams, long gameDuration, +public record FfConfig(Identifier map, WaitingLobbyConfig players, + GameTeamList teams, long gameDuration, long spawnInterval, int maxArrows, long arrowInterval) { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> { return instance.group( Identifier.CODEC.fieldOf("map").forGetter(config -> config.map), - PlayerConfig.CODEC.fieldOf("players").forGetter(config -> config.players), - GameTeam.CODEC.listOf().fieldOf("teams").forGetter(config -> config.teams), + WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(config -> config.players), + GameTeamList.CODEC.fieldOf("teams").forGetter(config -> config.teams), Codec.LONG.optionalFieldOf("game_duration", 60L * 8 * 20).forGetter(config -> config.gameDuration), Codec.LONG.optionalFieldOf("spawn_interval", 30L * 30).forGetter(config -> config.spawnInterval), Codec.INT.optionalFieldOf("max_arrows", 3).forGetter(config -> config.maxArrows), diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/FfSpawnLogic.java b/src/main/java/xyz/nucleoid/farmyfeud/game/FfSpawnLogic.java index eb8b33e..3fc3af1 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/FfSpawnLogic.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/FfSpawnLogic.java @@ -1,13 +1,18 @@ package xyz.nucleoid.farmyfeud.game; +import net.minecraft.command.argument.EntityAnchorArgumentType; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; import xyz.nucleoid.farmyfeud.game.map.FfMap; import xyz.nucleoid.map_templates.BlockBounds; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.GameMode; -import xyz.nucleoid.plasmid.game.common.team.GameTeam; -import xyz.nucleoid.plasmid.game.common.team.GameTeamKey; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeam; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey; + +import java.util.Set; public record FfSpawnLogic(ServerWorld world, FfMap map) { @@ -25,9 +30,9 @@ public void resetPlayer(ServerPlayerEntity player, GameMode gameMode) { public void spawnPlayerAtCenter(ServerPlayerEntity player) { BlockBounds centerSpawn = this.map.getCenterSpawn(); if (centerSpawn != null) { - this.spawnAt(player, BlockPos.ofFloored(centerSpawn.center())); + this.spawnAt(player, BlockPos.ofFloored(centerSpawn.center()), 0); } else { - this.spawnAt(player, BlockPos.ORIGIN); + this.spawnAt(player, BlockPos.ORIGIN, 0); } } @@ -40,11 +45,20 @@ public void spawnPlayerAtTeam(ServerPlayerEntity player, GameTeamKey team) { BlockBounds teamSpawn = teamRegions.spawn(); if (teamSpawn != null) { BlockPos spawnPos = BlockPos.ofFloored(teamSpawn.center()); - this.spawnAt(player, spawnPos); + BlockPos center; + var centerSpawn = this.map.getCenterSpawn(); + if (centerSpawn != null) { + center = BlockPos.ofFloored(centerSpawn.center()); + } else { + center = BlockPos.ORIGIN; + } + + this.spawnAt(player, spawnPos, 0); + player.lookAt(EntityAnchorArgumentType.EntityAnchor.FEET, Vec3d.ofCenter(center.withY(spawnPos.getY()))); } } - private void spawnAt(ServerPlayerEntity player, BlockPos spawnPos) { - player.teleport(this.world, spawnPos.getX() + 0.5, spawnPos.getY() + 0.5, spawnPos.getZ() + 0.5, 0.0F, 0.0F); + private void spawnAt(ServerPlayerEntity player, BlockPos spawnPos, float yaw) { + player.teleport(this.world, spawnPos.getX() + 0.5, spawnPos.getY() + 0.5, spawnPos.getZ() + 0.5, Set.of(), yaw, 0.0F, false); } } diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/FfWaiting.java b/src/main/java/xyz/nucleoid/farmyfeud/game/FfWaiting.java index 101a0fe..8a7612e 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/FfWaiting.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/FfWaiting.java @@ -3,20 +3,22 @@ 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.util.math.Vec3d; import net.minecraft.world.GameMode; import xyz.nucleoid.fantasy.RuntimeWorldConfig; import xyz.nucleoid.farmyfeud.game.active.FfActive; import xyz.nucleoid.farmyfeud.game.map.FfMap; import xyz.nucleoid.farmyfeud.game.map.FfMapBuilder; -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.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.common.team.TeamSelectionLobby; +import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents; +import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents; +import xyz.nucleoid.plasmid.api.game.player.JoinOffer; +import xyz.nucleoid.stimuli.event.EventResult; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; public final class FfWaiting { @@ -26,12 +28,14 @@ public final class FfWaiting { private final FfConfig config; private final FfSpawnLogic spawnLogic; + private final TeamSelectionLobby teamSelection; - private FfWaiting(GameSpace gameSpace, ServerWorld world, FfMap map, FfConfig config) { + private FfWaiting(GameSpace gameSpace, ServerWorld world, FfMap map, FfConfig config, TeamSelectionLobby teamSelection) { this.world = world; this.gameSpace = gameSpace; this.map = map; this.config = config; + this.teamSelection = teamSelection; this.spawnLogic = new FfSpawnLogic(this.world, map); } @@ -45,10 +49,12 @@ public static GameOpenProcedure open(GameOpenContext context) { .setGenerator(map.createGenerator(context.server())); return context.openWithWorld(worldConfig, (game, world) -> { - FfWaiting waiting = new FfWaiting(game.getGameSpace(), world, map, config); - + var teamSelection = TeamSelectionLobby.addTo(game, config.teams()); GameWaitingLobby.addTo(game, config.players()); - game.listen(GamePlayerEvents.OFFER, player -> player.accept(world, map.getCenterSpawn() != null ? map.getCenterSpawn().center() : new Vec3d(0, 256, 0))); + FfWaiting waiting = new FfWaiting(game.getGameSpace(), world, map, config, teamSelection); + + game.listen(GamePlayerEvents.OFFER, JoinOffer::accept); + game.listen(GamePlayerEvents.ACCEPT, player -> player.teleport(world, map.getCenterSpawn() != null ? map.getCenterSpawn().center() : new Vec3d(0, 256, 0))); game.listen(GameActivityEvents.REQUEST_START, waiting::requestStart); game.listen(GamePlayerEvents.ADD, waiting::addPlayer); game.listen(PlayerDeathEvent.EVENT, waiting::onPlayerDeath); @@ -56,7 +62,7 @@ public static GameOpenProcedure open(GameOpenContext context) { } private GameResult requestStart() { - FfActive.open(this.gameSpace, this.world, this.map, this.config); + FfActive.open(this.gameSpace, this.world, this.map, this.config, this.teamSelection); return GameResult.ok(); } @@ -64,9 +70,9 @@ private void addPlayer(ServerPlayerEntity player) { this.spawnPlayer(player); } - private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { + private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { this.spawnPlayer(player); - return ActionResult.FAIL; + return EventResult.DENY; } private void spawnPlayer(ServerPlayerEntity player) { diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/EntityCarryStack.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/EntityCarryStack.java index 1ce0c02..ad699b5 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/EntityCarryStack.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/EntityCarryStack.java @@ -6,6 +6,8 @@ import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import xyz.nucleoid.farmyfeud.FarmyFeud; import java.util.ArrayList; import java.util.Collections; @@ -13,7 +15,7 @@ import java.util.UUID; public final class EntityCarryStack { - private static final UUID SLOW_MODIFIER_ID = UUID.fromString("19462f6a-7346-4e27-846f-68864be3ddcb"); + private static final Identifier SLOW_MODIFIER_ID = Identifier.of(FarmyFeud.ID, "stack_slowness"); private final int maximumHeight; private final List stack = new ArrayList<>(); @@ -64,7 +66,7 @@ public List dropAll(ServerPlayerEntity player) { private void onStackChange(ServerPlayerEntity player) { player.networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player)); - EntityAttributeInstance attribute = player.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED); + EntityAttributeInstance attribute = player.getAttributeInstance(EntityAttributes.MOVEMENT_SPEED); if (attribute == null) { return; } @@ -76,8 +78,8 @@ private void onStackChange(ServerPlayerEntity player) { double targetValue = baseValue / (this.stack.size() * 0.3 + 1); EntityAttributeModifier modifier = new EntityAttributeModifier( - SLOW_MODIFIER_ID, "carry slow", - targetValue - baseValue, EntityAttributeModifier.Operation.ADDITION + SLOW_MODIFIER_ID, + targetValue - baseValue, EntityAttributeModifier.Operation.ADD_VALUE ); attribute.addTemporaryModifier(modifier); diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfActive.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfActive.java index 382cb31..60510fc 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfActive.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfActive.java @@ -17,7 +17,6 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -29,15 +28,17 @@ import xyz.nucleoid.farmyfeud.game.FfSpawnLogic; import xyz.nucleoid.farmyfeud.game.map.FfMap; import xyz.nucleoid.map_templates.BlockBounds; -import xyz.nucleoid.plasmid.game.GameCloseReason; -import xyz.nucleoid.plasmid.game.GameSpace; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.game.common.team.*; -import xyz.nucleoid.plasmid.game.event.GameActivityEvents; -import xyz.nucleoid.plasmid.game.event.GamePlayerEvents; -import xyz.nucleoid.plasmid.game.rule.GameRuleType; -import xyz.nucleoid.plasmid.util.ColoredBlocks; -import xyz.nucleoid.plasmid.util.ItemStackBuilder; +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.common.team.*; +import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents; +import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents; +import xyz.nucleoid.plasmid.api.game.player.JoinOffer; +import xyz.nucleoid.plasmid.api.game.rule.GameRuleType; +import xyz.nucleoid.plasmid.api.util.ColoredBlocks; +import xyz.nucleoid.plasmid.api.util.ItemStackBuilder; +import xyz.nucleoid.stimuli.event.EventResult; import xyz.nucleoid.stimuli.event.item.ItemUseEvent; import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; @@ -116,29 +117,32 @@ private FfActive(GameSpace gameSpace, ServerWorld world, FfMap map, FfConfig con } } - public static void open(GameSpace gameSpace, ServerWorld world, FfMap map, FfConfig config) { + public static void open(GameSpace gameSpace, ServerWorld world, FfMap map, FfConfig config, TeamSelectionLobby teamSelection) { gameSpace.setActivity(game -> { GlobalWidgets widgets = GlobalWidgets.addTo(game); var teamManager = TeamManager.addTo(game); FfActive active = new FfActive(gameSpace, world, map, config, teamManager, widgets); + teamSelection.allocate(gameSpace.getPlayers().participants(), (gameTeamKey, player) -> teamManager.addPlayerTo(player, gameTeamKey)); - game.setRule(GameRuleType.CRAFTING, ActionResult.FAIL); - game.setRule(GameRuleType.PORTALS, ActionResult.FAIL); - game.setRule(GameRuleType.PVP, ActionResult.SUCCESS); - game.setRule(GameRuleType.FALL_DAMAGE, ActionResult.SUCCESS); - game.setRule(GameRuleType.BLOCK_DROPS, ActionResult.FAIL); - game.setRule(GameRuleType.HUNGER, ActionResult.FAIL); - game.setRule(GameRuleType.SATURATED_REGENERATION, ActionResult.FAIL); - game.setRule(GameRuleType.THROW_ITEMS, ActionResult.FAIL); + game.setRule(GameRuleType.CRAFTING, EventResult.DENY); + game.setRule(GameRuleType.PORTALS, EventResult.DENY); + game.setRule(GameRuleType.PVP, EventResult.ALLOW); + game.setRule(GameRuleType.FALL_DAMAGE, EventResult.ALLOW); + game.setRule(GameRuleType.BLOCK_DROPS, EventResult.DENY); + game.setRule(GameRuleType.HUNGER, EventResult.DENY); + game.setRule(GameRuleType.SATURATED_REGENERATION, EventResult.DENY); + game.setRule(GameRuleType.THROW_ITEMS, EventResult.DENY); TeamChat.addTo(game, teamManager); game.listen(GameActivityEvents.ENABLE, active::open); game.listen(GameActivityEvents.DISABLE, active::close); + game.listen(GameActivityEvents.STATE_UPDATE, state -> state.canPlay(false)); - game.listen(GamePlayerEvents.OFFER, player -> player.accept(world, map.getCenterSpawn() != null ? map.getCenterSpawn().center() : new Vec3d(0, 256, 0))); + game.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators); + game.listen(GamePlayerEvents.ACCEPT, player -> player.teleport(world, map.getCenterSpawn() != null ? map.getCenterSpawn().center() : new Vec3d(0, 256, 0))); game.listen(GamePlayerEvents.ADD, active::addPlayer); game.listen(GameActivityEvents.TICK, active::tick); @@ -158,7 +162,7 @@ private void open() { this.initNextSpawnTime(time); this.initNextArrowTime(time); - int sheepCount = (this.config.teams().size() * 3) / 2; + int sheepCount = (this.config.teams().list().size() * 3) / 2; for (int i = 0; i < sheepCount; i++) { this.spawnSheep(); } @@ -174,8 +178,13 @@ private void close() { } private void addPlayer(ServerPlayerEntity player) { - FfParticipant participant = this.getOrCreateParticipant(player); - this.spawnParticipant(player, participant); + if (this.gameSpace.getPlayers().participants().contains(player)) { + FfParticipant participant = this.getOrCreateParticipant(player); + this.spawnParticipant(player, participant); + } else { + this.spawnLogic.spawnPlayerAtCenter(player); + this.spawnLogic.resetPlayer(player, GameMode.SPECTATOR); + } } private void tick() { @@ -316,7 +325,7 @@ private void onSwingHand(ServerPlayerEntity player, Hand hand) { } } - private TypedActionResult onUseItem(ServerPlayerEntity player, Hand hand) { + private ActionResult onUseItem(ServerPlayerEntity player, Hand hand) { ItemStack heldStack = player.getStackInHand(hand); if (heldStack.getItem() == Items.SADDLE) { @@ -328,12 +337,12 @@ private TypedActionResult onUseItem(ServerPlayerEntity player, Hand h if (traceResult != null) { this.tryPickUpSheep(player, participant, (FarmSheepEntity) traceResult.getEntity()); - return TypedActionResult.consume(heldStack); + return ActionResult.CONSUME; } } } else if (heldStack.getItem() instanceof AxeItem) { ItemCooldownManager cooldown = player.getItemCooldownManager(); - if (!cooldown.isCoolingDown(heldStack.getItem())) { + if (!cooldown.isCoolingDown(heldStack)) { FfParticipant participant = this.getParticipant(player); if (participant != null) { Vec3d rotationVec = player.getRotationVec(1.0F); @@ -341,12 +350,12 @@ private TypedActionResult onUseItem(ServerPlayerEntity player, Hand h player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player)); player.playSound(SoundEvents.ENTITY_HORSE_SADDLE, 1.0F, 1.0F); - cooldown.set(heldStack.getItem(), LEAP_INTERVAL_TICKS); + cooldown.set(heldStack, LEAP_INTERVAL_TICKS); } } } - return TypedActionResult.pass(ItemStack.EMPTY); + return ActionResult.PASS; } public boolean tryPickUpSheep(ServerPlayerEntity player, FfParticipant participant, FarmSheepEntity sheep) { @@ -426,7 +435,7 @@ private void throwEntities(ServerPlayerEntity player, Collection { - FfTeamState teamState = this.getSmallestTeam(); + FfTeamState teamState = this.teams.get(this.teamManager.teamFor(player)); teamState.addParticipant(uuid); this.teamManager.addPlayerTo(player, teamState.team); @@ -572,15 +581,6 @@ public FfParticipant getParticipant(Entity entity) { return this.participants.get(entity.getUuid()); } - private FfTeamState getSmallestTeam() { - List teams = new ArrayList<>(this.teams.values()); - Collections.shuffle(teams); - - return teams.stream() - .min(Comparator.comparingInt(FfTeamState::getParticipantCount)) - .orElseThrow(() -> new IllegalStateException("no teams present!")); - } - private record WinResult(@Nullable GameTeamKey winningTeam, boolean win) { public static WinResult win(GameTeamKey winningTeam) { diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfCaptureLogic.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfCaptureLogic.java index a792c74..75a7fca 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfCaptureLogic.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfCaptureLogic.java @@ -1,5 +1,6 @@ package xyz.nucleoid.farmyfeud.game.active; +import net.minecraft.component.type.FireworkExplosionComponent; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.FireworkRocketEntity; import net.minecraft.item.FireworkRocketItem; @@ -10,9 +11,9 @@ import xyz.nucleoid.farmyfeud.entity.FarmSheepEntity; import xyz.nucleoid.farmyfeud.game.map.FfMap; import xyz.nucleoid.map_templates.BlockBounds; -import xyz.nucleoid.plasmid.game.common.team.GameTeam; -import xyz.nucleoid.plasmid.game.common.team.GameTeamKey; -import xyz.nucleoid.plasmid.util.ItemStackBuilder; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeam; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey; +import xyz.nucleoid.plasmid.api.util.ItemStackBuilder; record FfCaptureLogic(FfActive game) { @@ -57,7 +58,7 @@ private void spawnFireworkAt(Entity entity, GameTeamKey team) { int flight = world.random.nextInt(3); - FireworkRocketItem.Type type = world.random.nextInt(4) == 0 ? FireworkRocketItem.Type.STAR : FireworkRocketItem.Type.BURST; + var type = world.random.nextInt(4) == 0 ? FireworkExplosionComponent.Type.STAR : FireworkExplosionComponent.Type.BURST; FireworkRocketEntity firework = new FireworkRocketEntity( world, entity.getX(), diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfParticipant.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfParticipant.java index 34d3e1c..89263b5 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfParticipant.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfParticipant.java @@ -3,8 +3,8 @@ import net.minecraft.server.network.ServerPlayerEntity; import org.jetbrains.annotations.Nullable; import xyz.nucleoid.farmyfeud.entity.FarmSheepEntity; -import xyz.nucleoid.plasmid.game.GameSpace; -import xyz.nucleoid.plasmid.game.common.team.GameTeamKey; +import xyz.nucleoid.plasmid.api.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey; import java.util.UUID; diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfScoreboard.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfScoreboard.java index 47a036c..3a7ce92 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfScoreboard.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfScoreboard.java @@ -4,8 +4,8 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget; +import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets; +import xyz.nucleoid.plasmid.api.game.common.widget.SidebarWidget; public record FfScoreboard(FfActive game, SidebarWidget sidebar) { diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTeamState.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTeamState.java index f6283f1..a23881f 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTeamState.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTeamState.java @@ -1,6 +1,6 @@ package xyz.nucleoid.farmyfeud.game.active; -import xyz.nucleoid.plasmid.game.common.team.GameTeamKey; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey; import java.util.HashSet; import java.util.Set; diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTimerBar.java b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTimerBar.java index 9c8f5f5..efd5fbd 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTimerBar.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/active/FfTimerBar.java @@ -2,8 +2,8 @@ import net.minecraft.entity.boss.BossBar; import net.minecraft.text.Text; -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 record FfTimerBar(BossBarWidget widget) { diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMap.java b/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMap.java index 764d8e2..c56dc20 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMap.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMap.java @@ -5,8 +5,8 @@ import org.jetbrains.annotations.Nullable; import xyz.nucleoid.map_templates.BlockBounds; import xyz.nucleoid.map_templates.MapTemplate; -import xyz.nucleoid.plasmid.game.common.team.GameTeamKey; -import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey; +import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMapBuilder.java b/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMapBuilder.java index 84d3d10..88bbcdd 100644 --- a/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMapBuilder.java +++ b/src/main/java/xyz/nucleoid/farmyfeud/game/map/FfMapBuilder.java @@ -8,7 +8,7 @@ import xyz.nucleoid.map_templates.MapTemplate; import xyz.nucleoid.map_templates.MapTemplateMetadata; import xyz.nucleoid.map_templates.MapTemplateSerializer; -import xyz.nucleoid.plasmid.game.common.team.GameTeam; +import xyz.nucleoid.plasmid.api.game.common.team.GameTeam; import java.io.IOException; diff --git a/src/main/resources/data/farmy_feud/map_templates/farmy_feud_1.nbt b/src/main/resources/data/farmy_feud/map_template/farmy_feud_1.nbt similarity index 100% rename from src/main/resources/data/farmy_feud/map_templates/farmy_feud_1.nbt rename to src/main/resources/data/farmy_feud/map_template/farmy_feud_1.nbt diff --git a/src/main/resources/data/farmy_feud/games/standard.json b/src/main/resources/data/farmy_feud/plasmid/game/standard.json similarity index 100% rename from src/main/resources/data/farmy_feud/games/standard.json rename to src/main/resources/data/farmy_feud/plasmid/game/standard.json diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 58fe89a..d3fb19e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,7 +12,7 @@ }, "depends": { "fabric": "*", - "minecraft": ">=1.19.3", - "plasmid": "0.5.x" + "minecraft": ">=1.20.4", + "plasmid": "0.6.x" } }