Java Code Examples for com.nukkitx.math.vector.Vector3i#add()

The following examples show how to use com.nukkitx.math.vector.Vector3i#add() . 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: BlockInventoryHolder.java    From Geyser with MIT License 6 votes vote down vote up
@Override
public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
    Vector3i position = session.getPlayerEntity().getPosition().toInt();
    position = position.add(Vector3i.UP);
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(position);
    blockPacket.setRuntimeId(blockId);
    blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
    session.sendUpstreamPacket(blockPacket);
    inventory.setHolderPosition(position);

    CompoundTag tag = CompoundTag.builder()
            .intTag("x", position.getX())
            .intTag("y", position.getY())
            .intTag("z", position.getZ())
            .stringTag("CustomName", LocaleUtils.getLocaleString(inventory.getTitle(), session.getClientData().getLanguageCode())).buildRootTag();
    BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
    dataPacket.setData(tag);
    dataPacket.setBlockPosition(position);
    session.sendUpstreamPacket(dataPacket);
}
 
Example 2
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());
}
 
Example 3
Source File: StructureBlockUpdateSerializer_v340.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 4
Source File: StructureBlockUpdateSerializer_v313.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 5
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 6
Source File: StructureBlockUpdateSerializer_v291.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());
}