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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations