Merge pull request #14 from Fretuks/find-and-fix-mod-issues

Fix execution cancellation and carry cleanup
This commit is contained in:
IM23a-spirgif
2026-01-20 09:31:38 +01:00
committed by GitHub
2 changed files with 37 additions and 7 deletions
@@ -89,11 +89,19 @@ public class CarryManager {
} }
for (UUID kid : toDrop) { for (UUID kid : toDrop) {
UUID cid = carrying.get(kid); UUID cid = carrying.get(kid);
if (cid == null) {
carrying.remove(kid);
continue;
}
ServerPlayer carrier = NetworkHandlerHelper.getPlayerByUuid( ServerPlayer carrier = NetworkHandlerHelper.getPlayerByUuid(
net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(), cid); net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(), cid);
ServerPlayer knocked = NetworkHandlerHelper.getPlayerByUuid( ServerPlayer knocked = NetworkHandlerHelper.getPlayerByUuid(
net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(), kid); net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(), kid);
if (carrier != null && knocked != null) stopCarry(knocked, carrier); if (carrier != null && knocked != null) {
stopCarry(knocked, carrier);
} else {
carrying.remove(kid);
}
} }
} }
@@ -124,4 +132,4 @@ public class CarryManager {
public static boolean isBeingCarried(UUID knockedId) { public static boolean isBeingCarried(UUID knockedId) {
return carrying.containsKey(knockedId); return carrying.containsKey(knockedId);
} }
} }
@@ -108,9 +108,12 @@ public class PlayerExecutionHandler {
public static void onLivingHurt(LivingHurtEvent event) { public static void onLivingHurt(LivingHurtEvent event) {
if (!(event.getEntity() instanceof ServerPlayer hurtPlayer)) return; if (!(event.getEntity() instanceof ServerPlayer hurtPlayer)) return;
UUID hurtId = hurtPlayer.getUUID(); UUID hurtId = hurtPlayer.getUUID();
boolean wasExecutor = executionAttempts.values().removeIf(attempt -> attempt.executorUuid.equals(hurtId)); List<UUID> toCancel = executionAttempts.entrySet().stream()
if (wasExecutor) { .filter(entry -> entry.getValue().executorUuid.equals(hurtId))
hurtPlayer.sendSystemMessage(Component.translatable("message.knockedback.execution_interrupted")); .map(Map.Entry::getKey)
.toList();
for (UUID knockedId : toCancel) {
cancelExecution(knockedId);
} }
} }
@@ -147,16 +150,19 @@ public class PlayerExecutionHandler {
public static void onServerTick(TickEvent.ServerTickEvent event) { public static void onServerTick(TickEvent.ServerTickEvent event) {
if (event.phase != TickEvent.Phase.END || !event.side.isServer()) return; if (event.phase != TickEvent.Phase.END || !event.side.isServer()) return;
Map<UUID, PlayerExecutionAttempt> updated = new HashMap<>(); Map<UUID, PlayerExecutionAttempt> updated = new HashMap<>();
List<UUID> toCancel = new ArrayList<>();
List<UUID> toExecute = new ArrayList<>();
for (Map.Entry<UUID, PlayerExecutionAttempt> entry : executionAttempts.entrySet()) { for (Map.Entry<UUID, PlayerExecutionAttempt> entry : executionAttempts.entrySet()) {
UUID knockedId = entry.getKey(); UUID knockedId = entry.getKey();
PlayerExecutionAttempt attempt = entry.getValue(); PlayerExecutionAttempt attempt = entry.getValue();
ServerPlayer knocked = getPlayerByUuid(knockedId); ServerPlayer knocked = getPlayerByUuid(knockedId);
ServerPlayer executor = getPlayerByUuid(attempt.executorUuid); ServerPlayer executor = getPlayerByUuid(attempt.executorUuid);
if (knocked == null || executor == null || !KnockedManager.isKnocked(knocked)) { if (knocked == null || executor == null || !KnockedManager.isKnocked(knocked)) {
toCancel.add(knockedId);
continue; continue;
} }
if (executor.distanceTo(knocked) > EXECUTION_RANGE) { if (executor.distanceTo(knocked) > EXECUTION_RANGE) {
cancelExecution(knockedId); toCancel.add(knockedId);
continue; continue;
} }
attempt.timeLeft--; attempt.timeLeft--;
@@ -169,11 +175,27 @@ public class PlayerExecutionHandler {
new ExecutionProgressPacket(attempt.timeLeft, attempt.executorUuid) new ExecutionProgressPacket(attempt.timeLeft, attempt.executorUuid)
); );
if (attempt.timeLeft <= 0) { if (attempt.timeLeft <= 0) {
executeKnockedPlayer(executor, knocked); toExecute.add(knockedId);
} else { } else {
updated.put(knockedId, attempt); updated.put(knockedId, attempt);
} }
} }
for (UUID knockedId : toCancel) {
cancelExecution(knockedId);
}
for (UUID knockedId : toExecute) {
PlayerExecutionAttempt attempt = executionAttempts.get(knockedId);
if (attempt == null) {
continue;
}
ServerPlayer knocked = getPlayerByUuid(knockedId);
ServerPlayer executor = getPlayerByUuid(attempt.executorUuid);
if (knocked == null || executor == null) {
cancelExecution(knockedId);
continue;
}
executeKnockedPlayer(executor, knocked);
}
executionAttempts.clear(); executionAttempts.clear();
executionAttempts.putAll(updated); executionAttempts.putAll(updated);
} }