From adc326a89774d4bdc8da16488a5d7f2f3e2a9026 Mon Sep 17 00:00:00 2001 From: gastinelt <264859180+gastinelt@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:36:45 +0200 Subject: [PATCH] =?UTF-8?q?P1.13=20:=20diagnostic=20=C2=AB=20Mismatch=20in?= =?UTF-8?q?=20destroy=20block=20pos=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core.ActionsBloc : START / ABORT de casse de bloc (LeftClickBlock, ecoute en LOWEST, meme annule). Un ABORT sans START accepte correspondant donne une ligne DIAGNOSTIC (au plus une toutes les 10 s par joueur), avec le dernier START et s'il a ete annule par un mod. - D'apres ServerPlayerGameMode (sources NeoForge 21.1.234), destroyPos vaut (0,0,0) tant qu'aucun START n'a ete accepte : un START annule par une protection de zone puis un ABORT suffit a produire le message. - Reglage [diagnostic] : actionsBlocIncoherentes (true). Jamais de sanction. - Tests : ActionsBlocP1Test. Co-Authored-By: Claude Sonnet 5.5 --- src/main/java/com/gastinelgarde/Garde.java | 14 +++++ .../java/com/gastinelgarde/GardeEvents.java | 10 ++++ .../java/com/gastinelgarde/GardeSpec.java | 9 +++- .../com/gastinelgarde/core/ActionsBloc.java | 53 +++++++++++++++++++ .../com/gastinelgarde/core/GardeConfig.java | 4 ++ .../java/com/gastinelgarde/core/Suivi.java | 2 + .../gastinelgarde/core/ActionsBlocP1Test.java | 49 +++++++++++++++++ 7 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gastinelgarde/core/ActionsBloc.java create mode 100644 src/test/java/com/gastinelgarde/core/ActionsBlocP1Test.java diff --git a/src/main/java/com/gastinelgarde/Garde.java b/src/main/java/com/gastinelgarde/Garde.java index 14a48f1..73099cd 100644 --- a/src/main/java/com/gastinelgarde/Garde.java +++ b/src/main/java/com/gastinelgarde/Garde.java @@ -410,6 +410,20 @@ public final class Garde { if (s == Sanction.EXPULSION) appliquerSanctionMouvement(p, s, v); return Cablage.sanctionDeMouvement(s); } + /** + * 0.5 (P1.13) : action de casse de bloc reçue (événement LeftClickBlock, vu même annulé). Diagnostic seulement : + * ligne de journal pour un ABORT sans START correspondant (message vanilla « Mismatch in destroy block pos »). + */ + public static void noterActionBloc(ServerPlayer p, boolean start, boolean abort, BlockPos pos, boolean annule) { + if (!CONFIG.diagnosticActionsBloc || !surThreadServeur(p) || MOTEUR.estExpulse(p.getUUID())) return; + com.gastinelgarde.core.ActionsBloc a = MOTEUR.suivi(p.getUUID()).actionsBloc; + if (start) { + a.start(pos.getX(), pos.getY(), pos.getZ(), annule); + } else if (abort) { + String ligne = a.abort(pos.getX(), pos.getY(), pos.getZ(), System.currentTimeMillis()); + if (ligne != null) ecrireJournal("DIAGNOSTIC " + p.getGameProfile().getName() + " casse de bloc : " + ligne); + } + } public static void noterTickServeur(MinecraftServer server, long dureeNs) { double ms = dureeNs / 1_000_000.0; if (ms > 250.0) gelTick = server.getTickCount(); diff --git a/src/main/java/com/gastinelgarde/GardeEvents.java b/src/main/java/com/gastinelgarde/GardeEvents.java index 49f2827..2855179 100644 --- a/src/main/java/com/gastinelgarde/GardeEvents.java +++ b/src/main/java/com/gastinelgarde/GardeEvents.java @@ -124,6 +124,16 @@ public final class GardeEvents { event.setDamageMultiplier(1.0F); } } + /** 0.5 (P1.13) : diagnostic « Mismatch in destroy block pos » (vu après les autres mods, même annulé). */ + @SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true) + public static void onClicGaucheBloc(net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event) { + if (event.getLevel().isClientSide()) return; + if (!(event.getEntity() instanceof ServerPlayer p) || p instanceof FakePlayer) return; + var a = event.getAction(); + Garde.noterActionBloc(p, a == net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.LeftClickBlock.Action.START, + a == net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.LeftClickBlock.Action.ABORT, + event.getPos(), event.isCanceled()); + } /** F04 : seul un trident Impulsion relâché après charge ouvre la tolérance riptide (pas le trident tenu). */ @SubscribeEvent public static void onRelache(LivingEntityUseItemEvent.Stop event) { diff --git a/src/main/java/com/gastinelgarde/GardeSpec.java b/src/main/java/com/gastinelgarde/GardeSpec.java index 85afa88..e1576c0 100644 --- a/src/main/java/com/gastinelgarde/GardeSpec.java +++ b/src/main/java/com/gastinelgarde/GardeSpec.java @@ -22,7 +22,7 @@ public final class GardeSpec { private static final ModConfigSpec.DoubleValue SEUIL_EXPULSION; private static final ModConfigSpec.EnumValue SANCTION_MAX; - private static final ModConfigSpec.BooleanValue JOURNAL_TOUJOURS, SETBACK_SOL; + private static final ModConfigSpec.BooleanValue JOURNAL_TOUJOURS, SETBACK_SOL, DIAG_ACTIONS; private static final ModConfigSpec.IntValue GRACE_CONNEXION, GRACE_APRES_EXPULSION; private static final ModConfigSpec.DoubleValue STEP_HAUTEUR, STEP_MARGE, CRIT_MICRO; private static final ModConfigSpec.IntValue CRIT_SERIE, ANTI_FAIM_TICKS, ELY_DEPLOIEMENTS; @@ -267,6 +267,12 @@ public final class GardeSpec { .defineInRange("antiFaimTicks", 20, 5, 1200); b.pop(); + b.comment("0.5 : diagnostics (journal seulement, jamais de sanction).").push("diagnostic"); + DIAG_ACTIONS = b.comment("Journaliser les ABORT de casse de bloc sans START correspondant (message vanilla « Mismatch in destroy block pos »),", + "au plus une ligne toutes les 10 s par joueur.") + .define("actionsBlocIncoherentes", true); + b.pop(); + b.comment("0.5 : grâces à la connexion (reconnexion en l'air, expulsion récente).").push("graces"); GRACE_CONNEXION = b.comment("Ticks sans contrôle de mouvement ni timer après la connexion (la téléportation de connexion en donne déjà graceTeleportTicks).") .defineInRange("graceConnexionTicks", 100, 0, 1200); @@ -365,6 +371,7 @@ public final class GardeSpec { c.sanctionMax = SANCTION_MAX.get(); c.journalToujoursSanctions = JOURNAL_TOUJOURS.get(); c.journalLignesParSeconde = JOURNAL_LIMITE.get(); + c.diagnosticActionsBloc = DIAG_ACTIONS.get(); c.angleMaxDegres = ANGLE_MAX.get(); c.ciblesMax = CIBLES_MAX.get(); c.fenetreCiblesMs = FENETRE_CIBLES_MS.get(); diff --git a/src/main/java/com/gastinelgarde/core/ActionsBloc.java b/src/main/java/com/gastinelgarde/core/ActionsBloc.java new file mode 100644 index 0000000..f4edf01 --- /dev/null +++ b/src/main/java/com/gastinelgarde/core/ActionsBloc.java @@ -0,0 +1,53 @@ +package com.gastinelgarde.core; + +/** + * 0.5 (P1.13) : diagnostic du message vanilla « Mismatch in destroy block pos: (0,0,0) … ». D'après + * ServerPlayerGameMode.handleBlockBreakAction (sources NeoForge 21.1.234) : {@code destroyPos} vaut (0,0,0) au départ + * et n'est mis à jour qu'à un START_DESTROY_BLOCK accepté (événement LeftClickBlock non annulé, à portée, interaction + * permise, pas créatif, pas de casse instantanée). Un ABORT sur une autre position donne le message. Causes + * possibles : START annulé par un mod (protection de zone), START refusé (trop loin), casse instantanée, ou client + * qui envoie ABORT sans START (FastBreak, Nuker, mod client) [À VÉRIFIER avec ces lignes de journal]. + * + * Aucun contrôle, aucune sanction : une ligne de journal par incohérence, au plus une toutes les 10 s par joueur. + */ +public final class ActionsBloc { + + public static final long DELAI_JOURNAL_MS = 10_000; + + private boolean startVu; + private long startX, startY, startZ; + private boolean startAnnule; + private long dernierJournalMs = Long.MIN_VALUE; + private int incoherences; + + /** START_DESTROY_BLOCK reçu ; {@code annule} : l'événement a été annulé par un mod. */ + public void start(long x, long y, long z, boolean annule) { + startVu = true; + startX = x; + startY = y; + startZ = z; + startAnnule = annule; + } + + /** + * ABORT_DESTROY_BLOCK reçu : texte de diagnostic s'il ne correspond pas au dernier START accepté (null sinon, ou si + * une ligne a déjà été écrite il y a moins de {@link #DELAI_JOURNAL_MS}). + */ + public String abort(long x, long y, long z, long nowMs) { + boolean memePos = startVu && startX == x && startY == y && startZ == z; + if (memePos && !startAnnule) return null; + incoherences++; + if (dernierJournalMs != Long.MIN_VALUE && nowMs - dernierJournalMs < DELAI_JOURNAL_MS && nowMs >= dernierJournalMs) { + return null; + } + dernierJournalMs = nowMs; + String start = !startVu ? "aucun START vu" + : String.format("dernier START (%d,%d,%d)%s", startX, startY, startZ, startAnnule ? " annule par un mod" : ""); + return String.format("ABORT (%d,%d,%d) sans START correspondant : %s, %d incoherence(s) depuis la connexion", + x, y, z, start, incoherences); + } + + public int incoherences() { + return incoherences; + } +} diff --git a/src/main/java/com/gastinelgarde/core/GardeConfig.java b/src/main/java/com/gastinelgarde/core/GardeConfig.java index b15ce08..5d8de32 100644 --- a/src/main/java/com/gastinelgarde/core/GardeConfig.java +++ b/src/main/java/com/gastinelgarde/core/GardeConfig.java @@ -181,6 +181,10 @@ public final class GardeConfig { /** Anti-faim : paquets consécutifs de course au sol déclarée « en l'air » avant infraction (1 s à 20 paquets/s). */ public int antiFaimTicks = 20; + // --- 0.5 (P1.13, section [diagnostic]) : journal seulement, jamais de sanction --- + /** Journaliser les ABORT de casse de bloc sans START correspondant (« Mismatch in destroy block pos »). */ + public boolean diagnosticActionsBloc = true; + // --- Exemptions --- public int graceTeleportTicks = 40; /** 0.5 (P1.2) : grâce de mouvement / timer après la connexion (ticks) ; plus longue après une expulsion récente. */ diff --git a/src/main/java/com/gastinelgarde/core/Suivi.java b/src/main/java/com/gastinelgarde/core/Suivi.java index ee8d95b..e69193d 100644 --- a/src/main/java/com/gastinelgarde/core/Suivi.java +++ b/src/main/java/com/gastinelgarde/core/Suivi.java @@ -67,6 +67,8 @@ public final class Suivi { public final AntiFaim antiFaim = new AntiFaim(); /** 0.5 (P1.6) : déploiements d'élytres répétés. */ public final DeploiementsElytres deploiements = new DeploiementsElytres(); + /** 0.5 (P1.13) : diagnostic des actions de casse de bloc. */ + public final ActionsBloc actionsBloc = new ActionsBloc(); public Suivi(double decroissanceParSeconde) { this(decroissanceParSeconde, new GardeConfig()); diff --git a/src/test/java/com/gastinelgarde/core/ActionsBlocP1Test.java b/src/test/java/com/gastinelgarde/core/ActionsBlocP1Test.java new file mode 100644 index 0000000..a40668c --- /dev/null +++ b/src/test/java/com/gastinelgarde/core/ActionsBlocP1Test.java @@ -0,0 +1,49 @@ +package com.gastinelgarde.core; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** 0.5, P1.13 : automate START / ABORT de casse de bloc (diagnostic « Mismatch in destroy block pos »). */ +class ActionsBlocP1Test { + + @Test + void startPuisAbortMemePositionRien() { + ActionsBloc a = new ActionsBloc(); + a.start(1, 64, 2, false); + assertNull(a.abort(1, 64, 2, 1000)); + assertEquals(0, a.incoherences()); + } + + @Test + void abortSansStartCommeLeMessageVanilla() { + ActionsBloc a = new ActionsBloc(); + String l = a.abort(5, 70, -3, 1000); + assertTrue(l.contains("ABORT (5,70,-3)") && l.contains("aucun START vu"), l); + } + + @Test + void startAnnuleParUnModEstSignale() { + ActionsBloc a = new ActionsBloc(); + a.start(5, 70, -3, true); // protection de zone : destroyPos vanilla pas mis à jour + String l = a.abort(5, 70, -3, 1000); + assertTrue(l.contains("annule par un mod"), l); + } + + @Test + void autrePositionEtLimiteDeJournal() { + ActionsBloc a = new ActionsBloc(); + a.start(0, 64, 0, false); + assertTrue(a.abort(1, 64, 0, 1000) != null); + assertNull(a.abort(2, 64, 0, 5000), "moins de 10 s : compté, pas écrit"); + String l = a.abort(3, 64, 0, 1000 + ActionsBloc.DELAI_JOURNAL_MS); + assertTrue(l.contains("3 incoherence(s)"), l); + } + + @Test + void diagnosticActifParDefaut() { + assertTrue(new GardeConfig().diagnosticActionsBloc); + } +}