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

The following examples show how to use com.nukkitx.math.vector.Vector3i#getZ() . 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: 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 2
Source File: JavaBlockChangeTranslator.java    From Geyser with MIT License 5 votes vote down vote up
private boolean checkPlace(GeyserSession session, ServerBlockChangePacket packet) {
    Vector3i lastPlacePos = session.getLastBlockPlacePosition();
    if (lastPlacePos == null) {
        return false;
    }
    if ((lastPlacePos.getX() != packet.getRecord().getPosition().getX()
            || lastPlacePos.getY() != packet.getRecord().getPosition().getY()
            || lastPlacePos.getZ() != packet.getRecord().getPosition().getZ())) {
        return false;
    }

    // We need to check if the identifier is the same, else a packet with the sound of what the
    // player has in their hand is played, despite if the block is being placed or not
    boolean contains = false;
    String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(packet.getRecord().getBlock()).split("\\[")[0];
    if (identifier.equals(session.getLastBlockPlacedId())) {
        contains = true;
    }

    if (!contains) {
        session.setLastBlockPlacePosition(null);
        session.setLastBlockPlacedId(null);
        return false;
    }

    // This is not sent from the server, so we need to send it this way
    LevelSoundEventPacket placeBlockSoundPacket = new LevelSoundEventPacket();
    placeBlockSoundPacket.setSound(SoundEvent.PLACE);
    placeBlockSoundPacket.setPosition(lastPlacePos.toFloat());
    placeBlockSoundPacket.setBabySound(false);
    placeBlockSoundPacket.setExtraData(BlockTranslator.getBedrockBlockId(packet.getRecord().getBlock()));
    placeBlockSoundPacket.setIdentifier(":");
    session.sendUpstreamPacket(placeBlockSoundPacket);
    session.setLastBlockPlacePosition(null);
    session.setLastBlockPlacedId(null);
    return true;
}
 
Example 3
Source File: JavaBlockChangeTranslator.java    From Geyser with MIT License 5 votes vote down vote up
private void checkInteract(GeyserSession session, ServerBlockChangePacket packet) {
    Vector3i lastInteractPos = session.getLastInteractionPosition();
    if (lastInteractPos == null || !session.isInteracting()) {
        return;
    }
    if ((lastInteractPos.getX() != packet.getRecord().getPosition().getX()
            || lastInteractPos.getY() != packet.getRecord().getPosition().getY()
            || lastInteractPos.getZ() != packet.getRecord().getPosition().getZ())) {
        return;
    }
    String identifier = BlockTranslator.getJavaIdBlockMap().inverse().get(packet.getRecord().getBlock());
    session.setInteracting(false);
    BlockSoundInteractionHandler.handleBlockInteraction(session, lastInteractPos.toFloat(), identifier);
}
 
Example 4
Source File: BlockInventoryHolder.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void closeInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
    Vector3i holderPos = inventory.getHolderPosition();
    Position pos = new Position(holderPos.getX(), holderPos.getY(), holderPos.getZ());
    BlockState realBlock = session.getConnector().getWorldManager().getBlockAt(session, pos.getX(), pos.getY(), pos.getZ());
    UpdateBlockPacket blockPacket = new UpdateBlockPacket();
    blockPacket.setDataLayer(0);
    blockPacket.setBlockPosition(holderPos);
    blockPacket.setRuntimeId(BlockTranslator.getBedrockBlockId(realBlock));
    session.sendUpstreamPacket(blockPacket);
}
 
Example 5
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 6
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 7
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 8
Source File: MoveEntityDeltaSerializer_v313.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 9
Source File: MoveEntityDeltaSerializer_v361.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 10
Source File: MoveEntityDeltaSerializer_v332.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 11
Source File: MoveEntityDeltaSerializer_v291.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: BedrockActionTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void translate(PlayerActionPacket packet, GeyserSession session) {
    Entity entity = session.getPlayerEntity();
    if (entity == null)
        return;

    Vector3i vector = packet.getBlockPosition();
    Position position = new Position(vector.getX(), vector.getY(), vector.getZ());

    switch (packet.getAction()) {
        case RESPAWN:
            // Don't put anything here as respawn is already handled
            // in BedrockRespawnTranslator
            break;
        case START_SWIMMING:
            ClientPlayerStatePacket startSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
            session.sendDownstreamPacket(startSwimPacket);
            break;
        case STOP_SWIMMING:
            ClientPlayerStatePacket stopSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
            session.sendDownstreamPacket(stopSwimPacket);
            break;
        case START_GLIDE:
        case STOP_GLIDE:
            ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
            session.sendDownstreamPacket(glidePacket);
            break;
        case START_SNEAK:
            ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
            session.sendDownstreamPacket(startSneakPacket);
            session.setSneaking(true);
            break;
        case STOP_SNEAK:
            ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
            session.sendDownstreamPacket(stopSneakPacket);
            session.setSneaking(false);
            break;
        case START_SPRINT:
            ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
            session.sendDownstreamPacket(startSprintPacket);
            session.setSprinting(true);
            break;
        case STOP_SPRINT:
            ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
            session.sendDownstreamPacket(stopSprintPacket);
            session.setSprinting(false);
            break;
        case DROP_ITEM:
            ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
            session.sendDownstreamPacket(dropItemPacket);
            break;
        case STOP_SLEEP:
            ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.LEAVE_BED);
            session.sendDownstreamPacket(stopSleepingPacket);
            break;
        case BLOCK_INTERACT:
            // Handled in BedrockInventoryTransactionTranslator
            break;
        case START_BREAK:
            ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
                    packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
            session.sendDownstreamPacket(startBreakingPacket);
            break;
        case CONTINUE_BREAK:
            LevelEventPacket continueBreakPacket = new LevelEventPacket();
            continueBreakPacket.setType(LevelEventType.PUNCH_BLOCK);
            continueBreakPacket.setData(BlockTranslator.getBedrockBlockId(session.getBreakingBlock() == null ? BlockTranslator.AIR : session.getBreakingBlock()));
            continueBreakPacket.setPosition(packet.getBlockPosition().toFloat());
            session.sendUpstreamPacket(continueBreakPacket);
            break;
        case ABORT_BREAK:
            ClientPlayerActionPacket abortBreakingPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, new Position(packet.getBlockPosition().getX(),
                    packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.DOWN);
            session.sendDownstreamPacket(abortBreakingPacket);
            break;
        case STOP_BREAK:
            // Handled in BedrockInventoryTransactionTranslator
            break;
        case DIMENSION_CHANGE_SUCCESS:
            if (session.getPendingDimSwitches().decrementAndGet() == 0) {
                //sometimes the client doesn't feel like loading
                PlayStatusPacket spawnPacket = new PlayStatusPacket();
                spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
                session.sendUpstreamPacket(spawnPacket);
                entity.updateBedrockAttributes(session);
                session.getEntityCache().updateBossBars();
            }
            break;
        case JUMP:
            session.setJumping(true);
            session.getConnector().getGeneralThreadPool().schedule(() -> {
                session.setJumping(false);
            }, 1, TimeUnit.SECONDS);
            break;
    }
}