aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/world/anhgelus/manhunt/Config.java6
-rw-r--r--src/main/java/world/anhgelus/manhunt/Manhunt.java408
-rw-r--r--src/main/java/world/anhgelus/manhunt/mixins/Tracker.java8
-rw-r--r--src/main/java/world/anhgelus/manhunt/mixins/WorldTimerAccess.java56
-rw-r--r--src/main/java/world/anhgelus/manhunt/timer/TickTask.java118
-rw-r--r--src/main/java/world/anhgelus/manhunt/timer/TimerAccess.java96
-rw-r--r--src/main/resources/data/minecraft/loot_table/gameplay/piglin_bartering.json504
-rw-r--r--src/main/resources/fabric.mod.json58
-rw-r--r--src/main/resources/manhunt.mixins.json20
9 files changed, 638 insertions, 636 deletions
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<UUID> hunters = new HashSet<>();
- private final Set<UUID> speedrunners = new HashSet<>();
- private final Map<UUID, UUID> trackedMap = new HashMap<>();
+ private final Set<UUID> hunters = new HashSet<>();
+ private final Set<UUID> speedrunners = new HashSet<>();
+ private final Map<UUID, UUID> 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<ServerCommandSource> command = literal("manhunt");
+ final LiteralArgumentBuilder<ServerCommandSource> command = literal("manhunt");
- final LiteralArgumentBuilder<ServerCommandSource> track = literal("track");
- track.then(RequiredArgumentBuilder.<ServerCommandSource, EntitySelector>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<ServerCommandSource> team = literal("team");
- final RequiredArgumentBuilder<ServerCommandSource, EntitySelector> teamP = RequiredArgumentBuilder.argument("player", EntityArgumentType.player());
- teamP.then(LiteralArgumentBuilder.<ServerCommandSource>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.<ServerCommandSource>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<ServerCommandSource> 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<ServerCommandSource> track = literal("track");
+ track.then(RequiredArgumentBuilder.<ServerCommandSource, EntitySelector>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<ServerCommandSource> team = literal("team");
+ final RequiredArgumentBuilder<ServerCommandSource, EntitySelector> teamP = RequiredArgumentBuilder.argument("player", EntityArgumentType.player());
+ teamP.then(LiteralArgumentBuilder.<ServerCommandSource>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.<ServerCommandSource>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<ServerCommandSource> 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<ServerCommandSource> 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<ServerCommandSource> 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<LodestoneTrackerComponent> cir) {
- cir.setReturnValue((LodestoneTrackerComponent) (Object) this);
- }
+ @Inject(method = "forWorld", at = @At("HEAD"), cancellable = true)
+ public void forWorld(ServerWorld world, CallbackInfoReturnable<LodestoneTrackerComponent> 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<TimerAccess.TickTask> tasks = new ArrayList<>();
-
- @Unique
- private final List<TimerAccess.TickTask> 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<TickTask> dds_getTasks() {
- return tasks.stream().filter(TickTask::isRunning).toList();
- }
+ @Unique
+ private final List<TimerAccess.TickTask> tasks = new ArrayList<>();
+
+ @Unique
+ private final List<TimerAccess.TickTask> 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<TickTask> 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<TickTask> dds_getTasks();
+ /**
+ * @return All non-cancelled tasks
+ */
+ List<TickTask> 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