Skip to content

Commit

Permalink
Update minigame to Minecraft 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Nov 29, 2024
1 parent eba1495 commit f58d5c9
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 116 deletions.
26 changes: 9 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
name: Build
'on':
push:
branches:
- master
- push
- pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.gradle/loom-cache
~/.gradle/caches
key: gradle-${{hashFiles('**/*.gradle*')}}
restore-keys: gradle-
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 17
cache: gradle
distribution: microsoft
java-version: 21
- name: Build with Gradle
run: gradle build
- name: Upload Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: artifacts
path: build/libs
retention-days: 30
path: build/libs
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
plugins {
id "fabric-loom" version "1.8.11"
id "fabric-loom" version "1.8.13"
id "maven-publish"
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
Expand Down Expand Up @@ -42,7 +39,13 @@ processResources {
}
}

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

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

Expand Down
10 changes: 5 additions & 5 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
loader_version = 0.16.7
fabric_version = 0.97.2+1.20.4
minecraft_version = 1.21.3
yarn_mappings = 1.21.3+build.2
loader_version = 0.16.9
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
12 changes: 8 additions & 4 deletions src/main/java/io/github/haykam821/sculkprison/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
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 {
public static final String MOD_ID = "sculkprison";
private static final String MOD_ID = "sculkprison";

private static final Identifier SCULK_PRISON_ID = new Identifier(MOD_ID, "sculk_prison");
private static final Identifier SCULK_PRISON_ID = Main.identifier("sculk_prison");
public static final GameType<SculkPrisonConfig> SCULK_PRISON_TYPE = GameType.register(SCULK_PRISON_ID, SculkPrisonConfig.CODEC, SculkPrisonWaitingPhase::open);

private static final Identifier WARDEN_CAGE_BREAK_BLOCKS_ID = new Identifier(MOD_ID, "warden_cage_break_blocks");
private static final Identifier WARDEN_CAGE_BREAK_BLOCKS_ID = Main.identifier("warden_cage_break_blocks");
public static final TagKey<Block> WARDEN_CAGE_BREAK_BLOCKS = TagKey.of(RegistryKeys.BLOCK, WARDEN_CAGE_BREAK_BLOCKS_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,8 +3,8 @@
import io.github.haykam821.sculkprison.game.phase.SculkPrisonActivePhase;
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 class SculkPrisonBar {
private static final Text CAGE_LOCKED_TEXT = Text.translatable("text.sculkprison.cage_locked");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
package io.github.haykam821.sculkprison.game;

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

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 SculkPrisonConfig {
public static final Codec<SculkPrisonConfig> CODEC = RecordCodecBuilder.create(instance -> {
public static final MapCodec<SculkPrisonConfig> CODEC = RecordCodecBuilder.mapCodec(instance -> {
return instance.group(
PlayerConfig.CODEC.fieldOf("players").forGetter(SculkPrisonConfig::getPlayerConfig),
WaitingLobbyConfig.CODEC.fieldOf("players").forGetter(SculkPrisonConfig::getPlayerConfig),
Codec.INT.optionalFieldOf("lock_time", 20 * 30).forGetter(SculkPrisonConfig::getLockTime),
Codec.INT.optionalFieldOf("survive_time", 20 * 60 * 5).forGetter(SculkPrisonConfig::getSurviveTime),
IntProvider.NON_NEGATIVE_CODEC.optionalFieldOf("ticks_until_close", ConstantIntProvider.create(SharedConstants.TICKS_PER_SECOND * 5)).forGetter(SculkPrisonConfig::getTicksUntilClose)
).apply(instance, SculkPrisonConfig::new);
});

private final PlayerConfig playerConfig;
private final WaitingLobbyConfig playerConfig;
private final int lockTime;
private final int surviveTime;
private final IntProvider ticksUntilClose;

public SculkPrisonConfig(PlayerConfig playerConfig, int lockTime, int surviveTime, IntProvider ticksUntilClose) {
public SculkPrisonConfig(WaitingLobbyConfig playerConfig, int lockTime, int surviveTime, IntProvider ticksUntilClose) {
this.playerConfig = playerConfig;
this.lockTime = lockTime;
this.surviveTime = surviveTime;
this.ticksUntilClose = ticksUntilClose;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.structure.StructureLiquidSettings;
import net.minecraft.structure.StructurePiece;
import net.minecraft.structure.StructureTemplateManager;
import net.minecraft.structure.pool.StructurePool;
Expand All @@ -30,17 +31,19 @@
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.noise.NoiseConfig;
import net.minecraft.world.gen.structure.DimensionPadding;
import net.minecraft.world.gen.structure.Structure;
import net.minecraft.world.gen.structure.Structure.StructurePosition;
import xyz.nucleoid.plasmid.game.world.generator.GameChunkGenerator;
import xyz.nucleoid.plasmid.api.game.world.generator.GameChunkGenerator;

public final class SculkPrisonChunkGenerator extends GameChunkGenerator {
private static final BlockPos ORIGIN = new BlockPos(0, 64, 0);
private static final DimensionPadding PADDING = new DimensionPadding(Integer.MAX_VALUE);

private static final int MAX_DEPTH = 16;
private static final int MAX_DISTANCE_FROM_CENTER = 1024;

private static final Identifier PRISON_STARTS_ID = new Identifier(Main.MOD_ID, "prison_starts");
private static final Identifier PRISON_STARTS_ID = Main.identifier("prison_starts");
private static final RegistryKey<StructurePool> PRISON_STARTS = RegistryKey.of(RegistryKeys.TEMPLATE_POOL, PRISON_STARTS_ID);

private final Long2ObjectMap<List<StructurePiece>> piecesByChunk = new Long2ObjectOpenHashMap<>();
Expand All @@ -60,9 +63,9 @@ public SculkPrisonChunkGenerator(MinecraftServer server) {
HeightLimitView heightLimitView = new ChunkGeneratorHeightLimitView(this);

Structure.Context context = new Structure.Context(registryManager, this, this.getBiomeSource(), noiseConfig, structureManager, random, seed, chunkPos, heightLimitView, biome -> true);
RegistryEntry<StructurePool> structurePool = registryManager.get(RegistryKeys.TEMPLATE_POOL).getEntry(PRISON_STARTS).orElseThrow();
RegistryEntry<StructurePool> structurePool = registryManager.getOrThrow(RegistryKeys.TEMPLATE_POOL).getOrThrow(PRISON_STARTS);

StructurePosition structurePosition = StructurePoolBasedGenerator.generate(context, structurePool, Optional.empty(), MAX_DEPTH, ORIGIN, false, Optional.empty(), MAX_DISTANCE_FROM_CENTER, StructurePoolAliasLookup.EMPTY).orElseThrow();
StructurePosition structurePosition = StructurePoolBasedGenerator.generate(context, structurePool, Optional.empty(), MAX_DEPTH, ORIGIN, false, Optional.empty(), MAX_DISTANCE_FROM_CENTER, StructurePoolAliasLookup.EMPTY, PADDING, StructureLiquidSettings.APPLY_WATERLOGGING).orElseThrow();
this.addStructurePieces(structurePosition.generate().toList().pieces());
}

Expand Down Expand Up @@ -113,7 +116,7 @@ private static BlockBox getChunkBox(Chunk chunk) {
int minZ = pos.getStartZ();

int maxX = pos.getEndX();
int maxY = chunk.getTopY();
int maxY = chunk.getTopYInclusive();
int maxZ = pos.getEndZ();

return new BlockBox(minX, minY, minZ, maxX, maxY, maxZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;

Expand All @@ -17,26 +18,27 @@
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.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.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.stimuli.event.EventResult;
import xyz.nucleoid.stimuli.event.player.PlayerAttackEntityEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

public class SculkPrisonActivePhase implements WardenDataListener, PlayerAttackEntityEvent, GameActivityEvents.Enable, GameActivityEvents.Tick, GamePlayerEvents.Offer, PlayerDeathEvent, GamePlayerEvents.Remove {
public class SculkPrisonActivePhase implements WardenDataListener, PlayerAttackEntityEvent, GameActivityEvents.Enable, GameActivityEvents.Tick, GamePlayerEvents.Accept, PlayerDeathEvent, GamePlayerEvents.Remove {
private final ServerWorld world;
private final GameSpace gameSpace;
private final SculkPrisonMap map;
Expand Down Expand Up @@ -88,15 +90,16 @@ public static void open(GameSpace gameSpace, ServerWorld world, SculkPrisonMap m
gameSpace.setActivity(activity -> {
GlobalWidgets widgets = GlobalWidgets.addTo(activity);

SculkPrisonActivePhase phase = new SculkPrisonActivePhase(gameSpace, world, map, config, Lists.newArrayList(gameSpace.getPlayers()), widgets);
SculkPrisonActivePhase phase = new SculkPrisonActivePhase(gameSpace, world, map, config, Lists.newArrayList(gameSpace.getPlayers().participants()), widgets);
SculkPrisonActivePhase.setRules(activity, true);

// Listeners
activity.listen(WardenDataListener.EVENT, phase);
activity.listen(PlayerAttackEntityEvent.EVENT, phase);
activity.listen(GameActivityEvents.ENABLE, phase);
activity.listen(GameActivityEvents.TICK, phase);
activity.listen(GamePlayerEvents.OFFER, phase);
activity.listen(GamePlayerEvents.ACCEPT, phase);
activity.listen(GamePlayerEvents.OFFER, JoinOffer::acceptSpectators);
activity.listen(PlayerDeathEvent.EVENT, phase);
activity.listen(GamePlayerEvents.REMOVE, phase);
});
Expand All @@ -113,11 +116,11 @@ public WardenData getWardenData(ServerPlayerEntity entity) {
}

@Override
public ActionResult onAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) {
public EventResult onAttackEntity(ServerPlayerEntity attacker, Hand hand, Entity attacked, EntityHitResult hitResult) {
if (!this.isGameEnding() && this.warden.isOf(attacker) && attacked instanceof ServerPlayerEntity) {
this.eliminate((ServerPlayerEntity) attacked, Text.translatable("text.sculkprison.eliminated.warden", attacked.getDisplayName(), attacker.getDisplayName()), true);
}
return ActionResult.FAIL;
return EventResult.DENY;
}

@Override
Expand All @@ -128,6 +131,11 @@ public void onEnable() {
}

this.warden.initialize();

for (ServerPlayerEntity player : this.gameSpace.getPlayers().spectators()) {
player.changeGameMode(GameMode.SPECTATOR);
SculkPrisonActivePhase.spawn(this.world, this.map, player, false);
}
}

@Override
Expand Down Expand Up @@ -168,16 +176,16 @@ public void onTick() {
}

@Override
public PlayerOfferResult onOfferPlayer(PlayerOffer offer) {
return offer.accept(this.world, SculkPrisonMap.WARDEN_SPAWN).and(() -> {
this.setSpectator(offer.player());
public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) {
return acceptor.teleport(this.world, SculkPrisonMap.WARDEN_SPAWN).thenRunForEach(player -> {
this.setSpectator(player);
});
}

@Override
public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) {
public EventResult onDeath(ServerPlayerEntity player, DamageSource source) {
SculkPrisonActivePhase.spawn(this.world, this.map, player, this.warden.isOf(player));
return ActionResult.FAIL;
return EventResult.DENY;
}

@Override
Expand Down Expand Up @@ -284,6 +292,6 @@ public List<ServerPlayerEntity> getPlayers() {
*/
public static void spawn(ServerWorld world, SculkPrisonMap map, ServerPlayerEntity player, boolean warden) {
Vec3d pos = warden ? SculkPrisonMap.WARDEN_SPAWN : SculkPrisonMap.SPAWN;
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), 0, 0);
player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), 0, 0, true);
}
}
Loading

0 comments on commit f58d5c9

Please sign in to comment.