本文整理汇总了Java中net.minecraftforge.items.IItemHandler.extractItem方法的典型用法代码示例。如果您正苦于以下问题:Java IItemHandler.extractItem方法的具体用法?Java IItemHandler.extractItem怎么用?Java IItemHandler.extractItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.items.IItemHandler
的用法示例。
在下文中一共展示了IItemHandler.extractItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transferOneItem
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
/**
* Returns true if succeeded
* @param input
* @param output
* @return
*/
public static boolean transferOneItem(IItemHandler input, IItemHandler output){
if(input == null || output == null) return false;
for(int i = 0; i < input.getSlots(); i++){
ItemStack extracted = input.extractItem(i, 1, true);
if(!extracted.isEmpty()){
if(ItemHandlerHelper.insertItemStacked(output, extracted, false).isEmpty()){
input.extractItem(i, 1, false);
return true;
}
}
}
return false;
}
示例2: tryCookSlot
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private boolean tryCookSlot(IItemHandler handler, int slot) {
ItemStack stack = handler.getStackInSlot(slot);
if (!stack.isEmpty()) {
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (!result.isEmpty()) {
ItemStack remainder = IOHelper.insert(getTileEntity(), result, true);
if (remainder.isEmpty()) {
IOHelper.insert(getTileEntity(), result, false);
handler.extractItem(slot, 1, false);
lastValidSlot = slot;
return true;
}
}
}
return false;
}
示例3: dropItems
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void dropItems() {
if(world.getTotalWorldTime() % 10 != 0) return;
applyGravity(repulse, false);
IItemHandler handler = from.getKey();
ISidedInventory sidedInv = from.getValue();
Vector3 spawn = Vector3.create(getPos()).add(0.5D).offset(getFacingLazy(), 1);
for(int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack inSlot = handler.getStackInSlot(slot);
if(!inSlot.isEmpty()
&& (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot))
&& (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x, spawn.y, spawn.z, out);
impulseEntityItem(spawn, entity);
world.spawnEntity(entity);
break;
}
}
}
示例4: transferOut
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private ItemStack transferOut(BlockPos pos, boolean test) {
EnumFacing facing = getFacing().getOpposite();
Pair<IItemHandler, ISidedInventory> inv = getInventory(pos, facing);
if(inv.getKey() != null) {
IItemHandler handler = inv.getKey();
ISidedInventory tile = inv.getValue();
for(int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack in = handler.getStackInSlot(slot);
if(!in.isEmpty() && (tile == null || tile.canExtractItem(slot, in, facing))) {
return handler.extractItem(slot, Integer.MAX_VALUE, test);
}
}
}
return ItemStack.EMPTY;
}
示例5: work
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void work()
{
for(EnumFacing facing : checkFaces)
{
TileEntity tile = world.getTileEntity(pos.offset(facing));
if(tile != null)
{
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()))
{
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
ItemStack outStack = ItemStack.EMPTY;
for(int i = 0; i < handler.getSlots(); i++)
{
outStack = handler.extractItem(i, handler.getStackInSlot(i).getCount(), false);
if(!outStack.isEmpty())
{
break;
}
}
ItemStack remain = addItem(outStack);
ItemHandlerHelper.insertItem(handler, remain ,false);
}
}
}
}
示例6: apply
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
/** Applies the recipe to the storage provided, determining whether or not the output should be produced. Optionally
* consumes the items.
*/
public boolean apply(FluidTank tank, IItemHandler inventory, boolean consume) {
if (consume && !apply(tank, inventory, false)) return false; //Always dry-run before destructive ops
if (tank.getFluid()==null) return false;
//Next line shouldn't happen but it pays to plan for the impossible
if (tank.getFluid().getFluid() != FluidRegistry.WATER) return false;
if (tank.getFluidAmount()<water) return false;
FluidStack fluidExtracted = tank.drainInternal(water, consume);
if (fluidExtracted.amount<water) return false;
int remaining = count;
for(int i=0; i<inventory.getSlots(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack.isEmpty()) continue;
if (item.apply(stack)) {
ItemStack extracted = inventory.extractItem(i, remaining, !consume);
if (extracted.isEmpty()) continue;
remaining -= extracted.getCount();
}
}
return remaining<=0;
}
示例7: doDisarm
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void doDisarm(EntityLiving entity, Random rand, IItemHandler handler, float[] dropChances) {
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
boolean flag1 = dropChances[i] > 1.0F;
if (!stack.isEmpty() && rand.nextFloat() < dropChances[i]) {
if (!flag1 && stack.isItemStackDamageable()) {
int k = Math.max(stack.getMaxDamage() - 25, 1);
int l = stack.getMaxDamage() - rand.nextInt(rand.nextInt(k) + 1);
stack.setItemDamage(MathHelper.clamp(l, 1, k));
}
entity.entityDropItem(stack, 0f);
}
handler.extractItem(i, stack.getCount(), false);
}
}
示例8: extractOneItem
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Nonnull
public static LocatedItemStack extractOneItem(IItemHandler handler, boolean simulate) {
if (handler != null) {
for (int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack stack = handler.getStackInSlot(slot);
if (stack.getCount() > 0) {
ItemStack ret = handler.extractItem(slot, 1, simulate);
return new LocatedItemStack(ret, slot);
}
}
}
return LocatedItemStack.NONE;
}
示例9: doImport
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
protected boolean doImport(int maxItems) {
boolean success = false;
// Suck from input inventory
IItemHandler handler = IOHelper.getInventoryForTE(IOHelper.getNeighbor(this, inputDir));
if (handler != null) {
for (int i = 0; i < maxItems; i++) {
LocatedItemStack extracted = IOHelper.extractOneItem(handler, true);
if (!extracted.stack.isEmpty()) {
ItemStack excess = ItemHandlerHelper.insertItem(inventory, extracted.stack, false);
if (excess.isEmpty()) {
handler.extractItem(extracted.slot, 1, false);
success = true;
} else {
break;
}
} else {
break;
}
}
}
// Suck in item entities
for (EntityItem entity : getNeighborItems(this, inputDir)) {
if (!entity.isDead) {
ItemStack remainder = IOHelper.insert(this, entity.getItem(), null, false);
if (remainder.isEmpty()) {
entity.setDead();
success = true;
}
}
}
return success;
}
示例10: fetchFromInventory
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void fetchFromInventory(BlockPos pos, Predicate<ItemStack> matcher, int maxAmount) {
materialChest = pos;
World world = entity.getEntityWorld();
if (!InventoryTools.isInventory(world, pos)) {
// No longer an inventory. We cannot get the items from here
return;
}
TileEntity te = world.getTileEntity(pos);
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
for (int i = 0; i < handler.getSlots(); i++) {
if (maxAmount <= 0) {
return;
}
ItemStack stack = handler.getStackInSlot(i);
if (stack == null) {
// There are still bad mods!
String badBlock = world.getBlockState(pos).getBlock().getRegistryName().toString();
MeeCreeps.logger.warn("Block " + badBlock + " is returning null for handler.getStackInSlot()! That's a bug!");
} else if (!stack.isEmpty() && matcher.test(stack)) {
ItemStack extracted = handler.extractItem(i, Math.min(maxAmount, stack.getCount()), false);
ItemStack remaining = entity.addStack(extracted);
maxAmount -= extracted.getCount() - remaining.getCount();
if (!remaining.isEmpty()) {
handler.insertItem(i, remaining, false);
}
}
}
}
示例11: takeItem
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
default void takeItem(EntityPlayer player) {
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
if(hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
IItemHandler handler = getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if(handler == null) return;
ItemStack contained = handler.extractItem(0, Integer.MAX_VALUE, false);
if(stack.isEmpty()) {
player.setHeldItem(EnumHand.MAIN_HAND, contained);
} else {
ItemHandlerHelper.giveItemToPlayer(player, contained);
}
}
}
示例12: performCraft
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public ItemStack performCraft(IItemHandler inv) {
for(int i=0; i<9; i++) {
if (ingredients[i]!=null) {
if (ingredients[i] instanceof ItemStack) {
inv.extractItem(i, ((ItemStack)ingredients[i]).getCount(), false);
} else {
inv.extractItem(i, 1, false);
}
}
}
return result.copy();
}
示例13: setInventorySlotContents
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void setInventorySlotContents(int index, ItemStack stack)
{
IItemHandler itemHandler = getItemHandler();
if(itemHandler != null)
{
itemHandler.extractItem(index, 64, false);
itemHandler.insertItem(index, stack, false);
}
}
示例14: clear
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void clear() {
IItemHandler itemHandler = getItemHandler();
if(itemHandler != null)
for (int i = 0; i < itemHandler.getSlots(); i++)
itemHandler.extractItem(i, 64, false);
}
示例15: importItems
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private boolean importItems(BlockPos pos, boolean simulate) {
TileEntity te = drone.world().getTileEntity(pos);
boolean[] sides = ((ISidedWidget) widget).getSides();
for (int d = 0; d < sides.length; d++) {
if (!sides[d]) {
continue;
}
IItemHandler inv = IOHelper.getInventoryForTE(te, EnumFacing.getFront(d));
if (inv == null) {
continue;
}
for (int i = 0; i < inv.getSlots(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (!stack.isEmpty()) {
if (widget.isItemValidForFilters(stack)) {
ItemStack importedStack = IOHelper.extract(inv, i, true);
if (importedStack.isEmpty()) {
continue;
}
if (((ICountWidget) widget).useCount())
importedStack.setCount(Math.min(importedStack.getCount(), getRemainingCount()));
ItemStack remainder = IOHelper.insert(drone, importedStack.copy(), EnumFacing.UP, simulate);
int removedItems = importedStack.getCount() - remainder.getCount();
if (!simulate) {
inv.extractItem(i, removedItems, false);
decreaseCount(removedItems);
drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
if (((ICountWidget) widget).useCount() && getRemainingCount() <= 0) {
return false;
}
} else if (removedItems > 0) {
return true;
} else {
drone.addDebugEntry("gui.progWidget.inventoryImport.debug.filledToMax", pos);
}
} else {
drone.addDebugEntry("gui.progWidget.inventoryImport.debug.stackdoesntPassFilter", pos);
}
}
}
}
// } else {
// drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
// }
return false;
}