Send executor id with execution progress
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user