Search in sources :

Example 6 with Notice

use of pl.asie.charset.lib.notify.Notice in project Charset by CharsetMC.

the class TileEntityDayBarrel method activate.

// *             Left-Click         Right-Click
// * No Shift:   Remove stack       Add item
// * Shift:      Remove 1 item      Use item
// * Double:                        Add all but 1 item
public boolean activate(EntityPlayer player, EnumFacing side, EnumHand hand) {
    if (lockable.hasLock())
        return false;
    ItemStack held = player.getHeldItem(hand);
    if (!world.isRemote && isNested(held) && (item.isEmpty() || itemMatch(held))) {
        new Notice(notice_target, new TextComponentTranslation("notice.charset.barrel.no")).sendTo(player);
        return true;
    }
    if (doubleClickHandler.isDoubleClick(player) && !item.isEmpty()) {
        addAllItems(player, hand);
        return true;
    }
    doubleClickHandler.markLastClick(player);
    // right click: put an item
    if (held.isEmpty()) {
        info(player);
        return true;
    }
    switch(insertFromItemHandler(player, false)) {
        case PASS:
            break;
        case SUCCESS:
            return true;
        case FAIL:
            info(player);
            return true;
    }
    if (!canInsert(held)) {
        info(player);
        return true;
    }
    boolean hadNoItem = item.isEmpty();
    int free = getMaxItemCount() - getItemCount();
    if (free <= 0) {
        info(player);
        return true;
    }
    int take = Math.min(free, held.getCount());
    if (take > 0) {
        ItemStack toInsert = held.copy();
        toInsert.setCount(take);
        ItemStack leftover = insertionView.insertItem(0, toInsert, false);
        take -= leftover.getCount();
        if (take > 0) {
            held.shrink(take);
            if (hadNoItem) {
                markBlockForUpdate();
            }
        } else {
            info(player);
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Notice(pl.asie.charset.lib.notify.Notice) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Notice (pl.asie.charset.lib.notify.Notice)6 ItemStack (net.minecraft.item.ItemStack)5 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)3 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 CauldronContents (pl.asie.charset.module.crafting.cauldron.api.CauldronContents)2 Nullable (javax.annotation.Nullable)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 Vec3d (net.minecraft.util.math.Vec3d)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 Capability (net.minecraftforge.common.capabilities.Capability)1 Constants (net.minecraftforge.common.util.Constants)1 CapabilityItemHandler (net.minecraftforge.items.CapabilityItemHandler)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1