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

The following examples show how to use com.nukkitx.math.vector.Vector3i#from() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: ItemFrameEntity.java    From Geyser with MIT License 5 votes vote down vote up
public ItemFrameEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, HangingDirection direction) {
    super(entityId, geyserId, entityType, position, motion, rotation);
    CompoundTagBuilder builder = CompoundTag.builder();
    builder.tag(CompoundTag.builder()
            .stringTag("name", "minecraft:frame")
            .intTag("version", BlockTranslator.getBlockStateVersion())
            .tag(CompoundTag.builder()
                    .intTag("facing_direction", direction.ordinal())
                    .byteTag("item_frame_map_bit", (byte) 0)
                    .build("states"))
            .build("block"));
    builder.shortTag("id", (short) 199);
    bedrockRuntimeId = BlockTranslator.getItemFrame(builder.buildRootTag());
    bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ());
}
 
Example 13
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 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 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 16
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 17
Source File: DimensionUtils.java    From Geyser with MIT License 5 votes vote down vote up
public static void switchDimension(GeyserSession session, int javaDimension) {
    int bedrockDimension = javaToBedrock(javaDimension);
    Entity player = session.getPlayerEntity();
    if (bedrockDimension == player.getDimension())
        return;

    session.getEntityCache().removeAllEntities();
    session.getItemFrameCache().clear();
    if (session.getPendingDimSwitches().getAndIncrement() > 0) {
        ChunkUtils.sendEmptyChunks(session, player.getPosition().toInt(), 3, true);
    }

    Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0);

    ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
    changeDimensionPacket.setDimension(bedrockDimension);
    changeDimensionPacket.setRespawn(true);
    changeDimensionPacket.setPosition(pos.toFloat());
    session.sendUpstreamPacket(changeDimensionPacket);
    player.setDimension(bedrockDimension);
    player.setPosition(pos.toFloat());
    session.setSpawned(false);
    session.setLastChunkPosition(null);

    for (Effect effect : session.getPlayerEntity().getEffectCache().getEntityEffects().keySet()) {
        MobEffectPacket mobEffectPacket = new MobEffectPacket();
        mobEffectPacket.setEvent(MobEffectPacket.Event.REMOVE);
        mobEffectPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
        mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(effect));
        session.sendUpstreamPacket(mobEffectPacket);
    }
    // Effects are re-sent from server
    session.getPlayerEntity().getEffectCache().getEntityEffects().clear();

    //let java server handle portal travel sound
    StopSoundPacket stopSoundPacket = new StopSoundPacket();
    stopSoundPacket.setStoppingAllSound(true);
    stopSoundPacket.setSoundName("");
    session.sendUpstreamPacket(stopSoundPacket);
}
 
Example 18
Source File: BedrockItemFrameDropItemTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ItemFrameDropItemPacket packet, GeyserSession session) {
    // I hope that, when we die, God (or whoever is waiting for us) tells us exactly why this code exists
    // The packet sends the Y coordinate (and just the Y coordinate) divided by two, and it's negative if it needs to be subtracted by one
    int y;
    if (packet.getBlockPosition().getY() > 0) {
        y = packet.getBlockPosition().getY() * 2;
    } else {
        y = (packet.getBlockPosition().getY() * -2) - 1;
    }
    Vector3i position = Vector3i.from(packet.getBlockPosition().getX(), y, packet.getBlockPosition().getZ());
    ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) ItemFrameEntity.getItemFrameEntityId(session, position),
            InteractAction.ATTACK, Hand.MAIN_HAND);
    session.sendDownstreamPacket(interactPacket);
}
 
Example 19
Source File: ChunkUtils.java    From Geyser with MIT License 4 votes vote down vote up
public static void updateBlock(GeyserSession session, BlockState blockState, Position position) {
    Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ());
    updateBlock(session, blockState, pos);
}
 
Example 20
Source File: JavaBlockValueTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void translate(ServerBlockValuePacket packet, GeyserSession session) {
    BlockEventPacket blockEventPacket = new BlockEventPacket();
    blockEventPacket.setBlockPosition(Vector3i.from(packet.getPosition().getX(),
            packet.getPosition().getY(), packet.getPosition().getZ()));
    if (packet.getValue() instanceof ChestValue) {
        ChestValue value = (ChestValue) packet.getValue() ;
        blockEventPacket.setEventType(1);
        blockEventPacket.setEventData(value.getViewers() > 0 ? 1 : 0);
        session.sendUpstreamPacket(blockEventPacket);
    }
    if (packet.getValue() instanceof EndGatewayValue) {
        blockEventPacket.setEventType(1);
        session.sendUpstreamPacket(blockEventPacket);
    }
    if (packet.getValue() instanceof NoteBlockValue) {
        NoteblockBlockEntityTranslator.translate(session, packet.getPosition());
        return;
    }
    if (packet.getValue() instanceof PistonValue) {
        PistonValueType type = (PistonValueType) packet.getType();

        // Unlike everything else, pistons need a block entity packet to convey motion
        // TODO: Doesn't register on chunk load; needs to be interacted with first
        Vector3i position = Vector3i.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
        if (type == PistonValueType.PUSHING) {
            extendPiston(session, position, 0.0f, 0.0f);
        } else {
            retractPiston(session, position, 1.0f, 1.0f);
        }
    }
    if (packet.getValue() instanceof BeaconValue) {
        blockEventPacket.setEventType(1);
        session.sendUpstreamPacket(blockEventPacket);
    }
    if (packet.getValue() instanceof MobSpawnerValue) {
        blockEventPacket.setEventType(1);
        session.sendUpstreamPacket(blockEventPacket);
    }
    if (packet.getValue() instanceof EndGatewayValue) {
        blockEventPacket.setEventType(1);
        session.sendUpstreamPacket(blockEventPacket);
    }
}