GastinelGarde 0.2.0 : phase 2 (no-fall corrige en enforce, vitesse horizontale, vol vertical), 90 tests
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
b7e57250ff
révision
a70809df6c
15 fichiers modifiés
+750
-11
Aucun fichier ne correspond à votre recherche
@@ -1,7 +1,10 @@
|
||||
package com.gastinelgarde;
|
||||
|
||||
import com.gastinelgarde.core.Controle;
|
||||
import com.gastinelgarde.core.EtatJoueur;
|
||||
import com.gastinelgarde.core.EtatMouvement;
|
||||
import com.gastinelgarde.core.GardeConfig;
|
||||
import com.gastinelgarde.core.Mode;
|
||||
import com.gastinelgarde.core.Moteur;
|
||||
import com.gastinelgarde.core.Sanction;
|
||||
import com.gastinelgarde.core.Suivi;
|
||||
@@ -21,7 +24,14 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
@@ -50,6 +60,12 @@ public final class Garde {
|
||||
long exemptJusquaMs = 0;
|
||||
double dernierX, dernierY, dernierZ;
|
||||
boolean aDernierePosition;
|
||||
// Mouvement (phase 2)
|
||||
int mouvementTick = Integer.MIN_VALUE;
|
||||
double mouvementX, mouvementY, mouvementZ;
|
||||
// Cache de la détection de contraption (la requête d'entités coûte plus que le reste)
|
||||
int contraptionTick = Integer.MIN_VALUE;
|
||||
boolean contraptionProche;
|
||||
}
|
||||
|
||||
private static final GardeConfig CONFIG = new GardeConfig();
|
||||
@@ -194,7 +210,7 @@ public final class Garde {
|
||||
.levitation(p.hasEffect(MobEffects.LEVITATION))
|
||||
.chuteLente(p.hasEffect(MobEffects.SLOW_FALLING))
|
||||
.enVehicule(p.isPassenger())
|
||||
.pocheContraption(chercherContraption && pocheContraption(p))
|
||||
.pocheContraption(chercherContraption && pocheContraptionEnCache(p, m, tick))
|
||||
.utiliseObjet(mange)
|
||||
.ticksDepuisTeleport(depuis(tick, m.teleportTick))
|
||||
.ticksDepuisRecul(depuis(tick, m.reculTick))
|
||||
@@ -213,6 +229,15 @@ public final class Garde {
|
||||
return stack.is(Items.TRIDENT) && EnchantmentHelper.getTridentSpinAttackStrength(stack, joueur) > 0.0F;
|
||||
}
|
||||
|
||||
/** La détection est refaite au plus toutes les 10 ticks par joueur. */
|
||||
private static boolean pocheContraptionEnCache(Player p, Marques m, int tick) {
|
||||
if (m.contraptionTick == Integer.MIN_VALUE || tick - m.contraptionTick >= 10 || tick < m.contraptionTick) {
|
||||
m.contraptionProche = pocheContraption(p);
|
||||
m.contraptionTick = tick;
|
||||
}
|
||||
return m.contraptionProche;
|
||||
}
|
||||
|
||||
/** Une entité de contraption (Create, Aeronautics…) est-elle toute proche ? Détection par nom de classe. */
|
||||
private static boolean pocheContraption(Player p) {
|
||||
int dist = GardeSpec.distanceContraption();
|
||||
@@ -238,11 +263,15 @@ public final class Garde {
|
||||
public static Sanction traiter(ServerPlayer p, List<Verdict> verdicts) {
|
||||
if (verdicts.isEmpty()) return Sanction.AUCUNE;
|
||||
marques(p.getUUID()).dernierVerdictTick = p.server.getTickCount();
|
||||
long maintenant = System.currentTimeMillis();
|
||||
Suivi suivi = MOTEUR.suivi(p.getUUID());
|
||||
for (Verdict v : verdicts) {
|
||||
String ligne = String.format("%s %s mode=%s vl=%.1f (+%.1f) palier=%s applique=%s %s exemptions=%s",
|
||||
p.getGameProfile().getName(), v.controle().id(), v.mode(), v.vl(), v.points(),
|
||||
v.palier(), v.applicable(), v.details(), v.exemptions());
|
||||
ecrireJournal(ligne);
|
||||
if (suivi.autoriserJournal(v.controle(), maintenant, 1000)) { // au plus une ligne par seconde et par contrôle
|
||||
String ligne = String.format("%s %s mode=%s vl=%.1f (+%.1f) palier=%s applique=%s %s exemptions=%s",
|
||||
p.getGameProfile().getName(), v.controle().id(), v.mode(), v.vl(), v.points(),
|
||||
v.palier(), v.applicable(), v.details(), v.exemptions());
|
||||
ecrireJournal(ligne);
|
||||
}
|
||||
if (v.notifier()) alerterOps(p, v);
|
||||
}
|
||||
return Verdict.pire(verdicts);
|
||||
@@ -295,6 +324,25 @@ public final class Garde {
|
||||
public static void apresMouvement(ServerPlayer p) {
|
||||
int tick = p.server.getTickCount();
|
||||
Marques m = marques(p.getUUID());
|
||||
boolean solServeur = auSolServeur(p);
|
||||
|
||||
// Phase 2 : no-fall (divergence), vitesse horizontale, vol.
|
||||
if (mouvementControlesActifs() && !estExempteManuellement(p.getUUID()) && m.mouvementTick != Integer.MIN_VALUE) {
|
||||
double dx = p.getX() - m.mouvementX;
|
||||
double dz = p.getZ() - m.mouvementZ;
|
||||
EtatMouvement em = new EtatMouvement(Math.sqrt(dx * dx + dz * dz), p.getY() - m.mouvementY,
|
||||
tick - m.mouvementTick, p.onGround(), solServeur, p.isSprinting(), p.isShiftKeyDown(),
|
||||
p.isUsingItem(), niveau(p, MobEffects.MOVEMENT_SPEED), niveau(p, MobEffects.MOVEMENT_SLOWDOWN),
|
||||
milieuSpecial(p), frictionAnormale(p));
|
||||
List<Verdict> v = MOTEUR.mouvement(p.getUUID(), tick * 50L, etat(p, true), em);
|
||||
Sanction s = traiter(p, v);
|
||||
if (s.ordinal() >= Sanction.SETBACK.ordinal()) appliquerSanctionMouvement(p, s, v);
|
||||
}
|
||||
m.mouvementTick = tick;
|
||||
m.mouvementX = p.getX();
|
||||
m.mouvementY = p.getY();
|
||||
m.mouvementZ = p.getZ();
|
||||
|
||||
if (m.dernierVerdictTick != tick) {
|
||||
MOTEUR.suivi(p.getUUID()).memoriserPosition(p.getX(), p.getY(), p.getZ(), p.getYRot(), p.getXRot(),
|
||||
p.level().dimension().location().toString());
|
||||
@@ -308,12 +356,53 @@ public final class Garde {
|
||||
m.dernierY = p.getY();
|
||||
m.dernierZ = p.getZ();
|
||||
m.aDernierePosition = true;
|
||||
boolean solServeur = !p.level().noCollision(p, p.getBoundingBox().move(0.0, -0.05, 0.0));
|
||||
tracer(new TraceLigne(tick, p.getGameProfile().getName(), "move", p.getX(), p.getY(), p.getZ(),
|
||||
vx, vy, vz, p.onGround(), solServeur, TraceLigne.masque(etat(p, false)), -1, Double.NaN, null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drapeau « au sol » à donner aux dégâts de chute (appelé par le mixin). En OBSERVE ou hors exemption
|
||||
* inapplicable, c'est celui du client : comportement vanilla.
|
||||
*/
|
||||
public static boolean auSolPourChute(ServerPlayer p, boolean auSolClient) {
|
||||
if (!auSolClient) return false;
|
||||
if (CONFIG.mode(Controle.NO_FALL) != Mode.ENFORCE) return auSolClient;
|
||||
if (estExempteManuellement(p.getUUID())) return auSolClient;
|
||||
return MOTEUR.auSolPourDegatsDeChute(etat(p, true), auSolClient, auSolServeur(p));
|
||||
}
|
||||
|
||||
private static boolean mouvementControlesActifs() {
|
||||
return CONFIG.mode(Controle.NO_FALL) != Mode.OFF || CONFIG.mode(Controle.VITESSE) != Mode.OFF
|
||||
|| CONFIG.mode(Controle.VOL) != Mode.OFF;
|
||||
}
|
||||
|
||||
/** Bloc solide sous la boîte du joueur, vu par le serveur (0,05 bloc de marge). */
|
||||
private static boolean auSolServeur(ServerPlayer p) {
|
||||
return !p.level().noCollision(p, p.getBoundingBox().move(0.0, -0.05, 0.0));
|
||||
}
|
||||
|
||||
private static int niveau(ServerPlayer p, Holder<MobEffect> effet) {
|
||||
MobEffectInstance e = p.getEffect(effet);
|
||||
return e == null ? 0 : e.getAmplifier() + 1;
|
||||
}
|
||||
|
||||
/** Eau, lave, échelle, vol créatif, toile, neige poudreuse, miel, slime, lit : la vitesse et le vol vanilla ne s'appliquent pas. */
|
||||
private static boolean milieuSpecial(ServerPlayer p) {
|
||||
if (p.isInWater() || p.isInLava() || p.onClimbable() || p.isSwimming() || p.getAbilities().flying) return true;
|
||||
BlockPos pos = p.blockPosition();
|
||||
BlockState pied = p.level().getBlockState(pos);
|
||||
BlockState sous = p.level().getBlockState(pos.below());
|
||||
return pied.is(Blocks.COBWEB) || pied.is(Blocks.POWDER_SNOW) || pied.is(Blocks.SWEET_BERRY_BUSH)
|
||||
|| sous.is(Blocks.SLIME_BLOCK) || sous.is(BlockTags.BEDS);
|
||||
}
|
||||
|
||||
/** Glace, slime, âmes, miel : friction ou facteur de vitesse du bloc différents de la normale. */
|
||||
private static boolean frictionAnormale(ServerPlayer p) {
|
||||
BlockState sous = p.level().getBlockState(p.getBlockPosBelowThatAffectsMyMovement());
|
||||
return sous.getBlock().getFriction() != 0.6F || sous.getBlock().getSpeedFactor() != 1.0F;
|
||||
}
|
||||
|
||||
public static void appliquerSanctionMouvement(ServerPlayer p, Sanction s, List<Verdict> verdicts) {
|
||||
String raison = verdicts.isEmpty() ? "anti-triche" : verdicts.get(0).controle().id();
|
||||
if (s == Sanction.EXPULSION) {
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur