Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update minigame to Minecraft 1.21.3 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.8.12"
id "fabric-loom" version "1.8.13"
id "maven-publish"
}

Expand Down Expand Up @@ -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"
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.110.0+1.21.3

plasmid_version = 0.5.102-SNAPSHOT+1.20.4
plasmid_version = 0.6.0+1.21.3
4 changes: 2 additions & 2 deletions src/main/java/io/github/haykam821/parkourrun/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.api.game.GameType;

public class Main implements ModInitializer {
private static final String MOD_ID = "parkourrun";
Expand All @@ -24,6 +24,6 @@ public void onInitialize() {
}

public static Identifier identifier(String path) {
return new Identifier(MOD_ID, path);
return Identifier.of(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package io.github.haykam821.parkourrun.game;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import io.github.haykam821.parkourrun.game.map.ParkourRunMapConfig;
import xyz.nucleoid.plasmid.game.common.config.PlayerConfig;
import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig;

public class ParkourRunConfig {
public static final Codec<ParkourRunConfig> CODEC = RecordCodecBuilder.create(instance -> {
public static final MapCodec<ParkourRunConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> {
return instance.group(
ParkourRunMapConfig.CODEC.fieldOf("map").forGetter(ParkourRunConfig::getMapConfig),
PlayerConfig.CODEC.fieldOf("players").forGetter(ParkourRunConfig::getPlayerConfig)
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(ParkourRunConfig::getPlayerConfig)
).apply(instance, ParkourRunConfig::new);
});

private final ParkourRunMapConfig mapConfig;
private final PlayerConfig playerConfig;
private final WaitingLobbyConfig playerConfig;

public ParkourRunConfig(ParkourRunMapConfig mapConfig, PlayerConfig playerConfig) {
public ParkourRunConfig(ParkourRunMapConfig mapConfig, WaitingLobbyConfig playerConfig) {
this.mapConfig = mapConfig;
this.playerConfig = playerConfig;
}
Expand All @@ -26,7 +26,7 @@ public ParkourRunMapConfig getMapConfig() {
return this.mapConfig;
}

public PlayerConfig getPlayerConfig() {
public WaitingLobbyConfig getPlayerConfig() {
return this.playerConfig;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.haykam821.parkourrun.game;

import java.util.Set;

import io.github.haykam821.parkourrun.game.map.ParkourRunMap;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -22,6 +24,6 @@ public Vec3d getSpawnPos() {

public void spawnPlayer(ServerPlayerEntity player) {
Vec3d pos = this.getSpawnPos();
player.teleport(this.world, pos.getX(), pos.getY(), pos.getZ(), player.getYaw(), player.getPitch());
player.teleport(this.world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), player.getYaw(), player.getPitch(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer;
import net.minecraft.structure.PoolStructurePiece;
import net.minecraft.structure.StructureLiquidSettings;
import net.minecraft.structure.StructureTemplate;
import net.minecraft.structure.StructureTemplateManager;
import net.minecraft.structure.pool.SinglePoolElement;
Expand All @@ -28,7 +29,7 @@
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.plasmid.game.world.generator.GameChunkGenerator;
import xyz.nucleoid.plasmid.api.game.world.generator.GameChunkGenerator;

public class ParkourRunChunkGenerator extends GameChunkGenerator {
private static final Identifier STARTS_ID = Main.identifier("starts");
Expand All @@ -50,7 +51,7 @@ public ParkourRunChunkGenerator(MinecraftServer server, ParkourRunMap map) {
this.map = map;
this.structureTemplateManager = server.getStructureTemplateManager();

Registry<StructurePool> poolRegistry = server.getRegistryManager().get(RegistryKeys.TEMPLATE_POOL);
Registry<StructurePool> poolRegistry = server.getRegistryManager().getOrThrow(RegistryKeys.TEMPLATE_POOL);
this.starts = poolRegistry.get(STARTS_ID);
this.areas = poolRegistry.get(AREAS_ID);
this.connectors = poolRegistry.get(CONNECTORS_ID);
Expand Down Expand Up @@ -78,7 +79,7 @@ private void generatePiece(String marker, Set<PoolStructurePiece> pieces, Struct
StructureTemplate structure = ((SinglePoolElement) element).getStructure(this.structureTemplateManager);

BlockBox box = BlockBox.create(pos, pos.add(structure.getSize()));
PoolStructurePiece piece = new PoolStructurePiece(this.structureTemplateManager, element, pos.toImmutable(), 0, BlockRotation.NONE, box);
PoolStructurePiece piece = new PoolStructurePiece(this.structureTemplateManager, element, pos.toImmutable(), 0, BlockRotation.NONE, box, StructureLiquidSettings.APPLY_WATERLOGGING);
pieces.add(piece);

this.map.getTemplate().getMetadata().addRegion(marker, BlockBounds.of(pos, pos.add(structure.getSize())));
Expand Down Expand Up @@ -114,7 +115,7 @@ public void generateFeatures(StructureWorldAccess world, Chunk chunk, StructureA
List<PoolStructurePiece> pieces = this.piecesByChunk.remove(chunkPos.toLong());

if (pieces != null) {
BlockBox chunkBox = new BlockBox(chunkPos.getStartX(), world.getBottomY(), chunkPos.getStartZ(), chunkPos.getEndX(), world.getTopY(), chunkPos.getEndZ());
BlockBox chunkBox = new BlockBox(chunkPos.getStartX(), world.getBottomY(), chunkPos.getStartZ(), chunkPos.getEndX(), world.getTopYInclusive(), chunkPos.getEndZ());
for (PoolStructurePiece piece : pieces) {
piece.generate(world, structures, this, world.getRandom(), chunkBox, this.map.getOrigin(), false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
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.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameCloseReason;
import xyz.nucleoid.plasmid.game.GameSpace;
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.GameActivity;
import xyz.nucleoid.plasmid.api.game.GameCloseReason;
import xyz.nucleoid.plasmid.api.game.GameSpace;
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 ParkourRunActivePhase {
Expand All @@ -34,7 +35,7 @@ public ParkourRunActivePhase(GameSpace gameSpace, ServerWorld world, ParkourRunS
this.gameSpace = gameSpace;
this.world = world;
this.spawnLogic = spawnLogic;
this.players = Sets.newHashSet(gameSpace.getPlayers());
this.players = Sets.newHashSet(gameSpace.getPlayers().participants());
this.startTime = world.getTime();
}

Expand All @@ -53,12 +54,21 @@ public static void open(GameSpace gameSpace, ServerWorld world, ParkourRunSpawnL
ParkourRunActivePhase.setRules(activity);

// 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::accept);
activity.listen(PlayerDeathEvent.EVENT, phase::onPlayerDeath);
});
}

public void enable() {
for (ServerPlayerEntity player : this.gameSpace.getPlayers().spectators()) {
this.spawnLogic.spawnPlayer(player);
player.changeGameMode(GameMode.SPECTATOR);
}
}

public void tick() {
Iterator<ServerPlayerEntity> iterator = this.players.iterator();
while (iterator.hasNext()) {
Expand All @@ -75,19 +85,19 @@ public void tick() {
}
}

public PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.accept(this.world, this.spawnLogic.getSpawnPos()).and(() -> {
if (this.players.contains(offer.player())) {
offer.player().changeGameMode(GameMode.ADVENTURE);
public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) {
return acceptor.teleport(this.world, this.spawnLogic.getSpawnPos()).thenRunForEach(player -> {
if (this.players.contains(player)) {
player.changeGameMode(GameMode.ADVENTURE);
} else {
offer.player().changeGameMode(GameMode.SPECTATOR);
player.changeGameMode(GameMode.SPECTATOR);
}
});
}

public ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
public EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
// Respawn player at the start
this.spawnLogic.spawnPlayer(player);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
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.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.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

public class ParkourRunWaitingPhase {
Expand All @@ -43,7 +44,8 @@ public static GameOpenProcedure open(GameOpenContext<ParkourRunConfig> context)
ParkourRunActivePhase.setRules(activity);

// Listeners
activity.listen(GamePlayerEvents.OFFER, phase::offerPlayer);
activity.listen(GamePlayerEvents.ACCEPT, phase::onAcceptPlayers);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept);
activity.listen(PlayerDeathEvent.EVENT, phase::onPlayerDeath);
activity.listen(GameActivityEvents.REQUEST_START, phase::requestStart);
});
Expand All @@ -54,15 +56,15 @@ public GameResult requestStart() {
return GameResult.ok();
}

public PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.accept(this.world, this.spawnLogic.getSpawnPos()).and(() -> {
offer.player().changeGameMode(GameMode.ADVENTURE);
public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) {
return acceptor.teleport(this.world, this.spawnLogic.getSpawnPos()).thenRunForEach(player -> {
player.changeGameMode(GameMode.ADVENTURE);
});
}

public ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
public EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
// Respawn player at the start
this.spawnLogic.spawnPlayer(player);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"icon": "assets/parkourrun/icon.png",
"depends": {
"fabricloader": ">=0.5.0",
"java": ">=17",
"plasmid": ">=0.5.0"
"java": ">=21",
"plasmid": ">=0.6.0"
}
}