Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 11 May 2025 19:45:58 +0200
Subject: [PATCH] Leaf - Flush location while knockback

Authored by: Taiyou06 <kaandindar21@gmail.com>
As part of Leaf: https://github.com/Winds-Studio/Leaf/blob/58a4a9cb7994474e63ba49205cd21e89f8dacc9a/leaf-server/minecraft-patches/features/0216-Flush-location-while-knockback.patch
Licensed under: https://github.com/Winds-Studio/Leaf/blob/9e1b4ca7bc2e9154bc5620b7a9fef0eab3c7aae5/LICENSE.md

diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index a9058f3c401979fa8ba35124c83734d790508e46..16b42374e32aa2d54237f035757aedbc37c57fcc 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -1081,6 +1081,12 @@ public abstract class Player extends Avatar implements ContainerUser {
this.itemAttackInteraction(entity, attackingItemStack, damageSource, true);
this.damageStatsAndHearts(entity, oldLivingEntityHealth);
this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot - Change to use configurable value
+ // Leaf start - Flush location while knockback
+ if (io.canvasmc.canvas.GlobalConfiguration.getInstance().networking.flushLocationWhileKnockback && this instanceof ServerPlayer attacker && entity instanceof ServerPlayer victim) {
+ attacker.connection.connection.flushChannel();
+ victim.connection.connection.flushChannel();
+ }
+ // Leaf end - Flush location while knockback
} else {
this.playServerSideSound(SoundEvents.PLAYER_ATTACK_NODAMAGE);
}
@@ -1246,7 +1252,17 @@ public abstract class Player extends Avatar implements ContainerUser {
}

if (!cancelled) {
- serverPlayer.connection.send(new ClientboundSetEntityMotionPacket(entity));
+ // Leaf start - Flush location while knockback
+ if (io.canvasmc.canvas.GlobalConfiguration.getInstance().networking.flushLocationWhileKnockback) {
+ entity.needsSync = true;
+ net.minecraft.server.level.ChunkMap.TrackedEntity targetTrackedEntity = entity.moonrise$getTrackedEntity();
+ if (targetTrackedEntity != null) {
+ targetTrackedEntity.serverEntity.sendChanges();
+ }
+ } else {
+ serverPlayer.connection.send(new ClientboundSetEntityMotionPacket(entity));
+ }
+ // Leaf end - Flush location while knockback
entity.hurtMarked = false;
entity.setDeltaMovement(oldMovement);
}
@@ -1364,6 +1380,12 @@ public abstract class Player extends Avatar implements ContainerUser {
this.itemAttackInteraction(target, weaponItem, damageSource, wasHurt);
this.damageStatsAndHearts(target, oldLivingEntityHealth);
this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot - Change to use configurable value
+ // Leaf start - Flush location while knockback
+ if (io.canvasmc.canvas.GlobalConfiguration.getInstance().networking.flushLocationWhileKnockback && this instanceof ServerPlayer attacker && target instanceof ServerPlayer victim) {
+ attacker.connection.connection.flushChannel();
+ victim.connection.connection.flushChannel();
+ }
+ // Leaf end - Flush location while knockback
return true;
}

Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,20 @@ public static class Networking extends Part {
"Responding to any of them in any order will keep the player connected.")
.blank()
.wordWrap("AKA, it won't kick your players because one packet gets dropped somewhere along the lines"));

option("flushLocationWhileKnockback")
.docs("Derived from Leaf, this synchronizes the player immediately when knocked back");
}

public boolean filterVelocityPacket = false;
public boolean filterMovePackets = false;
public boolean alternativePlayerListTick = false;
public int playerInfoSendInterval = 600;
public boolean purpurAlternativeKeepalive = false;

// Originally from Leaf: https://github.com/Winds-Studio/Leaf/blob/58a4a9cb7994474e63ba49205cd21e89f8dacc9a/leaf-server/minecraft-patches/features/0216-Flush-location-while-knockback.patch
// License described in Leaf-Flush-location-while-knockback.patch
public boolean flushLocationWhileKnockback = false;
}

{
Expand Down
Loading