From b867fa2efb789818dbc2b41e7483ecd5ba0b6279 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Wed, 18 Mar 2026 14:24:35 +0100 Subject: style(): switch to tab and to lf --- .editorconfig | 7 + README.md | 7 +- build.gradle | 116 ++--- gradle.properties | 4 - src/main/java/world/anhgelus/manhunt/Config.java | 6 +- src/main/java/world/anhgelus/manhunt/Manhunt.java | 408 ++++++++--------- .../world/anhgelus/manhunt/mixins/Tracker.java | 8 +- .../anhgelus/manhunt/mixins/WorldTimerAccess.java | 56 +-- .../world/anhgelus/manhunt/timer/TickTask.java | 118 ++--- .../world/anhgelus/manhunt/timer/TimerAccess.java | 96 ++-- .../loot_table/gameplay/piglin_bartering.json | 504 ++++++++++----------- src/main/resources/fabric.mod.json | 58 +-- src/main/resources/manhunt.mixins.json | 20 +- 13 files changed, 708 insertions(+), 700 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..886d72a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[*] +end_of_line = lf +indent_style = tab +ij_smart_tabs = true + +[*.json] +tab_width = 2 \ No newline at end of file diff --git a/README.md b/README.md index 56903ac..95f2fdd 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ same as Minecraft 1.16.1). ## Why did I create this mod? Because there was no server-side Minecraft mod for the latest Minecraft version. -In addition to this, these mods do not revert the Nether which is essential for speedrunning the game, and they do not +In addition to this, these mods do not revert the Nether which is essential for speedrunning the game, and they do not update automatically the compass. ## Usage @@ -20,6 +20,7 @@ update automatically the compass. `/manhunt` is the main command. `/manhunt team` edits the team. + - `/manhunt team hunter` adds the player to the hunters. - `/manhunt team speedrunner` adds the player to the speedrunners. @@ -31,10 +32,12 @@ update automatically the compass. ## Config file -You can config the time before the release of the hunters and the time between two compass' updates by modifying the config +You can config the time before the release of the hunters and the time between two compass' updates by modifying the +config file `config/manhunt.json`. The default config file is: + ```json { "secondsBeforeRelease": 30, diff --git a/build.gradle b/build.gradle index 1057c5b..6bdf007 100644 --- a/build.gradle +++ b/build.gradle @@ -1,96 +1,96 @@ plugins { - id 'fabric-loom' version '1.15-SNAPSHOT' - id 'maven-publish' + id 'fabric-loom' version '1.15-SNAPSHOT' + id 'maven-publish' } version = project.mod_version group = project.maven_group base { - archivesName = project.archives_base_name + archivesName = project.archives_base_name } repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. - maven { - url = "https://api.modrinth.com/maven" - } + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. + maven { + url = "https://api.modrinth.com/maven" + } } loom { - splitEnvironmentSourceSets() + splitEnvironmentSourceSets() - mods { - "manhunt" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } + mods { + "manhunt" { + sourceSet sourceSets.main + sourceSet sourceSets.client + } + } } dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // Fabric API. This is technically optional, but you probably want it anyway. + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}" - include "maven.modrinth:midnightlib:${project.midnightlib_version}" + modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}" + include "maven.modrinth:midnightlib:${project.midnightlib_version}" } processResources { - inputs.property "version", project.version - inputs.property "minecraft_version", project.minecraft_version - inputs.property "loader_version", project.loader_version - filteringCharset "UTF-8" - - filesMatching("fabric.mod.json") { - expand "version": inputs.properties.version, - "minecraft_version": inputs.properties.minecraft_version, - "loader_version": inputs.properties.loader_version - } + inputs.property "version", project.version + inputs.property "minecraft_version", project.minecraft_version + inputs.property "loader_version", project.loader_version + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": inputs.properties.version, + "minecraft_version": inputs.properties.minecraft_version, + "loader_version": inputs.properties.loader_version + } } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 - it.options.encoding = "UTF-8" + it.options.release = 21 + it.options.encoding = "UTF-8" } java { - withSourcesJar() + withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { - from("LICENSE") { - rename { "${it}_${inputs.properties.archivesName}" } - } + from("LICENSE") { + rename { "${it}_${inputs.properties.archivesName}" } + } } // configure the maven publication publishing { - publications { - create("mavenJava", MavenPublication) { - artifactId = project.archives_base_name - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } + publications { + create("mavenJava", MavenPublication) { + artifactId = project.archives_base_name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 8a80059..ba0ac23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,15 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true - # Fabric Properties # check these on https://fabricmc.net/develop minecraft_version=1.21.11 yarn_mappings=1.21.11+build.4 loader_version=0.18.4 - # Fabric API fabric_version=0.141.3+1.21.11 - # Libs midnightlib_version=1.9.2+1.21.11-fabric - # Mod Properties mod_version=1.4.0 maven_group=world.anhgelus.manhunt diff --git a/src/main/java/world/anhgelus/manhunt/Config.java b/src/main/java/world/anhgelus/manhunt/Config.java index d669de2..f441a58 100644 --- a/src/main/java/world/anhgelus/manhunt/Config.java +++ b/src/main/java/world/anhgelus/manhunt/Config.java @@ -3,6 +3,8 @@ package world.anhgelus.manhunt; import eu.midnightdust.lib.config.MidnightConfig; public class Config extends MidnightConfig { - @Entry(category = "timings") public static int secondsBeforeRelease = 30; - @Entry(category = "timings") public static int updateCompassEach = 15; + @Entry(category = "timings") + public static int secondsBeforeRelease = 30; + @Entry(category = "timings") + public static int updateCompassEach = 15; } diff --git a/src/main/java/world/anhgelus/manhunt/Manhunt.java b/src/main/java/world/anhgelus/manhunt/Manhunt.java index 66b8fb4..4a3ba4e 100644 --- a/src/main/java/world/anhgelus/manhunt/Manhunt.java +++ b/src/main/java/world/anhgelus/manhunt/Manhunt.java @@ -41,221 +41,221 @@ import java.util.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; public class Manhunt implements ModInitializer { - public static final String MOD_ID = "manhunt"; - public static final Logger LOGGER = LogManager.getLogger(MOD_ID); + public static final String MOD_ID = "manhunt"; + public static final Logger LOGGER = LogManager.getLogger(MOD_ID); - private final Set hunters = new HashSet<>(); - private final Set speedrunners = new HashSet<>(); - private final Map trackedMap = new HashMap<>(); + private final Set hunters = new HashSet<>(); + private final Set speedrunners = new HashSet<>(); + private final Map trackedMap = new HashMap<>(); - private State state = State.OFF; + private State state = State.OFF; - @Override - public void onInitialize() { - LOGGER.info("Initializing Manhunt"); - MidnightConfig.init(MOD_ID, Config.class); + @Override + public void onInitialize() { + LOGGER.info("Initializing Manhunt"); + MidnightConfig.init(MOD_ID, Config.class); - final LiteralArgumentBuilder command = literal("manhunt"); + final LiteralArgumentBuilder command = literal("manhunt"); - final LiteralArgumentBuilder track = literal("track"); - track.then(RequiredArgumentBuilder.argument("player", EntityArgumentType.player()) - .executes(context -> { - final var source = context.getSource(); - final var tracked = (ServerPlayerEntity) EntityArgumentType.getEntity(context, "player"); - assert tracked.getDisplayName() != null; - final var player = source.getPlayer(); - if (player == null) return 2; - final var uuid = player.getUuid(); - if (trackedMap.get(uuid) != null && trackedMap.get(uuid) == tracked.getUuid()) { - source.sendFeedback(() -> Text.literal("Already tracking " + tracked.getDisplayName().getString()), false); - return Command.SINGLE_SUCCESS; - } - trackedMap.put(player.getUuid(), tracked.getUuid()); - updateCompass(player, tracked); - source.sendFeedback(() -> Text.literal("Tracking " + tracked.getDisplayName().getString()), false); - return Command.SINGLE_SUCCESS; - }) - ); - final LiteralArgumentBuilder team = literal("team"); - final RequiredArgumentBuilder teamP = RequiredArgumentBuilder.argument("player", EntityArgumentType.player()); - teamP.then(LiteralArgumentBuilder.literal("hunter").executes(context -> { - final var p = (ServerPlayerEntity) EntityArgumentType.getEntity(context, "player"); - speedrunners.remove(p.getUuid()); - hunters.add(p.getUuid()); - assert p.getDisplayName() != null; - context.getSource().sendFeedback(() -> Text.literal(p.getDisplayName().getString() + " added to hunter"), true); - return Command.SINGLE_SUCCESS; - })) - .then(LiteralArgumentBuilder.literal("speedrunner").executes(context -> { - final var p = (ServerPlayerEntity) EntityArgumentType.getEntity(context, "player"); - hunters.remove(p.getUuid()); - speedrunners.add(p.getUuid()); - assert p.getDisplayName() != null; - context.getSource().sendFeedback(() -> Text.literal(p.getDisplayName().getString() + " added to speedrunner"), true); - return Command.SINGLE_SUCCESS; - })); - team.then(teamP); - final LiteralArgumentBuilder start = literal("start"); - start.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)); - start.executes(context -> { - final var source = context.getSource(); - if (state == State.ON) { - source.sendFeedback(() -> Text.literal("Cannot start a manhunt if one is already started!"), false); - return Command.SINGLE_SUCCESS; - } - final var server = source.getServer(); - final var timer = TimerAccess.getTimerFromOverworld(server); - final PlayerManager pm = server.getPlayerManager(); - for (final ServerPlayerEntity player : pm.getPlayerList()) { - player.setHealth(player.getMaxHealth()); - player.setExperienceLevel(0); - player.getInventory().clear(); - player.getHungerManager().eat( - new FoodComponent(20, 20.0f, true) - ); - final var spawn = player.getEntityWorld().getSpawnPoint().getPos(); - player.teleport(spawn.getX(), spawn.getY(), spawn.getZ(), false); - } - state = State.ON; - for (final UUID uuid : hunters) { - final var hunter = pm.getPlayer(uuid); - assert hunter != null; - final var isACompass = new ItemStack(Items.COMPASS); - hunter.giveItemStack(isACompass); - hunter.addStatusEffect(new StatusEffectInstance(StatusEffects.MINING_FATIGUE, Config.secondsBeforeRelease * 20, 255, false, false)); - var attr = hunter.getAttributeInstance(EntityAttributes.MOVEMENT_SPEED); - if (attr != null) { - final var modifier = new EntityAttributeModifier( - Identifier.of("manhunt.speed"), - -1, - EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE - ); - attr.addTemporaryModifier(modifier); - } - attr = hunter.getAttributeInstance(EntityAttributes.GRAVITY); - if (attr != null) { - final var modifier = new EntityAttributeModifier( - Identifier.of("manhunt.gravity"), - 5, - EntityAttributeModifier.Operation.ADD_VALUE - ); - attr.addTemporaryModifier(modifier); - } - LOGGER.info("Added modifiers to {}", hunter.getDisplayName()); - } - timer.dds_runTask(new TickTask(() -> { - LOGGER.info("Removing modifier to hunters"); - for (final UUID uuid : hunters) { - final var hunter = pm.getPlayer(uuid); - assert hunter != null; - var attr = hunter.getAttributeInstance(EntityAttributes.MOVEMENT_SPEED); - if (attr != null) { - attr.removeModifier(Identifier.of("manhunt.speed")); - } - attr = hunter.getAttributeInstance(EntityAttributes.GRAVITY); - if (attr != null) { - attr.removeModifier(Identifier.of("manhunt.gravity")); - } - } - pm.broadcast(Text.of("Hunters released!"), false); - }, Config.secondsBeforeRelease * 20L)); - setTimer(pm); - source.sendFeedback(() -> Text.literal("Game started!"), true); - return Command.SINGLE_SUCCESS; - }); + final LiteralArgumentBuilder track = literal("track"); + track.then(RequiredArgumentBuilder.argument("player", EntityArgumentType.player()) + .executes(context -> { + final var source = context.getSource(); + final var tracked = (ServerPlayerEntity) EntityArgumentType.getEntity(context, "player"); + assert tracked.getDisplayName() != null; + final var player = source.getPlayer(); + if (player == null) return 2; + final var uuid = player.getUuid(); + if (trackedMap.get(uuid) != null && trackedMap.get(uuid) == tracked.getUuid()) { + source.sendFeedback(() -> Text.literal("Already tracking " + tracked.getDisplayName().getString()), false); + return Command.SINGLE_SUCCESS; + } + trackedMap.put(player.getUuid(), tracked.getUuid()); + updateCompass(player, tracked); + source.sendFeedback(() -> Text.literal("Tracking " + tracked.getDisplayName().getString()), false); + return Command.SINGLE_SUCCESS; + }) + ); + final LiteralArgumentBuilder team = literal("team"); + final RequiredArgumentBuilder teamP = RequiredArgumentBuilder.argument("player", EntityArgumentType.player()); + teamP.then(LiteralArgumentBuilder.literal("hunter").executes(context -> { + final var p = (ServerPlayerEntity) EntityArgumentType.getEntity(context, "player"); + speedrunners.remove(p.getUuid()); + hunters.add(p.getUuid()); + assert p.getDisplayName() != null; + context.getSource().sendFeedback(() -> Text.literal(p.getDisplayName().getString() + " added to hunter"), true); + return Command.SINGLE_SUCCESS; + })) + .then(LiteralArgumentBuilder.literal("speedrunner").executes(context -> { + final var p = (ServerPlayerEntity) EntityArgumentType.getEntity(context, "player"); + hunters.remove(p.getUuid()); + speedrunners.add(p.getUuid()); + assert p.getDisplayName() != null; + context.getSource().sendFeedback(() -> Text.literal(p.getDisplayName().getString() + " added to speedrunner"), true); + return Command.SINGLE_SUCCESS; + })); + team.then(teamP); + final LiteralArgumentBuilder start = literal("start"); + start.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)); + start.executes(context -> { + final var source = context.getSource(); + if (state == State.ON) { + source.sendFeedback(() -> Text.literal("Cannot start a manhunt if one is already started!"), false); + return Command.SINGLE_SUCCESS; + } + final var server = source.getServer(); + final var timer = TimerAccess.getTimerFromOverworld(server); + final PlayerManager pm = server.getPlayerManager(); + for (final ServerPlayerEntity player : pm.getPlayerList()) { + player.setHealth(player.getMaxHealth()); + player.setExperienceLevel(0); + player.getInventory().clear(); + player.getHungerManager().eat( + new FoodComponent(20, 20.0f, true) + ); + final var spawn = player.getEntityWorld().getSpawnPoint().getPos(); + player.teleport(spawn.getX(), spawn.getY(), spawn.getZ(), false); + } + state = State.ON; + for (final UUID uuid : hunters) { + final var hunter = pm.getPlayer(uuid); + assert hunter != null; + final var isACompass = new ItemStack(Items.COMPASS); + hunter.giveItemStack(isACompass); + hunter.addStatusEffect(new StatusEffectInstance(StatusEffects.MINING_FATIGUE, Config.secondsBeforeRelease * 20, 255, false, false)); + var attr = hunter.getAttributeInstance(EntityAttributes.MOVEMENT_SPEED); + if (attr != null) { + final var modifier = new EntityAttributeModifier( + Identifier.of("manhunt.speed"), + -1, + EntityAttributeModifier.Operation.ADD_MULTIPLIED_BASE + ); + attr.addTemporaryModifier(modifier); + } + attr = hunter.getAttributeInstance(EntityAttributes.GRAVITY); + if (attr != null) { + final var modifier = new EntityAttributeModifier( + Identifier.of("manhunt.gravity"), + 5, + EntityAttributeModifier.Operation.ADD_VALUE + ); + attr.addTemporaryModifier(modifier); + } + LOGGER.info("Added modifiers to {}", hunter.getDisplayName()); + } + timer.dds_runTask(new TickTask(() -> { + LOGGER.info("Removing modifier to hunters"); + for (final UUID uuid : hunters) { + final var hunter = pm.getPlayer(uuid); + assert hunter != null; + var attr = hunter.getAttributeInstance(EntityAttributes.MOVEMENT_SPEED); + if (attr != null) { + attr.removeModifier(Identifier.of("manhunt.speed")); + } + attr = hunter.getAttributeInstance(EntityAttributes.GRAVITY); + if (attr != null) { + attr.removeModifier(Identifier.of("manhunt.gravity")); + } + } + pm.broadcast(Text.of("Hunters released!"), false); + }, Config.secondsBeforeRelease * 20L)); + setTimer(pm); + source.sendFeedback(() -> Text.literal("Game started!"), true); + return Command.SINGLE_SUCCESS; + }); - final LiteralArgumentBuilder resetTimer = literal("reset-timer"); - resetTimer.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)); - resetTimer.executes(context -> { - state = State.ON; - setTimer(context.getSource().getServer().getPlayerManager()); - context.getSource().sendFeedback(() -> Text.literal("Timer reset"), true); - return Command.SINGLE_SUCCESS; - }); + final LiteralArgumentBuilder resetTimer = literal("reset-timer"); + resetTimer.requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)); + resetTimer.executes(context -> { + state = State.ON; + setTimer(context.getSource().getServer().getPlayerManager()); + context.getSource().sendFeedback(() -> Text.literal("Timer reset"), true); + return Command.SINGLE_SUCCESS; + }); - command.then(track); - command.then(team); - command.then(start); - command.then(resetTimer); + command.then(track); + command.then(team); + command.then(start); + command.then(resetTimer); - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(command)); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(command)); - ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> { - if (state == State.OFF) return; - final var uuid = oldPlayer.getUuid(); - if (hunters.contains(uuid)) { - newPlayer.giveItemStack(new ItemStack(Items.COMPASS)); - return; - } - speedrunners.remove(uuid); - newPlayer.changeGameMode(GameMode.SPECTATOR); - if (!speedrunners.isEmpty()) return; - final var server = newPlayer.getEntityWorld().getServer(); - assert server != null; - for (final ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { - player.changeGameMode(GameMode.SPECTATOR); - hunters.remove(player.getUuid()); - speedrunners.remove(player.getUuid()); - } - state = State.OFF; - TimerAccess.getTimerFromOverworld(server).dds_cancel(); - }); + ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> { + if (state == State.OFF) return; + final var uuid = oldPlayer.getUuid(); + if (hunters.contains(uuid)) { + newPlayer.giveItemStack(new ItemStack(Items.COMPASS)); + return; + } + speedrunners.remove(uuid); + newPlayer.changeGameMode(GameMode.SPECTATOR); + if (!speedrunners.isEmpty()) return; + final var server = newPlayer.getEntityWorld().getServer(); + assert server != null; + for (final ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) { + player.changeGameMode(GameMode.SPECTATOR); + hunters.remove(player.getUuid()); + speedrunners.remove(player.getUuid()); + } + state = State.OFF; + TimerAccess.getTimerFromOverworld(server).dds_cancel(); + }); - ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> { - if (!(entity instanceof PiglinBruteEntity)) return; - EntityType.PIGLIN.spawn(world, entity.getBlockPos(), SpawnReason.MOB_SUMMONED); - entity.discard(); - }); - } + ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> { + if (!(entity instanceof PiglinBruteEntity)) return; + EntityType.PIGLIN.spawn(world, entity.getBlockPos(), SpawnReason.MOB_SUMMONED); + entity.discard(); + }); + } - private void setTimer(PlayerManager pm) { - TimerAccess.getTimerFromOverworld(pm.getServer()).dds_runTask(new TickTask(() -> { - for (final UUID uuid : hunters) { - final ServerPlayerEntity hunter = pm.getPlayer(uuid); - if (hunter == null) continue; - final ServerPlayerEntity tracked = pm.getPlayer(trackedMap.get(uuid)); - if (tracked == null) continue; - updateCompass(hunter, tracked); - } - }, Config.secondsBeforeRelease * 20L, Config.updateCompassEach * 20L)); - } + private void setTimer(PlayerManager pm) { + TimerAccess.getTimerFromOverworld(pm.getServer()).dds_runTask(new TickTask(() -> { + for (final UUID uuid : hunters) { + final ServerPlayerEntity hunter = pm.getPlayer(uuid); + if (hunter == null) continue; + final ServerPlayerEntity tracked = pm.getPlayer(trackedMap.get(uuid)); + if (tracked == null) continue; + updateCompass(hunter, tracked); + } + }, Config.secondsBeforeRelease * 20L, Config.updateCompassEach * 20L)); + } - private void updateCompass(ServerPlayerEntity player, ServerPlayerEntity tracked) { - final var trackerCpnt = new LodestoneTrackerComponent(Optional.of(GlobalPos.create(tracked.getEntityWorld().getRegistryKey(), tracked.getBlockPos())), true); - LOGGER.info(tracked.getEntityWorld().getRegistryKey().toString()); - LOGGER.info(tracked.getBlockPos().toString()); - LOGGER.info(trackerCpnt.toString()); - ItemStack is = null; - int slot = PlayerInventory.NOT_FOUND; - final var inv = player.getInventory(); - if (inv.getSelectedStack().isOf(Items.COMPASS)) { - is = inv.getSelectedStack(); - slot = inv.getSlotWithStack(is); - } else if (inv.getStack(PlayerInventory.OFF_HAND_SLOT).isOf(Items.COMPASS)) { - is = inv.getStack(PlayerInventory.OFF_HAND_SLOT); - slot = PlayerInventory.OFF_HAND_SLOT; - } else { - for (int i = 0; i < PlayerInventory.MAIN_SIZE && is == null; i++) { - final var stack = inv.getStack(i); - if (stack.isOf(Items.COMPASS)) { - is = stack; - slot = i; - } - } - } - if (is == null) { - LOGGER.warn("Compass item is null"); - is = new ItemStack(Items.COMPASS); - } - is.set(DataComponentTypes.LODESTONE_TRACKER, trackerCpnt); - if (slot == PlayerInventory.NOT_FOUND) { - player.giveItemStack(is); - return; - } - inv.setStack(slot, is); - } + private void updateCompass(ServerPlayerEntity player, ServerPlayerEntity tracked) { + final var trackerCpnt = new LodestoneTrackerComponent(Optional.of(GlobalPos.create(tracked.getEntityWorld().getRegistryKey(), tracked.getBlockPos())), true); + LOGGER.info(tracked.getEntityWorld().getRegistryKey().toString()); + LOGGER.info(tracked.getBlockPos().toString()); + LOGGER.info(trackerCpnt.toString()); + ItemStack is = null; + int slot = PlayerInventory.NOT_FOUND; + final var inv = player.getInventory(); + if (inv.getSelectedStack().isOf(Items.COMPASS)) { + is = inv.getSelectedStack(); + slot = inv.getSlotWithStack(is); + } else if (inv.getStack(PlayerInventory.OFF_HAND_SLOT).isOf(Items.COMPASS)) { + is = inv.getStack(PlayerInventory.OFF_HAND_SLOT); + slot = PlayerInventory.OFF_HAND_SLOT; + } else { + for (int i = 0; i < PlayerInventory.MAIN_SIZE && is == null; i++) { + final var stack = inv.getStack(i); + if (stack.isOf(Items.COMPASS)) { + is = stack; + slot = i; + } + } + } + if (is == null) { + LOGGER.warn("Compass item is null"); + is = new ItemStack(Items.COMPASS); + } + is.set(DataComponentTypes.LODESTONE_TRACKER, trackerCpnt); + if (slot == PlayerInventory.NOT_FOUND) { + player.giveItemStack(is); + return; + } + inv.setStack(slot, is); + } - private enum State { - ON, OFF - } + private enum State { + ON, OFF + } } \ No newline at end of file diff --git a/src/main/java/world/anhgelus/manhunt/mixins/Tracker.java b/src/main/java/world/anhgelus/manhunt/mixins/Tracker.java index eaaa336..0155652 100644 --- a/src/main/java/world/anhgelus/manhunt/mixins/Tracker.java +++ b/src/main/java/world/anhgelus/manhunt/mixins/Tracker.java @@ -9,8 +9,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LodestoneTrackerComponent.class) public class Tracker { - @Inject(method = "forWorld", at = @At("HEAD"), cancellable = true) - public void forWorld(ServerWorld world, CallbackInfoReturnable cir) { - cir.setReturnValue((LodestoneTrackerComponent) (Object) this); - } + @Inject(method = "forWorld", at = @At("HEAD"), cancellable = true) + public void forWorld(ServerWorld world, CallbackInfoReturnable cir) { + cir.setReturnValue((LodestoneTrackerComponent) (Object) this); + } } diff --git a/src/main/java/world/anhgelus/manhunt/mixins/WorldTimerAccess.java b/src/main/java/world/anhgelus/manhunt/mixins/WorldTimerAccess.java index b61a204..4d390e1 100644 --- a/src/main/java/world/anhgelus/manhunt/mixins/WorldTimerAccess.java +++ b/src/main/java/world/anhgelus/manhunt/mixins/WorldTimerAccess.java @@ -14,32 +14,32 @@ import java.util.function.BooleanSupplier; @Mixin(ServerWorld.class) public class WorldTimerAccess implements TimerAccess { - @Unique - private final List tasks = new ArrayList<>(); - - @Unique - private final List tasksToAdd = new ArrayList<>(); - - @Inject(method = "tick", at = @At("TAIL")) - private void onTick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { - tasks.stream().filter(TickTask::isRunning).forEach(TickTask::tick); - tasks.addAll(tasksToAdd); - tasksToAdd.clear(); - } - - @Override - public void dds_runTask(TimerAccess.TickTask task) { - tasksToAdd.add(task); - } - - @Override - public void dds_cancel() { - tasks.stream().filter(TickTask::isRunning).forEach(TickTask::cancel); - tasks.clear(); - } - - @Override - public List dds_getTasks() { - return tasks.stream().filter(TickTask::isRunning).toList(); - } + @Unique + private final List tasks = new ArrayList<>(); + + @Unique + private final List tasksToAdd = new ArrayList<>(); + + @Inject(method = "tick", at = @At("TAIL")) + private void onTick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) { + tasks.stream().filter(TickTask::isRunning).forEach(TickTask::tick); + tasks.addAll(tasksToAdd); + tasksToAdd.clear(); + } + + @Override + public void dds_runTask(TimerAccess.TickTask task) { + tasksToAdd.add(task); + } + + @Override + public void dds_cancel() { + tasks.stream().filter(TickTask::isRunning).forEach(TickTask::cancel); + tasks.clear(); + } + + @Override + public List dds_getTasks() { + return tasks.stream().filter(TickTask::isRunning).toList(); + } } \ No newline at end of file diff --git a/src/main/java/world/anhgelus/manhunt/timer/TickTask.java b/src/main/java/world/anhgelus/manhunt/timer/TickTask.java index 5449166..4d9a1a5 100644 --- a/src/main/java/world/anhgelus/manhunt/timer/TickTask.java +++ b/src/main/java/world/anhgelus/manhunt/timer/TickTask.java @@ -4,69 +4,69 @@ package world.anhgelus.manhunt.timer; * Represents a complete task called each tick */ public class TickTask implements TimerAccess.TickTask { - public final long ticksDelay; - public final long ticksRepeat; - public final boolean repeating; - public final TimerAccess.Task task; - private boolean cancelled = false; - private long currentTicking; + public final long ticksDelay; + public final long ticksRepeat; + public final boolean repeating; + public final TimerAccess.Task task; + private boolean cancelled = false; + private long currentTicking; - /** - * Create a new repeating TickTask - * - * @param task Task to run after the delay or the repeat time - * @param ticksDelay Delay before the first task's run - * @param ticksRepeat Repeat each tick (if the repeat is 0, it will repeat each tick, if it is below 0, it will not repeat) - * @throws IllegalArgumentException if ticksDelay is below 0 - */ - public TickTask(TimerAccess.Task task, long ticksDelay, long ticksRepeat) { - if (ticksDelay < 0) throw new IllegalArgumentException("Ticks delay must be non-negative"); - this.ticksDelay = ticksDelay; - this.ticksRepeat = ticksRepeat; - this.task = task; - repeating = ticksRepeat >= 0; - currentTicking = ticksDelay; - } + /** + * Create a new repeating TickTask + * + * @param task Task to run after the delay or the repeat time + * @param ticksDelay Delay before the first task's run + * @param ticksRepeat Repeat each tick (if the repeat is 0, it will repeat each tick, if it is below 0, it will not repeat) + * @throws IllegalArgumentException if ticksDelay is below 0 + */ + public TickTask(TimerAccess.Task task, long ticksDelay, long ticksRepeat) { + if (ticksDelay < 0) throw new IllegalArgumentException("Ticks delay must be non-negative"); + this.ticksDelay = ticksDelay; + this.ticksRepeat = ticksRepeat; + this.task = task; + repeating = ticksRepeat >= 0; + currentTicking = ticksDelay; + } - /** - * Create a new delayed TickTask - * - * @param task Task to run after the delay or the repeat time - * @param ticksDelay Delay before the first task's run - * @throws IllegalArgumentException if ticksDelay or if ticksRepeat is below 0 - */ - public TickTask(TimerAccess.Task task, long ticksDelay) { - if (ticksDelay < 0) throw new IllegalArgumentException("Ticks delay must be non-negative"); - this.ticksDelay = ticksDelay; - this.ticksRepeat = -1; - this.task = task; - repeating = false; - currentTicking = ticksDelay; - } + /** + * Create a new delayed TickTask + * + * @param task Task to run after the delay or the repeat time + * @param ticksDelay Delay before the first task's run + * @throws IllegalArgumentException if ticksDelay or if ticksRepeat is below 0 + */ + public TickTask(TimerAccess.Task task, long ticksDelay) { + if (ticksDelay < 0) throw new IllegalArgumentException("Ticks delay must be non-negative"); + this.ticksDelay = ticksDelay; + this.ticksRepeat = -1; + this.task = task; + repeating = false; + currentTicking = ticksDelay; + } - public void tick() { - if (--currentTicking > 0) return; - task.run(); - if (repeating) { - currentTicking = ticksRepeat; - } else { - cancel(); - } - } + public void tick() { + if (--currentTicking > 0) return; + task.run(); + if (repeating) { + currentTicking = ticksRepeat; + } else { + cancel(); + } + } - public long cancel() { - if (cancelled) throw new IllegalStateException("Task already cancelled"); - cancelled = true; - return currentTicking; - } + public long cancel() { + if (cancelled) throw new IllegalStateException("Task already cancelled"); + cancelled = true; + return currentTicking; + } - public boolean isRunning() { - return !cancelled; - } + public boolean isRunning() { + return !cancelled; + } - @Override - public long getTickingBeforeRun() { - if (cancelled) return -1; - return currentTicking; - } + @Override + public long getTickingBeforeRun() { + if (cancelled) return -1; + return currentTicking; + } } \ No newline at end of file diff --git a/src/main/java/world/anhgelus/manhunt/timer/TimerAccess.java b/src/main/java/world/anhgelus/manhunt/timer/TimerAccess.java index f9ed08e..3307167 100644 --- a/src/main/java/world/anhgelus/manhunt/timer/TimerAccess.java +++ b/src/main/java/world/anhgelus/manhunt/timer/TimerAccess.java @@ -5,60 +5,60 @@ import net.minecraft.server.MinecraftServer; import java.util.List; public interface TimerAccess { - /** - * Get the timer linked to the overworld - * - * @param server Current server - * @return TimerAccess linked to the overworld - */ - static TimerAccess getTimerFromOverworld(MinecraftServer server) { - final var timer = (TimerAccess) server.getOverworld(); - if (timer == null) - throw new NullPointerException("Impossible to get TimerAccess from the overworld (it is null)"); - return timer; - } + /** + * Get the timer linked to the overworld + * + * @param server Current server + * @return TimerAccess linked to the overworld + */ + static TimerAccess getTimerFromOverworld(MinecraftServer server) { + final var timer = (TimerAccess) server.getOverworld(); + if (timer == null) + throw new NullPointerException("Impossible to get TimerAccess from the overworld (it is null)"); + return timer; + } - /** - * Run a task (called each tick ticked) - * - * @param task Task to run - */ - void dds_runTask(TimerAccess.TickTask task); + /** + * Run a task (called each tick ticked) + * + * @param task Task to run + */ + void dds_runTask(TimerAccess.TickTask task); - void dds_cancel(); + void dds_cancel(); - /** - * @return All non-cancelled tasks - */ - List dds_getTasks(); + /** + * @return All non-cancelled tasks + */ + List dds_getTasks(); - interface TickTask { - /** - * Tick the task - */ - void tick(); + interface TickTask { + /** + * Tick the task + */ + void tick(); - /** - * Cancel the task - * - * @return the remaining ticks before the run of the Task - * @throws IllegalStateException if the task is already cancelled - */ - long cancel(); + /** + * Cancel the task + * + * @return the remaining ticks before the run of the Task + * @throws IllegalStateException if the task is already cancelled + */ + long cancel(); - boolean isRunning(); + boolean isRunning(); - /** - * @return the number of ticks before run of the task (if the task is cancelled, returns -1) - */ - long getTickingBeforeRun(); - } + /** + * @return the number of ticks before run of the task (if the task is cancelled, returns -1) + */ + long getTickingBeforeRun(); + } - /** - * Represents a task to run after ticking - */ - @FunctionalInterface - interface Task { - void run(); - } + /** + * Represents a task to run after ticking + */ + @FunctionalInterface + interface Task { + void run(); + } } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/loot_table/gameplay/piglin_bartering.json b/src/main/resources/data/minecraft/loot_table/gameplay/piglin_bartering.json index 61599ab..2f711bc 100644 --- a/src/main/resources/data/minecraft/loot_table/gameplay/piglin_bartering.json +++ b/src/main/resources/data/minecraft/loot_table/gameplay/piglin_bartering.json @@ -1,254 +1,254 @@ { - "type": "minecraft:barter", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "minecraft:book", - "weight": 5, - "functions": [ - { - "function": "minecraft:enchant_randomly", - "options": "minecraft:soul_speed" - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:iron_boots", - "weight": 8, - "functions": [ - { - "function": "minecraft:enchant_randomly", - "options": "minecraft:soul_speed" - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:potion", - "weight": 10, - "functions": [ - { - "function": "minecraft:set_potion", - "id": "minecraft:fire_resistance" - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:splash_potion", - "weight": 10, - "functions": [ - { - "function": "minecraft:set_potion", - "id": "minecraft:fire_resistance" - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:iron_nugget", - "weight": 10, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 9, - "max": 36 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:dried_ghast", - "weight": 10, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 9, - "max": 36 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:quartz", - "weight": 20, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 8, - "max": 16 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:glowstone_dust", - "weight": 20, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 5, - "max": 12 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:magma_cream", - "weight": 20, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 2, - "max": 6 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:ender_pearl", - "weight": 20, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 4, - "max": 8 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:string", - "weight": 20, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 8, - "max": 24 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:fire_charge", - "weight": 40, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 1, - "max": 5 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:gravel", - "weight": 40, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 8, - "max": 16 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:leather", - "weight": 40, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 4, - "max": 10 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:nether_brick", - "weight": 40, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 4, - "max": 16 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:obsidian", - "weight": 40 - }, - { - "type": "minecraft:item", - "name": "minecraft:crying_obsidian", - "weight": 40, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 1, - "max": 3 - } - } - ] - }, - { - "type": "minecraft:item", - "name": "minecraft:soul_sand", - "weight": 40, - "functions": [ - { - "function": "minecraft:set_count", - "count": { - "type": "minecraft:uniform", - "min": 4, - "max": 16 - } - } - ] - } - ] - } - ] + "type": "minecraft:barter", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "minecraft:book", + "weight": 5, + "functions": [ + { + "function": "minecraft:enchant_randomly", + "options": "minecraft:soul_speed" + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:iron_boots", + "weight": 8, + "functions": [ + { + "function": "minecraft:enchant_randomly", + "options": "minecraft:soul_speed" + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:potion", + "weight": 10, + "functions": [ + { + "function": "minecraft:set_potion", + "id": "minecraft:fire_resistance" + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:splash_potion", + "weight": 10, + "functions": [ + { + "function": "minecraft:set_potion", + "id": "minecraft:fire_resistance" + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:iron_nugget", + "weight": 10, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 9, + "max": 36 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:dried_ghast", + "weight": 10, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 9, + "max": 36 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:quartz", + "weight": 20, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 8, + "max": 16 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:glowstone_dust", + "weight": 20, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 5, + "max": 12 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:magma_cream", + "weight": 20, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 2, + "max": 6 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:ender_pearl", + "weight": 20, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 4, + "max": 8 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:string", + "weight": 20, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 8, + "max": 24 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:fire_charge", + "weight": 40, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 1, + "max": 5 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:gravel", + "weight": 40, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 8, + "max": 16 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:leather", + "weight": 40, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 4, + "max": 10 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:nether_brick", + "weight": 40, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 4, + "max": 16 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:obsidian", + "weight": 40 + }, + { + "type": "minecraft:item", + "name": "minecraft:crying_obsidian", + "weight": 40, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 1, + "max": 3 + } + } + ] + }, + { + "type": "minecraft:item", + "name": "minecraft:soul_sand", + "weight": 40, + "functions": [ + { + "function": "minecraft:set_count", + "count": { + "type": "minecraft:uniform", + "min": 4, + "max": 16 + } + } + ] + } + ] + } + ] } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index abbd844..a84bf8c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,31 +1,31 @@ { - "schemaVersion": 1, - "id": "manhunt", - "version": "${version}", - "name": "Manhunt", - "description": "Best Manhunt Minecraft mod.", - "authors": [ - "Anhgelus Morhtuuzh" - ], - "contact": { - "sources": "https://github.com/anhgelus/manhunt-mod", - "issues": "https://github.com/anhgelus/manhunt-mod/issues", - "homepage": "https://modrinth.com/mod/manhunt-remastered" - }, - "license": "AGPL-3.0", - "icon": "assets/manhunt/icon.png", - "environment": "*", - "entrypoints": { - "main": [ - "world.anhgelus.manhunt.Manhunt" - ] - }, - "mixins": [ - "manhunt.mixins.json" - ], - "depends": { - "fabricloader": ">=${loader_version}", - "fabric-api": "*", - "minecraft": "${minecraft_version}" - } + "schemaVersion": 1, + "id": "manhunt", + "version": "${version}", + "name": "Manhunt", + "description": "Best Manhunt Minecraft mod.", + "authors": [ + "Anhgelus Morhtuuzh" + ], + "contact": { + "sources": "https://github.com/anhgelus/manhunt-mod", + "issues": "https://github.com/anhgelus/manhunt-mod/issues", + "homepage": "https://modrinth.com/mod/manhunt-remastered" + }, + "license": "AGPL-3.0", + "icon": "assets/manhunt/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "world.anhgelus.manhunt.Manhunt" + ] + }, + "mixins": [ + "manhunt.mixins.json" + ], + "depends": { + "fabricloader": ">=${loader_version}", + "fabric-api": "*", + "minecraft": "${minecraft_version}" + } } \ No newline at end of file diff --git a/src/main/resources/manhunt.mixins.json b/src/main/resources/manhunt.mixins.json index 6613627..34eab5f 100644 --- a/src/main/resources/manhunt.mixins.json +++ b/src/main/resources/manhunt.mixins.json @@ -1,12 +1,12 @@ { - "required": true, - "package": "world.anhgelus.manhunt.mixins", - "compatibilityLevel": "JAVA_21", - "mixins": [ - "Tracker", - "WorldTimerAccess" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "package": "world.anhgelus.manhunt.mixins", + "compatibilityLevel": "JAVA_21", + "mixins": [ + "Tracker", + "WorldTimerAccess" + ], + "injectors": { + "defaultRequire": 1 + } } \ No newline at end of file -- cgit v1.2.3