Search in sources :

Example 1 with Vector3i

use of com.nukkitx.math.vector.Vector3i in project Geyser by GeyserMC.

the class BlockInventoryHolder method prepareInventory.

@Override
public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
    // (This could be a virtual inventory that the player is opening)
    if (checkInteractionPosition(session)) {
        // Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
        int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
        String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
        if (isValidBlock(javaBlockString)) {
            // We can safely use this block
            inventory.setHolderPosition(session.getLastInteractionBlockPosition());
            ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
            setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
            return;
        }
    }
    // Otherwise, time to conjure up a fake block!
    Vector3i position = session.getPlayerEntity().getPosition().toInt();
    position = position.add(Vector3i.UP);
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(position);
    blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState));
    blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
    session.sendUpstreamPacket(blockPacket);
    inventory.setHolderPosition(position);
    setCustomName(session, position, inventory, defaultJavaBlockState);
}
Also used : Container(org.geysermc.geyser.inventory.Container) Vector3i(com.nukkitx.math.vector.Vector3i) UpdateBlockPacket(com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)

Example 2 with Vector3i

use of com.nukkitx.math.vector.Vector3i in project Geyser by GeyserMC.

the class BedrockBlockPickRequestTranslator method translate.

@Override
public void translate(GeyserSession session, BlockPickRequestPacket packet) {
    Vector3i vector = packet.getBlockPosition();
    int blockToPick = session.getGeyser().getWorldManager().getBlockAt(session, vector.getX(), vector.getY(), vector.getZ());
    // Block is air - chunk caching is probably off
    if (blockToPick == BlockStateValues.JAVA_AIR_ID) {
        // Check for an item frame since the client thinks that's a block when it's an entity in Java
        ItemFrameEntity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
        if (entity != null) {
            // Check to see if the item frame has an item in it first
            if (entity.getHeldItem() != null && entity.getHeldItem().getId() != 0) {
                // Grab the item in the frame
                InventoryUtils.findOrCreateItem(session, entity.getHeldItem());
            } else {
                // Grab the frame as the item
                InventoryUtils.findOrCreateItem(session, entity.getDefinition() == EntityDefinitions.GLOW_ITEM_FRAME ? "minecraft:glow_item_frame" : "minecraft:item_frame");
            }
        }
        return;
    }
    InventoryUtils.findOrCreateItem(session, BlockRegistries.JAVA_BLOCKS.get(blockToPick).getPickItem());
}
Also used : ItemFrameEntity(org.geysermc.geyser.entity.type.ItemFrameEntity) Vector3i(com.nukkitx.math.vector.Vector3i)

Example 3 with Vector3i

use of com.nukkitx.math.vector.Vector3i in project Protocol by CloudburstMC.

the class StructureBlockUpdateSerializer_v340 method serialize.

@Override
public void serialize(ByteBuf buffer, BedrockPacketHelper helper, StructureBlockUpdatePacket packet) {
    StructureEditorData editorData = packet.getEditorData();
    StructureSettings settings = editorData.getSettings();
    helper.writeBlockPosition(buffer, packet.getBlockPosition());
    VarInts.writeUnsignedInt(buffer, editorData.getType().ordinal());
    // Structure Editor Data start
    helper.writeString(buffer, editorData.getName());
    helper.writeString(buffer, editorData.getName());
    helper.writeBlockPosition(buffer, settings.getOffset());
    helper.writeBlockPosition(buffer, settings.getSize());
    buffer.writeBoolean(!settings.isIgnoringEntities());
    buffer.writeBoolean(settings.isIgnoringBlocks());
    buffer.writeBoolean(editorData.isIncludingPlayers());
    // show air
    buffer.writeBoolean(false);
    // Structure Settings start
    buffer.writeFloatLE(settings.getIntegrityValue());
    VarInts.writeUnsignedInt(buffer, settings.getIntegritySeed());
    VarInts.writeUnsignedInt(buffer, settings.getMirror().ordinal());
    VarInts.writeUnsignedInt(buffer, settings.getRotation().ordinal());
    buffer.writeBoolean(settings.isIgnoringEntities());
    // ignore structure blocks
    buffer.writeBoolean(true);
    Vector3i min = packet.getBlockPosition().add(settings.getOffset());
    helper.writeVector3i(buffer, min);
    Vector3i max = min.add(settings.getSize());
    helper.writeVector3i(buffer, max);
    // Structure Settings end
    // Structure Editor Data end
    buffer.writeBoolean(editorData.isBoundingBoxVisible());
    buffer.writeBoolean(packet.isPowered());
}
Also used : Vector3i(com.nukkitx.math.vector.Vector3i)

Example 4 with Vector3i

use of com.nukkitx.math.vector.Vector3i in project Protocol by CloudburstMC.

the class BedrockPacketHelper_v440 method readStructureSettings.

@Override
public StructureSettings readStructureSettings(ByteBuf buffer) {
    String paletteName = this.readString(buffer);
    boolean ignoringEntities = buffer.readBoolean();
    boolean ignoringBlocks = buffer.readBoolean();
    Vector3i size = this.readBlockPosition(buffer);
    Vector3i offset = this.readBlockPosition(buffer);
    long lastEditedByEntityId = VarInts.readLong(buffer);
    StructureRotation rotation = StructureRotation.from(buffer.readByte());
    StructureMirror mirror = StructureMirror.from(buffer.readByte());
    StructureAnimationMode animationMode = StructureAnimationMode.from(buffer.readUnsignedByte());
    float animationSeconds = buffer.readFloatLE();
    float integrityValue = buffer.readFloatLE();
    int integritySeed = buffer.readIntLE();
    Vector3f pivot = this.readVector3f(buffer);
    return new StructureSettings(paletteName, ignoringEntities, ignoringBlocks, size, offset, lastEditedByEntityId, rotation, mirror, animationMode, animationSeconds, integrityValue, integritySeed, pivot);
}
Also used : StructureRotation(com.nukkitx.protocol.bedrock.data.structure.StructureRotation) Vector3f(com.nukkitx.math.vector.Vector3f) Vector3i(com.nukkitx.math.vector.Vector3i) StructureSettings(com.nukkitx.protocol.bedrock.data.structure.StructureSettings) StructureMirror(com.nukkitx.protocol.bedrock.data.structure.StructureMirror) StructureAnimationMode(com.nukkitx.protocol.bedrock.data.structure.StructureAnimationMode)

Example 5 with Vector3i

use of com.nukkitx.math.vector.Vector3i in project Protocol by CloudburstMC.

the class BedrockPacketHelper_v388 method readStructureSettings.

@Override
public StructureSettings readStructureSettings(ByteBuf buffer) {
    String paletteName = this.readString(buffer);
    boolean ignoringEntities = buffer.readBoolean();
    boolean ignoringBlocks = buffer.readBoolean();
    Vector3i size = this.readBlockPosition(buffer);
    Vector3i offset = this.readBlockPosition(buffer);
    long lastEditedByEntityId = VarInts.readLong(buffer);
    StructureRotation rotation = StructureRotation.from(buffer.readByte());
    StructureMirror mirror = StructureMirror.from(buffer.readByte());
    float integrityValue = buffer.readFloatLE();
    int integritySeed = buffer.readIntLE();
    Vector3f pivot = this.readVector3f(buffer);
    return new StructureSettings(paletteName, ignoringEntities, ignoringBlocks, size, offset, lastEditedByEntityId, rotation, mirror, StructureAnimationMode.NONE, 0, integrityValue, integritySeed, pivot);
}
Also used : StructureRotation(com.nukkitx.protocol.bedrock.data.structure.StructureRotation) Vector3f(com.nukkitx.math.vector.Vector3f) Vector3i(com.nukkitx.math.vector.Vector3i) StructureSettings(com.nukkitx.protocol.bedrock.data.structure.StructureSettings) StructureMirror(com.nukkitx.protocol.bedrock.data.structure.StructureMirror)

Aggregations

Vector3i (com.nukkitx.math.vector.Vector3i)25 UpdateBlockPacket (com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket)5 Vector3f (com.nukkitx.math.vector.Vector3f)4 Container (org.geysermc.geyser.inventory.Container)4 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)3 NbtMap (com.nukkitx.nbt.NbtMap)3 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)3 StructureMirror (com.nukkitx.protocol.bedrock.data.structure.StructureMirror)3 StructureRotation (com.nukkitx.protocol.bedrock.data.structure.StructureRotation)3 StructureSettings (com.nukkitx.protocol.bedrock.data.structure.StructureSettings)3 ItemFrameEntity (org.geysermc.geyser.entity.type.ItemFrameEntity)3 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)2 BlockEntityDataPacket (com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket)2 ContainerClosePacket (com.nukkitx.protocol.bedrock.packet.ContainerClosePacket)2 LevelChunkPacket (com.nukkitx.protocol.bedrock.packet.LevelChunkPacket)2 LevelSoundEventPacket (com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket)2 BitStorage (com.github.steveice10.mc.protocol.data.game.chunk.BitStorage)1 ChunkSection (com.github.steveice10.mc.protocol.data.game.chunk.ChunkSection)1 DataPalette (com.github.steveice10.mc.protocol.data.game.chunk.DataPalette)1 GlobalPalette (com.github.steveice10.mc.protocol.data.game.chunk.palette.GlobalPalette)1