mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-18 00:25:30 +01:00
add update structure block packet
This commit is contained in:
parent
2f53388b9f
commit
11146186cc
@ -49,7 +49,7 @@ public class ClientPlayPacketsHandler extends ClientPacketsHandler {
|
||||
register(0x27, ClientUpdateCommandBlockMinecartPacket::new);
|
||||
register(0x28, ClientCreativeInventoryActionPacket::new);
|
||||
//Update Jigsaw Block??
|
||||
//Update Structure Block??
|
||||
register(0x2A, ClientUpdateStructureBlockPacket::new);
|
||||
register(0x2B, ClientUpdateSignPacket::new);
|
||||
register(0x2C, ClientAnimationPacket::new);
|
||||
register(0x2D, ClientSpectatePacket::new);
|
||||
|
@ -0,0 +1,111 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.Rotation;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClientUpdateStructureBlockPacket extends ClientPlayPacket {
|
||||
// Flag values
|
||||
public static final byte IGNORE_ENTITIES = 0x1;
|
||||
public static final byte SHOW_AIR = 0x2;
|
||||
/**
|
||||
* Requires the player to be in creative and have a permission level higher than 2.
|
||||
*/
|
||||
public static final byte SHOW_BOUNDING_BOX = 0x4;
|
||||
|
||||
public BlockPosition location;
|
||||
public Action action = Action.UPDATE_DATA;
|
||||
public Mode mode = Mode.DATA;
|
||||
public String name = "";
|
||||
public BlockPosition offset = new BlockPosition(0, 1, 0);
|
||||
public BlockPosition size = new BlockPosition(1, 1, 1);
|
||||
public Mirror mirror = Mirror.NONE;
|
||||
public Rotation rotation = Rotation.NONE;
|
||||
public String metadata = "";
|
||||
public float integrity = 1.0f;
|
||||
public long seed = 0;
|
||||
public byte flags = 0x0;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeBlockPosition(location);
|
||||
writer.writeVarInt(action.ordinal());
|
||||
writer.writeVarInt(mode.ordinal());
|
||||
writer.writeSizedString(name);
|
||||
writer.writeByte((byte) offset.getX());
|
||||
writer.writeByte((byte) offset.getY());
|
||||
writer.writeByte((byte) offset.getZ());
|
||||
writer.writeByte((byte) size.getX());
|
||||
writer.writeByte((byte) size.getY());
|
||||
writer.writeByte((byte) size.getZ());
|
||||
writer.writeVarInt(mirror.ordinal());
|
||||
writer.writeVarInt(toRestrictedRotation(rotation));
|
||||
writer.writeSizedString(metadata);
|
||||
writer.writeFloat(integrity);
|
||||
writer.writeVarLong(seed);
|
||||
writer.writeByte(flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
location = reader.readBlockPosition();
|
||||
action = Action.values()[reader.readVarInt()];
|
||||
mode = Mode.values()[reader.readVarInt()];
|
||||
name = reader.readSizedString(Short.MAX_VALUE);
|
||||
offset = new BlockPosition(
|
||||
reader.readByte(),
|
||||
reader.readByte(),
|
||||
reader.readByte()
|
||||
);
|
||||
size = new BlockPosition(
|
||||
reader.readByte(),
|
||||
reader.readByte(),
|
||||
reader.readByte()
|
||||
);
|
||||
mirror = Mirror.values()[reader.readVarInt()];
|
||||
rotation = fromRestrictedRotation(reader.readVarInt());
|
||||
metadata = reader.readSizedString(Short.MAX_VALUE);
|
||||
integrity = reader.readFloat();
|
||||
seed = reader.readVarLong();
|
||||
flags = reader.readByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update action, <code>UPDATE_DATA</code> indicates nothing special.
|
||||
*/
|
||||
public enum Action {
|
||||
UPDATE_DATA, SAVE, LOAD, DETECT_SIZE
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
SAVE, LOAD, CORNER, DATA
|
||||
}
|
||||
|
||||
public enum Mirror {
|
||||
NONE, LEFT_RIGHT, FRONT_BACK
|
||||
}
|
||||
|
||||
private int toRestrictedRotation(Rotation rotation) {
|
||||
switch (rotation) {
|
||||
case NONE: return 0;
|
||||
case CLOCKWISE: return 1;
|
||||
case FLIPPED: return 2;
|
||||
case COUNTER_CLOCKWISE: return 3;
|
||||
default: throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||
}
|
||||
}
|
||||
|
||||
private Rotation fromRestrictedRotation(int rotation) {
|
||||
switch (rotation) {
|
||||
case 0: return Rotation.NONE;
|
||||
case 1: return Rotation.CLOCKWISE;
|
||||
case 2: return Rotation.FLIPPED;
|
||||
case 3: return Rotation.COUNTER_CLOCKWISE;
|
||||
default: throw new IllegalArgumentException("ClientUpdateStructurePacket#rotation must be a valid 90-degree rotation.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user