Search in sources :

Example 1 with MessageContainerSeedStorage

use of com.infinityraider.agricraft.network.MessageContainerSeedStorage in project AgriCraft by AgriCraft.

the class ContainerSeedStorageBase method moveStackFromTileEntityToPlayer.

/**
     * Tries to move an item stack form the correct tile entity to the player's
     * inventory
     */
public void moveStackFromTileEntityToPlayer(int slotId, ItemStack stack) {
    ISeedStorageControllable controllable = this.getControllable(stack).orElse(null);
    if (controllable == null) {
        return;
    }
    ItemStack stackToMove = controllable.getStackForSlotId(slotId);
    if (stack == null) {
        return;
    }
    if (stackToMove == null || stackToMove.getItem() == null) {
        return;
    }
    stackToMove.stackSize = stack.stackSize > stackToMove.stackSize ? stackToMove.stackSize : stack.stackSize;
    stackToMove.setTagCompound(controllable.getStackForSlotId(slotId).getTagCompound());
    if (this.mergeItemStack(stackToMove, 0, PLAYER_INVENTORY_SIZE, false)) {
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
            //this method is only called form the gui client side, so we need to manually tell the server to execute it there
            new MessageContainerSeedStorage(stack, slotId).sendToServer();
        } else {
            //on the server decrease the size of the stack, where it is synced to the client
            controllable.decreaseStackSizeInSlot(slotId, stack.stackSize - stackToMove.stackSize);
        }
    }
}
Also used : ISeedStorageControllable(com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable) MessageContainerSeedStorage(com.infinityraider.agricraft.network.MessageContainerSeedStorage) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MessageContainerSeedStorage (com.infinityraider.agricraft.network.MessageContainerSeedStorage)1 ISeedStorageControllable (com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable)1 ItemStack (net.minecraft.item.ItemStack)1