Merge pull request #8 from Fretuks/implement-gripping-execution-animation

Gate execution animation to executor client
This commit is contained in:
2026-01-07 18:09:37 +01:00
committed by GitHub
5 changed files with 44 additions and 17 deletions
@@ -3,26 +3,37 @@ package net.fretux.knockedback;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import javax.annotation.Nullable;
import java.util.UUID;
import java.util.function.Supplier;
public class ExecutionProgressPacket {
private final int timeLeft;
@Nullable
private final UUID executorId;
public ExecutionProgressPacket(int timeLeft) {
public ExecutionProgressPacket(int timeLeft, @Nullable UUID executorId) {
this.timeLeft = timeLeft;
this.executorId = executorId;
}
public static void encode(ExecutionProgressPacket msg, FriendlyByteBuf buf) {
buf.writeInt(msg.timeLeft);
buf.writeBoolean(msg.executorId != null);
if (msg.executorId != null) {
buf.writeUUID(msg.executorId);
}
}
public static ExecutionProgressPacket decode(FriendlyByteBuf buf) {
return new ExecutionProgressPacket(buf.readInt());
int timeLeft = buf.readInt();
UUID executorId = buf.readBoolean() ? buf.readUUID() : null;
return new ExecutionProgressPacket(timeLeft, executorId);
}
public static void handle(ExecutionProgressPacket msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
net.fretux.knockedback.client.ClientExecutionState.setTimeLeft(msg.timeLeft);
net.fretux.knockedback.client.ClientExecutionState.setExecution(msg.timeLeft, msg.executorId);
});
ctx.get().setPacketHandled(true);
}
@@ -215,7 +215,7 @@ public class KnockedManager {
);
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
NetworkHandler.CHANNEL.send(
PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> sp),
@@ -65,7 +65,7 @@ public class MobKillHandler {
if (p instanceof ServerPlayer sp) {
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
setGripped(p, false);
@@ -85,7 +85,7 @@ public class MobKillHandler {
if (knocked instanceof ServerPlayer sp) {
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
setGripped(knocked, false);
@@ -100,7 +100,7 @@ public class MobKillHandler {
if (knocked instanceof ServerPlayer sp) {
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
setGripped(knocked, false);
@@ -114,7 +114,7 @@ public class MobKillHandler {
if (knocked instanceof ServerPlayer sp) {
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(attempt.timeLeft)
new ExecutionProgressPacket(attempt.timeLeft, null)
);
}
if (attempt.timeLeft <= 0) {
@@ -141,7 +141,7 @@ public class MobKillHandler {
if (knocked instanceof ServerPlayer sp) {
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
}
@@ -90,7 +90,7 @@ public class PlayerExecutionHandler {
knocked.sendSystemMessage(Component.translatable("message.knockedback.execution_interrupted"));
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> knocked),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
ServerPlayer executor = getPlayerByUuid(attempt.executorUuid);
@@ -98,7 +98,7 @@ public class PlayerExecutionHandler {
executor.sendSystemMessage(Component.translatable("message.knockedback.execution_interrupted_executor"));
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> executor),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
}
@@ -128,12 +128,12 @@ public class PlayerExecutionHandler {
KnockedManager.unmarkKillInProgress(knockedPlayer);
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> executor),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
if (knockedPlayer instanceof ServerPlayer sp) {
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> sp),
new ExecutionProgressPacket(0)
new ExecutionProgressPacket(0, null)
);
}
executor.sendSystemMessage(Component.translatable("message.knockedback.you_executed", knockedPlayer.getDisplayName(), "!"));
@@ -160,8 +160,14 @@ public class PlayerExecutionHandler {
continue;
}
attempt.timeLeft--;
NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> executor), new ExecutionProgressPacket(attempt.timeLeft));
NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> knocked), new ExecutionProgressPacket(attempt.timeLeft));
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> executor),
new ExecutionProgressPacket(attempt.timeLeft, attempt.executorUuid)
);
NetworkHandler.CHANNEL.send(
PacketDistributor.PLAYER.with(() -> knocked),
new ExecutionProgressPacket(attempt.timeLeft, attempt.executorUuid)
);
if (attempt.timeLeft <= 0) {
executeKnockedPlayer(executor, knocked);
} else {
@@ -1,10 +1,16 @@
package net.fretux.knockedback.client;
import javax.annotation.Nullable;
import java.util.UUID;
public class ClientExecutionState {
private static int timeLeft = 0;
@Nullable
private static UUID executorId;
public static void setTimeLeft(int ticks) {
public static void setExecution(int ticks, @Nullable UUID executor) {
timeLeft = ticks;
executorId = ticks > 0 ? executor : null;
}
public static int getTimeLeft() {
@@ -14,4 +20,8 @@ public class ClientExecutionState {
public static boolean isExecuting() {
return timeLeft > 0;
}
}
public static boolean isExecutor(UUID playerId) {
return timeLeft > 0 && executorId != null && executorId.equals(playerId);
}
}