当前位置: 首页>>代码示例>>Java>>正文


Java ItemHandlerHelper.insertItemStacked方法代码示例

本文整理汇总了Java中net.minecraftforge.items.ItemHandlerHelper.insertItemStacked方法的典型用法代码示例。如果您正苦于以下问题:Java ItemHandlerHelper.insertItemStacked方法的具体用法?Java ItemHandlerHelper.insertItemStacked怎么用?Java ItemHandlerHelper.insertItemStacked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraftforge.items.ItemHandlerHelper的用法示例。


在下文中一共展示了ItemHandlerHelper.insertItemStacked方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInsertItem

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
public static int doInsertItem(Object into, ItemStack item, EnumFacing side, boolean insert) {
	if (into == null || ItemStackTools.isNullStack(item)) {
		return 0;
	}
	if (into instanceof ISidedInventory) {
		return ItemUtil.doInsertItemInv((ISidedInventory) into, item, side, insert);
	} else if (into instanceof IInventory) {
		return ItemUtil.doInsertItemInv(getInventory((IInventory) into), item, side, insert);
	} else if (into instanceof IItemHandler){
		IItemHandler handler = (IItemHandler)into;
		int startSize = ItemStackTools.getStackSize(item);
		ItemStack res = ItemHandlerHelper.insertItemStacked(handler, item.copy(), !insert);
		int val = ItemStackTools.isNullStack(res) ? startSize : startSize - ItemStackTools.getStackSize(res);
		return val;
	}

	return 0;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:19,代码来源:ItemUtil.java

示例2: outputItems

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
public boolean outputItems(List<ItemStack> loot) {
    if ((loot != null) && (loot.size() > 0)) {
        for (ItemStack lootStack : loot) {
            ItemStack remaining = (this.filteredInStackHandler == null)
                    ? ItemStackUtil.insertItemInExistingStacks(this.inStackHandler, lootStack, false)
                    : ItemHandlerHelper.insertItemStacked(this.filteredInStackHandler, lootStack, false);
            if (!ItemStackUtil.isEmpty(remaining)) {
                remaining = ItemHandlerHelper.insertItem(this.outStackHandler, lootStack, false);
            }
            if (!ItemStackUtil.isEmpty(remaining)) {
                return this.spawnOverloadedItem(remaining);
            }
        }
    }
    return true;
}
 
开发者ID:faceofcat,项目名称:Mekfarm,代码行数:17,代码来源:ElectricMekfarmMachine.java

示例3: tryTransfer

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public boolean tryTransfer(IItemHandler from, IItemHandler to, List<Pair<TileEntity, EnumFacing>> filters){
    int totalExtracted = 0;

    for(int i = 0; i < from.getSlots(); i++) {
        ItemStack extracted = from.extractItem(i, MAX_TRANSFER_RATE - totalExtracted, true);
        if(!extracted.isEmpty() && passesFilters(extracted, filters)) {
            ItemStack leftover = ItemHandlerHelper.insertItemStacked(to, extracted, false);
            int leftoverCount = !leftover.isEmpty() ? leftover.getCount() : 0;

            int actuallyExtracted = extracted.getCount() - leftoverCount;
            if(actuallyExtracted > 0) {
                from.extractItem(i, actuallyExtracted, false);
                totalExtracted += actuallyExtracted;
                if(totalExtracted >= MAX_TRANSFER_RATE) break;
            }
        }
    }
    return totalExtracted > 0;
}
 
开发者ID:MineMaarten,项目名称:Signals,代码行数:21,代码来源:CartHopperBehaviourItems.java

示例4: tryOutput

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
private boolean tryOutput(ItemWrapper wrapper, IItemHandler outputInventory) {
	if(outputInventory == null) {
		// Output to world
		if(!worldObj.isRemote && wrapper.itemStack != null) {
			EntityItem item = new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() - 0.3, pos.getZ() + 0.5, wrapper.itemStack);
			item.motionX = 0;
			item.motionY = 0;
			item.motionZ = 0;
			worldObj.spawnEntityInWorld(item);
			wrapper.itemStack = null;
		}
		return true;
	}
	// Output to inventory
	if(wrapper.itemStack == null) {
		return true;
	}
	wrapper.itemStack = ItemHandlerHelper.insertItemStacked(outputInventory, wrapper.itemStack, false);
	return wrapper.itemStack == null;
}
 
开发者ID:Team-IO,项目名称:taam,代码行数:21,代码来源:TileEntityConveyorSieve.java

示例5: extractFuelFromHopper

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
/**
 * 
 * @param cart
 * @return true if there was a valid hopper (not necessarily if extracted an item)
 */
private boolean extractFuelFromHopper(EntityMinecart cart, BlockPos pos){
    boolean foundHopper = false;
    for(EnumFacing dir : EnumFacing.VALUES) {
        BlockPos neighbor = pos;
        for(int offsetTimes = 0; offsetTimes < (dir == EnumFacing.UP ? 2 : 1); offsetTimes++) {
            neighbor = neighbor.offset(dir);
            TileEntity te = cart.world.getTileEntity(neighbor);
            if(te instanceof TileEntityHopper) {
                EnumFacing hopperDir = cart.world.getBlockState(neighbor).getValue(BlockHopper.FACING);
                if(hopperDir.getOpposite() == dir) {
                    TileEntityHopper hopper = (TileEntityHopper)te;
                    for(int i = 0; i < hopper.getSizeInventory(); i++) {
                        ItemStack stack = hopper.getStackInSlot(i);
                        if(!stack.isEmpty() && getFuelInv().isItemValidForSlot(0, stack)) {
                            ItemStack inserted = stack.copy();
                            inserted.setCount(1);
                            ItemStack left = ItemHandlerHelper.insertItemStacked(getEngineItemHandler(), inserted, false);
                            if(left.isEmpty()) {
                                stack.shrink(1);
                                hopper.markDirty();
                                return true;
                            }
                        }
                    }
                    foundHopper = true;
                }
            }
        }
    }
    return foundHopper;
}
 
开发者ID:MineMaarten,项目名称:Signals,代码行数:37,代码来源:CapabilityMinecartDestination.java

示例6: insertItemAt

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public int insertItemAt(ItemStack item, int slot, boolean simulate) {
	if (item == null || item.stackSize == 0) {
		return 0;
	}
	ItemStack notAdded = ItemHandlerHelper.insertItemStacked(inventory, item, simulate);
	int added = item.stackSize;
	if(notAdded != null)
		added -= notAdded.stackSize;
	return added;
}
 
开发者ID:Team-IO,项目名称:taam,代码行数:12,代码来源:ConveyorSlotsInventory.java

示例7: insertItemAt

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@Override
public int insertItemAt(ItemStack stack, int slot, boolean simulate) {
	IItemHandler target = getTargetItemHandler();

	ItemStack notAdded = ItemHandlerHelper.insertItemStacked(target, stack, simulate);
	int added = stack.stackSize;
	if(notAdded != null)
		added -= notAdded.stackSize;
	return added;
}
 
开发者ID:Team-IO,项目名称:taam,代码行数:11,代码来源:TileEntityChute.java

示例8: getLoot

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
protected IInventory getLoot() {
	final GenericInventory loot = new GenericInventory("tmpplayer", false, this.loot.size());
	final IItemHandler handler = loot.getHandler();
	for (EntityItem entityItem : this.loot) {
		ItemStack stack = entityItem.getItem();
		if (!stack.isEmpty()) ItemHandlerHelper.insertItemStacked(handler, stack, false);
	}
	return loot;
}
 
开发者ID:OpenMods,项目名称:OpenBlocks,代码行数:10,代码来源:PlayerDeathHandler.java

示例9: pickAmmo

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
@SubscribeEvent
public void pickAmmo(EntityItemPickupEvent event) {
	ItemStack stack = event.getItem().getItem();
	
	if (event.getItem().getEntityData().getBoolean("Fake")) {
		event.setResult(Result.ALLOW);
		return;
	}
	if (WeaponsCapability.get(event.getEntity()).isInvisible()) {
		event.setResult(Result.DENY);
		event.setCanceled(true);
		return;
	}
	
	if (stack.getItem() instanceof ItemAmmoPackage){
		ItemStack weapon=event.getEntityPlayer().getHeldItemMainhand();
		if(!weapon.isEmpty() && weapon.getItem() instanceof ItemFromData && ItemFromData.getData(weapon).getInt(PropertyType.AMMO_TYPE)!=0)
			stack.setItemDamage(ItemFromData.getData(weapon).getInt(PropertyType.AMMO_TYPE));
		stack=ItemAmmoPackage.convertPackage(stack, event.getEntityPlayer());
		event.getItem().setItem(stack);
		event.setResult(Result.DENY);
		event.setCanceled(true);
		return;
	}
	/*if (!(stack.getItem() instanceof ItemCrate) && stack.hasTagCompound() && stack.getTagCompound().getBoolean("DropFrom")) {
		event.getEntityPlayer().addStat(TF2Achievements.SPOILS_WAR);
	}*/
	if (stack.getItem() instanceof ItemAmmo && event.getEntityLiving().hasCapability(TF2weapons.INVENTORY_CAP, null) ) {
		
		if (!event.getEntityLiving().getCapability(TF2weapons.INVENTORY_CAP, null).getStackInSlot(3).isEmpty()) {
			IItemHandler inv = event.getEntityLiving().getCapability(TF2weapons.INVENTORY_CAP, null).getStackInSlot(3)
					.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
			ItemStack orig=stack.copy();
			orig.setCount(0);
			stack=ItemHandlerHelper.insertItemStacked(inv, stack, false);
			if(stack.isEmpty()){
				event.getItem().setItem(orig);
			}
			if(!event.getEntityPlayer().getHeldItemMainhand().isEmpty() && event.getEntityPlayer().getHeldItemMainhand().getItem() instanceof ItemWeapon)
				TF2weapons.network.sendTo(new TF2Message.UseMessage(event.getEntityPlayer().getHeldItemMainhand().getItemDamage(), false,
						ItemAmmo.getAmmoAmount(event.getEntityPlayer(), event.getEntityPlayer().getHeldItemMainhand()), EnumHand.MAIN_HAND),(EntityPlayerMP) event.getEntityPlayer());
			/*for (int i = 0; i < inv.getSlots(); i++) {
				ItemStack inSlot = inv.getStackInSlot(i);
				if (inSlot == null) {fg
					inv.insertItem(i, stack.copy(),false);v
					stack.setCount( 0;
				} else if (stack.isItemEqual(inSlot) && ItemStack.areItemStackTagsEqual(stack, inSlot)) {
					int size = stack.getCount() + inSlot.getCount();

					if (size > stack.getMaxStackSize()) {
						stack.setCount( size - inSlot.getMaxStackSize();
						inSlot.setCount( stack.getMaxStackSize();
					} else {
						inSlot.setCount( size;
						stack.setCount( 0;
					}
				}
				if (stack.getCount() <= 0) {
					break;
				}
			}*/
		}
		if (stack.isEmpty()) {
			event.setResult(Result.ALLOW);
			return;
		}
	}
	event.setResult(Result.DEFAULT);
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:70,代码来源:TF2EventsCommon.java

示例10: tryInsert

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
private static boolean tryInsert(TileEntity tileEntity, EntityItem ei) {
	ItemStack entityItemStack = ei.getEntityItem();
	if (entityItemStack == null || entityItemStack.stackSize == 0 || entityItemStack.getItem() == null) {
		// We are tidy. Clean up "empty" item entities
		ei.setDead();
		return false;
	}

	BlockPos pos = tileEntity.getPos();
	double relativeX = ei.posX - pos.getX();
	double relativeY = ei.posY - pos.getY();
	double relativeZ = ei.posZ - pos.getZ();

	IConveyorSlots conveyorTE = TaamUtil.getCapability(Taam.CAPABILITY_CONVEYOR, tileEntity, EnumFacing.UP);
	if (conveyorTE != null) {
		int slot = getSlotForRelativeCoordinates(relativeX, relativeZ);

		if (slot >= 0 && slot < 9 // wrapped slot == outside x / z
		// Then check vertical position
				&& relativeY > conveyorTE.getInsertMinY() && relativeY < conveyorTE.getInsertMaxY()) {

			int previousStackSize = entityItemStack.stackSize;

			// Insert into conveyor at the determined slot
			int added = conveyorTE.insertItemAt(entityItemStack, slot, false);

			// Update item entity
			if (added == previousStackSize) {
				ei.setDead();
				return true;
			} else if (added > 0) {
				entityItemStack.stackSize = previousStackSize - added;
				ei.setEntityItemStack(entityItemStack);
				return true;
			}
		}
	} else {
		// Check if the item is directly on top of the block, with some extra room & buffer
		if (relativeX >= 0 && relativeX < 1 && relativeY >= 0.9 && relativeY < 1.2 && relativeZ >= 0 && relativeZ < 1) {
			// Get item handler
			IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
			if (itemHandler != null) {
				// Insert item into item handler
				ItemStack notInserted = ItemHandlerHelper.insertItemStacked(itemHandler, entityItemStack, false);

				// Update item entity
				if (notInserted == null) {
					ei.setDead();
					return true;
				}

				// If the instance is still the same, it was not changed by
				// the itemHandler > nothing inserted.
				if (notInserted != entityItemStack) {
					ei.setEntityItemStack(notInserted);
					return true;
				}
			}
		}
	}
	// Finally, nothing was added if we arrive here
	return false;
}
 
开发者ID:Team-IO,项目名称:taam,代码行数:64,代码来源:ConveyorUtil.java

示例11: addtoExtInventory

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
public boolean addtoExtInventory(IItemHandler inv, int fromSlot) {
	if (ItemHandlerHelper.insertItemStacked(inv, slots[fromSlot], true) != slots[fromSlot]) {
		slots[fromSlot] = ItemHandlerHelper.insertItemStacked(inv, slots[fromSlot], false);
	}
	return false;
}
 
开发者ID:Vanhal,项目名称:ProgressiveAutomation,代码行数:7,代码来源:BaseTileEntity.java

示例12: canInsertStack

import net.minecraftforge.items.ItemHandlerHelper; //导入方法依赖的package包/类
public static boolean canInsertStack(IItemHandler handler, @Nonnull ItemStack stack) {
	final ItemStack toInsert = ItemHandlerHelper.insertItemStacked(handler, stack, true);
	return toInsert.getCount() < stack.getCount();
}
 
开发者ID:OpenMods,项目名称:OpenModsLib,代码行数:5,代码来源:InventoryUtils.java


注:本文中的net.minecraftforge.items.ItemHandlerHelper.insertItemStacked方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。