diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fd4769..0aac695 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file + path: build/libs \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4949827..f5ac13d 100644 --- a/build.gradle +++ b/build.gradle @@ -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 @@ -42,7 +39,13 @@ processResources { } } +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + tasks.withType(JavaCompile) { + options.release = 21 options.encoding = "UTF-8" } diff --git a/gradle.properties b/gradle.properties index 6ddd9a0..6808164 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file +plasmid_version = 0.6.1+1.21.3 \ No newline at end of file diff --git a/src/main/java/io/github/haykam821/sculkprison/Main.java b/src/main/java/io/github/haykam821/sculkprison/Main.java index 86d9029..1ec8da0 100644 --- a/src/main/java/io/github/haykam821/sculkprison/Main.java +++ b/src/main/java/io/github/haykam821/sculkprison/Main.java @@ -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 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 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); + } } diff --git a/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonBar.java b/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonBar.java index 6fc08b0..84f27ee 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonBar.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonBar.java @@ -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"); diff --git a/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonConfig.java b/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonConfig.java index 89cc683..fa36808 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonConfig.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/SculkPrisonConfig.java @@ -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 CODEC = RecordCodecBuilder.create(instance -> { + public static final MapCodec 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; } diff --git a/src/main/java/io/github/haykam821/sculkprison/game/map/SculkPrisonChunkGenerator.java b/src/main/java/io/github/haykam821/sculkprison/game/map/SculkPrisonChunkGenerator.java index a84363a..2db2d26 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/map/SculkPrisonChunkGenerator.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/map/SculkPrisonChunkGenerator.java @@ -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; @@ -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 PRISON_STARTS = RegistryKey.of(RegistryKeys.TEMPLATE_POOL, PRISON_STARTS_ID); private final Long2ObjectMap> piecesByChunk = new Long2ObjectOpenHashMap<>(); @@ -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 = registryManager.get(RegistryKeys.TEMPLATE_POOL).getEntry(PRISON_STARTS).orElseThrow(); + RegistryEntry 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()); } @@ -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); diff --git a/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonActivePhase.java b/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonActivePhase.java index 0e8b2d5..2374ba3 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonActivePhase.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonActivePhase.java @@ -2,6 +2,7 @@ import java.util.Iterator; import java.util.List; +import java.util.Set; import com.google.common.collect.Lists; @@ -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; @@ -88,7 +90,7 @@ 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 @@ -96,7 +98,8 @@ public static void open(GameSpace gameSpace, ServerWorld world, SculkPrisonMap m 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); }); @@ -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 @@ -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 @@ -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 @@ -284,6 +292,6 @@ public List 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); } } diff --git a/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonWaitingPhase.java b/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonWaitingPhase.java index bf65b19..84eaffe 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonWaitingPhase.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/phase/SculkPrisonWaitingPhase.java @@ -5,21 +5,22 @@ 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 SculkPrisonWaitingPhase implements GamePlayerEvents.Offer, PlayerDeathEvent, GameActivityEvents.RequestStart { +public class SculkPrisonWaitingPhase implements GamePlayerEvents.Accept, PlayerDeathEvent, GameActivityEvents.RequestStart { private final GameSpace gameSpace; private final ServerWorld world; private final SculkPrisonMap map; @@ -45,7 +46,8 @@ public static GameOpenProcedure open(GameOpenContext context) SculkPrisonActivePhase.setRules(activity, false); // Listeners - activity.listen(GamePlayerEvents.OFFER, phase); + activity.listen(GamePlayerEvents.ACCEPT, phase); + activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept); activity.listen(PlayerDeathEvent.EVENT, phase); activity.listen(GameActivityEvents.REQUEST_START, phase); }); @@ -53,16 +55,16 @@ public static GameOpenProcedure open(GameOpenContext context) // Listeners @Override - public PlayerOfferResult onOfferPlayer(PlayerOffer offer) { - return offer.accept(this.world, SculkPrisonMap.WARDEN_SPAWN).and(() -> { - offer.player().changeGameMode(GameMode.ADVENTURE); + public JoinAcceptorResult onAcceptPlayers(JoinAcceptor acceptor) { + return acceptor.teleport(this.world, SculkPrisonMap.WARDEN_SPAWN).thenRunForEach(player -> { + player.changeGameMode(GameMode.ADVENTURE); }); } @Override - public ActionResult onDeath(ServerPlayerEntity player, DamageSource source) { + public EventResult onDeath(ServerPlayerEntity player, DamageSource source) { SculkPrisonActivePhase.spawn(this.world, this.map, player, true); - return ActionResult.FAIL; + return EventResult.DENY; } @Override diff --git a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenColors.java b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenColors.java index a2f2fbd..f3b08d5 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenColors.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenColors.java @@ -1,21 +1,14 @@ package io.github.haykam821.sculkprison.game.player; -import org.joml.Vector3fc; - import net.minecraft.particle.DustColorTransitionParticleEffect; -import net.minecraft.util.math.MathHelper; public class WardenColors { private static final int INACTIVE = 0x649683; - private static final int ACTIVE = packRgb(DustColorTransitionParticleEffect.SCULK_BLUE); + private static final int ACTIVE = DustColorTransitionParticleEffect.SCULK_BLUE; public static final int INACTIVE_ARMOR = INACTIVE; public static final int ACTIVE_ARMOR = ACTIVE; public static final int INACTIVE_TARGET = INACTIVE; public static final int ACTIVE_TARGET = ACTIVE; - - private static int packRgb(Vector3fc color) { - return MathHelper.packRgb(color.x(), color.y(), color.z()); - } } diff --git a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenData.java b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenData.java index 046c2d0..a44a09d 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenData.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenData.java @@ -27,6 +27,7 @@ import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.mob.Angriness; import net.minecraft.particle.ParticleTypes; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -60,6 +61,8 @@ public class WardenData implements Vibrations { private final SculkPrisonActivePhase phase; private final ServerPlayerEntity player; + private final WardenInventoryManager inventoryManager; + private final SculkSpreadManager spreadManager = SculkSpreadHelper.createSpreadManager(); private final Set spreadRoots = new HashSet<>(); private final EvictingQueue breadcrumbs = EvictingQueue.create(SculkSpreadHelper.MAX_BREADCRUMBS); @@ -84,11 +87,13 @@ private WardenData(SculkPrisonActivePhase phase, ServerPlayerEntity player) { this.phase = Objects.requireNonNull(phase); this.player = Objects.requireNonNull(player); + this.inventoryManager = new WardenInventoryManager(this.player.getRegistryManager()); + this.vibrationCallback = new WardenVibrationCallback(this, this.player); } public void initialize() { - WardenInventoryManager.applyTo(player); + this.inventoryManager.applyTo(player); player.addStatusEffect(new StatusEffectInstance(StatusEffects.BLINDNESS, StatusEffectInstance.INFINITE, 1, true, false)); this.player.updateEventHandler(EntityGameEventHandler::onEntitySetPosCallback); @@ -184,7 +189,7 @@ public void createSonicBoom(SonicBoomTarget target) { this.phase.eliminate(player, Text.translatable("text.sculkprison.eliminated.sonic_boom", player.getDisplayName(), this.player.getDisplayName()), false); iterator.remove(); - double knockbackResistance = player.getAttributeValue(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE); + double knockbackResistance = player.getAttributeValue(EntityAttributes.KNOCKBACK_RESISTANCE); double horizontalKnockbackScale = 2.5 * (1.0 - knockbackResistance); double verticalKnockbackScale = 0.5 * (1.0 - knockbackResistance); @@ -312,9 +317,9 @@ public void setVibrationCooldown(int vibrationCooldown) { int clampedCooldown = Math.max(0, vibrationCooldown); if (clampedCooldown == 0 && this.vibrationCooldown > 0) { - WardenInventoryManager.applyHelmet(player); + this.inventoryManager.applyHelmet(player); } else if (clampedCooldown > 0 && this.vibrationCooldown == 0) { - WardenInventoryManager.applyActiveHelmet(player); + this.inventoryManager.applyActiveHelmet(player); } this.vibrationCooldown = clampedCooldown; @@ -334,7 +339,7 @@ public void updateEventHandler(BiConsumer, ServerWorld callback.accept(this.gameEventHandler, this.player.getServerWorld()); } - public boolean canProduceVibration(ServerWorld world, BlockPos pos, GameEvent event, Emitter emitter) { + public boolean canProduceVibration(ServerWorld world, BlockPos pos, RegistryEntry event, Emitter emitter) { if (this.vibrationCooldown > 0) return false; if (this.phase.getLockTime() > 0) return false; @@ -344,7 +349,7 @@ public boolean canProduceVibration(ServerWorld world, BlockPos pos, GameEvent ev return true; } - protected void acceptGameEvent(ServerWorld world, BlockPos pos, GameEvent event, Entity sourceEntity, Entity entity, float distance) { + protected void acceptGameEvent(ServerWorld world, BlockPos pos, RegistryEntry event, Entity sourceEntity, Entity entity, float distance) { this.setVibrationCooldown(MAX_VIBRATION_COOLDOWN); this.playSound(SoundEvents.ENTITY_WARDEN_TENDRIL_CLICKS, 5); diff --git a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenInventoryManager.java b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenInventoryManager.java index 04ec611..66573a5 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenInventoryManager.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenInventoryManager.java @@ -5,46 +5,56 @@ import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.registry.RegistryWrapper; import net.minecraft.server.network.ServerPlayerEntity; -import xyz.nucleoid.plasmid.util.ItemStackBuilder; +import xyz.nucleoid.plasmid.api.util.ItemStackBuilder; public class WardenInventoryManager { - public static final ItemStack HELMET = WardenInventoryManager.createArmorStack(Items.LEATHER_HELMET, false); - public static final ItemStack CHESTPLATE = WardenInventoryManager.createArmorStack(Items.LEATHER_CHESTPLATE, false); - public static final ItemStack LEGGINGS = WardenInventoryManager.createArmorStack(Items.LEATHER_LEGGINGS, false); - public static final ItemStack BOOTS = WardenInventoryManager.createArmorStack(Items.LEATHER_BOOTS, false); + private final ItemStack helmet; + private final ItemStack chestplate; + private final ItemStack leggings; + private final ItemStack boots; - public static final ItemStack ACTIVE_HELMET = WardenInventoryManager.createArmorStack(Items.LEATHER_HELMET, true); + private final ItemStack activeHelmet; + + public WardenInventoryManager(RegistryWrapper.WrapperLookup registries) { + this.helmet = WardenInventoryManager.createArmorStack(registries, Items.LEATHER_HELMET, false); + this.chestplate = WardenInventoryManager.createArmorStack(registries, Items.LEATHER_CHESTPLATE, false); + this.leggings = WardenInventoryManager.createArmorStack(registries, Items.LEATHER_LEGGINGS, false); + this.boots = WardenInventoryManager.createArmorStack(registries, Items.LEATHER_BOOTS, false); + + this.activeHelmet = WardenInventoryManager.createArmorStack(registries, Items.LEATHER_HELMET, true); + } private static void updateInventory(ServerPlayerEntity player) { player.currentScreenHandler.sendContentUpdates(); player.playerScreenHandler.onContentChanged(player.getInventory()); } - public static void applyTo(ServerPlayerEntity player) { + public void applyTo(ServerPlayerEntity player) { PlayerInventory inventory = player.getInventory(); - inventory.armor.set(3, HELMET.copy()); - inventory.armor.set(2, CHESTPLATE.copy()); - inventory.armor.set(1, LEGGINGS.copy()); - inventory.armor.set(0, BOOTS.copy()); + inventory.armor.set(3, this.helmet.copy()); + inventory.armor.set(2, this.chestplate.copy()); + inventory.armor.set(1, this.leggings.copy()); + inventory.armor.set(0, this.boots.copy()); WardenInventoryManager.updateInventory(player); } - public static void applyHelmet(ServerPlayerEntity player) { - player.getInventory().armor.set(3, HELMET.copy()); + public void applyHelmet(ServerPlayerEntity player) { + player.getInventory().armor.set(3, this.helmet.copy()); WardenInventoryManager.updateInventory(player); } - public static void applyActiveHelmet(ServerPlayerEntity player) { - player.getInventory().armor.set(3, ACTIVE_HELMET.copy()); + public void applyActiveHelmet(ServerPlayerEntity player) { + player.getInventory().armor.set(3, this.activeHelmet.copy()); WardenInventoryManager.updateInventory(player); } - private static ItemStack createArmorStack(ItemConvertible item, boolean active) { + private static ItemStack createArmorStack(RegistryWrapper.WrapperLookup registries, ItemConvertible item, boolean active) { return ItemStackBuilder.of(item) - .addEnchantment(Enchantments.BINDING_CURSE, 1) + .addEnchantment(registries, Enchantments.BINDING_CURSE, 1) .setDyeColor(active ? WardenColors.ACTIVE_ARMOR : WardenColors.INACTIVE_ARMOR) .setUnbreakable() .build(); diff --git a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenVibrationCallback.java b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenVibrationCallback.java index ccd0f01..3f078c2 100644 --- a/src/main/java/io/github/haykam821/sculkprison/game/player/WardenVibrationCallback.java +++ b/src/main/java/io/github/haykam821/sculkprison/game/player/WardenVibrationCallback.java @@ -1,6 +1,7 @@ package io.github.haykam821.sculkprison.game.player; import net.minecraft.entity.Entity; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.GameEventTags; import net.minecraft.registry.tag.TagKey; import net.minecraft.server.network.ServerPlayerEntity; @@ -38,12 +39,12 @@ public TagKey getTag() { } @Override - public boolean accepts(ServerWorld world, BlockPos pos, GameEvent event, GameEvent.Emitter emitter) { + public boolean accepts(ServerWorld world, BlockPos pos, RegistryEntry event, GameEvent.Emitter emitter) { return this.warden.canProduceVibration(world, pos, event, emitter); } @Override - public void accept(ServerWorld world, BlockPos pos, GameEvent event, Entity sourceEntity, Entity entity, float distance) { + public void accept(ServerWorld world, BlockPos pos, RegistryEntry event, Entity sourceEntity, Entity entity, float distance) { this.warden.acceptGameEvent(world, pos, event, sourceEntity, entity, distance); } } diff --git a/src/main/resources/data/sculkprison/games/standard_sculk_prison.json b/src/main/resources/data/sculkprison/plasmid/game/standard_sculk_prison.json similarity index 100% rename from src/main/resources/data/sculkprison/games/standard_sculk_prison.json rename to src/main/resources/data/sculkprison/plasmid/game/standard_sculk_prison.json diff --git a/src/main/resources/data/sculkprison/structures/dinner_table.nbt b/src/main/resources/data/sculkprison/structure/dinner_table.nbt similarity index 100% rename from src/main/resources/data/sculkprison/structures/dinner_table.nbt rename to src/main/resources/data/sculkprison/structure/dinner_table.nbt diff --git a/src/main/resources/data/sculkprison/structures/door_wall.nbt b/src/main/resources/data/sculkprison/structure/door_wall.nbt similarity index 100% rename from src/main/resources/data/sculkprison/structures/door_wall.nbt rename to src/main/resources/data/sculkprison/structure/door_wall.nbt diff --git a/src/main/resources/data/sculkprison/structures/start.nbt b/src/main/resources/data/sculkprison/structure/start.nbt similarity index 100% rename from src/main/resources/data/sculkprison/structures/start.nbt rename to src/main/resources/data/sculkprison/structure/start.nbt diff --git a/src/main/resources/data/sculkprison/structures/wall.nbt b/src/main/resources/data/sculkprison/structure/wall.nbt similarity index 100% rename from src/main/resources/data/sculkprison/structures/wall.nbt rename to src/main/resources/data/sculkprison/structure/wall.nbt diff --git a/src/main/resources/data/sculkprison/structures/water_paths.nbt b/src/main/resources/data/sculkprison/structure/water_paths.nbt similarity index 100% rename from src/main/resources/data/sculkprison/structures/water_paths.nbt rename to src/main/resources/data/sculkprison/structure/water_paths.nbt diff --git a/src/main/resources/data/sculkprison/tags/blocks/warden_cage_break_blocks.json b/src/main/resources/data/sculkprison/tags/block/warden_cage_break_blocks.json similarity index 100% rename from src/main/resources/data/sculkprison/tags/blocks/warden_cage_break_blocks.json rename to src/main/resources/data/sculkprison/tags/block/warden_cage_break_blocks.json diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8d12238..034ad68 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,6 +23,7 @@ "icon": "assets/sculkprison/icon.png", "depends": { "fabricloader": ">=0.4.0", - "plasmid": ">=0.5.0" + "java": ">=21", + "plasmid": ">=0.6.0" } } diff --git a/src/main/resources/sculkprison.mixin.json b/src/main/resources/sculkprison.mixin.json index 07688f8..e3eb910 100644 --- a/src/main/resources/sculkprison.mixin.json +++ b/src/main/resources/sculkprison.mixin.json @@ -1,7 +1,7 @@ { "required": true, "package": "io.github.haykam821.sculkprison.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "mixins": [ "BlockRotationMixin", "PlayerEntityMixin",