本文整理汇总了Java中net.minecraftforge.items.IItemHandler.getStackInSlot方法的典型用法代码示例。如果您正苦于以下问题:Java IItemHandler.getStackInSlot方法的具体用法?Java IItemHandler.getStackInSlot怎么用?Java IItemHandler.getStackInSlot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.items.IItemHandler
的用法示例。
在下文中一共展示了IItemHandler.getStackInSlot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addInformation
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void addInformation(World world, BlockPos pos, TileEntity te, List<String> infoList) {
try {
IItemHandler inventory = IOHelper.getInventoryForTE(te);
if (inventory != null) {
boolean empty = true;
ItemStack[] inventoryStacks = new ItemStack[inventory.getSlots()];
for (int i = 0; i < inventory.getSlots(); i++) {
ItemStack iStack = inventory.getStackInSlot(i);
if (!iStack.isEmpty()) {
empty = false;
}
inventoryStacks[i] = iStack;
}
if (empty) {
infoList.add("Contents: Empty");
} else {
infoList.add("Contents:");
PneumaticCraftUtils.sortCombineItemStacksAndToString(infoList, inventoryStacks);
}
}
} catch (Throwable e) {
addTileEntityToBlackList(te, e);
}
}
示例2: getEvaluator
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) {
return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) {
@Override
protected boolean evaluate(BlockPos pos) {
if (drone.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
int count = 0;
IItemHandler handler = drone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
if (widget.isItemValidForFilters(stack)) {
count += stack.getCount();
}
}
return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ?
count == ((ICondition) widget).getRequiredCount() :
count >= ((ICondition) widget).getRequiredCount();
}
return false;
}
};
}
示例3: validate
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
void validate() {
if (isValid) return;
Arrays.fill(upgradeCount, 0);
customUpgradeCount = null;
IItemHandler inv = te.getUpgradesInventory();
for (int i = 0; i < inv.getSlots(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.getItem() instanceof ItemMachineUpgrade) {
// native upgrade
int idx = ((ItemMachineUpgrade) stack.getItem()).getUpgradeType().ordinal();
upgradeCount[idx] += inv.getStackInSlot(i).getCount();
} else if (!inv.getStackInSlot(i).isEmpty()) {
// custom upgrade from another mod
if (customUpgradeCount == null)
customUpgradeCount = Maps.newHashMap();
String key = makeUpgradeKey(stack);
customUpgradeCount.put(key, customUpgradeCount.getOrDefault(key, 0) + stack.getCount());
}
}
te.onUpgradesChanged();
isValid = true;
}
示例4: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state)
{
TileEntityInfernalSmelter te = (TileEntityInfernalSmelter) world.getTileEntity(pos);
IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int i = 0; i < cap.getSlots(); ++i)
{
ItemStack itemstack = cap.getStackInSlot(i);
if (!itemstack.isEmpty())
{
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
}
}
super.breakBlock(world, pos, state);
}
示例5: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
TileEntity tile = worldIn.getTileEntity(pos);
if (tile != null)
{
IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (itemHandler != null)
{
for (int i = 0; i < itemHandler.getSlots(); i++)
{
ItemStack stack = itemHandler.getStackInSlot(i);
if (!stack.isEmpty())
{
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
}
}
}
}
super.breakBlock(worldIn, pos, state);
}
示例6: amountRequested
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public int amountRequested(ItemStack stack) {
int totalRequestingAmount = getTotalRequestedAmount(stack);
if (totalRequestingAmount > 0) {
IItemHandler inv = IOHelper.getInventoryForTE(getTileEntity());
int count = 0;
if (inv != null) {
for (int i = 0; i < inv.getSlots(); i++) {
ItemStack s = inv.getStackInSlot(i);
if (!s.isEmpty() && isItemEqual(s, stack)) {
count += s.getCount();
}
}
count += getIncomingItems(stack);
return Math.max(0, Math.min(stack.getCount(), totalRequestingAmount - count));
}
}
return 0;
}
示例7: 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;
}
示例8: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TileEntityPhotoProcessor te = (TileEntityPhotoProcessor) worldIn.getTileEntity(pos);
IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
for (int i = inv.getSlots() - 1; i >= 0; --i) {
if (inv.getStackInSlot(i) != null) {
Block.spawnAsEntity(worldIn, pos, inv.getStackInSlot(i));
((IItemHandlerModifiable) inv).setStackInSlot(i, null);
}
}
super.breakBlock(worldIn, pos, state);
}
示例9: 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);
}
}
示例10: dropInventory
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public static void dropInventory(World world, BlockPos pos, IItemHandler itemHandler)
{
for(int i = 0; i < itemHandler.getSlots(); i++)
{
if(itemHandler.getStackInSlot(i) != null)
{
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemHandler.getStackInSlot(i));
}
}
}
示例11: update
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void update() {
super.update();
IItemHandler handler = getConnectedInventory();
if (handler != null) {
for (int i = 0; i < (upgraded ? 10 : 1) * PneumaticValues.CHARGING_STATION_CHARGE_RATE; i++) {
boolean charged = false;
for (int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack chargedItem = handler.getStackInSlot(slot);
if (chargedItem.getItem() instanceof IPressurizable) {
IPressurizable chargingItem = (IPressurizable) chargedItem.getItem();
IAirHandler airHandler = pressureTube.getAirHandler(null);
if (chargingItem.getPressure(chargedItem) > airHandler.getPressure() + 0.01F && chargingItem.getPressure(chargedItem) > 0F) {
chargingItem.addAir(chargedItem, -1);
airHandler.addAir(1);
charged = true;
} else if (chargingItem.getPressure(chargedItem) < airHandler.getPressure() - 0.01F && chargingItem.getPressure(chargedItem) < chargingItem.maxPressure(chargedItem)) {// if there is pressure, and the item isn't fully charged yet..
chargingItem.addAir(chargedItem, 1);
airHandler.addAir(-1);
charged = true;
}
}
}
if (!charged) break;
}
}
}
示例12: renderTool
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
private void renderTool(TileEntityInfusionRepair te, double x, double y, double z, float partialTicks)
{
IItemHandler itemHandler = CapUtils.getItemHandler(te);
ItemStack stack = itemHandler.getStackInSlot(TileEntityInfusionRepair.SLOT_ENCH_ITEM);
if(Prep1_11.isEmpty(stack)) return;
GlStateManager.pushMatrix();
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.translate(-0.25F * PIXEL_SIZE, -1.5F * PIXEL_SIZE, 0.15F);
mc.getRenderItem().renderItem(stack, TransformType.GROUND);
GlStateManager.popMatrix();
}
示例13: getFirstItem
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public static ItemStack getFirstItem(IItemHandler inventory, Predicate<ItemStack> pred) {
for (int i = 0; i<inventory.getSlots(); i++) {
ItemStack stack=inventory.getStackInSlot(i);
if (!stack.isEmpty() && pred.apply(stack))
return stack;
}
return ItemStack.EMPTY;
}
示例14: hasEnoughPuzzleStacks
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
public boolean hasEnoughPuzzleStacks(EntityPlayer player, ItemStack stack) {
int amountLeft = stack.getCount();
if (player != null) {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack playerStack = player.inventory.getStackInSlot(i);
if (PneumaticCraftUtils.areStacksEqual(playerStack, stack, true, true, false, false)) {
amountLeft -= playerStack.getCount();
if (amountLeft <= 0) return true;
}
}
}
for (EnumFacing d : EnumFacing.VALUES) {
TileEntity te = getWorld().getTileEntity(getPos().offset(d));
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d.getOpposite())) {
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d.getOpposite());
for (int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack neighborStack = handler.getStackInSlot(slot);
if (PneumaticCraftUtils.areStacksEqual(neighborStack, stack, true, true, false, false)) {
amountLeft -= neighborStack.getCount();
if (amountLeft <= 0) return true;
}
}
}
}
return false;
}
示例15: breakBlock
import net.minecraftforge.items.IItemHandler; //导入方法依赖的package包/类
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntityBlockBreaker te = (TileEntityBlockBreaker) world.getTileEntity(pos);
IItemHandler handler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
for (int slot = 0; slot < handler.getSlots(); slot++) {
ItemStack stack = handler.getStackInSlot(slot);
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack);
}
super.breakBlock(world, pos, state);
}