Tenir un trident Impulsion ne releve plus le seuil vanilla ni n'exempte le mouvement. Nouveau core/RiptideSuivi, evenement LivingEntityUseItemEvent.Stop, 104 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lignes
4.5 KiB
Java
116 lignes
4.5 KiB
Java
package com.gastinelgarde;
|
|
|
|
import com.gastinelgarde.core.EtatJoueur;
|
|
import com.gastinelgarde.core.KillauraAngle;
|
|
import com.gastinelgarde.core.Sanction;
|
|
import com.gastinelgarde.core.TraceLigne;
|
|
import com.gastinelgarde.core.Verdict;
|
|
import java.util.List;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.phys.AABB;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.neoforged.bus.api.SubscribeEvent;
|
|
import net.neoforged.neoforge.common.util.FakePlayer;
|
|
import net.neoforged.neoforge.event.entity.living.LivingDamageEvent;
|
|
import net.neoforged.neoforge.event.entity.living.LivingEntityUseItemEvent;
|
|
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
|
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
|
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
|
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
|
import net.neoforged.neoforge.event.tick.ServerTickEvent;
|
|
|
|
/** Collecte des faits côté serveur (D3) : coups, déconnexions, téléportations, reculs, durée des ticks. */
|
|
public final class GardeEvents {
|
|
|
|
private static long debutTickNs;
|
|
|
|
private GardeEvents() { }
|
|
|
|
@SubscribeEvent
|
|
public static void onServerStarting(ServerStartingEvent event) {
|
|
Garde.demarrer();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onServerStopped(ServerStoppedEvent event) {
|
|
Garde.arreter();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onTickPre(ServerTickEvent.Pre event) {
|
|
debutTickNs = System.nanoTime();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onTickPost(ServerTickEvent.Post event) {
|
|
long duree = System.nanoTime() - debutTickNs;
|
|
Garde.noterTickServeur(event.getServer(), duree);
|
|
if (event.getServer().getTickCount() % 20 == 0) Garde.flushTraces();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onAttaque(AttackEntityEvent event) {
|
|
if (!(event.getEntity() instanceof ServerPlayer p) || p instanceof FakePlayer) return;
|
|
if (Garde.estExempteManuellement(p.getUUID())) return;
|
|
|
|
Entity cible = event.getTarget();
|
|
int tick = p.server.getTickCount();
|
|
EtatJoueur etat = Garde.etat(p, true);
|
|
|
|
AABB bb = cible.getBoundingBox();
|
|
Vec3 oeil = p.getEyePosition();
|
|
Vec3 regard = p.getLookAngle();
|
|
double excedent = KillauraAngle.excedentDegres(oeil.x, oeil.y, oeil.z, regard.x, regard.y, regard.z,
|
|
bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ);
|
|
boolean visible = p.hasLineOfSight(cible);
|
|
|
|
List<Verdict> verdicts = Garde.moteur().attaque(p.getUUID(), tick * 50L, etat, excedent, cible.getId(), visible);
|
|
|
|
if (Garde.tracesEnCours()) {
|
|
Garde.tracer(new TraceLigne(tick, p.getGameProfile().getName(), "atk", p.getX(), p.getY(), p.getZ(),
|
|
0, 0, 0, p.onGround(), p.onGround(), TraceLigne.masque(etat), cible.getId(), excedent,
|
|
visible ? null : "non-visible"));
|
|
}
|
|
|
|
Sanction s = Garde.traiter(p, verdicts);
|
|
if (s.ordinal() >= Sanction.SETBACK.ordinal()) {
|
|
event.setCanceled(true); // le « retour en arrière » d'un coup : il est simplement annulé
|
|
if (s == Sanction.EXPULSION) Garde.appliquerSanctionMouvement(p, s, verdicts);
|
|
}
|
|
}
|
|
|
|
/** 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) {
|
|
if (event.getEntity() instanceof ServerPlayer p && !(p instanceof FakePlayer)) {
|
|
Garde.noterRelache(p, event.getItem(), event.getDuration());
|
|
}
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onDegats(LivingDamageEvent.Post event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterRecul(p);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onConnexion(PlayerEvent.PlayerLoggedInEvent event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterTeleport(p);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onDeconnexion(PlayerEvent.PlayerLoggedOutEvent event) {
|
|
Garde.joueurParti(event.getEntity().getUUID());
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onChangementDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterTeleport(p);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onReapparition(PlayerEvent.PlayerRespawnEvent event) {
|
|
if (event.getEntity() instanceof ServerPlayer p) Garde.noterTeleport(p);
|
|
}
|
|
}
|