aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-19 15:20:55 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-19 15:20:55 +0100
commitc4288cbd82e9a2b347d102c1747f0b105e89fee1 (patch)
tree5c16f9f1a4f178bd56ed7cc8fa6b4f46072cb5d5 /src/main
parentdaccaa1e8cfce5c61426d57ee2b5520c54d9794a (diff)
feat(game): replace every mole by infected
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/world/anhgelus/floodhunt/Floodhunt.java8
-rw-r--r--src/main/java/world/anhgelus/floodhunt/config/Config.java4
-rw-r--r--src/main/java/world/anhgelus/floodhunt/game/Game.java55
-rw-r--r--src/main/java/world/anhgelus/floodhunt/mixin/WorldTimerAccess.java6
-rw-r--r--src/main/java/world/anhgelus/floodhunt/timer/TimerAccess.java10
5 files changed, 40 insertions, 43 deletions
diff --git a/src/main/java/world/anhgelus/floodhunt/Floodhunt.java b/src/main/java/world/anhgelus/floodhunt/Floodhunt.java
index 71ba29d..5dcaf6e 100644
--- a/src/main/java/world/anhgelus/floodhunt/Floodhunt.java
+++ b/src/main/java/world/anhgelus/floodhunt/Floodhunt.java
@@ -137,7 +137,7 @@ public class Floodhunt implements ModInitializer {
final var player = source.getPlayer();
assert player != null;
- if (game.isMole(player)) {
+ if (game.isInfected(player)) {
source.sendFeedback(
() -> Text.translatable("commands.floodhunt.role.mole")
.append("\n\n")
@@ -145,13 +145,13 @@ public class Floodhunt implements ModInitializer {
false);
} else if (player.isSpectator()) {
source.sendFeedback(
- () -> Text.translatable("commands.floodhunt.role.survivor.mole_count", game.getMolesCount()),
+ () -> Text.translatable("commands.floodhunt.role.survivor.mole_count", game.getInfectedCount()),
false);
} else {
source.sendFeedback(
() -> Text.translatable("commands.floodhunt.role.survivor")
.append("\n\n")
- .append(Text.translatable("commands.floodhunt.role.survivor.mole_count", game.getMolesCount())),
+ .append(Text.translatable("commands.floodhunt.role.survivor.mole_count", game.getInfectedCount())),
false);
}
@@ -178,7 +178,7 @@ public class Floodhunt implements ModInitializer {
ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> {
if (!(entity instanceof ServerPlayerEntity) || game == null) return;
if (!game.started()) return;
- if (game.wonByMoles()) game.end();
+ if (game.wonByInfected()) game.end();
});
ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> {
diff --git a/src/main/java/world/anhgelus/floodhunt/config/Config.java b/src/main/java/world/anhgelus/floodhunt/config/Config.java
index 4ec87fb..274ea04 100644
--- a/src/main/java/world/anhgelus/floodhunt/config/Config.java
+++ b/src/main/java/world/anhgelus/floodhunt/config/Config.java
@@ -98,11 +98,11 @@ public class Config {
return server.getOverworld().getGameRules().getValue(Floodhunt.GAME_DURATION);
}
- public int getMolePercentage() {
+ public int getFloodPercentage() {
return server.getOverworld().getGameRules().getValue(Floodhunt.MOLE_PERCENTAGE);
}
- public int getMoleCount() {
+ public int getFloodCount() {
return server.getOverworld().getGameRules().getValue(Floodhunt.MOLE_COUNT);
}
diff --git a/src/main/java/world/anhgelus/floodhunt/game/Game.java b/src/main/java/world/anhgelus/floodhunt/game/Game.java
index b395a06..868b145 100644
--- a/src/main/java/world/anhgelus/floodhunt/game/Game.java
+++ b/src/main/java/world/anhgelus/floodhunt/game/Game.java
@@ -28,7 +28,7 @@ public class Game {
public final int defaultTime = Floodhunt.CONFIG.getGameDuration() * 60;
private final MinecraftServer server;
- private final List<UUID> moles = new ArrayList<>();
+ private final Set<UUID> infected = new HashSet<>();
private final TitleFadeS2CPacket timing = new TitleFadeS2CPacket(20, 40, 20);
private int remaining = defaultTime;
private boolean started = false;
@@ -38,18 +38,18 @@ public class Game {
}
public void start() {
- final int n = Floodhunt.CONFIG.getMoleCount() < 0
- ? Math.floorDiv(server.getCurrentPlayerCount(), Math.floorDiv(100, Floodhunt.CONFIG.getMolePercentage()))
- : Floodhunt.CONFIG.getMoleCount();
+ final int n = Floodhunt.CONFIG.getFloodCount() < 0
+ ? Math.floorDiv(server.getCurrentPlayerCount(), Math.floorDiv(100, Floodhunt.CONFIG.getFloodPercentage()))
+ : Floodhunt.CONFIG.getFloodCount();
final var playerManager = server.getPlayerManager();
final var players = new ArrayList<>(playerManager.getPlayerList());
for (int i = 0; i < n && !players.isEmpty(); i++) {
final var r = ThreadLocalRandom.current().nextInt(0, players.size());
- final var mole = players.get(r);
- if (mole == null) throw new IllegalStateException("Mole is null!");
- moles.add(mole.getUuid());
+ final var infect = players.get(r);
+ if (infect == null) throw new IllegalStateException("Mole is null!");
+ infected.add(infect.getUuid());
players.remove(r);
}
@@ -57,7 +57,6 @@ public class Game {
// immutable gamerules
gamerules.setValue(GameRules.SHOW_DEATH_MESSAGES, false, server);
gamerules.setValue(GameRules.ANNOUNCE_ADVANCEMENTS, false, server);
- // gamerules for the start
gamerules.setValue(GameRules.DO_IMMEDIATE_RESPAWN, true, server);
final var timer = TimerAccess.getTimerFromOverworld(server);
@@ -65,7 +64,7 @@ public class Game {
final var worldBorder = server.getOverworld().getWorldBorder();
worldBorder.setSize(Floodhunt.CONFIG.getInitialWorldSize());
if (Floodhunt.CONFIG.getBorderShrinkingStartingTimeOffset() < Floodhunt.CONFIG.getGameDuration()) {
- timer.dds_runTask(new TickTask(() -> worldBorder.interpolateSize(
+ timer.floodhunt_runTask(new TickTask(() -> worldBorder.interpolateSize(
Floodhunt.CONFIG.getInitialWorldSize(),
Floodhunt.CONFIG.getFinalWorldSize(),
(Floodhunt.CONFIG.getGameDuration() - Floodhunt.CONFIG.getBorderShrinkingStartingTimeOffset()) * 60 * 20L,
@@ -85,10 +84,10 @@ public class Game {
server.setDefaultGameMode(GameMode.SPECTATOR);
- timer.dds_runTask(new TickTask(() -> {
+ timer.floodhunt_runTask(new TickTask(() -> {
playerManager.getPlayerList().forEach(p -> {
p.networkHandler.sendPacket(timing);
- if (moles.contains(p.getUuid())) {
+ if (infected.contains(p.getUuid())) {
p.networkHandler.sendPacket(new TitleS2CPacket(Text.translatable("floodhunt.game.start.mole.title")));
p.networkHandler.sendPacket(new SubtitleS2CPacket(Text.translatable("floodhunt.game.start.mole.subtitle")));
} else {
@@ -100,13 +99,11 @@ public class Game {
p.getHungerManager().setFoodLevel(20);
p.getHungerManager().setSaturationLevel(5.0f);
});
- // reset gamerules after the start
- gamerules.setValue(GameRules.DO_IMMEDIATE_RESPAWN, false, server);
// reset time and weather
server.getOverworld().setTimeOfDay(0);
server.getOverworld().resetWeather();
changeState(true);
- timer.dds_runTask(new TickTask(() -> {
+ timer.floodhunt_runTask(new TickTask(() -> {
remaining--;
playerManager.getPlayerList().forEach(player -> {
if (Floodhunt.timerVisibility.getOrDefault(player.getUuid(), true)) {
@@ -126,7 +123,7 @@ public class Game {
public void end() {
final var timer = TimerAccess.getTimerFromOverworld(server);
- timer.dds_cancel();
+ timer.floodhunt_cancel();
final var worldBorder = server.getOverworld().getWorldBorder();
// Stops the border shrinking.
@@ -140,9 +137,9 @@ public class Game {
p.networkHandler.sendPacket(winnerSuspense);
p.changeGameMode(GameMode.CREATIVE);
});
- timer.dds_runTask(new TickTask(() -> {
+ timer.floodhunt_runTask(new TickTask(() -> {
TitleS2CPacket winner;
- if (wonByMoles()) {
+ if (wonByInfected()) {
winner = new TitleS2CPacket(Text.translatable("floodhunt.game.end.winners.moles.title"));
} else {
winner = new TitleS2CPacket(Text.translatable("floodhunt.game.end.winners.survivors.title"));
@@ -150,7 +147,7 @@ public class Game {
pm.sendToAll(new SubtitleS2CPacket(Text.translatable("floodhunt.game.end.winners.subtitle", getMolesAsString())));
pm.sendToAll(winner);
pm.sendToAll(timing);
- moles.clear();
+ infected.clear();
}, 4 * 20));
}
@@ -158,37 +155,37 @@ public class Game {
return Text.of("§c" + TimeUtils.generateShortString(remaining));
}
- private Stream<ServerPlayerEntity> getMoles() {
- return moles.stream()
+ private Stream<ServerPlayerEntity> getInfected() {
+ return infected.stream()
.map(uuid -> server.getPlayerManager().getPlayer(uuid))
.filter(Objects::nonNull)
.filter(p -> !p.isSpectator() && !p.isCreative());
}
- public int getMolesCount() {
- return getMoles().toArray().length;
+ public int getInfectedCount() {
+ return getInfected().toArray().length;
}
public String getMolesAsString() {
- return getMoles().map(PlayerEntity::getDisplayName)
+ return getInfected().map(PlayerEntity::getDisplayName)
.filter(Objects::nonNull)
.map(Object::toString)
.collect(Collectors.joining(", "));
}
- public boolean isMole(ServerPlayerEntity player) {
- return moles.contains(player.getUuid());
+ public boolean isInfected(ServerPlayerEntity player) {
+ return infected.contains(player.getUuid());
}
- public boolean wonByMoles() {
- final var moles = getMoles().map(PlayerEntity::getUuid).toList();
- return !moles.isEmpty() && new HashSet<>(moles).containsAll(
+ public boolean wonByInfected() {
+ final var moles = getInfected().map(PlayerEntity::getUuid).collect(Collectors.toSet());
+ return !moles.isEmpty() && moles.containsAll(
server.getPlayerManager()
.getPlayerList()
.stream()
.filter(p -> !p.isSpectator() && !p.isCreative())
.map(Entity::getUuid)
- .toList()
+ .collect(Collectors.toSet())
);
}
diff --git a/src/main/java/world/anhgelus/floodhunt/mixin/WorldTimerAccess.java b/src/main/java/world/anhgelus/floodhunt/mixin/WorldTimerAccess.java
index 3b7d7fb..27ba086 100644
--- a/src/main/java/world/anhgelus/floodhunt/mixin/WorldTimerAccess.java
+++ b/src/main/java/world/anhgelus/floodhunt/mixin/WorldTimerAccess.java
@@ -28,18 +28,18 @@ public class WorldTimerAccess implements TimerAccess {
}
@Override
- public void dds_runTask(TimerAccess.TickTask task) {
+ public void floodhunt_runTask(TimerAccess.TickTask task) {
tasksToAdd.add(task);
}
@Override
- public void dds_cancel() {
+ public void floodhunt_cancel() {
tasks.stream().filter(TickTask::isRunning).forEach(TickTask::cancel);
tasks.clear();
}
@Override
- public List<TickTask> dds_getTasks() {
+ public List<TickTask> floodhunt_getTasks() {
return tasks.stream().filter(TickTask::isRunning).toList();
}
}
diff --git a/src/main/java/world/anhgelus/floodhunt/timer/TimerAccess.java b/src/main/java/world/anhgelus/floodhunt/timer/TimerAccess.java
index 714ee59..52273b0 100644
--- a/src/main/java/world/anhgelus/floodhunt/timer/TimerAccess.java
+++ b/src/main/java/world/anhgelus/floodhunt/timer/TimerAccess.java
@@ -24,14 +24,14 @@ public interface TimerAccess {
*
* @param task Task to run
*/
- void dds_runTask(TimerAccess.TickTask task);
+ void floodhunt_runTask(TimerAccess.TickTask task);
- void dds_cancel();
+ void floodhunt_cancel();
/**
* @return All non-cancelled tasks
*/
- List<TickTask> dds_getTasks();
+ List<TickTask> floodhunt_getTasks();
interface TickTask {
/**
@@ -43,14 +43,14 @@ public interface TimerAccess {
* Cancel the task
*
* @return the remaining ticks before the run of the Task
- * @throws IllegalStateException if the task is already cancelled
+ * @throws IllegalStateException if the task is already canceled
*/
long cancel();
boolean isRunning();
/**
- * @return the number of ticks before run of the task (if the task is cancelled, returns -1)
+ * @return the number of ticks before run of the task (if the task is canceled, returns -1)
*/
long getTickingBeforeRun();
}