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
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
8 changes: 6 additions & 2 deletions src/main/java/io/github/haykam821/anvildrop/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import io.github.haykam821.anvildrop.game.phase.AnvilDropWaitingPhase;
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 Main implements ModInitializer {
private static final String MOD_ID = "anvildrop";

private static final Identifier ANVIL_DROP_ID = new Identifier(MOD_ID, "anvil_drop");
private static final Identifier ANVIL_DROP_ID = Main.identifier("anvil_drop");
public static final GameType<AnvilDropConfig> ANVIL_DROP_TYPE = GameType.register(ANVIL_DROP_ID, AnvilDropConfig.CODEC, AnvilDropWaitingPhase::open);

@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
@@ -1,19 +1,20 @@
package io.github.haykam821.anvildrop.game;

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

import io.github.haykam821.anvildrop.game.map.AnvilDropMapConfig;
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 AnvilDropConfig {
public static final Codec<AnvilDropConfig> CODEC = RecordCodecBuilder.create(instance -> {
public static final MapCodec<AnvilDropConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> {
return instance.group(
AnvilDropMapConfig.CODEC.fieldOf("map").forGetter(AnvilDropConfig::getMapConfig),
PlayerConfig.CODEC.fieldOf("players").forGetter(AnvilDropConfig::getPlayerConfig),
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(AnvilDropConfig::getPlayerConfig),
IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(AnvilDropConfig::getTicksUntilClose),
Codec.INT.optionalFieldOf("delay", 20 * 2).forGetter(AnvilDropConfig::getDelay),
Codec.DOUBLE.optionalFieldOf("chance", 0.4).forGetter(AnvilDropConfig::getChance),
Expand All @@ -24,15 +25,15 @@ public class AnvilDropConfig {
});

private final AnvilDropMapConfig mapConfig;
private final PlayerConfig playerConfig;
private final WaitingLobbyConfig playerConfig;
private final IntProvider ticksUntilClose;
private final int delay;
private final double chance;
private final int dropHeight;
private final int stackHeight;
private final boolean breaking;

public AnvilDropConfig(AnvilDropMapConfig mapConfig, PlayerConfig playerConfig, IntProvider ticksUntilClose, int delay, double chance, int dropHeight, int stackHeight, boolean breaking) {
public AnvilDropConfig(AnvilDropMapConfig mapConfig, WaitingLobbyConfig playerConfig, IntProvider ticksUntilClose, int delay, double chance, int dropHeight, int stackHeight, boolean breaking) {
this.mapConfig = mapConfig;
this.playerConfig = playerConfig;
this.ticksUntilClose = ticksUntilClose;
Expand All @@ -47,7 +48,7 @@ public AnvilDropMapConfig 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 @@ -14,7 +14,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 AnvilDropMap {
private static final BlockState CLEAR_STATE = Blocks.AIR.getDefaultState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
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.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.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.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.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.util.PlayerRef;
import xyz.nucleoid.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

Expand Down Expand Up @@ -60,7 +61,7 @@ public static void setRules(GameActivity activity) {
}

public static void open(GameSpace gameSpace, ServerWorld world, AnvilDropMap map, AnvilDropConfig config) {
Set<PlayerRef> players = gameSpace.getPlayers().stream().map(PlayerRef::of).collect(Collectors.toSet());
Set<PlayerRef> players = gameSpace.getPlayers().participants().stream().map(PlayerRef::of).collect(Collectors.toSet());
AnvilDropActivePhase phase = new AnvilDropActivePhase(gameSpace, world, map, config, players);

gameSpace.setActivity(activity -> {
Expand All @@ -69,7 +70,8 @@ public static void open(GameSpace gameSpace, ServerWorld world, AnvilDropMap 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(PlayerDeathEvent.EVENT, phase::onPlayerDeath);
activity.listen(PlayerDamageEvent.EVENT, phase::onPlayerDamage);
Expand All @@ -86,6 +88,12 @@ private void enable() {
AnvilDropActivePhase.spawn(this.world, this.map, player);
});
}

for (ServerPlayerEntity player : this.gameSpace.getPlayers().spectators()) {
this.updateRoundsExperienceLevel(player);
this.setSpectator(player);
AnvilDropActivePhase.spawn(this.world, this.map, player);
}
}

private void updateRoundsExperienceLevel(ServerPlayerEntity player) {
Expand Down Expand Up @@ -167,10 +175,10 @@ private void setSpectator(ServerPlayerEntity player) {
player.changeGameMode(GameMode.SPECTATOR);
}

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

Expand Down Expand Up @@ -199,29 +207,29 @@ private void eliminate(ServerPlayerEntity eliminatedPlayer, boolean remove) {
this.eliminate(eliminatedPlayer, "", remove);
}

private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
if (this.players.contains(PlayerRef.of(player))) {
this.eliminate(player, true);
} else {
AnvilDropActivePhase.spawn(this.world, this.map, player);
}
return ActionResult.FAIL;
return EventResult.DENY;
}

private static boolean isEliminatingDamageSource(DamageSource source) {
return source.isIn(DamageTypeTags.DAMAGES_HELMET);
}

private ActionResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) {
private EventResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) {
if (AnvilDropActivePhase.isEliminatingDamageSource(source) && this.players.contains(PlayerRef.of(player))) {
this.eliminate(player, ".falling_anvil", true);
}
return ActionResult.SUCCESS;
return EventResult.ALLOW;
}

public static void spawn(ServerWorld world, AnvilDropMap map, ServerPlayerEntity player) {
Vec3d spawnPos = AnvilDropActivePhase.getSpawnPos(map);
player.teleport(world, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), 0, 0);
player.teleport(world, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), Set.of(), 0, 0, true);
}

protected static Vec3d getSpawnPos(AnvilDropMap map) {
Expand Down
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 AnvilDropWaitingPhase {
Expand Down Expand Up @@ -48,14 +49,15 @@ public static GameOpenProcedure open(GameOpenContext<AnvilDropConfig> context) {

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

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

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

private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) {
AnvilDropActivePhase.spawn(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/anvildrop/icon.png",
"depends": {
"fabricloader": ">=0.4.0",
"java": ">=17",
"plasmid": ">=0.5.0"
"java": ">=21",
"plasmid": ">=0.6.0"
}
}