Search in sources :

Example 41 with Nonnull

use of javax.annotation.Nonnull in project Railcraft by Railcraft.

the class InvTools method findMatchingItems.

/**
     * Returns all items from the inventory that match the
     * filter, but does not remove them.
     * The resulting set will be populated with a single instance of each item type.
     *
     * @param inv    the inventory    The inventory
     * @param filter EnumItemType to match against
     * @return A Set of ItemStacks
     */
@Nonnull
public static Set<StackKey> findMatchingItems(IInventoryComposite inv, Predicate<ItemStack> filter) {
    Set<StackKey> items = CollectionTools.createItemStackSet();
    for (IInventoryObject inventoryObject : inv) {
        for (IInvSlot slot : InventoryIterator.getRailcraft(inventoryObject)) {
            ItemStack stack = slot.getStack();
            if (!isEmpty(stack) && filter.test(stack)) {
                stack = stack.copy();
                stack.stackSize = 1;
                items.add(StackKey.make(stack));
            }
        }
    }
    return items;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) StackKey(mods.railcraft.common.util.collections.StackKey) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 42 with Nonnull

use of javax.annotation.Nonnull in project Overloaded by CJ-MC-Mods.

the class ItemEnergyShield method onItemUse.

@Override
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        System.out.println("On Item Use");
        IHyperHandlerEnergy handler = player.getHeldItem(hand).getCapability(HYPER_ENERGY_HANDLER, null);
        LongEnergyStack energy = handler.take(new LongEnergyStack(constantUseCost), true);
        if (energy.amount == constantUseCost) {
            System.out.println("On Item Use Success");
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.PASS;
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.LongEnergyStack) IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy) Nonnull(javax.annotation.Nonnull)

Example 43 with Nonnull

use of javax.annotation.Nonnull in project Overloaded by CJ-MC-Mods.

the class AbstractBlockInfiniteContainer method getDrops.

@Override
@Nonnull
public final List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune) {
    IHyperType stack = getHyperStack(world, pos);
    if (stack != null && stack.getAmount() != 0) {
        ItemStack toDrop = new ItemStack(this, 1);
        NBTTagCompound compound = new NBTTagCompound();
        world.getTileEntity(pos).writeToNBT(compound);
        toDrop.setTagCompound(compound);
        return Collections.singletonList(toDrop);
    }
    return super.getDrops(world, pos, state, fortune);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IHyperType(com.cjm721.overloaded.storage.IHyperType) Nonnull(javax.annotation.Nonnull)

Example 44 with Nonnull

use of javax.annotation.Nonnull in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method breakAndUseEnergy.

/**
     * @return True if the break was successful, false otherwise
     */
@Nonnull
private BlockResult breakAndUseEnergy(@Nonnull World worldIn, @Nonnull BlockPos blockPos, @Nonnull IEnergyStorage energy, EntityPlayerMP player, int efficiency, int unbreaking) {
    IBlockState state = worldIn.getBlockState(blockPos);
    if (!player.capabilities.isCreativeMode) {
        float hardness = state.getBlockHardness(worldIn, blockPos);
        if (hardness < 0) {
            return BlockResult.FAIL_UNBREAKABLE;
        }
        float floatBreakCost = getBreakCost(hardness, efficiency, unbreaking, getDistance(player, blockPos));
        if (Float.isInfinite(floatBreakCost) || Float.isNaN(floatBreakCost))
            return BlockResult.FAIL_ENERGY;
        int breakCost = Math.round(floatBreakCost);
        if (breakCost < 0 || energy.getEnergyStored() < breakCost) {
            return BlockResult.FAIL_ENERGY;
        }
    }
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldIn, blockPos, state, player);
    MinecraftForge.EVENT_BUS.post(event);
    if (event.isCanceled())
        return BlockResult.FAIL_REMOVE;
    boolean result = PlayerInteractionUtil.tryHarvestBlock(player, worldIn, blockPos);
    return result ? BlockResult.SUCCESS : BlockResult.FAIL_REMOVE;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockEvent(net.minecraftforge.event.world.BlockEvent) Nonnull(javax.annotation.Nonnull)

Example 45 with Nonnull

use of javax.annotation.Nonnull in project Overloaded by CJ-MC-Mods.

the class LongItemStorage method take.

@Nonnull
@Override
public LongItemStack take(@Nonnull LongItemStack stack, boolean doAction) {
    if (longItemStack.getItemStack() == null)
        return LongItemStack.EMPTY_STACK;
    long result = Math.min(stack.getAmount(), longItemStack.getAmount());
    LongItemStack toReturn = new LongItemStack(longItemStack.getItemStack(), result);
    if (doAction) {
        longItemStack.removeAmount(result);
        if (longItemStack.getAmount() == 0L)
            longItemStack.setItemStack(ItemStack.EMPTY);
    }
    return toReturn;
}
Also used : LongItemStack(com.cjm721.overloaded.storage.LongItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)2624 Nullable (javax.annotation.Nullable)338 ArrayList (java.util.ArrayList)336 ItemStack (net.minecraft.item.ItemStack)327 List (java.util.List)305 Map (java.util.Map)229 Layer (com.simiacryptus.mindseye.lang.Layer)188 Tensor (com.simiacryptus.mindseye.lang.Tensor)185 Arrays (java.util.Arrays)182 Collectors (java.util.stream.Collectors)169 IOException (java.io.IOException)165 JsonObject (com.google.gson.JsonObject)156 HashMap (java.util.HashMap)145 IntStream (java.util.stream.IntStream)145 Test (org.junit.Test)143 LoggerFactory (org.slf4j.LoggerFactory)138 Logger (org.slf4j.Logger)137 Result (com.simiacryptus.mindseye.lang.Result)130 TensorList (com.simiacryptus.mindseye.lang.TensorList)123 DeltaSet (com.simiacryptus.mindseye.lang.DeltaSet)111