com.nukkitx.math.vector.Vector3i Java Examples

The following examples show how to use com.nukkitx.math.vector.Vector3i. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 6 votes vote down vote up
public static StructureSettings readStructureSettings(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");

    String paletteName = BedrockUtils.readString(buffer);
    boolean ignoreEntities = buffer.readBoolean();
    boolean ignoreBlocks = buffer.readBoolean();
    Vector3i structureSize = BedrockUtils.readBlockPosition(buffer);
    Vector3i structureOffset = BedrockUtils.readBlockPosition(buffer);
    long lastTouchedByEntityId = VarInts.readLong(buffer);
    byte rotation = buffer.readByte();
    byte mirror = buffer.readByte();
    float integrityValue = buffer.readFloatLE();
    int integritySeed = VarInts.readUnsignedInt(buffer);

    return new StructureSettings(paletteName, ignoreEntities, ignoreBlocks, structureSize, structureOffset,
            lastTouchedByEntityId, rotation, mirror, integrityValue, integritySeed);
}
 
Example #2
Source File: EnderCrystalEntity.java    From Geyser with MIT License 6 votes vote down vote up
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
    // Show beam
    // Usually performed client-side on Bedrock except for Ender Dragon respawn event
    if (entityMetadata.getId() == 7) {
        if (entityMetadata.getValue() instanceof Position) {
            Position pos = (Position) entityMetadata.getValue();
            metadata.put(EntityData.BLOCK_TARGET, Vector3i.from(pos.getX(), pos.getY(), pos.getZ()));
        } else {
            metadata.put(EntityData.BLOCK_TARGET, Vector3i.ZERO);
        }
    }
    // There is a base located on the ender crystal
    if (entityMetadata.getId() == 8) {
        metadata.getFlags().setFlag(EntityFlag.SHOW_BOTTOM, (boolean) entityMetadata.getValue());
    }
    super.updateBedrockMetadata(entityMetadata, session);
}
 
Example #3
Source File: ShulkerEntity.java    From Geyser with MIT License 6 votes vote down vote up
@Override
    public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
        if (entityMetadata.getId() == 15) {
            BlockFace blockFace = (BlockFace) entityMetadata.getValue();
            metadata.put(EntityData.SHULKER_ATTACH_FACE, (byte) blockFace.ordinal());
        }
        if (entityMetadata.getId() == 16) {
            Position position = (Position) entityMetadata.getValue();
            if (position != null) {
                metadata.put(EntityData.SHULKER_ATTACH_POS, Vector3i.from(position.getX(), position.getY(), position.getZ()));
            }
        }
        //TODO Outdated metadata flag SHULKER_PEAK_HEIGHT
//        if (entityMetadata.getId() == 17) {
//            int height = (byte) entityMetadata.getValue();
//            metadata.put(EntityData.SHULKER_PEAK_HEIGHT, height);
//        }
        if (entityMetadata.getId() == 18) {
            int color = Math.abs((byte) entityMetadata.getValue() - 15);
            metadata.put(EntityData.VARIANT, color);
        }
        super.updateBedrockMetadata(entityMetadata, session);
    }
 
Example #4
Source File: FlowerPotBlockEntityTranslator.java    From Geyser with MIT License 6 votes vote down vote up
/**
 * Get the Nukkit CompoundTag of the flower pot.
 * @param blockState Java BlockState of flower pot.
 * @param position Bedrock position of flower pot.
 * @return Bedrock tag of flower pot.
 */
public static CompoundTag getTag(BlockState blockState, Vector3i position) {
    CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
            .intTag("x", position.getX())
            .intTag("y", position.getY())
            .intTag("z", position.getZ())
            .byteTag("isMovable", (byte) 1)
            .stringTag("id", "FlowerPot");
    // Get the Java name of the plant inside. e.g. minecraft:oak_sapling
    String name = BlockStateValues.getFlowerPotValues().get(blockState.getId());
    if (name != null) {
        // Get the Bedrock CompoundTag of the block.
        // This is where we need to store the *Java* name because Bedrock has six minecraft:sapling blocks with different block states.
        CompoundTag plant = BlockStateValues.getFlowerPotBlocks().get(name);
        if (plant != null) {
            tagBuilder.tag(plant.toBuilder().build("PlantBlock"));
        }
    }
    return tagBuilder.buildRootTag();
}
 
Example #5
Source File: ChunkUtils.java    From Geyser with MIT License 6 votes vote down vote up
public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) {
    int chunkX = position.getX() >> 4;
    int chunkZ = position.getZ() >> 4;
    for (int x = -radius; x <= radius; x++) {
        for (int z = -radius; z <= radius; z++) {
            LevelChunkPacket data = new LevelChunkPacket();
            data.setChunkX(chunkX + x);
            data.setChunkZ(chunkZ + z);
            data.setSubChunksLength(0);
            data.setData(EMPTY_LEVEL_CHUNK_DATA);
            data.setCachingEnabled(false);
            session.sendUpstreamPacket(data);

            if (forceUpdate) {
                Vector3i pos = Vector3i.from(chunkX + x << 4, 80, chunkZ + z << 4);
                UpdateBlockPacket blockPacket = new UpdateBlockPacket();
                blockPacket.setBlockPosition(pos);
                blockPacket.setDataLayer(0);
                blockPacket.setRuntimeId(1);
                session.sendUpstreamPacket(blockPacket);
            }
        }
    }
}
 
Example #6
Source File: PistonBlockEntityTranslator.java    From Geyser with MIT License 6 votes vote down vote up
/**
 * Calculates the Nukkit CompoundTag to send to the client on chunk
 * @param blockState Java BlockState of block.
 * @param position Bedrock position of piston.
 * @return Bedrock tag of piston.
 */
public static CompoundTag getTag(BlockState blockState, Vector3i position) {
    CompoundTagBuilder tagBuilder = CompoundTagBuilder.builder()
            .intTag("x", position.getX())
            .intTag("y", position.getY())
            .intTag("z", position.getZ())
            .byteTag("isMovable", (byte) 1)
            .stringTag("id", "PistonArm");
    if (BlockStateValues.getPistonValues().containsKey(blockState.getId())) {
        boolean extended = BlockStateValues.getPistonValues().get(blockState.getId());
        // 1f if extended, otherwise 0f
        tagBuilder.floatTag("Progress", (extended) ? 1.0f : 0.0f);
        // 1 if sticky, 0 if not
        tagBuilder.byteTag("Sticky", (byte)((BlockStateValues.isStickyPiston(blockState)) ? 1 : 0));
    }
    return tagBuilder.buildRootTag();
}
 
Example #7
Source File: StructureBlockUpdateSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    int structureType = VarInts.readUnsignedInt(buffer);
    // Structure Editor Data start
    String name = BedrockUtils.readString(buffer);
    String dataField = BedrockUtils.readString(buffer);
    Vector3i offset = BedrockUtils.readBlockPosition(buffer);
    Vector3i size = BedrockUtils.readBlockPosition(buffer);
    buffer.readBoolean(); // include entities
    boolean ignoreBlocks = !buffer.readBoolean();
    boolean includePlayers = buffer.readBoolean();
    buffer.readBoolean(); // show air
    // Structure Settings start
    float structureIntegrity = buffer.readFloatLE();
    int integritySeed = VarInts.readUnsignedInt(buffer);
    int mirror = VarInts.readUnsignedInt(buffer);
    int rotation = VarInts.readUnsignedInt(buffer);
    boolean ignoreEntities = buffer.readBoolean();
    buffer.readBoolean(); // ignore structure bocks
    BedrockUtils.readVector3i(buffer); // bounding box min
    BedrockUtils.readVector3i(buffer); // bounding box max
    // Structure Settings end
    // Structure Editor Data end
    boolean boundingBoxVisible = buffer.readBoolean();

    StructureSettings settings = new StructureSettings("", ignoreEntities, ignoreBlocks, size, offset,
            -1, (byte) rotation, (byte) mirror, structureIntegrity, integritySeed);
    StructureEditorData editorData = new StructureEditorData(name, dataField, includePlayers, boundingBoxVisible,
            structureType, settings);

    packet.setEditorData(editorData);
    packet.setPowered(buffer.readBoolean());
}
 
Example #8
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(vector3i, "vector3i");
    VarInts.writeInt(buffer, vector3i.getX());
    VarInts.writeInt(buffer, vector3i.getY());
    VarInts.writeInt(buffer, vector3i.getZ());
}
 
Example #9
Source File: StructureBlockUpdateSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    int structureType = VarInts.readUnsignedInt(buffer);
    // Structure Editor Data start
    String name = BedrockUtils.readString(buffer);
    String dataField = BedrockUtils.readString(buffer);
    Vector3i offset = BedrockUtils.readBlockPosition(buffer);
    Vector3i size = BedrockUtils.readBlockPosition(buffer);
    buffer.readBoolean(); // include entities
    boolean ignoreBlocks = !buffer.readBoolean();
    boolean includePlayers = buffer.readBoolean();
    buffer.readBoolean(); // show air
    // Structure Settings start
    float structureIntegrity = buffer.readFloatLE();
    int integritySeed = VarInts.readUnsignedInt(buffer);
    int mirror = VarInts.readUnsignedInt(buffer);
    int rotation = VarInts.readUnsignedInt(buffer);
    boolean ignoreEntities = buffer.readBoolean();
    buffer.readBoolean(); // ignore structure bocks
    BedrockUtils.readVector3i(buffer); // bounding box min
    BedrockUtils.readVector3i(buffer); // bounding box max
    // Structure Settings end
    // Structure Editor Data end
    boolean boundingBoxVisible = buffer.readBoolean();

    StructureSettings settings = new StructureSettings("", ignoreEntities, ignoreBlocks, size, offset,
            -1, (byte) rotation, (byte) mirror, structureIntegrity, integritySeed);
    StructureEditorData editorData = new StructureEditorData(name, dataField, includePlayers, boundingBoxVisible,
            structureType, settings);

    packet.setEditorData(editorData);
    packet.setPowered(buffer.readBoolean());
}
 
Example #10
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeBlockPosition(ByteBuf buffer, Vector3i blockPosition) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(blockPosition, "blockPosition");
    VarInts.writeInt(buffer, blockPosition.getX());
    VarInts.writeUnsignedInt(buffer, blockPosition.getY());
    VarInts.writeInt(buffer, blockPosition.getZ());
}
 
Example #11
Source File: MoveEntityDeltaSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, MoveEntityDeltaPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    byte flags = 0;
    Vector3i movementDelta = packet.getMovementDelta();
    Vector3f rotationDelta = packet.getRotationDelta();
    flags |= movementDelta.getX() != 0 ? HAS_X : 0;
    flags |= movementDelta.getY() != 0 ? HAS_Y : 0;
    flags |= movementDelta.getZ() != 0 ? HAS_Z : 0;
    flags |= rotationDelta.getX() != 0 ? HAS_PITCH : 0;
    flags |= rotationDelta.getY() != 0 ? HAS_YAW : 0;
    flags |= rotationDelta.getZ() != 0 ? HAS_ROLL : 0;
    buffer.writeByte(flags);
    if ((flags & HAS_X) != 0) {
        VarInts.writeInt(buffer, movementDelta.getX());
    }
    if ((flags & HAS_Y) != 0) {
        VarInts.writeInt(buffer, movementDelta.getY());
    }
    if ((flags & HAS_Z) != 0) {
        VarInts.writeInt(buffer, movementDelta.getZ());
    }
    if ((flags & HAS_PITCH) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getX());
    }
    if ((flags & HAS_YAW) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getY());
    }
    if ((flags & HAS_ROLL) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getZ());
    }
}
 
Example #12
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeBlockPosition(ByteBuf buffer, Vector3i blockPosition) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(blockPosition, "blockPosition");
    VarInts.writeInt(buffer, blockPosition.getX());
    VarInts.writeUnsignedInt(buffer, blockPosition.getY());
    VarInts.writeInt(buffer, blockPosition.getZ());
}
 
Example #13
Source File: StructureBlockUpdateSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    StructureEditorData editorData = packet.getEditorData();
    StructureSettings settings = editorData.getStructureSettings();

    BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition());
    VarInts.writeUnsignedInt(buffer, editorData.getStructureBlockType());
    // Structure Editor Data start
    BedrockUtils.writeString(buffer, editorData.getName());
    BedrockUtils.writeString(buffer, editorData.getStructureDataField());
    BedrockUtils.writeBlockPosition(buffer, settings.getStructureOffset());
    BedrockUtils.writeBlockPosition(buffer, settings.getStructureSize());
    buffer.writeBoolean(!settings.isIgnoreEntities());
    buffer.writeBoolean(settings.isIgnoreBlocks());
    buffer.writeBoolean(editorData.isIncludePlayers());
    buffer.writeBoolean(false); // show air
    // Structure Settings start
    buffer.writeFloatLE(settings.getIntegrityValue());
    VarInts.writeUnsignedInt(buffer, settings.getIntegritySeed());
    VarInts.writeUnsignedInt(buffer, settings.getMirror());
    VarInts.writeUnsignedInt(buffer, settings.getRotation());
    buffer.writeBoolean(settings.isIgnoreEntities());
    buffer.writeBoolean(true); // ignore structure blocks
    Vector3i min = packet.getBlockPosition().add(settings.getStructureOffset());
    BedrockUtils.writeVector3i(buffer, min);
    Vector3i max = min.add(settings.getStructureSize());
    BedrockUtils.writeVector3i(buffer, max);
    // Structure Settings end
    // Structure Editor Data end
    buffer.writeBoolean(editorData.isShowBoundingBox());
    buffer.writeBoolean(packet.isPowered());
}
 
Example #14
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readVector3i(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #15
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(vector3i, "vector3i");
    VarInts.writeInt(buffer, vector3i.getX());
    VarInts.writeInt(buffer, vector3i.getY());
    VarInts.writeInt(buffer, vector3i.getZ());
}
 
Example #16
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readBlockPosition(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readUnsignedInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #17
Source File: MoveEntityDeltaSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, MoveEntityDeltaPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    byte flags = buffer.readByte();
    int x = 0, y = 0, z = 0;
    float pitch = 0, yaw = 0, roll = 0;
    if ((flags & HAS_X) != 0) {
        x = VarInts.readInt(buffer);
    }
    if ((flags & HAS_Y) != 0) {
        y = VarInts.readInt(buffer);
    }
    if ((flags & HAS_Z) != 0) {
        z = VarInts.readInt(buffer);
    }
    if ((flags & HAS_PITCH) != 0) {
        pitch = BedrockUtils.readByteAngle(buffer);
    }
    if ((flags & HAS_YAW) != 0) {
        yaw = BedrockUtils.readByteAngle(buffer);
    }
    if ((flags & HAS_ROLL) != 0) {
        roll = BedrockUtils.readByteAngle(buffer);
    }
    packet.setMovementDelta(Vector3i.from(x, y, z));
    packet.setRotationDelta(Vector3f.from(pitch, yaw, roll));
}
 
Example #18
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readVector3i(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #19
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readVector3i(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #20
Source File: MoveEntityDeltaSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, MoveEntityDeltaPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    short flags = buffer.readShortLE();
    int x = 0, y = 0, z = 0;
    float pitch = 0, yaw = 0, roll = 0;
    if ((flags & HAS_X) != 0) {
        x = VarInts.readInt(buffer);
    }
    if ((flags & HAS_Y) != 0) {
        y = VarInts.readInt(buffer);
    }
    if ((flags & HAS_Z) != 0) {
        z = VarInts.readInt(buffer);
    }
    if ((flags & HAS_PITCH) != 0) {
        pitch = BedrockUtils.readByteAngle(buffer);
    }
    if ((flags & HAS_YAW) != 0) {
        yaw = BedrockUtils.readByteAngle(buffer);
    }
    if ((flags & HAS_ROLL) != 0) {
        roll = BedrockUtils.readByteAngle(buffer);
    }
    packet.setMovementDelta(Vector3i.from(x, y, z));
    packet.setRotationDelta(Vector3f.from(pitch, yaw, roll));
}
 
Example #21
Source File: MoveEntityDeltaSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, MoveEntityDeltaPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    short flags = 0;
    Vector3i movementDelta = packet.getMovementDelta();
    Vector3f rotationDelta = packet.getRotationDelta();
    flags |= movementDelta.getX() != 0 ? HAS_X : 0;
    flags |= movementDelta.getY() != 0 ? HAS_Y : 0;
    flags |= movementDelta.getZ() != 0 ? HAS_Z : 0;
    flags |= rotationDelta.getX() != 0 ? HAS_PITCH : 0;
    flags |= rotationDelta.getY() != 0 ? HAS_YAW : 0;
    flags |= rotationDelta.getZ() != 0 ? HAS_ROLL : 0;
    buffer.writeShortLE(flags);
    if ((flags & HAS_X) != 0) {
        VarInts.writeInt(buffer, movementDelta.getX());
    }
    if ((flags & HAS_Y) != 0) {
        VarInts.writeInt(buffer, movementDelta.getY());
    }
    if ((flags & HAS_Z) != 0) {
        VarInts.writeInt(buffer, movementDelta.getZ());
    }
    if ((flags & HAS_PITCH) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getX());
    }
    if ((flags & HAS_YAW) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getY());
    }
    if ((flags & HAS_ROLL) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getZ());
    }
}
 
Example #22
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readVector3i(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #23
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeBlockPosition(ByteBuf buffer, Vector3i blockPosition) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(blockPosition, "blockPosition");
    VarInts.writeInt(buffer, blockPosition.getX());
    VarInts.writeUnsignedInt(buffer, blockPosition.getY());
    VarInts.writeInt(buffer, blockPosition.getZ());
}
 
Example #24
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readBlockPosition(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readUnsignedInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #25
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(vector3i, "vector3i");
    VarInts.writeInt(buffer, vector3i.getX());
    VarInts.writeInt(buffer, vector3i.getY());
    VarInts.writeInt(buffer, vector3i.getZ());
}
 
Example #26
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static Vector3i readVector3i(ByteBuf buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int x = VarInts.readInt(buffer);
    int y = VarInts.readInt(buffer);
    int z = VarInts.readInt(buffer);

    return Vector3i.from(x, y, z);
}
 
Example #27
Source File: MoveEntityDeltaSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, MoveEntityDeltaPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    byte flags = buffer.readByte();
    int x = 0, y = 0, z = 0;
    float pitch = 0, yaw = 0, roll = 0;
    if ((flags & HAS_X) != 0) {
        x = VarInts.readInt(buffer);
    }
    if ((flags & HAS_Y) != 0) {
        y = VarInts.readInt(buffer);
    }
    if ((flags & HAS_Z) != 0) {
        z = VarInts.readInt(buffer);
    }
    if ((flags & HAS_PITCH) != 0) {
        pitch = BedrockUtils.readByteAngle(buffer);
    }
    if ((flags & HAS_YAW) != 0) {
        yaw = BedrockUtils.readByteAngle(buffer);
    }
    if ((flags & HAS_ROLL) != 0) {
        roll = BedrockUtils.readByteAngle(buffer);
    }
    packet.setMovementDelta(Vector3i.from(x, y, z));
    packet.setRotationDelta(Vector3f.from(pitch, yaw, roll));
}
 
Example #28
Source File: MoveEntityDeltaSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, MoveEntityDeltaPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    byte flags = 0;
    Vector3i movementDelta = packet.getMovementDelta();
    Vector3f rotationDelta = packet.getRotationDelta();
    flags |= movementDelta.getX() != 0 ? HAS_X : 0;
    flags |= movementDelta.getY() != 0 ? HAS_Y : 0;
    flags |= movementDelta.getZ() != 0 ? HAS_Z : 0;
    flags |= rotationDelta.getX() != 0 ? HAS_PITCH : 0;
    flags |= rotationDelta.getY() != 0 ? HAS_YAW : 0;
    flags |= rotationDelta.getZ() != 0 ? HAS_ROLL : 0;
    buffer.writeByte(flags);
    if ((flags & HAS_X) != 0) {
        VarInts.writeInt(buffer, movementDelta.getX());
    }
    if ((flags & HAS_Y) != 0) {
        VarInts.writeInt(buffer, movementDelta.getY());
    }
    if ((flags & HAS_Z) != 0) {
        VarInts.writeInt(buffer, movementDelta.getZ());
    }
    if ((flags & HAS_PITCH) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getX());
    }
    if ((flags & HAS_YAW) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getY());
    }
    if ((flags & HAS_ROLL) != 0) {
        BedrockUtils.writeByteAngle(buffer, rotationDelta.getZ());
    }
}
 
Example #29
Source File: StructureBlockUpdateSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    int structureType = VarInts.readUnsignedInt(buffer);
    // Structure Editor Data start
    String name = BedrockUtils.readString(buffer);
    String dataField = BedrockUtils.readString(buffer);
    Vector3i offset = BedrockUtils.readBlockPosition(buffer);
    Vector3i size = BedrockUtils.readBlockPosition(buffer);
    buffer.readBoolean(); // include entities
    boolean ignoreBlocks = !buffer.readBoolean();
    boolean includePlayers = buffer.readBoolean();
    buffer.readBoolean(); // show air
    // Structure Settings start
    float structureIntegrity = buffer.readFloatLE();
    int integritySeed = VarInts.readUnsignedInt(buffer);
    int mirror = VarInts.readUnsignedInt(buffer);
    int rotation = VarInts.readUnsignedInt(buffer);
    boolean ignoreEntities = buffer.readBoolean();
    buffer.readBoolean(); // ignore structure bocks
    BedrockUtils.readVector3i(buffer); // bounding box min
    BedrockUtils.readVector3i(buffer); // bounding box max
    // Structure Settings end
    // Structure Editor Data end
    boolean boundingBoxVisible = buffer.readBoolean();

    StructureSettings settings = new StructureSettings("", ignoreEntities, ignoreBlocks, size, offset,
            -1, (byte) rotation, (byte) mirror, structureIntegrity, integritySeed);
    StructureEditorData editorData = new StructureEditorData(name, dataField, includePlayers, boundingBoxVisible,
            structureType, settings);

    packet.setEditorData(editorData);
    packet.setPowered(buffer.readBoolean());
}
 
Example #30
Source File: StructureBlockUpdateSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, StructureBlockUpdatePacket packet) {
    StructureEditorData editorData = packet.getEditorData();
    StructureSettings settings = editorData.getStructureSettings();

    BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition());
    VarInts.writeUnsignedInt(buffer, editorData.getStructureBlockType());
    // Structure Editor Data start
    BedrockUtils.writeString(buffer, editorData.getName());
    BedrockUtils.writeString(buffer, editorData.getStructureDataField());
    BedrockUtils.writeBlockPosition(buffer, settings.getStructureOffset());
    BedrockUtils.writeBlockPosition(buffer, settings.getStructureSize());
    buffer.writeBoolean(!settings.isIgnoreEntities());
    buffer.writeBoolean(settings.isIgnoreBlocks());
    buffer.writeBoolean(editorData.isIncludePlayers());
    buffer.writeBoolean(false); // show air
    // Structure Settings start
    buffer.writeFloatLE(settings.getIntegrityValue());
    VarInts.writeUnsignedInt(buffer, settings.getIntegritySeed());
    VarInts.writeUnsignedInt(buffer, settings.getMirror());
    VarInts.writeUnsignedInt(buffer, settings.getRotation());
    buffer.writeBoolean(settings.isIgnoreEntities());
    buffer.writeBoolean(true); // ignore structure blocks
    Vector3i min = packet.getBlockPosition().add(settings.getStructureOffset());
    BedrockUtils.writeVector3i(buffer, min);
    Vector3i max = min.add(settings.getStructureSize());
    BedrockUtils.writeVector3i(buffer, max);
    // Structure Settings end
    // Structure Editor Data end
    buffer.writeBoolean(editorData.isShowBoundingBox());
    buffer.writeBoolean(packet.isPowered());
}