Search in sources :

Example 1 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry 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 2 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class ItemBlockTranslator method swap.

private static void swap(int pcId, int peId, IItemDataTranslator translator) {
    PC_TO_PE_OVERRIDE.put(pcId, new ItemEntry(peId, null, translator));
    PE_TO_PC_OVERRIDE.put(peId, new ItemEntry(pcId, null, translator));
}
Also used : ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Example 3 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class ItemBlockTranslator method translateData.

private static void translateData(int id, IItemDataTranslator translator) {
    PC_TO_PE_OVERRIDE.put(id, new ItemEntry(id, null, translator));
    PE_TO_PC_OVERRIDE.put(id, new ItemEntry(id, null, translator));
}
Also used : ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Example 4 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class ItemBlockTranslator method translateSlotToPE.

public static Slot translateSlotToPE(ItemStack item) {
    if (item == null || item.getId() == 0)
        return null;
    Slot slot = new Slot();
    ItemEntry entry = translateToPE(item.getId(), item.getData());
    slot.id = entry.getId();
    slot.damage = entry.getPEDamage() != null ? entry.getPEDamage() : item.getData();
    slot.count = item.getAmount();
    slot.tag = translateItemNBT(item.getId(), item.getNBT(), null);
    return slot;
}
Also used : Slot(org.dragonet.common.data.inventory.Slot) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Example 5 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class ItemBlockTranslator method swap.

private static void swap(int pcId, ItemEntry toPe) {
    PC_TO_PE_OVERRIDE.put(pcId, toPe);
    PE_TO_PC_OVERRIDE.put(toPe.getId(), new ItemEntry(pcId));
}
Also used : ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Aggregations

ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)8 BlockPosition (org.dragonet.common.maths.BlockPosition)3 UpdateBlockPacket (org.dragonet.protocol.packets.UpdateBlockPacket)2 BlockStorage (com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage)1 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)1 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)1 ClientPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)1 ClientVehicleMovePacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Block (org.dragonet.common.data.blocks.Block)1 Slot (org.dragonet.common.data.inventory.Slot)1 CompoundTag (org.dragonet.common.data.nbt.tag.CompoundTag)1 ChunkPos (org.dragonet.common.maths.ChunkPos)1 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)1 Section (org.dragonet.protocol.type.chunk.Section)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1