From 45bc3e54ac0698e0da4ebd0e1849a8ccca89249d Mon Sep 17 00:00:00 2001 From: Voxxin <59192970+Voxxin@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:47:29 -0500 Subject: [PATCH] 1.21.4 --- build.gradle | 8 +- gradle.properties | 10 +-- gradle/wrapper/gradle-wrapper.properties | 4 +- .../github/voxxin/blockhunt/BlockHunt.java | 7 +- .../blockhunt/game/BlockHuntActive.java | 67 ++++++++--------- .../blockhunt/game/BlockHuntConfig.java | 7 +- .../blockhunt/game/BlockHuntPlayer.java | 41 ++++++---- .../blockhunt/game/BlockHuntSidebar.java | 66 ++++++++--------- .../blockhunt/game/BlockHuntSpawnLogic.java | 70 +++++++++++------- .../blockhunt/game/BlockHuntStageManager.java | 9 +-- .../blockhunt/game/BlockHuntWaiting.java | 45 +++++------ .../blockhunt/game/map/BlockHuntMap.java | 6 +- .../game/mixin/BlockDisplayEntityMixin.java | 29 ++++++++ .../game/mixin/BossBarWidgetMixin.java | 7 -- .../ServerPlayerNetworkHandlerMixin.java | 2 +- .../game/mixin/WrittenBookItemMixin.java | 22 ++++-- .../game/util/BlockHuntAnimation.java | 6 +- .../blockhunt/game/util/BlockHuntBlock.java | 30 ++++---- .../game/util/ext/WrittenBookItemExt.java | 2 + src/main/resources/blockhunt.accesswidener | 4 + src/main/resources/blockhunt.mixins.json | 3 +- .../resources/data/blockhunt/lang/en_us.json | 1 + .../fort_du_perdu.nbt | Bin .../game}/fort_du_perdu.json | 0 24 files changed, 256 insertions(+), 190 deletions(-) create mode 100644 src/main/java/com/github/voxxin/blockhunt/game/mixin/BlockDisplayEntityMixin.java create mode 100644 src/main/resources/blockhunt.accesswidener rename src/main/resources/data/blockhunt/{map_templates => map_template}/fort_du_perdu.nbt (100%) rename src/main/resources/data/blockhunt/{games => plasmid/game}/fort_du_perdu.json (100%) diff --git a/build.gradle b/build.gradle index aa1a7e6..b446c60 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,15 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.9-SNAPSHOT' id 'maven-publish' } version = project.mod_version group = project.maven_group +loom { + accessWidenerPath = file("src/main/resources/blockhunt.accesswidener") +} + repositories { maven { url = "https://maven.nucleoid.xyz/" } maven { url = "https://maven.gegy.dev/" } @@ -34,7 +38,7 @@ processResources { } } -def targetJavaVersion = 17 +def targetJavaVersion = 21 tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { diff --git a/gradle.properties b/gradle.properties index 9560ea9..7a7903b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,10 +8,10 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop/ - minecraft_version=1.20.4 - yarn_mappings=1.20.4+build.1 - loader_version=0.15.6 - fabric_version=0.91.1+1.20.4 + minecraft_version=1.21.4 + yarn_mappings=1.21.4+build.1 + loader_version=0.16.9 + fabric_version=0.91.1+1.21.4 # check this on https://nucleoid.xyz/use/ - plasmid_version=0.5.102-SNAPSHOT+1.20.4 \ No newline at end of file + plasmid_version=0.6.3-SNAPSHOT+1.21.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..aaf4977 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ +#Mon Jan 06 20:48:19 EST 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip -networkTimeout=10000 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/github/voxxin/blockhunt/BlockHunt.java b/src/main/java/com/github/voxxin/blockhunt/BlockHunt.java index 2380686..c892f16 100644 --- a/src/main/java/com/github/voxxin/blockhunt/BlockHunt.java +++ b/src/main/java/com/github/voxxin/blockhunt/BlockHunt.java @@ -3,11 +3,10 @@ import com.github.voxxin.blockhunt.game.BlockHuntConfig; import com.github.voxxin.blockhunt.game.BlockHuntWaiting; import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import xyz.nucleoid.plasmid.game.GameType; +import xyz.nucleoid.plasmid.api.game.GameType; import java.util.ArrayList; import java.util.List; @@ -18,7 +17,7 @@ public class BlockHunt implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger(ID); public static final GameType TYPE = GameType.register( - new Identifier(ID, "blockhunt"), + Identifier.of(ID, "blockhunt"), BlockHuntConfig.CODEC, BlockHuntWaiting::open ); @@ -27,7 +26,7 @@ public void onInitialize() { } public static Identifier id(String value) { - return new Identifier(ID, value); + return Identifier.of(ID, value); } public static List deniedIDs = new ArrayList<>(); } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntActive.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntActive.java index ee41b62..227cdc0 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntActive.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntActive.java @@ -27,15 +27,19 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import net.minecraft.world.GameMode; -import xyz.nucleoid.plasmid.game.GameCloseReason; -import xyz.nucleoid.plasmid.game.GameLifecycle; -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.PlayerSet; -import xyz.nucleoid.plasmid.game.rule.GameRuleType; -import xyz.nucleoid.plasmid.util.PlayerRef; +import xyz.nucleoid.plasmid.api.game.GameCloseReason; +import xyz.nucleoid.plasmid.api.game.GameLifecycle; +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.JoinIntent; +import xyz.nucleoid.plasmid.api.game.player.JoinOffer; +import xyz.nucleoid.plasmid.api.game.player.JoinOfferResult; +import xyz.nucleoid.plasmid.api.game.player.PlayerSet; +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.block.BlockPunchEvent; import xyz.nucleoid.stimuli.event.block.BlockUseEvent; import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent; @@ -64,10 +68,6 @@ public class BlockHuntActive { private static Team hidersTeam = null; private static Team spectatorTeam = null; - private int lastHiddenReset = 20; - - private ArrayList bossBars = new ArrayList<>(); - private static final ArrayList deniedBlockInteractions = new ArrayList<>(); private static final ArrayList allowedMapDisguises = new ArrayList<>(); @@ -135,22 +135,23 @@ public static void open(GameSpace gameSpace, ServerWorld world, BlockHuntMap map // Game Rules - game.setRule(GameRuleType.FALL_DAMAGE, ActionResult.FAIL); - game.setRule(GameRuleType.PICKUP_ITEMS, ActionResult.FAIL); - game.setRule(GameRuleType.THROW_ITEMS, ActionResult.FAIL); - game.setRule(GameRuleType.CRAFTING, ActionResult.FAIL); - game.setRule(GameRuleType.FIRE_TICK, ActionResult.FAIL); - game.setRule(GameRuleType.FLUID_FLOW, ActionResult.FAIL); - game.setRule(GameRuleType.HUNGER, ActionResult.FAIL); - game.setRule(GameRuleType.MODIFY_ARMOR, ActionResult.FAIL); - //game.setRule(GameRuleType.PLACE_BLOCKS, ActionResult.FAIL); + game.setRule(GameRuleType.FALL_DAMAGE, EventResult.DENY); + game.setRule(GameRuleType.PICKUP_ITEMS, EventResult.DENY); + game.setRule(GameRuleType.THROW_ITEMS, EventResult.DENY); + game.setRule(GameRuleType.CRAFTING, EventResult.DENY); + game.setRule(GameRuleType.FIRE_TICK, EventResult.DENY); + game.setRule(GameRuleType.FLUID_FLOW, EventResult.DENY); + game.setRule(GameRuleType.HUNGER, EventResult.DENY); + game.setRule(GameRuleType.MODIFY_ARMOR, EventResult.DENY); + //game.setRule(GameRuleType.PLACE_BLOCKS, EventResult.DENY); // Unique Gamerules game.listen(GameActivityEvents.ENABLE, active::onOpen); - game.listen(GamePlayerEvents.OFFER, (offer) -> offer.accept(world, Vec3d.ZERO)); + game.listen(GamePlayerEvents.OFFER, JoinOffer::accept); + game.listen(GamePlayerEvents.ACCEPT, (offer) -> offer.teleport(world, Vec3d.ZERO)); game.listen(GamePlayerEvents.ADD, active::addPlayer); game.listen(GamePlayerEvents.REMOVE, active::removePlayer); @@ -172,8 +173,8 @@ private void onOpen() { seekerAnimation.settings.tick(); if (seekerAnimation.settings.startTime == 0) { BlockHunt.LOGGER.info("No start time set for seeker released animation. Defaulting to 1 minute."); - int mins = 1; - this.stageManager.onOpen(this.world.getTime(), this.config, (mins * 60) * 20); + int mins = 1200; + this.stageManager.onOpen(this.world.getTime(), this.config, mins); } else this.stageManager.onOpen(this.world.getTime(), this.config, (long) seekerAnimation.settings.startTime); } else { BlockHunt.LOGGER.fatal("No seeker released animation found. Please add one to your map."); @@ -251,7 +252,7 @@ private ActionResult allowInteraction(ServerPlayerEntity serverPlayerEntity, Han return ActionResult.PASS; } - private ActionResult blockAttack(ServerPlayerEntity serverPlayerEntity, Direction direction, BlockPos blockPos) { + private EventResult blockAttack(ServerPlayerEntity serverPlayerEntity, Direction direction, BlockPos blockPos) { BlockPos blockPosHit = ((BlockHitResult) serverPlayerEntity.raycast(5, 0, false)).getBlockPos(); BlockHuntPlayer player = this.participants.get(PlayerRef.of(serverPlayerEntity)); @@ -264,7 +265,7 @@ private ActionResult blockAttack(ServerPlayerEntity serverPlayerEntity, Directio } }); - return ActionResult.FAIL; + return EventResult.DENY; } private void addPlayer(ServerPlayerEntity player) { @@ -290,8 +291,8 @@ private void removePlayer(ServerPlayerEntity player) { } } - private ActionResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) { - if (source.getSource() == null) return ActionResult.FAIL; + private EventResult onPlayerDamage(ServerPlayerEntity player, DamageSource source, float amount) { + if (source.getSource() == null) return EventResult.DENY; if (source.getSource().isPlayer()) { if (!player.isTeammate(source.getAttacker())) { @@ -301,14 +302,14 @@ private ActionResult onPlayerDamage(ServerPlayerEntity player, DamageSource sour thisPlayer.updateTimeBar(true); thisPlayer.setHidden(false); } - return ActionResult.SUCCESS; + return EventResult.ALLOW; } } - return ActionResult.FAIL; + return EventResult.DENY; } - private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { + private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { if (source.getSource().isPlayer()) { BlockHuntPlayer thisPlayer = this.participants.get(PlayerRef.of(player)); BlockHuntPlayer thisAttacker = this.participants.get(PlayerRef.of((ServerPlayerEntity) source.getAttacker())); @@ -355,7 +356,7 @@ private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource sourc } } - return ActionResult.FAIL; + return EventResult.DENY; } private void spawnParticipant(ServerPlayerEntity player) { diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntConfig.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntConfig.java index 7ad41fa..97ad64f 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntConfig.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntConfig.java @@ -2,11 +2,12 @@ import com.github.voxxin.blockhunt.game.map.BlockHuntMapConfig; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import xyz.nucleoid.plasmid.game.common.config.PlayerConfig; +import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig; public record BlockHuntConfig(BlockHuntMapConfig mapConfig) { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( BlockHuntMapConfig.CODEC.fieldOf("map").forGetter(BlockHuntConfig::mapConfig) ).apply(instance, BlockHuntConfig::new)); -} +} \ No newline at end of file diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntPlayer.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntPlayer.java index 36637be..4419b1f 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntPlayer.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntPlayer.java @@ -4,8 +4,12 @@ import com.github.voxxin.blockhunt.game.util.BlockHuntBossBar; import com.github.voxxin.blockhunt.game.util.BlockHuntTitle; import net.minecraft.block.Block; +import net.minecraft.component.ComponentType; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.UnbreakableComponent; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.scoreboard.Team; @@ -13,11 +17,12 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import net.minecraft.util.Unit; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.Nullable; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.util.PlayerRef; +import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets; +import xyz.nucleoid.plasmid.api.util.PlayerRef; public class BlockHuntPlayer { private final ServerWorld world; @@ -68,7 +73,7 @@ public void setDisguise(BlockHuntBlock disguise, Block block) { } public void resetDisguise() { - if (this.disguise[0] != null) ((BlockHuntBlock) this.disguise[0]).kill(); + if (this.disguise[0] != null) ((BlockHuntBlock) this.disguise[0]).kill(world); this.disguise = new Object[]{null, null}; } @@ -127,10 +132,10 @@ public void loadPlayerInventory() { this.player.getInventory().clear(); this.player.getInventory().setStack(0, new ItemStack(Items.IRON_SWORD)); - this.player.getInventory().armor.set(0, new ItemStack(Items.CHAINMAIL_BOOTS).setCustomName(Text.of("§f§lHeavy Boots"))); - this.player.getInventory().armor.set(1, new ItemStack(Items.CHAINMAIL_LEGGINGS).setCustomName(Text.of("§f§lHeavy Pants"))); - this.player.getInventory().armor.set(2, new ItemStack(Items.CHAINMAIL_CHESTPLATE).setCustomName(Text.of("§f§lHeavy Chestplate"))); - this.player.getInventory().armor.set(3, new ItemStack(Items.CHAINMAIL_HELMET).setCustomName(Text.of("§f§lHeavy Helmet"))); + this.player.getInventory().armor.set(0, itemWName(Items.CHAINMAIL_BOOTS, Text.of("§f§lHeavy Boots"))); + this.player.getInventory().armor.set(1, itemWName(Items.CHAINMAIL_LEGGINGS, Text.of("§f§lHeavy Pants"))); + this.player.getInventory().armor.set(2, itemWName(Items.CHAINMAIL_CHESTPLATE, Text.of("§f§lHeavy Chestplate"))); + this.player.getInventory().armor.set(3, itemWName(Items.CHAINMAIL_HELMET, Text.of("§f§lHeavy Helmet"))); } case "hiders" -> { this.player.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, StatusEffectInstance.INFINITE, 2, false, false)); @@ -139,24 +144,30 @@ public void loadPlayerInventory() { this.player.getInventory().clear(); this.player.getInventory().setStack(0, new ItemStack(Items.STONE_SWORD)); - this.player.getInventory().armor.set(0, new ItemStack(Items.LEATHER_BOOTS).setCustomName(Text.of("§f§lSneaky Boots"))); - this.player.getInventory().armor.set(1, new ItemStack(Items.LEATHER_LEGGINGS).setCustomName(Text.of("§f§lSneaky Pants"))); - this.player.getInventory().armor.set(2, new ItemStack(Items.LEATHER_CHESTPLATE).setCustomName(Text.of("§f§lSneaky Chestplate"))); - this.player.getInventory().armor.set(3, new ItemStack(Items.LEATHER_HELMET).setCustomName(Text.of("§f§lSneaky Helmet"))); + this.player.getInventory().armor.set(0, itemWName(Items.LEATHER_BOOTS, Text.of("§f§lSneaky Boots"))); + this.player.getInventory().armor.set(1, itemWName(Items.LEATHER_LEGGINGS, Text.of("§f§lSneaky Pants"))); + this.player.getInventory().armor.set(2, itemWName(Items.LEATHER_CHESTPLATE, Text.of("§f§lSneaky Chestplate"))); + this.player.getInventory().armor.set(3, itemWName(Items.LEATHER_HELMET, Text.of("§f§lSneaky Helmet"))); } } for (ItemStack item : this.player.getInventory().main) { - item.getOrCreateNbt().putBoolean("Unbreakable", true); - item.addHideFlag(ItemStack.TooltipSection.UNBREAKABLE); + item.set(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)); + item.set(DataComponentTypes.HIDE_TOOLTIP, Unit.INSTANCE); } for (ItemStack item : this.player.getInventory().armor) { - item.getOrCreateNbt().putBoolean("Unbreakable", true); - item.addHideFlag(ItemStack.TooltipSection.UNBREAKABLE); + item.set(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)); + item.set(DataComponentTypes.HIDE_TOOLTIP, Unit.INSTANCE); } } + private ItemStack itemWName(Item stack, Text text) { + ItemStack itemStack = new ItemStack(stack); + itemStack.set(DataComponentTypes.ITEM_NAME, text); + return itemStack; + } + public void playerDeath() { BlockHuntTitle.sendTitle(this.player, Text.literal("") diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSidebar.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSidebar.java index 9ca8d64..bcf0185 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSidebar.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSidebar.java @@ -1,54 +1,51 @@ package com.github.voxxin.blockhunt.game; -import eu.pb4.sidebars.api.SidebarUtils; import eu.pb4.sidebars.api.lines.SidebarLine; -import net.minecraft.scoreboard.Team; +import net.minecraft.scoreboard.number.BlankNumberFormat; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.world.World; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget; +import xyz.nucleoid.plasmid.api.game.common.GlobalWidgets; +import xyz.nucleoid.plasmid.api.game.common.widget.SidebarWidget; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; public class BlockHuntSidebar { private final SidebarWidget sidebar; - private static ArrayList lines = new ArrayList<>(); + private static final ArrayList lines = new ArrayList<>(); private final World world; private final BlockHuntStageManager stageManager; public BlockHuntSidebar(GlobalWidgets widgets, Identifier map_name, World world, BlockHuntStageManager stageManager) { this.sidebar = widgets.addSidebar(Text.translatable("gameType.blockhunt.standard").formatted(Formatting.GOLD)); + this.sidebar.setDefaultNumberFormat(BlankNumberFormat.INSTANCE); this.world = world; this.stageManager = stageManager; - String mapName = map_name.toString(); - mapName = mapName.replaceAll("blockhunt:", ""); - mapName = mapName.replaceAll("_", " "); + String mapName = map_name.toString().replaceAll("blockhunt:", "").replaceAll("_", " "); mapName = mapName.substring(0, 1).toUpperCase() + mapName.substring(1); - lines.clear(); - - long seekersReleaseT = stageManager.seekersRelease; - long seekersDurationTick = seekersReleaseT - stageManager.startTime; + long seekersDurationTick = stageManager.seekersRelease - stageManager.startTime; long totalSecondsR = seekersDurationTick / 20; - int minutesR = (int) (totalSecondsR / 60); - int secondsR = (int) (totalSecondsR % 60); - String seekersRelease = String.format("%d:%02d", minutesR, secondsR); + String seekersRelease = String.format("%d:%02d", totalSecondsR / 60, totalSecondsR % 60); + + int hiderCount = world.getScoreboard().getTeam("hiders").getPlayerList().size(); + int seekerCount = world.getScoreboard().getTeam("seekers").getPlayerList().size(); + + int totalGameSeconds = (stageManager.gameTime[0] / 20) + (stageManager.gameTime[1] / 20); + String gameTime = String.format("%d:%02d", totalGameSeconds / 60, totalGameSeconds % 60); + lines.clear(); lines.add(SidebarLine.create(0, Text.literal(""))); lines.add(SidebarLine.create(1, Text.literal("").append(Text.translatable("sidebar.blockhunt.map_name", Text.literal(mapName).formatted(Formatting.AQUA))))); lines.add(SidebarLine.create(2, Text.literal(""))); - lines.add(SidebarLine.create(3, Text.literal("").append(Text.translatable("sidebar.blockhunt.hider_count", Text.literal(String.valueOf(world.getScoreboard().getTeam("hiders").getPlayerList().size())).formatted(Formatting.GREEN))))); + lines.add(SidebarLine.create(3, Text.literal("").append(Text.translatable("sidebar.blockhunt.hider_count", Text.literal(String.valueOf(hiderCount)).formatted(Formatting.GREEN))))); lines.add(SidebarLine.create(4, Text.literal(""))); - lines.add(SidebarLine.create(5, Text.literal("").append(Text.translatable("sidebar.blockhunt.seeker_count", Text.literal(String.valueOf(world.getScoreboard().getTeam("seekers").getPlayerList().size())).formatted(Formatting.GREEN))))); + lines.add(SidebarLine.create(5, Text.literal("").append(Text.translatable("sidebar.blockhunt.seeker_count", Text.literal(String.valueOf(seekerCount)).formatted(Formatting.GREEN))))); lines.add(SidebarLine.create(7, Text.literal(""))); - lines.add(SidebarLine.create(8, Text.literal("").append(Text.translatable("sidebar.blockhunt.game_time", Text.literal(stageManager.gameTime[0] / 60 / 20 + ":0" + stageManager.gameTime[1] / 20).formatted(Formatting.GREEN))))); + lines.add(SidebarLine.create(8, Text.literal("").append(Text.translatable("sidebar.blockhunt.game_time", Text.literal(gameTime).formatted(Formatting.GREEN))))); lines.add(SidebarLine.create(9, Text.literal(""))); lines.add(SidebarLine.create(10, Text.literal("").append(Text.translatable("sidebar.blockhunt.seeker_countdown", Text.literal(seekersRelease).formatted(Formatting.GREEN))))); lines.add(SidebarLine.create(11, Text.literal(""))); @@ -57,6 +54,7 @@ public BlockHuntSidebar(GlobalWidgets widgets, Identifier map_name, World world, this.sidebar.setLine(line); } } + public void tick() { long currentTick = this.world.getTime(); long finishTick = stageManager.finishTime; @@ -64,35 +62,29 @@ public void tick() { long totalSeconds = gameDurationTicks / 20; int minutes = (int) (totalSeconds / 60); int seconds = (int) (totalSeconds % 60); - String formattedTime = String.format("%d:%02d", minutes, seconds); + String formattedGameTime = String.format("%d:%02d", minutes, seconds); - this.world.getPlayers().forEach(playerEntity -> { - ServerPlayerEntity player = (ServerPlayerEntity) playerEntity; - sidebar.addPlayer(player); - }); + this.world.getPlayers().forEach(playerEntity -> sidebar.addPlayer((ServerPlayerEntity) playerEntity)); lines.set(3, SidebarLine.create(3, Text.literal("").append(Text.translatable("sidebar.blockhunt.hider_count", Text.literal(String.valueOf(this.world.getScoreboard().getTeam("hiders").getPlayerList().size())).formatted(Formatting.GREEN))))); lines.set(5, SidebarLine.create(5, Text.literal("").append(Text.translatable("sidebar.blockhunt.seeker_count", Text.literal(String.valueOf(this.world.getScoreboard().getTeam("seekers").getPlayerList().size())).formatted(Formatting.GREEN))))); - lines.set(8, SidebarLine.create(8, Text.literal("").append(Text.translatable("sidebar.blockhunt.game_time", Text.literal(formattedTime).formatted(Formatting.GREEN))))); + lines.set(8, SidebarLine.create(8, Text.literal("").append(Text.translatable("sidebar.blockhunt.game_time", Text.literal(formattedGameTime).formatted(Formatting.GREEN))))); + if (!stageManager.seekersReleased) { - long seekersRelease = stageManager.seekersRelease; - long seekersDurationTick = seekersRelease - currentTick; + long seekersDurationTick = stageManager.seekersRelease - currentTick; long totalSecondsR = seekersDurationTick / 20; int minutesR = (int) (totalSecondsR / 60); int secondsR = (int) (totalSecondsR % 60); - String formattedTimeR = String.format("%d:%02d", minutesR, secondsR); + String formattedSeekerTime = String.format("%d:%02d", minutesR, secondsR); - lines.set(lines.size() - 2, SidebarLine.create(10, Text.literal("").append(Text.translatable("sidebar.blockhunt.seeker_countdown", Text.literal(formattedTimeR).formatted(Formatting.GREEN))))); + lines.set(lines.size() - 2, SidebarLine.create(10, Text.literal("").append(Text.translatable("sidebar.blockhunt.seeker_countdown", Text.literal(formattedSeekerTime).formatted(Formatting.GREEN))))); lines.set(lines.size() - 1, SidebarLine.create(11, Text.literal(""))); } else if (lines.size() == 11) { - world.getPlayers().forEach(player -> { - ((ServerPlayerEntity) player).playSound(SoundEvents.ENTITY_ENDER_DRAGON_GROWL, 1.0f, 1.0f); - }); - + world.getPlayers().forEach(player -> ((ServerPlayerEntity) player).playSound(SoundEvents.ENTITY_ENDER_DRAGON_GROWL, 1.0f, 1.0f)); this.sidebar.removeLine(lines.size()); - lines.remove(lines.size() - 1); + lines.removeLast(); this.sidebar.removeLine(lines.size()); - lines.remove(lines.size() - 1); + lines.removeLast(); } for (SidebarLine line : lines) { diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSpawnLogic.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSpawnLogic.java index 91ee079..8e01b4f 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSpawnLogic.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntSpawnLogic.java @@ -2,6 +2,8 @@ import com.github.voxxin.blockhunt.BlockHunt; import com.github.voxxin.blockhunt.game.map.BlockHuntMap; +import com.google.common.collect.ImmutableSet; +import net.minecraft.network.packet.s2c.play.PositionFlag; import net.minecraft.scoreboard.AbstractTeam; import net.minecraft.scoreboard.Team; import net.minecraft.server.network.ServerPlayerEntity; @@ -10,12 +12,15 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; -import xyz.nucleoid.plasmid.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.GameSpace; + +import java.util.Set; public class BlockHuntSpawnLogic { private final GameSpace gameSpace; private final BlockHuntMap map; private final ServerWorld world; + private final Set flags = ImmutableSet.of(); public BlockHuntSpawnLogic(GameSpace gameSpace, ServerWorld world, BlockHuntMap map) { this.gameSpace = gameSpace; @@ -30,49 +35,62 @@ public void resetPlayer(ServerPlayerEntity player, GameMode gameMode) { } public void spawnPlayer(ServerPlayerEntity player, BlockHuntPlayer participant) { + var spawns = map.spawns(); + if (spawns == null) { + BlockHunt.LOGGER.error("Spawns are not defined!"); + return; + } - var spawnPos = map.spawns().containsKey("spawn_everyone") ? (Vec3d) map.spawns().get("spawn_everyone") : (Vec3d) map.spawns().get("spawn_hider"); - + // Determine the default spawn position + Vec3d spawnPos = (Vec3d) spawns.getOrDefault("spawn_everyone", spawns.get("spawn_hider")); if (participant == null) { - player.teleport(this.world, spawnPos.x, spawnPos.y, spawnPos.z, 0.0F, 0.0F); + player.teleport(this.world, spawnPos.x, spawnPos.y, spawnPos.z, flags, 0.0F, 0.0F, true); return; } - var spawnHides = (Vec3d) map.spawns().get("spawn_hider"); - var spawnSeekers = (Vec3d) map.spawns().get("spawn_seeker"); - + // Determine team-specific spawn position Team team = participant.getTeam(); + if (team == null) { + BlockHunt.LOGGER.error("Cannot spawn player! Team is not defined!"); + return; + } switch (team.getName()) { - case "seekers" -> { - spawnPos = spawnSeekers; - } - case "hiders" -> { - spawnPos = spawnHides; - } + case "seekers" -> spawnPos = (Vec3d) spawns.get("spawn_seeker"); + case "hiders" -> spawnPos = (Vec3d) spawns.get("spawn_hider"); default -> { - BlockHunt.LOGGER.error("Cannot spawn player! Team is not defined!"); + BlockHunt.LOGGER.error("Cannot spawn player! Unknown team: " + team.getName()); return; } } + // Find a safe position float radius = 4.5f; - int x = (int) (spawnPos.getX() + MathHelper.nextFloat(player.getRandom(), -radius, radius)); - int z = (int) (spawnPos.getZ() + MathHelper.nextFloat(player.getRandom(), -radius, radius)); - - - while (!this.world.getBlockState(new BlockPos((int) x, (int) spawnPos.y, (int) z)).isAir() && !this.world.getBlockState(new BlockPos((int) x, (int) spawnPos.y+1, (int) z)).isAir()) { - x = (int) (spawnPos.getX() + MathHelper.nextFloat(player.getRandom(), -radius, radius)); - z = (int) (spawnPos.getZ() + MathHelper.nextFloat(player.getRandom(), -radius, radius)); + BlockPos safePos = null; + for (int attempt = 0; attempt < 100; attempt++) { + int x = MathHelper.floor(spawnPos.x + MathHelper.nextFloat(player.getRandom(), -radius, radius)); + int z = MathHelper.floor(spawnPos.z + MathHelper.nextFloat(player.getRandom(), -radius, radius)); + BlockPos pos = new BlockPos(x, MathHelper.floor(spawnPos.y), z); + + if (this.world.getBlockState(pos).isAir() && + this.world.getBlockState(pos.up()).isAir() && + !this.world.getBlockState(pos.down()).isAir()) { + safePos = pos; + break; + } } - float xPos = x + 0.5f; - float zPos = z + 0.5f; + if (safePos == null) { + BlockHunt.LOGGER.error("Failed to find a safe spawn location."); + return; + } + // Adjust position for finer placement float newRadius = 0.25f; - xPos = xPos + MathHelper.nextFloat(player.getRandom(), -newRadius, newRadius); - zPos = zPos + MathHelper.nextFloat(player.getRandom(), -newRadius, newRadius); + float xPos = safePos.getX() + 0.5f + MathHelper.nextFloat(player.getRandom(), -newRadius, newRadius); + float zPos = safePos.getZ() + 0.5f + MathHelper.nextFloat(player.getRandom(), -newRadius, newRadius); - player.teleport(this.world, xPos, spawnPos.y, zPos, 0.0F, 0.0F); + // Teleport player + player.teleport(this.world, xPos, safePos.getY(), zPos, flags, 0.0F, 0.0F, true); } } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntStageManager.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntStageManager.java index 6cad76e..8407620 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntStageManager.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntStageManager.java @@ -10,8 +10,8 @@ import net.minecraft.text.Text; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; -import xyz.nucleoid.plasmid.game.GameSpace; -import xyz.nucleoid.plasmid.game.player.PlayerSet; +import xyz.nucleoid.plasmid.api.game.GameSpace; +import xyz.nucleoid.plasmid.api.game.player.PlayerSet; import java.util.Set; @@ -100,11 +100,8 @@ private void tickStartWaiting(long time, GameSpace space) { double destY = state.lastPos.y; double destZ = state.lastPos.z; - // Set X and Y as relative so it will send 0 change when we pass yaw (yaw - yaw = 0) and pitch - Set flags = ImmutableSet.of(PositionFlag.X_ROT, PositionFlag.Y_ROT); - // Teleport without changing the pitch and yaw - player.networkHandler.requestTeleport(destX, destY, destZ, player.getYaw(), player.getPitch(), flags); + player.networkHandler.requestTeleport(destX, destY, destZ, player.getYaw(), player.getPitch()); } } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntWaiting.java b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntWaiting.java index 9991ab4..82e257b 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntWaiting.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/BlockHuntWaiting.java @@ -11,12 +11,14 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.GameMode; -import xyz.nucleoid.plasmid.game.*; -import xyz.nucleoid.plasmid.game.common.GameWaitingLobby; -import xyz.nucleoid.plasmid.game.common.config.PlayerConfig; -import xyz.nucleoid.plasmid.game.event.GameActivityEvents; -import xyz.nucleoid.plasmid.game.event.GamePlayerEvents; -import xyz.nucleoid.plasmid.game.rule.GameRuleType; +import xyz.nucleoid.plasmid.api.game.*; +import xyz.nucleoid.plasmid.api.game.common.GameWaitingLobby; +import xyz.nucleoid.plasmid.api.game.common.config.WaitingLobbyConfig; +import xyz.nucleoid.plasmid.api.game.event.GameActivityEvents; +import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents; +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.block.BlockUseEvent; import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; @@ -30,20 +32,20 @@ public class BlockHuntWaiting { private final BlockHuntConfig config; private final BlockHuntSpawnLogic spawnLogic; private final ServerWorld world; - private static List deniedBlockInteractions = new ArrayList<>(); + private static final List deniedBlockInteractions = new ArrayList<>(); private static boolean warnedForSpawns = false; private BlockHuntWaiting(GameSpace gameSpace, ServerWorld world, BlockHuntMap map, BlockHuntConfig config) { this.gameSpace = gameSpace; - this.thisMap = map; + thisMap = map; this.config = config; this.world = world; this.spawnLogic = new BlockHuntSpawnLogic(gameSpace, world, map); } public static GameOpenProcedure open(GameOpenContext context) { - PlayerConfig config = new PlayerConfig(2, 32); + WaitingLobbyConfig config = new WaitingLobbyConfig(2, 32); BlockHuntMap map; try { @@ -70,19 +72,20 @@ public static GameOpenProcedure open(GameOpenContext context) { }); // Game Rules - game.setRule(GameRuleType.FALL_DAMAGE, ActionResult.FAIL); - game.setRule(GameRuleType.PICKUP_ITEMS, ActionResult.FAIL); - game.setRule(GameRuleType.CRAFTING, ActionResult.FAIL); - game.setRule(GameRuleType.BREAK_BLOCKS, ActionResult.FAIL); - game.setRule(GameRuleType.FIRE_TICK, ActionResult.FAIL); - game.setRule(GameRuleType.FLUID_FLOW, ActionResult.FAIL); - game.setRule(GameRuleType.HUNGER, ActionResult.FAIL); - game.setRule(GameRuleType.MODIFY_ARMOR, ActionResult.FAIL); - game.setRule(GameRuleType.PLACE_BLOCKS, ActionResult.FAIL); + game.setRule(GameRuleType.FALL_DAMAGE, EventResult.DENY); + game.setRule(GameRuleType.PICKUP_ITEMS, EventResult.DENY); + game.setRule(GameRuleType.CRAFTING, EventResult.DENY); + game.setRule(GameRuleType.BREAK_BLOCKS, EventResult.DENY); + game.setRule(GameRuleType.FIRE_TICK, EventResult.DENY); + game.setRule(GameRuleType.FLUID_FLOW, EventResult.DENY); + game.setRule(GameRuleType.HUNGER, EventResult.DENY); + game.setRule(GameRuleType.MODIFY_ARMOR, EventResult.DENY); + game.setRule(GameRuleType.PLACE_BLOCKS, EventResult.DENY); game.listen(GameActivityEvents.REQUEST_START, waiting::requestStart); game.listen(GamePlayerEvents.ADD, waiting::addPlayer); - game.listen(GamePlayerEvents.OFFER, (offer) -> offer.accept(world, map.spawns().containsKey("spawn_everyone") ? map.spawns().get("spawn_everyone") : map.spawns().get("spawn_hider"))); + game.listen(GamePlayerEvents.OFFER, JoinOffer::accept); + game.listen(GamePlayerEvents.ACCEPT, (offer) -> offer.teleport(world, map.spawns().containsKey("spawn_everyone") ? map.spawns().get("spawn_everyone") : map.spawns().get("spawn_hider"))); game.listen(PlayerDeathEvent.EVENT, waiting::onPlayerDeath); game.listen(BlockUseEvent.EVENT, waiting::allowInteraction); @@ -112,10 +115,10 @@ private void addPlayer(ServerPlayerEntity player) { this.spawnPlayer(player); } - private ActionResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { + private EventResult onPlayerDeath(ServerPlayerEntity player, DamageSource source) { player.setHealth(20.0f); this.spawnPlayer(player); - return ActionResult.FAIL; + return EventResult.DENY; } private void spawnPlayer(ServerPlayerEntity player) { diff --git a/src/main/java/com/github/voxxin/blockhunt/game/map/BlockHuntMap.java b/src/main/java/com/github/voxxin/blockhunt/game/map/BlockHuntMap.java index 8c19d5e..a26191b 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/map/BlockHuntMap.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/map/BlockHuntMap.java @@ -11,8 +11,8 @@ import net.minecraft.world.GameRules; import xyz.nucleoid.fantasy.RuntimeWorldConfig; import xyz.nucleoid.map_templates.MapTemplateSerializer; -import xyz.nucleoid.plasmid.game.GameOpenContext; -import xyz.nucleoid.plasmid.game.world.generator.TemplateChunkGenerator; +import xyz.nucleoid.plasmid.api.game.GameOpenContext; +import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator; import java.io.IOException; import java.util.ArrayList; @@ -113,7 +113,7 @@ public static BlockHuntMap from(GameOpenContext context) throws } BlockHuntAnimation newAnimation = - new BlockHuntAnimation(new Identifier(config.mapConfig().id().getNamespace(), animationParts[0]), + new BlockHuntAnimation(Identifier.of(config.mapConfig().id().getNamespace(), animationParts[0]), animationParts[1].contains("play") ? new BlockHuntAnimationPoints(region.getBounds().min(), region.getBounds().max(), true) : null, animationParts[1].contains("settings") ? region.getBounds().max() : null); diff --git a/src/main/java/com/github/voxxin/blockhunt/game/mixin/BlockDisplayEntityMixin.java b/src/main/java/com/github/voxxin/blockhunt/game/mixin/BlockDisplayEntityMixin.java new file mode 100644 index 0000000..f15b7c5 --- /dev/null +++ b/src/main/java/com/github/voxxin/blockhunt/game/mixin/BlockDisplayEntityMixin.java @@ -0,0 +1,29 @@ +package com.github.voxxin.blockhunt.game.mixin; + +import com.github.voxxin.blockhunt.game.util.BlockHuntBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.decoration.DisplayEntity; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(DisplayEntity.BlockDisplayEntity.class) +public abstract class BlockDisplayEntityMixin { + + + @Shadow @Nullable public abstract DisplayEntity.BlockDisplayEntity.Data getData(); + + @Shadow @Nullable private DisplayEntity.BlockDisplayEntity.Data data; + + @Inject(at = @At("HEAD"), method = "getBlockState", cancellable = true) + public void blockHunt$getBlockState(CallbackInfoReturnable cir) { + if (((Object) this) instanceof BlockHuntBlock) { + DisplayEntity.BlockDisplayEntity.Data data = ((DisplayEntity.BlockDisplayEntity.Data) this.getData()); + cir.setReturnValue(this.data != null && data.blockState() != null ? this.data.blockState() : Blocks.AIR.getDefaultState()); + } + } +} diff --git a/src/main/java/com/github/voxxin/blockhunt/game/mixin/BossBarWidgetMixin.java b/src/main/java/com/github/voxxin/blockhunt/game/mixin/BossBarWidgetMixin.java index 2e0f3ac..26eef24 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/mixin/BossBarWidgetMixin.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/mixin/BossBarWidgetMixin.java @@ -1,16 +1,9 @@ package com.github.voxxin.blockhunt.game.mixin; import com.github.voxxin.blockhunt.game.util.ext.BossBarWidgetExt; -import net.minecraft.entity.boss.BossBar; import net.minecraft.entity.boss.ServerBossBar; import net.minecraft.server.network.ServerPlayerEntity; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import xyz.nucleoid.plasmid.game.common.widget.BossBarWidget; @Mixin(ServerBossBar.class) public class BossBarWidgetMixin implements BossBarWidgetExt { diff --git a/src/main/java/com/github/voxxin/blockhunt/game/mixin/ServerPlayerNetworkHandlerMixin.java b/src/main/java/com/github/voxxin/blockhunt/game/mixin/ServerPlayerNetworkHandlerMixin.java index 33617cd..40c7874 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/mixin/ServerPlayerNetworkHandlerMixin.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/mixin/ServerPlayerNetworkHandlerMixin.java @@ -22,7 +22,7 @@ public class ServerPlayerNetworkHandlerMixin { public void sendPacket(Packet packet, PacketCallbacks callbacks, CallbackInfo ci) { //noinspection ConstantValue if (packet instanceof EntityEquipmentUpdateS2CPacket entityEquipmentUpdateS2CPacket && ((Object) this) instanceof ServerPlayNetworkHandler handler) { - int packetID = entityEquipmentUpdateS2CPacket.getId(); + int packetID = entityEquipmentUpdateS2CPacket.getEntityId(); if (handler.player.getServerWorld().getPlayers().stream().noneMatch(p -> p.getId() == packetID)) { ci.cancel(); } if (BlockHunt.deniedIDs.contains(packetID)) { ci.cancel(); } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/mixin/WrittenBookItemMixin.java b/src/main/java/com/github/voxxin/blockhunt/game/mixin/WrittenBookItemMixin.java index ad356e9..fcc37ca 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/mixin/WrittenBookItemMixin.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/mixin/WrittenBookItemMixin.java @@ -1,31 +1,39 @@ package com.github.voxxin.blockhunt.game.mixin; import com.github.voxxin.blockhunt.game.util.ext.WrittenBookItemExt; +import net.minecraft.component.ComponentMap; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.WrittenBookContentComponent; import net.minecraft.item.ItemStack; import net.minecraft.item.WrittenBookItem; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; -import net.minecraft.nbt.NbtString; import org.spongepowered.asm.mixin.Mixin; import java.util.ArrayList; -import static net.minecraft.item.WrittenBookItem.isValid; - @Mixin(WrittenBookItem.class) public class WrittenBookItemMixin implements WrittenBookItemExt { @Override public ArrayList getPages(ItemStack book) { ArrayList pages = new ArrayList<>(); - NbtCompound nbtCompound = book.getNbt(); + ComponentMap nbtCompound = book.getComponents(); assert nbtCompound != null; - NbtList rawPage = nbtCompound.getList("pages", 8); + WrittenBookContentComponent rawPage = nbtCompound.get(DataComponentTypes.WRITTEN_BOOK_CONTENT); - for (int i = 0; i < rawPage.size(); ++i) { - pages.add(rawPage.getString(i)); + for (int i = 0; i < rawPage.pages().size(); ++i) { + pages.add(rawPage.pages().get(i).get(false).getString()); } return pages; } + + @Override + public String getTitle(ItemStack book) { + ComponentMap nbtCompound = book.getComponents(); + assert nbtCompound != null; + WrittenBookContentComponent rawContents = nbtCompound.get(DataComponentTypes.WRITTEN_BOOK_CONTENT); + return rawContents.title().raw(); + } } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntAnimation.java b/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntAnimation.java index 22919f7..6b2b8c4 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntAnimation.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntAnimation.java @@ -4,6 +4,7 @@ import com.github.voxxin.blockhunt.game.util.ext.WrittenBookItemExt; import net.minecraft.block.entity.LecternBlockEntity; import net.minecraft.client.gui.screen.ingame.BookScreen; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.WrittenBookItem; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.ActionResult; @@ -130,8 +131,11 @@ private void parseValues() { WrittenBookItem book = (WrittenBookItem) lectern.getBook().getItem(); ArrayList bookContents = ((WrittenBookItemExt)book).getPages(lectern.getBook()); + String bookTitle = ((WrittenBookItemExt)book).getTitle(lectern.getBook()); + + if (!bookTitle.equals(animationName.getPath())) { + System.out.println(bookTitle); - if (!book.getName(lectern.getBook()).getString().equals(animationName.getPath())) { BlockHunt.LOGGER.error("Settings could not be created, since the book on lectern at position " + settingsPoint + " does not match the animation name " + animationName.getPath() + " (" + animationName + ") was looking for " + book.getName(lectern.getBook())); return; } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntBlock.java b/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntBlock.java index 3caf1e2..2351814 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntBlock.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/util/BlockHuntBlock.java @@ -1,15 +1,12 @@ package com.github.voxxin.blockhunt.game.util; import com.github.voxxin.blockhunt.game.util.ext.DisplayEntityExt; -import net.minecraft.block.AirBlock; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.EntityType; import net.minecraft.entity.decoration.DisplayEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtList; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mutable; public class BlockHuntBlock extends DisplayEntity.BlockDisplayEntity { @@ -19,19 +16,20 @@ public BlockHuntBlock(EntityType entityType, World world) { super(entityType, world); this.setNoGravity(true); this.setInvulnerable(true); + this.setTeleportDuration(1); } - public void setBlockState(BlockState state) { - ((DisplayEntityExt) this).blockHunt$setState(state); - } - - public BlockState getBlockState() { - Data data = this.getData(); - if (data != null && data.blockState() != null) { - return data.blockState(); - } else { - return Blocks.AIR.getDefaultState(); - } - } +// public void setBlockState(BlockState state) { +// ((DisplayEntityExt) this).blockHunt$setState(state); +// } +// +// public BlockState getBlockState() { +// Data data = this.getData(); +// if (data != null && data.blockState() != null) { +// return data.blockState(); +// } else { +// return Blocks.AIR.getDefaultState(); +// } +// } } diff --git a/src/main/java/com/github/voxxin/blockhunt/game/util/ext/WrittenBookItemExt.java b/src/main/java/com/github/voxxin/blockhunt/game/util/ext/WrittenBookItemExt.java index 0b0f306..31e189b 100644 --- a/src/main/java/com/github/voxxin/blockhunt/game/util/ext/WrittenBookItemExt.java +++ b/src/main/java/com/github/voxxin/blockhunt/game/util/ext/WrittenBookItemExt.java @@ -7,4 +7,6 @@ public interface WrittenBookItemExt { ArrayList getPages(ItemStack book); + + String getTitle(ItemStack book); } diff --git a/src/main/resources/blockhunt.accesswidener b/src/main/resources/blockhunt.accesswidener new file mode 100644 index 0000000..dcbb4e9 --- /dev/null +++ b/src/main/resources/blockhunt.accesswidener @@ -0,0 +1,4 @@ +accessWidener v2 named + +accessible method net/minecraft/entity/decoration/DisplayEntity$BlockDisplayEntity setBlockState (Lnet/minecraft/block/BlockState;)V +accessible method net/minecraft/entity/decoration/DisplayEntity$BlockDisplayEntity getBlockState ()Lnet/minecraft/block/BlockState; \ No newline at end of file diff --git a/src/main/resources/blockhunt.mixins.json b/src/main/resources/blockhunt.mixins.json index dca5633..8bc24ee 100644 --- a/src/main/resources/blockhunt.mixins.json +++ b/src/main/resources/blockhunt.mixins.json @@ -2,8 +2,9 @@ "required": true, "minVersion": "0.8", "package": "com.github.voxxin.blockhunt.game.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_18", "mixins": [ + "BlockDisplayEntityMixin", "BossBarWidgetMixin", "DisplayEntityMixin", "ServerPlayerNetworkHandlerMixin", diff --git a/src/main/resources/data/blockhunt/lang/en_us.json b/src/main/resources/data/blockhunt/lang/en_us.json index b282c8a..98f82d7 100644 --- a/src/main/resources/data/blockhunt/lang/en_us.json +++ b/src/main/resources/data/blockhunt/lang/en_us.json @@ -1,4 +1,5 @@ { + "gameType.blockhunt.blockhunt": "Block Hunt", "gameType.blockhunt.standard": "Block Hunt", "event.blockhunt.block_changed": "You are now disguised as a %s!", diff --git a/src/main/resources/data/blockhunt/map_templates/fort_du_perdu.nbt b/src/main/resources/data/blockhunt/map_template/fort_du_perdu.nbt similarity index 100% rename from src/main/resources/data/blockhunt/map_templates/fort_du_perdu.nbt rename to src/main/resources/data/blockhunt/map_template/fort_du_perdu.nbt diff --git a/src/main/resources/data/blockhunt/games/fort_du_perdu.json b/src/main/resources/data/blockhunt/plasmid/game/fort_du_perdu.json similarity index 100% rename from src/main/resources/data/blockhunt/games/fort_du_perdu.json rename to src/main/resources/data/blockhunt/plasmid/game/fort_du_perdu.json