Search in sources :

Example 1 with InventoryTransactionAction

use of org.dragonet.protocol.type.transaction.InventoryTransactionAction in project DragonProxy by DragonetMC.

the class InventoryTransactionPacket method encodePayload.

@Override
public void encodePayload() {
    this.reset();
    this.putUnsignedVarInt(this.transactionType);
    this.putUnsignedVarInt(this.actions.length);
    for (InventoryTransactionAction action : this.actions) {
        action.write(this);
    }
    switch(this.transactionType) {
        case TYPE_NORMAL:
        case TYPE_MISMATCH:
            break;
        case TYPE_USE_ITEM:
            UseItemData useItemData = (UseItemData) this.transactionData;
            this.putUnsignedVarInt(useItemData.actionType);
            this.putBlockPosition(useItemData.blockPos);
            this.putVarInt(useItemData.face);
            this.putVarInt(useItemData.hotbarSlot);
            this.putSlot(useItemData.itemInHand);
            // TODO check
            this.putVector3F(useItemData.playerPos);
            this.putVector3F(useItemData.clickPos);
            break;
        case TYPE_USE_ITEM_ON_ENTITY:
            UseItemOnEntityData useItemOnEntityData = (UseItemOnEntityData) this.transactionData;
            this.putEntityRuntimeId(useItemOnEntityData.entityRuntimeId);
            this.putUnsignedVarInt(useItemOnEntityData.actionType);
            this.putVarInt(useItemOnEntityData.hotbarSlot);
            this.putSlot(useItemOnEntityData.itemInHand);
            this.putVector3F(useItemOnEntityData.playerPos);
            this.putVector3F(useItemOnEntityData.clickPos);
            break;
        case TYPE_RELEASE_ITEM:
            ReleaseItemData releaseItemData = (ReleaseItemData) this.transactionData;
            this.putUnsignedVarInt(releaseItemData.actionType);
            this.putVarInt(releaseItemData.hotbarSlot);
            this.putSlot(releaseItemData.itemInHand);
            this.putVector3F(releaseItemData.headRot);
            break;
        default:
            throw new RuntimeException("Unknown transaction type " + this.transactionType);
    }
}
Also used : ReleaseItemData(org.dragonet.protocol.type.transaction.data.ReleaseItemData) InventoryTransactionAction(org.dragonet.protocol.type.transaction.InventoryTransactionAction) UseItemData(org.dragonet.protocol.type.transaction.data.UseItemData) UseItemOnEntityData(org.dragonet.protocol.type.transaction.data.UseItemOnEntityData)

Example 2 with InventoryTransactionAction

use of org.dragonet.protocol.type.transaction.InventoryTransactionAction in project DragonProxy by DragonetMC.

the class InventoryTransactionPacket method decodePayload.

@Override
public void decodePayload() {
    this.transactionType = (int) this.getUnsignedVarInt();
    this.actions = new InventoryTransactionAction[(int) this.getUnsignedVarInt()];
    for (int i = 0; i < this.actions.length; i++) {
        this.actions[i] = new InventoryTransactionAction().read(this);
    }
    switch(this.transactionType) {
        case TYPE_NORMAL:
        case TYPE_MISMATCH:
            // Regular ComplexInventoryTransaction doesn't read any extra data
            break;
        case TYPE_USE_ITEM:
            UseItemData itemData = new UseItemData();
            itemData.actionType = (int) this.getUnsignedVarInt();
            itemData.blockPos = this.getBlockPosition();
            itemData.face = this.getVarInt();
            itemData.hotbarSlot = this.getVarInt();
            itemData.itemInHand = this.getSlot();
            itemData.playerPos = this.getVector3F();
            itemData.clickPos = this.getVector3F();
            this.transactionData = itemData;
            break;
        case TYPE_USE_ITEM_ON_ENTITY:
            UseItemOnEntityData useItemOnEntityData = new UseItemOnEntityData();
            useItemOnEntityData.entityRuntimeId = this.getEntityRuntimeId();
            useItemOnEntityData.actionType = (int) this.getUnsignedVarInt();
            useItemOnEntityData.hotbarSlot = this.getVarInt();
            useItemOnEntityData.itemInHand = this.getSlot();
            useItemOnEntityData.playerPos = this.getVector3F();
            useItemOnEntityData.clickPos = this.getVector3F();
            this.transactionData = useItemOnEntityData;
            break;
        case TYPE_RELEASE_ITEM:
            ReleaseItemData releaseItemData = new ReleaseItemData();
            releaseItemData.actionType = (int) getUnsignedVarInt();
            releaseItemData.hotbarSlot = getVarInt();
            releaseItemData.itemInHand = getSlot();
            releaseItemData.headRot = this.getVector3F();
            this.transactionData = releaseItemData;
            break;
        default:
            throw new RuntimeException("Unknown transaction type " + this.transactionType);
    }
}
Also used : ReleaseItemData(org.dragonet.protocol.type.transaction.data.ReleaseItemData) InventoryTransactionAction(org.dragonet.protocol.type.transaction.InventoryTransactionAction) UseItemData(org.dragonet.protocol.type.transaction.data.UseItemData) UseItemOnEntityData(org.dragonet.protocol.type.transaction.data.UseItemOnEntityData)

Aggregations

InventoryTransactionAction (org.dragonet.protocol.type.transaction.InventoryTransactionAction)2 ReleaseItemData (org.dragonet.protocol.type.transaction.data.ReleaseItemData)2 UseItemData (org.dragonet.protocol.type.transaction.data.UseItemData)2 UseItemOnEntityData (org.dragonet.protocol.type.transaction.data.UseItemOnEntityData)2