Search in sources :

Example 11 with BlockPosition

use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.

the class PCUpdateTileEntityPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerUpdateTileEntityPacket packet) {
    BlockEntityDataPacket data = new BlockEntityDataPacket();
    data.blockPosition = new BlockPosition(packet.getPosition());
    data.tag = ItemBlockTranslator.translateBlockEntityToPE(packet.getNBT());
    return new PEPacket[] { data };
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) BlockEntityDataPacket(org.dragonet.protocol.packets.BlockEntityDataPacket)

Example 12 with BlockPosition

use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.

the class PEMovePlayerPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, MovePlayerPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.riding != 0 && packet.ridingRuntimeId != 0) {
        // Riding case
        ClientVehicleMovePacket pk = new ClientVehicleMovePacket(packet.position.x, packet.position.y - EntityType.PLAYER.getOffset(), packet.position.z, packet.yaw, packet.pitch);
        session.getDownstream().send(pk);
    } else {
        // not riding
        ClientPlayerPositionRotationPacket pk = new ClientPlayerPositionRotationPacket(packet.onGround, packet.position.x, // To simplify the movements
        ceilToHalf(packet.position.y - EntityType.PLAYER.getOffset()), packet.position.z, packet.yaw, packet.pitch);
        // Special blocks handling
        boolean isColliding = false;
        BlockPosition blockPos = new BlockPosition(NukkitMath.floorDouble(packet.position.x), NukkitMath.floorDouble(packet.position.y), NukkitMath.floorDouble(packet.position.z));
        // System.out.println("block " + blockPos.toString());
        try {
            ItemEntry PEBlock = session.getChunkCache().translateBlock(blockPos.asPosition());
            if (PEBlock != null) {
                Block b = Block.get(PEBlock.getId(), PEBlock.getPEDamage(), blockPos);
                if (b != null && b.collidesWithBB(session.getEntityCache().getClientEntity().boundingBox.clone())) {
                    DragonProxy.getInstance().getLogger().info("Player position : " + entity.x + ", " + entity.y + ", " + entity.z + " collide with " + b.getClass().getSimpleName() + " on " + blockPos.toString());
                    isColliding = true;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        entity.absoluteMove(pk.getX(), pk.getY(), pk.getZ(), (float) pk.getYaw(), (float) pk.getPitch());
        if (!isColliding) {
            session.getDownstream().send(pk);
            session.getChunkCache().sendOrderedChunks();
        }
    }
    return null;
}
Also used : ClientVehicleMovePacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) ClientPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket) Block(org.dragonet.common.data.blocks.Block) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Example 13 with BlockPosition

use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.

the class ChestWindowTranslator method open.

public boolean open(UpstreamSession session, CachedWindow window) {
    BlockPosition pos = new BlockPosition((int) session.getEntityCache().getClientEntity().x, (int) session.getEntityCache().getClientEntity().y - 4, (int) session.getEntityCache().getClientEntity().z);
    ContainerOpenPacket pk = new ContainerOpenPacket();
    pk.windowId = window.windowId;
    pk.type = 0;
    pk.position = pos;
    session.putCachePacket(pk);
    // System.out.println("ChestWindowTranslator.open " + window.windowId);
    return true;
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition)

Example 14 with BlockPosition

use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.

the class PCMultiBlockChangePacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerMultiBlockChangePacket packet) {
    UpdateBlockPacket[] packets = new UpdateBlockPacket[packet.getRecords().length];
    // int generalFlag = packet.getRecords().length > 64 ? UpdateBlockPacket.FLAG_ALL_PRIORITY : UpdateBlockPacket.FLAG_NEIGHBORS;
    for (int i = 0; i < packets.length; i++) {
        // update cache
        session.getChunkCache().update(packet.getRecords()[i].getPosition(), packet.getRecords()[i].getBlock());
        packets[i] = new UpdateBlockPacket();
        packets[i].blockPosition = new BlockPosition(packet.getRecords()[i].getPosition().getX(), packet.getRecords()[i].getPosition().getY(), packet.getRecords()[i].getPosition().getZ());
        ItemEntry entry = session.getChunkCache().translateBlock(packet.getRecords()[i].getPosition());
        packets[i].id = entry.getId();
        packets[i].flags = UpdateBlockPacket.FLAG_NEIGHBORS;
        packets[i].data = entry.getPEDamage();
    // Save glitchy items in cache
    // Position blockPosition = new Position(packets[i].blockPosition.x, packets[i].blockPosition.y, packets[i].blockPosition.z);
    }
    return packets;
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) UpdateBlockPacket(org.dragonet.protocol.packets.UpdateBlockPacket) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Example 15 with BlockPosition

use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.

the class ExplodePacket method encodePayload.

@Override
public void encodePayload() {
    putVector3F(this.position);
    putFloat(this.radius);
    putUnsignedVarInt(this.destroyedBlocks.size());
    for (BlockPosition position : this.destroyedBlocks) putBlockPosition(position);
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition)

Aggregations

BlockPosition (org.dragonet.common.maths.BlockPosition)22 Vector3F (org.dragonet.common.maths.Vector3F)5 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)5 ChunkPos (org.dragonet.common.maths.ChunkPos)4 PEPacket (org.dragonet.protocol.PEPacket)4 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)3 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)3 ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)3 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)2 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)2 ArrayList (java.util.ArrayList)2 ByteArrayMeta (org.dragonet.common.data.entity.meta.type.ByteArrayMeta)2 SlotMeta (org.dragonet.common.data.entity.meta.type.SlotMeta)2 UpdateBlockPacket (org.dragonet.protocol.packets.UpdateBlockPacket)2 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)2 Section (org.dragonet.protocol.type.chunk.Section)2 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 AuthenticationService (com.github.steveice10.mc.auth.service.AuthenticationService)1 MinecraftProtocol (com.github.steveice10.mc.protocol.MinecraftProtocol)1 EntityMetadata (com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata)1