diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 822a466..ea9a391 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: with: cache: gradle distribution: zulu - 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 6ab0165..52a3acd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.8.12" + id "fabric-loom" version "1.9.2" id "maven-publish" } @@ -44,12 +44,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 9c6ff3f..419f0d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,10 +5,10 @@ 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.110.0+1.21.3 -plasmid_version = 0.5.102-SNAPSHOT+1.20.4 +plasmid_version = 0.6.1+1.21.3 wasmtime_version = 0.18.0 diff --git a/src/main/java/io/github/haykam821/consolebox/ConsoleBox.java b/src/main/java/io/github/haykam821/consolebox/ConsoleBox.java index 5bfdaa6..078bdf6 100644 --- a/src/main/java/io/github/haykam821/consolebox/ConsoleBox.java +++ b/src/main/java/io/github/haykam821/consolebox/ConsoleBox.java @@ -5,16 +5,20 @@ import io.github.haykam821.consolebox.resource.ConsoleGameManager; import net.fabricmc.api.ModInitializer; import net.minecraft.util.Identifier; -import xyz.nucleoid.plasmid.game.GameType; +import xyz.nucleoid.plasmid.api.game.GameType; public class ConsoleBox implements ModInitializer { public static final String MOD_ID = "consolebox"; - private static final Identifier CONSOLE_BOX_ID = new Identifier(MOD_ID, "console_box"); + private static final Identifier CONSOLE_BOX_ID = ConsoleBox.identifier("console_box"); public static final GameType CONSOLE_BOX = GameType.register(CONSOLE_BOX_ID, ConsoleBoxConfig.CODEC, ConsoleBoxGame::open); @Override public void onInitialize() { ConsoleGameManager.register(); } + + public static Identifier identifier(String path) { + return Identifier.of(MOD_ID, path); + } } diff --git a/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxConfig.java b/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxConfig.java index 93d54b5..cadcf4e 100644 --- a/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxConfig.java +++ b/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxConfig.java @@ -1,6 +1,7 @@ package io.github.haykam821.consolebox.game; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.haykam821.consolebox.resource.ConsoleGameManager; @@ -8,7 +9,7 @@ import net.minecraft.util.Identifier; import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.Vec3d; -import xyz.nucleoid.plasmid.game.GameOpenException; +import xyz.nucleoid.plasmid.api.game.GameOpenException; public record ConsoleBoxConfig( Identifier game, @@ -18,7 +19,7 @@ public record ConsoleBoxConfig( ) { private static final Vec3d DEFAULT_SPECTATOR_SPAWN_OFFSET = new Vec3d(0, 2, 0); - public static final Codec CODEC = RecordCodecBuilder.create(instance -> { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> { return instance.group( Identifier.CODEC.fieldOf("game").forGetter(ConsoleBoxConfig::game), Codecs.VECTOR_3F.xmap(Vec3d::new, Vec3d::toVector3f).optionalFieldOf("spectator_spawn_offset", DEFAULT_SPECTATOR_SPAWN_OFFSET).forGetter(ConsoleBoxConfig::spectatorSpawnOffset), diff --git a/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxGame.java b/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxGame.java index 0ad2816..86bd2a6 100644 --- a/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxGame.java +++ b/src/main/java/io/github/haykam821/consolebox/game/ConsoleBoxGame.java @@ -4,38 +4,44 @@ import io.github.haykam821.consolebox.game.audio.BaseAudioController; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.passive.MuleEntity; +import net.minecraft.entity.player.PlayerPosition; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.PlayerInputC2SPacket; import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; -import net.minecraft.registry.RegistryKeys; +import net.minecraft.network.packet.s2c.play.PositionFlag; +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.PlayerInput; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; import xyz.nucleoid.fantasy.RuntimeWorldConfig; import xyz.nucleoid.fantasy.util.VoidChunkGenerator; -import xyz.nucleoid.plasmid.game.*; -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.*; +import xyz.nucleoid.plasmid.api.game.common.PlayerLimiter; +import xyz.nucleoid.plasmid.api.game.common.config.PlayerLimiterConfig; +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.rule.GameRuleType; +import xyz.nucleoid.stimuli.event.EventResult; import xyz.nucleoid.stimuli.event.player.PlayerC2SPacketEvent; import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; import java.util.Set; -public class ConsoleBoxGame implements GamePlayerEvents.Add, GameActivityEvents.Destroy, GameActivityEvents.Tick, GameActivityEvents.Enable, GamePlayerEvents.Remove, GamePlayerEvents.Offer, PlayerDamageEvent, PlayerDeathEvent, PlayerC2SPacketEvent { +public class ConsoleBoxGame implements GamePlayerEvents.Add, GameActivityEvents.Destroy, GameActivityEvents.Tick, GameActivityEvents.Enable, GamePlayerEvents.Remove, GamePlayerEvents.Accept, PlayerDamageEvent, PlayerDeathEvent, PlayerC2SPacketEvent { private final Thread thread; private final GameSpace gameSpace; @@ -86,7 +92,7 @@ public static GameOpenProcedure open(GameOpenContext context) ConsoleBoxConfig config = context.config(); RuntimeWorldConfig worldConfig = new RuntimeWorldConfig() - .setGenerator(new VoidChunkGenerator(context.server().getRegistryManager().get(RegistryKeys.BIOME))); + .setGenerator(new VoidChunkGenerator(context.server())); var audioController = new BaseAudioController(); @@ -101,12 +107,14 @@ public static GameOpenProcedure open(GameOpenContext context) audioController.setOutput(phase); ConsoleBoxGame.setRules(activity); + PlayerLimiter.addTo(activity, new PlayerLimiterConfig(phase.players.length)); + // Listeners activity.listen(GamePlayerEvents.ADD, phase); activity.listen(GameActivityEvents.ENABLE, phase); activity.listen(GameActivityEvents.DESTROY, phase); activity.listen(GameActivityEvents.TICK, phase); - activity.listen(GamePlayerEvents.OFFER, phase); + activity.listen(GamePlayerEvents.ACCEPT, phase); activity.listen(PlayerDamageEvent.EVENT, phase); activity.listen(PlayerDeathEvent.EVENT, phase); activity.listen(GamePlayerEvents.REMOVE, phase); @@ -132,7 +140,7 @@ public void onDestroy(GameCloseReason reason) { } @Override - public ActionResult onPacket(ServerPlayerEntity player, Packet packet) { + public EventResult onPacket(ServerPlayerEntity player, Packet packet) { int id = -1; for (int i = 0; i < 4; i++) { if (this.players[i] == player) { @@ -142,27 +150,31 @@ public ActionResult onPacket(ServerPlayerEntity player, Packet packet) { } if (id == -1) { - return ActionResult.PASS; + return EventResult.PASS; } if (packet instanceof PlayerInputC2SPacket playerInputC2SPacket) { - var isJumping = this.config.swapXZ() ? playerInputC2SPacket.isSneaking() : playerInputC2SPacket.isJumping(); - var isSneaking = !this.config.swapXZ() ? playerInputC2SPacket.isSneaking() : playerInputC2SPacket.isJumping(); + PlayerInput input = playerInputC2SPacket.input(); + + var isJumping = this.config.swapXZ() ? input.sneak() : input.jump(); + var isSneaking = !this.config.swapXZ() ? input.sneak() : input.jump(); - this.canvas.updateGamepad(id, playerInputC2SPacket.getSideways(), playerInputC2SPacket.getForward(), + this.canvas.updateGamepad(id, input.forward(), input.left(), input.backward(), input.right(), isSneaking, isJumping); } - return ActionResult.PASS; + return EventResult.PASS; } @Override public void onTick() { for (var player : this.players) { if (player != null) { + PlayerPosition pos = new PlayerPosition(Vec3d.ZERO, Vec3d.ZERO, 180, 0); + Set flags = Set.of(); + player.networkHandler.sendPacket( - new PlayerPositionLookS2CPacket(player.getX(), player.getY(), player.getZ(), 180f, 0f, - Set.of(), 0)); + new PlayerPositionLookS2CPacket(0, pos, flags)); } } } @@ -191,15 +203,15 @@ private void runThread() { // /game open {type:"consolebox:console_box", game:"consolebox:cart"} @Override - public PlayerOfferResult onOfferPlayer(PlayerOffer offer) { + public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) { Vec3d spawnPos = this.canvas.getSpawnPos(); - if (this.playerCount < this.config.playerCount()) { + if (acceptor.intent().canPlay()) { for (int i = 0; i < players.length; i++) { final var x = i; if (this.players[x] == null) { - return offer.accept(this.world, spawnPos).and(() -> { - this.players[x] = offer.player(); + return acceptor.teleport(this.world, spawnPos).thenRunForEach(player -> { + this.players[x] = player; this.playerCount++; this.spawnMount(spawnPos, this.players[x]); @@ -210,19 +222,19 @@ public PlayerOfferResult onOfferPlayer(PlayerOffer offer) { } Vec3d pos = spawnPos.add(this.config.spectatorSpawnOffset()); - return offer.accept(this.world, pos).and(() -> { - this.initializePlayer(offer.player(), GameMode.SPECTATOR); + return acceptor.teleport(this.world, pos).thenRunForEach(player -> { + this.initializePlayer(player, GameMode.SPECTATOR); }); } @Override - public ActionResult onDamage(ServerPlayerEntity player, DamageSource source, float damage) { - return ActionResult.FAIL; + public EventResult onDamage(ServerPlayerEntity player, DamageSource source, float damage) { + return EventResult.DENY; } @Override - public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) { - return ActionResult.FAIL; + public EventResult onDeath(ServerPlayerEntity player, DamageSource source) { + return EventResult.DENY; } @Override @@ -240,7 +252,7 @@ public void onRemovePlayer(ServerPlayerEntity player) { for (int i = 0; i < 4; i++) { if (this.players[i] == player) { this.players[i] = null; - this.canvas.updateGamepad(i, 0, 0, false, false); + this.canvas.updateGamepad(i, false, false, false, false, false, false); this.playerCount--; break; } @@ -250,7 +262,7 @@ public void onRemovePlayer(ServerPlayerEntity player) { // Utilities private Entity spawnMount(Vec3d playerPos, ServerPlayerEntity player) { - MuleEntity mount = EntityType.MULE.create(this.world); + MuleEntity mount = EntityType.MULE.create(this.world, SpawnReason.JOCKEY); mount.calculateDimensions(); double y = playerPos.getY() - 1.25f; mount.setPos(playerPos.getX(), y, playerPos.getZ()); @@ -266,7 +278,7 @@ private Entity spawnMount(Vec3d playerPos, ServerPlayerEntity player) { mount.setInvisible(true); // Remove mount hearts from HUD - mount.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).setBaseValue(0); + mount.getAttributeInstance(EntityAttributes.MAX_HEALTH).setBaseValue(0); this.world.spawnEntity(mount); player.startRiding(mount, true); @@ -285,7 +297,7 @@ private void initializePlayer(ServerPlayerEntity player, GameMode gameMode) { player.setPitch(Float.MIN_VALUE); } - private StatusEffectInstance createInfiniteStatusEffect(StatusEffect statusEffect) { - return new StatusEffectInstance(statusEffect, Integer.MAX_VALUE, 0, true, false); + private StatusEffectInstance createInfiniteStatusEffect(RegistryEntry statusEffect) { + return new StatusEffectInstance(statusEffect, StatusEffectInstance.INFINITE, 0, true, false); } } \ No newline at end of file diff --git a/src/main/java/io/github/haykam821/consolebox/game/GameCanvas.java b/src/main/java/io/github/haykam821/consolebox/game/GameCanvas.java index c54c584..19bdb23 100644 --- a/src/main/java/io/github/haykam821/consolebox/game/GameCanvas.java +++ b/src/main/java/io/github/haykam821/consolebox/game/GameCanvas.java @@ -319,9 +319,9 @@ public void render() { } } - public void updateGamepad(int id, float leftRight, float upDown, boolean isSneaking, boolean isJumping) { + public void updateGamepad(int id, boolean forward, boolean left, boolean backward, boolean right, boolean isSneaking, boolean isJumping) { synchronized (this) { - this.memory.updateGamepad(id, leftRight, upDown, isSneaking, isJumping); + this.memory.updateGamepad(id, forward, left, backward, right, isSneaking, isJumping); } } diff --git a/src/main/java/io/github/haykam821/consolebox/game/GameMemory.java b/src/main/java/io/github/haykam821/consolebox/game/GameMemory.java index 504e21a..35a68f2 100644 --- a/src/main/java/io/github/haykam821/consolebox/game/GameMemory.java +++ b/src/main/java/io/github/haykam821/consolebox/game/GameMemory.java @@ -105,16 +105,16 @@ public ByteBuffer readSprite(int start, int width, int height, int bit) { return this.buffer.slice(start, width * height * bit); } - public void updateGamepad(int id, float leftRight, float upDown, boolean isSneaking, boolean isJumping) { + public void updateGamepad(int id, boolean forward, boolean left, boolean backward, boolean right, boolean isSneaking, boolean isJumping) { byte gamepad = 0; if (isJumping) gamepad |= 1; // Z if (isSneaking) gamepad |= 2; // X - if (leftRight > 0) gamepad |= 16; // Left - if (leftRight < 0) gamepad |= 32; // Right - if (upDown > 0) gamepad |= 64; // Up - if (upDown < 0) gamepad |= 128; // Down + if (left) gamepad |= 16; // Left + if (right) gamepad |= 32; // Right + if (forward) gamepad |= 64; // Up + if (backward) gamepad |= 128; // Down this.buffer.put(GAMEPADS_ADDRESS + id, gamepad); } diff --git a/src/main/java/io/github/haykam821/consolebox/resource/ConsoleGameManager.java b/src/main/java/io/github/haykam821/consolebox/resource/ConsoleGameManager.java index d35707e..64ffe93 100644 --- a/src/main/java/io/github/haykam821/consolebox/resource/ConsoleGameManager.java +++ b/src/main/java/io/github/haykam821/consolebox/resource/ConsoleGameManager.java @@ -16,7 +16,7 @@ import net.minecraft.util.Identifier; public class ConsoleGameManager implements SimpleSynchronousResourceReloadListener { - private static final Identifier ID = new Identifier(ConsoleBox.MOD_ID, "console_games"); + private static final Identifier ID = ConsoleBox.identifier("console_games"); private static final Logger LOGGER = LoggerFactory.getLogger("ConsoleGameManager"); private static final String GAME_PREFIX = "console_games"; @@ -50,9 +50,10 @@ private boolean isGamePath(Identifier path) { private Identifier parsePath(Identifier id) { String prefix = GAME_PREFIX + "/"; - String path = id.getPath().substring(prefix.length(), id.getPath().length() - GAME_EXTENSION.length()); - return new Identifier(id.getNamespace(), path); + return id.withPath(path -> { + return path.substring(prefix.length(), path.length() - GAME_EXTENSION.length()); + }); } public static byte[] getGameData(Identifier id) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1a86842..6cffab4 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,7 +22,7 @@ "license": "MIT", "depends": { "fabricloader": ">=0.4.0", - "java": ">=17", - "plasmid": ">=0.5.0" + "java": ">=21", + "plasmid": ">=0.6.0" } }