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 #7

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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ processResources {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile) {
options.release = 17
options.release = 21
options.encoding = "UTF-8"
}

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.109.0+1.21.3

plasmid_version = 0.5.102-SNAPSHOT+1.20.4
plasmid_version = 0.6.0+1.21.3
16 changes: 10 additions & 6 deletions src/main/java/io/github/haykam821/downpour/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
import io.github.haykam821.downpour.game.phase.DownpourWaitingPhase;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.game.stats.StatisticKey;
import xyz.nucleoid.plasmid.api.game.GameType;
import xyz.nucleoid.plasmid.api.game.stats.StatisticKey;

public class Main implements ModInitializer {
public static final String MOD_ID = "downpour";
private static final String MOD_ID = "downpour";

private static final Identifier DOWNPOUR_ID = new Identifier(MOD_ID, "downpour");
private static final Identifier DOWNPOUR_ID = Main.identifier("downpour");
public static final GameType<DownpourConfig> DOWNPOUR_TYPE = GameType.register(DOWNPOUR_ID, DownpourConfig.CODEC, DownpourWaitingPhase::open);

private static final Identifier ROUNDS_SURVIVED_ID = new Identifier(MOD_ID, "rounds_survived");
private static final Identifier ROUNDS_SURVIVED_ID = Main.identifier("rounds_survived");
public static final StatisticKey<Integer> ROUNDS_SURVIVED = StatisticKey.intKey(ROUNDS_SURVIVED_ID);

private static final Identifier PLAYERS_PUNCHED_ID = new Identifier(MOD_ID, "players_punched");
private static final Identifier PLAYERS_PUNCHED_ID = Main.identifier("players_punched");
public static final StatisticKey<Integer> PLAYERS_PUNCHED = StatisticKey.intKey(PLAYERS_PUNCHED_ID);

@Override
public void onInitialize() {
return;
}

public static Identifier identifier(String path) {
return Identifier.of(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

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

import io.github.haykam821.downpour.game.map.DownpourMapConfig;
Expand All @@ -11,15 +12,15 @@
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.math.intprovider.IntProvider;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.config.PlayerConfig;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig;
import xyz.nucleoid.plasmid.api.game.stats.GameStatisticBundle;

public class DownpourConfig {
public static final Codec<DownpourConfig> CODEC = RecordCodecBuilder.create(instance -> {
public static final MapCodec<DownpourConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> {
return instance.group(
DownpourMapConfig.CODEC.fieldOf("map").forGetter(DownpourConfig::getMapConfig),
PlayerConfig.CODEC.fieldOf("players").forGetter(DownpourConfig::getPlayerConfig),
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(DownpourConfig::getPlayerConfig),
IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(DownpourConfig::getTicksUntilClose),
SoundEvent.CODEC.optionalFieldOf("lock_sound", SoundEvents.BLOCK_NOTE_BLOCK_SNARE.value()).forGetter(DownpourConfig::getLockSound),
SoundEvent.CODEC.optionalFieldOf("unlock_sound", SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER).forGetter(DownpourConfig::getUnlockSound),
Expand All @@ -31,7 +32,7 @@ public class DownpourConfig {
});

private final DownpourMapConfig mapConfig;
private final PlayerConfig playerConfig;
private final WaitingLobbyConfig playerConfig;
private final IntProvider ticksUntilClose;
private final SoundEvent lockSound;
private final SoundEvent unlockSound;
Expand All @@ -40,7 +41,7 @@ public class DownpourConfig {
private final int noKnockbackRounds;
private final Optional<String> statisticBundleNamespace;

public DownpourConfig(DownpourMapConfig mapConfig, PlayerConfig playerConfig, IntProvider ticksUntilClose, SoundEvent lockSound, SoundEvent unlockSound, int lockTime, int unlockTime, int noKnockbackRounds, Optional<String> statisticBundleNamespace) {
public DownpourConfig(DownpourMapConfig mapConfig, WaitingLobbyConfig playerConfig, IntProvider ticksUntilClose, SoundEvent lockSound, SoundEvent unlockSound, int lockTime, int unlockTime, int noKnockbackRounds, Optional<String> statisticBundleNamespace) {
this.mapConfig = mapConfig;
this.playerConfig = playerConfig;
this.ticksUntilClose = ticksUntilClose;
Expand All @@ -56,7 +57,7 @@ public DownpourMapConfig getMapConfig() {
return this.mapConfig;
}

public PlayerConfig getPlayerConfig() {
public WaitingLobbyConfig getPlayerConfig() {
return this.playerConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import net.minecraft.entity.boss.BossBar;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.widget.BossBarWidget;
import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.api.game.common.widget.BossBarWidget;

public class DownpourTimerBar {
private static final Text TITLE = Text.translatable("gameType.downpour.downpour").formatted(Formatting.AQUA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.minecraft.world.gen.chunk.ChunkGenerator;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.map_templates.MapTemplate;
import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator;
import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator;

public class DownpourMap {
private final MapTemplate template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import io.github.haykam821.downpour.Main;
Expand All @@ -18,27 +19,28 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameCloseReason;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.game.stats.GameStatisticBundle;
import xyz.nucleoid.plasmid.game.stats.StatisticKey;
import xyz.nucleoid.plasmid.game.stats.StatisticKeys;
import xyz.nucleoid.plasmid.util.PlayerRef;
import xyz.nucleoid.plasmid.api.game.GameActivity;
import xyz.nucleoid.plasmid.api.game.GameCloseReason;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptor;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptorResult;
import xyz.nucleoid.plasmid.api.game.player.JoinOffer;
import xyz.nucleoid.plasmid.api.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.api.game.stats.GameStatisticBundle;
import xyz.nucleoid.plasmid.api.game.stats.StatisticKey;
import xyz.nucleoid.plasmid.api.game.stats.StatisticKeys;
import xyz.nucleoid.plasmid.api.util.PlayerRef;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerAttackEntityEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;
Expand Down Expand Up @@ -85,7 +87,7 @@ public static void open(GameSpace gameSpace, ServerWorld world, DownpourMap map,
gameSpace.setActivity(activity -> {
GlobalWidgets widgets = GlobalWidgets.addTo(activity);

List<PlayerRef> players = gameSpace.getPlayers().stream().map(PlayerRef::of).collect(Collectors.toList());
List<PlayerRef> players = gameSpace.getPlayers().participants().stream().map(PlayerRef::of).collect(Collectors.toList());
Collections.shuffle(players);

DownpourActivePhase phase = new DownpourActivePhase(gameSpace, world, map, config, players, widgets);
Expand All @@ -95,7 +97,8 @@ public static void open(GameSpace gameSpace, ServerWorld world, DownpourMap map,
// Listeners
activity.listen(GameActivityEvents.ENABLE, phase::enable);
activity.listen(GameActivityEvents.TICK, phase::tick);
activity.listen(GamePlayerEvents.OFFER, phase::offerPlayer);
activity.listen(GamePlayerEvents.ACCEPT, phase::onAcceptPlayers);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators);
activity.listen(GamePlayerEvents.REMOVE, phase::removePlayer);
activity.listen(PlayerAttackEntityEvent.EVENT, phase::onPlayerAttackEntity);
activity.listen(PlayerDamageEvent.EVENT, phase::onPlayerDamage);
Expand Down Expand Up @@ -137,6 +140,11 @@ private void enable() {

index++;
}

for (ServerPlayerEntity player : this.gameSpace.getPlayers().spectators()) {
DownpourActivePhase.spawn(this.world, this.map.getBounds().center(), 0, player);
this.setSpectator(player);
}
}

private void createShelter() {
Expand Down Expand Up @@ -268,10 +276,10 @@ private void setSpectator(ServerPlayerEntity player) {
player.changeGameMode(GameMode.SPECTATOR);
}

private PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.accept(this.world, this.map.getBounds().center()).and(() -> {
this.updateRoundsExperienceLevel(offer.player());
this.setSpectator(offer.player());
private JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) {
return acceptor.teleport(this.world, this.map.getBounds().center()).thenRunForEach(player -> {
this.updateRoundsExperienceLevel(player);
this.setSpectator(player);
});
}

Expand Down Expand Up @@ -313,31 +321,31 @@ public void applyPlayerFinishStatistics(ServerPlayerEntity player, StatisticKey<
}
}

private ActionResult onPlayerAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) {
private EventResult onPlayerAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) {
if (!this.isGameEnding() && attacker != attacked && this.players.contains(PlayerRef.of(attacker)) && !this.singleplayer && this.statistics != null) {
ServerPlayerEntity attackedPlayer = (ServerPlayerEntity) attacked;
if (this.players.contains(PlayerRef.of(attackedPlayer))) {
this.statistics.forPlayer(attacker).increment(Main.PLAYERS_PUNCHED, 1);
}
}

return ActionResult.PASS;
return EventResult.PASS;
}

private ActionResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) {
return this.rounds >= this.config.getNoKnockbackRounds() ? ActionResult.SUCCESS : ActionResult.FAIL;
private EventResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) {
return this.rounds >= this.config.getNoKnockbackRounds() ? EventResult.ALLOW : EventResult.DENY;
}

private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
if (!this.eliminate(player, true)) {
DownpourActivePhase.spawnAtCenter(this.world, this.map, player);
}
return ActionResult.FAIL;
return EventResult.DENY;
}

public static void spawn(ServerWorld world, Vec3d pos, float yaw, ServerPlayerEntity player) {
player.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, StatusEffectInstance.INFINITE, 127, true, false));
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), yaw, 0);
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), yaw, 0, true);
}

public static void spawnAtCenter(ServerWorld world, DownpourMap map, ServerPlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.world.GameMode;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.game.GameResult;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.common.GameWaitingLobby;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.game.player.PlayerOffer;
import xyz.nucleoid.plasmid.game.player.PlayerOfferResult;
import xyz.nucleoid.plasmid.game.rule.GameRuleType;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.api.game.GameResult;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.common.GameWaitingLobby;
import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptor;
import xyz.nucleoid.plasmid.api.game.player.JoinAcceptorResult;
import xyz.nucleoid.plasmid.api.game.player.JoinOffer;
import xyz.nucleoid.plasmid.api.game.rule.GameRuleType;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

public class DownpourWaitingPhase {
Expand Down Expand Up @@ -50,14 +51,15 @@ public static GameOpenProcedure open(GameOpenContext<DownpourConfig> context) {

// Listeners
activity.listen(PlayerDeathEvent.EVENT, phase::onPlayerDeath);
activity.listen(GamePlayerEvents.OFFER, phase::offerPlayer);
activity.listen(GamePlayerEvents.ACCEPT, phase::onAcceptPlayers);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept);
activity.listen(GameActivityEvents.REQUEST_START, phase::requestStart);
});
}

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

Expand All @@ -66,8 +68,8 @@ private GameResult requestStart() {
return GameResult.ok();
}

private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
DownpourActivePhase.spawnAtCenter(this.world, this.map, player);
return ActionResult.FAIL;
return EventResult.DENY;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"icon": "assets/downpour/icon.png",
"depends": {
"fabricloader": ">=0.4.0",
"java": ">=17",
"plasmid": ">=0.5.0"
"java": ">=21",
"plasmid": ">=0.6.0"
}
}