mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-20 01:25:27 +01:00
hollow-cube/1.19.4_2 (#14)
* oopsie woopsie
* use double vector
* fix `minecraft:time` argument min property
(cherry picked from commit 6f11e42d46
)
This commit is contained in:
parent
cc6ff539f0
commit
8a56d147f3
@ -5,8 +5,10 @@ import it.unimi.dsi.fastutil.chars.CharList;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.TemporalUnit;
|
||||
@ -23,10 +25,17 @@ public class ArgumentTime extends Argument<Duration> {
|
||||
|
||||
private static final CharList SUFFIXES = new CharArrayList(new char[]{'d', 's', 't'});
|
||||
|
||||
private int min = 0;
|
||||
|
||||
public ArgumentTime(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public @NotNull ArgumentTime min(int min) {
|
||||
this.min = min;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Duration parse(@NotNull CommandSender sender, @NotNull String input) throws ArgumentSyntaxException {
|
||||
@ -57,7 +66,13 @@ public class ArgumentTime extends Argument<Duration> {
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ArgumentSyntaxException("Time needs to be a number", input, NO_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte @Nullable [] nodeProperties() {
|
||||
return BinaryWriter.makeArray(packetWriter -> {
|
||||
packetWriter.writeInt(min);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,6 +72,7 @@ public final class NetworkBuffer {
|
||||
public static final Type<FrogMeta.Variant> FROG_VARIANT = NetworkBufferTypes.FROG_VARIANT;
|
||||
public static final Type<SnifferMeta.State> SNIFFER_STATE = NetworkBufferTypes.SNIFFER_STATE;
|
||||
public static final Type<Point> VECTOR3 = NetworkBufferTypes.VECTOR3;
|
||||
public static final Type<Point> VECTOR3D = NetworkBufferTypes.VECTOR3D;
|
||||
public static final Type<float[]> QUATERNION = NetworkBufferTypes.QUATERNION;
|
||||
|
||||
ByteBuffer nioBuffer;
|
||||
|
@ -572,6 +572,19 @@ final class NetworkBufferTypes {
|
||||
final float z = buffer.read(FLOAT);
|
||||
return new Vec(x, y, z);
|
||||
});
|
||||
static final TypeImpl<Point> VECTOR3D = new TypeImpl<>(Point.class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(DOUBLE, value.x());
|
||||
buffer.write(DOUBLE, value.y());
|
||||
buffer.write(DOUBLE, value.z());
|
||||
return -1;
|
||||
},
|
||||
buffer -> {
|
||||
final double x = buffer.read(DOUBLE);
|
||||
final double y = buffer.read(DOUBLE);
|
||||
final double z = buffer.read(DOUBLE);
|
||||
return new Vec(x, y, z);
|
||||
});
|
||||
static final TypeImpl<float[]> QUATERNION = new TypeImpl<>(float[].class,
|
||||
(buffer, value) -> {
|
||||
buffer.write(FLOAT, value[0]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
@ -12,13 +12,12 @@ import static net.minestom.server.network.NetworkBuffer.*;
|
||||
// Notes
|
||||
// sourceEntityId - 0 indicates no source entity, otherwise it is entityId + 1
|
||||
// sourceDirectId - 0 indicates no direct source. Direct attacks (e.g. melee) will have this number me the same as sourceEntityId, indirect attacks (e.g. projectiles) will have this be be the projectile entity id + 1
|
||||
public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId, @Nullable Vec sourcePos) implements ServerPacket {
|
||||
public record DamageEventPacket(int targetEntityId, int damageTypeId, int sourceEntityId, int sourceDirectId, @Nullable Point sourcePos) implements ServerPacket {
|
||||
|
||||
public DamageEventPacket(@NotNull NetworkBuffer reader) {
|
||||
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT),
|
||||
reader.read(BOOLEAN) ? new Vec(reader.read(DOUBLE), reader.read(DOUBLE), reader.read(DOUBLE)) : null
|
||||
);
|
||||
this(reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), reader.readOptional(VECTOR3D));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.DAMAGE_EVENT;
|
||||
@ -27,16 +26,9 @@ public record DamageEventPacket(int targetEntityId, int damageTypeId, int source
|
||||
@Override
|
||||
public void write(@NotNull NetworkBuffer writer) {
|
||||
writer.write(VAR_INT, targetEntityId);
|
||||
writer.write(VAR_INT, targetEntityId);
|
||||
writer.write(VAR_INT, targetEntityId);
|
||||
writer.write(VAR_INT, targetEntityId);
|
||||
if (sourcePos != null) {
|
||||
writer.write(BOOLEAN, true);
|
||||
writer.write(DOUBLE, sourcePos.x());
|
||||
writer.write(DOUBLE, sourcePos.y());
|
||||
writer.write(DOUBLE, sourcePos.z());
|
||||
} else {
|
||||
writer.write(BOOLEAN, false);
|
||||
}
|
||||
writer.write(VAR_INT, damageTypeId);
|
||||
writer.write(VAR_INT, sourceEntityId);
|
||||
writer.write(VAR_INT, sourceDirectId);
|
||||
writer.writeOptional(VECTOR3D, sourcePos);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user