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


Java ItemStack.getCount方法代码示例

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


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

示例1: transferIn

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean transferIn(BlockPos pos, ItemStack inserted, boolean test) {
	EnumFacing facing = getFacing();
	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 inSlot = handler.getStackInSlot(slot);
			if(tile != null && !tile.canInsertItem(slot, inserted, facing)) return false;
			if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, inserted) && (inSlot.getCount() < inSlot.getMaxStackSize() && inSlot.getCount() < handler.getSlotLimit(slot)))) {
				return handler.insertItem(slot, inserted, test) != inserted;
			}
		}
	}
	return false;
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:18,代码来源:TileGravityHopper.java

示例2: updateCurrentRecipe

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void updateCurrentRecipe() {
    String oldIndex = getRecipeIndex();
    setRecipeIndex("");
    ItemStack inputStack = itemStackHandler.getStackInSlot(0);
    if(!inputStack.isEmpty() && inputStack.getCount() > 0) {
        for(String id : getRecipes().keySet()) {
            E recipe = getRecipe(id);
            if(recipe != null && recipe.matchesExact(inputStack)) {
                setRecipeIndex(id);
                break;
            }
        }
    }
    if(!oldIndex.equals(getRecipeIndex())){
        currentTime = 0;
        itemCycleTime = 0;
        deviceCycleTime = 40;
        needCycleTime = 40;
    }
    
}
 
开发者ID:jaredlll08,项目名称:Machines-and-Stuff,代码行数:22,代码来源:TileEntityMachineBase.java

示例3: collectCobble

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void collectCobble(EntityItem entityItem) {
    ItemStack blockStack = entityItem.getItem();
    ItemStack actual = blockStack.splitStack(6);
    if (blockStack.isEmpty()) {
        entityItem.setDead();
    }
    if (actual.isEmpty()) {
        return;
    }
    Item item = actual.getItem();
    if (!(item instanceof ItemBlock)) {
        // Safety
        return;
    }
    numCobble += actual.getCount();
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:17,代码来源:DigdownStairsActionWorker.java

示例4: dropItemOnGround

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void dropItemOnGround(ItemStack stack, World world, double x, double y, double z) {
    float dX = rand.nextFloat() * 0.8F + 0.1F;
    float dY = rand.nextFloat() * 0.8F + 0.1F;
    float dZ = rand.nextFloat() * 0.8F + 0.1F;

    EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(stack.getItem(), stack.getCount(), stack.getItemDamage()));

    if (stack.hasTagCompound()) {
        entityItem.getItem().setTagCompound(stack.getTagCompound().copy());
    }

    float factor = 0.05F;
    entityItem.motionX = rand.nextGaussian() * factor;
    entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
    entityItem.motionZ = rand.nextGaussian() * factor;
    world.spawnEntity(entityItem);
    stack.setCount(0);
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:19,代码来源:PneumaticCraftUtils.java

示例5: anvilChange

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@SubscribeEvent
public static void anvilChange(AnvilUpdateEvent ev)
{
    ItemStack left = ev.getLeft();
    ItemStack right = ev.getRight();
    if (left.getCount() <= 0 || left.getItem() != belt)
        return;
    if (right.getCount() <= 0 || right.getItem() != pouch)
        return;
    int cost = ItemToolBelt.getUpgradeXP(left);
    if (cost < 0)
    {
        ev.setCanceled(true);
        return;
    }
    ev.setCost(cost);
    ev.setMaterialCost(1);

    ev.setOutput(ItemToolBelt.upgrade(left));
}
 
开发者ID:gigaherz,项目名称:ToolBelt,代码行数:21,代码来源:ToolBelt.java

示例6: findStack

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Nullable
public BeltGetter findStack(EntityPlayer player)
{
    IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player);
    for (int i = 0; i < baubles.getSlots(); i++)
    {
        ItemStack inSlot = baubles.getStackInSlot(i);
        if (inSlot.getCount() > 0)
        {
            if (inSlot.getItem() instanceof ItemToolBelt)
            {
                return new BaublesBeltGetter(player, i);
            }
        }
    }

    return super.findStack(player);
}
 
开发者ID:gigaherz,项目名称:ToolBelt,代码行数:19,代码来源:BeltFinderBaubles.java

示例7: interact

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean interact(PlayerInteractEvent.RightClickBlock event, ItemStack curItem, BlockPos pos){
    ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.getWorld(), pos, curItem);
    newBlock.initialize(event.getWorld(), pos);
    newBlock.prePlacement(event.getEntityPlayer(), curItem, event.getFace());
    
    Stream<ISemiBlock> existingSemiblocks = getSemiBlocks(event.getWorld(), pos);
    List<ISemiBlock> collidingBlocks = existingSemiblocks.filter(s -> !s.canCoexistInSameBlock(newBlock)).collect(Collectors.toList());
    
    if (!collidingBlocks.isEmpty()) {
        for(ISemiBlock collidingBlock : collidingBlocks){
            if (event.getEntityPlayer().capabilities.isCreativeMode) {
                removeSemiBlock(collidingBlock);
            } else {
                breakSemiBlock(collidingBlock, event.getEntityPlayer());
            }
        }
        
        return true;
    } else {            
        if (newBlock.canPlace(event.getFace())) {
            addSemiBlock(event.getWorld(), pos, newBlock);
            newBlock.onPlaced(event.getEntityPlayer(), curItem, event.getFace());
            event.getWorld().playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
                    SoundType.GLASS.getPlaceSound(), SoundCategory.BLOCKS,
                    (SoundType.GLASS.getVolume() + 1.0F) / 2.0F, SoundType.GLASS.getPitch() * 0.8F,
                    false);
            if (!event.getEntityPlayer().capabilities.isCreativeMode) {
                curItem.shrink(1);
                if (curItem.getCount() <= 0) event.getEntityPlayer().setHeldItem(event.getHand(), ItemStack.EMPTY);
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:36,代码来源:SemiBlockManager.java

示例8: setInventorySlotContents

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	final boolean flag = !stack.isEmpty() && stack.isItemEqual(itemStacks.get(index)) && ItemStack.areItemStackTagsEqual(stack, itemStacks.get(index));
	itemStacks.set(index, stack);

	if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit()) {
		stack.setCount(getInventoryStackLimit());
	}

	if (index == 0 && !flag) {
		this.markDirty();
	}
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:14,代码来源:TileApiary.java

示例9: transferStackInSlot

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index)
{
    Slot slot = this.inventorySlots.get(index);
    if(slot == null || !slot.getHasStack())
        return ItemStack.EMPTY;

    ItemStack originalItem = slot.getStack();
    ItemStack copyItem = originalItem.copy();

    if(index >= 36) //Item is in our container, try placing in player's inventory.
    {
        if(!this.mergeItemStack(originalItem, 0, 36, true))
            return ItemStack.EMPTY;
    }
    else
    {
        if(!this.mergeItemStack(originalItem, 36, this.inventorySlots.size(), false))
            return ItemStack.EMPTY;
    }

    if(copyItem.getCount() == 0)
        slot.putStack(ItemStack.EMPTY);
    else
        slot.onSlotChanged();

    if(originalItem.getCount() == 0)
        slot.putStack(ItemStack.EMPTY);
    else
        slot.onSlotChanged();

    if(copyItem.getCount() == originalItem.getCount())
        return ItemStack.EMPTY;
    slot.onTake(player, copyItem);
    return originalItem;
}
 
开发者ID:Lumaceon,项目名称:CraftingParadiseMod,代码行数:37,代码来源:ContainerWorldMachine.java

示例10: insertItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
	if (stack.isEmpty() || stack.getCount() == 0) {
		return ItemStack.EMPTY;
	}

	validateSlotIndex(slot);

	ItemStack existing = stacks.get(slot);

	if (!existing.isEmpty() && !ItemUtils.areItemsEqual(stack, stacks.get(slot))) {
		return ItemStack.EMPTY;
	}

	if (!simulate) {
		if (existing.isEmpty()) {
			stacks.set(slot, stack);
		}
		else {
			existing.setCount(stack.getCount());
		}
		//onContentsChanged(slot);
		serializeNBT();
	}

	return stacks.get(slot);
}
 
开发者ID:p455w0rd,项目名称:DankNull,代码行数:28,代码来源:DankNullItemHandler.java

示例11: outputInChamber

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void outputInChamber() {
    // place items from the interface block into the pressure chamber
    // all items in the interface will be moved at once, but the pressure chamber must have enough presure to do so
    TileEntityPressureChamberValve valve = getCore();
    if (valve != null) {
        ItemStack inputStack = inventory.getStackInSlot(0);
        enoughAir = Math.abs(valve.getAirHandler(null).getAir()) > inputStack.getCount() * PneumaticValues.USAGE_CHAMBER_INTERFACE;
        if (enoughAir) {
            ItemStack leftover = ItemHandlerHelper.insertItem(valve.getStacksInChamber(), inputStack.copy(), false);
            int inserted = inputStack.getCount() - leftover.getCount();
            valve.addAir((valve.getAirHandler(null).getAir() > 0 ? -1 : 1) * inserted * PneumaticValues.USAGE_CHAMBER_INTERFACE);
            inventory.setStackInSlot(0, leftover);
        }
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:16,代码来源:TileEntityPressureChamberInterface.java

示例12: hasRoom

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean hasRoom(Predicate<ItemStack> matcher) {
    for (ItemStack stack : inventory) {
        if (stack.isEmpty()) {
            return true;
        }
        if (!stack.isEmpty() && matcher.test(stack)) {
            if (stack.getCount() < stack.getMaxStackSize()) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:15,代码来源:EntityMeeCreeps.java

示例13: extractItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if(amount == 0)
        return null;
    
    validateSlotIndex(slot);
    
    ItemStack existing = this.stacks.get(slot);
    
    if(existing == null)
        return null;
    
    int toExtract = Math.min(amount, existing.getMaxStackSize());
    
    if(existing.getCount() <= toExtract) {
        if(!simulate) {
            this.stacks.set(slot, null);
            onContentsChanged(slot);
        }
        return existing;
    } else {
        if(!simulate) {
            this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
            onContentsChanged(slot);
        }
        
        return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
    }
}
 
开发者ID:jaredlll08,项目名称:Machines-and-Stuff,代码行数:29,代码来源:ItemStackHandlerAdvanced.java

示例14: transferStackInSlot

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Nonnull
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
    ItemStack stack = ItemStack.EMPTY;
    Slot srcSlot = inventorySlots.get(slotIndex);

    if (srcSlot != null && srcSlot.getHasStack()) {
        ItemStack stackInSlot = srcSlot.getStack();
        stack = stackInSlot.copy();

        if (slotIndex == 0) {
            if (!mergeItemStack(stackInSlot, 1, 36, false)) return ItemStack.EMPTY;
            srcSlot.onSlotChange(stackInSlot, stack);
        } else if (isProgrammableItem(stack)) {
            if (!mergeItemStack(stackInSlot, 0, 1, false)) return ItemStack.EMPTY;
            srcSlot.onSlotChange(stackInSlot, stack);
        }
        if (stackInSlot.isEmpty()) {
            srcSlot.putStack(ItemStack.EMPTY);
        } else {
            srcSlot.onSlotChanged();
        }

        if (stackInSlot.getCount() == stack.getCount()) return ItemStack.EMPTY;

        srcSlot.onTake(par1EntityPlayer, stackInSlot);
    }

    return stack;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:31,代码来源:ContainerProgrammer.java

示例15: update

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void update() {
	boolean curTickPower = world.isBlockIndirectlyGettingPowered(pos)!=0;
	
	//TODO: Actually lock tanks
	
	
	{ //Bottle fluids out
		ItemStack bottles = itemStorage.getStackInSlot(SLOT_EMPTY_BUCKET_IN);
		ItemStack outputItem = itemStorage.getStackInSlot(SLOT_FULL_BUCKET_OUT);
		FluidStack outputFluid = outputTank.getFluid();
		//Are there bottles to fill, is there room to put them, is there fluid to fill them with, and is there *enough* of that fluid?
		if (!bottles.isEmpty() && outputItem.getCount()<outputItem.getMaxStackSize() && outputFluid!=null && outputFluid.amount>250) {
			ItemStack outBottle = new ItemStack(ThermionicsItems.SPIRIT_BOTTLE);
			outBottle.setTagCompound(outputFluid.tag.copy());
			
			if (itemStorage.insertItem(SLOT_FULL_BUCKET_OUT, outBottle, true).isEmpty()) {
				outputTank.drainInternal(250,  true);
				itemStorage.insertItem(SLOT_FULL_BUCKET_OUT, outBottle, false);
				itemStorage.extractItem(SLOT_EMPTY_BUCKET_IN, 1, false);
			}
		}
	}
	
	if (!tanksLocked) {
		if (curTickPower & !lastTickPower) {
			//Lock the tanks on a rising current edge.
			setTanksLocked(true);
			processTime = 0;
		} else {
			//Fluid loading/unloading mode
			ItemStack inBucket = itemStorage.getStackInSlot(SLOT_FULL_BUCKET_IN);
			FluidActionResult result = FluidUtil.tryEmptyContainer(inBucket, inputTank, inputTank.getCapacity(), null, true);
			if (result.isSuccess()) {
				itemStorage.setStackInSlot(SLOT_FULL_BUCKET_IN, ItemStack.EMPTY);
				itemStorage.setStackInSlot(SLOT_EMPTY_BUCKET_OUT, result.getResult());
			}
		}
	} else {
		if (processTime<MAX_PROCESS_TIME) processTime++;
		FluidStack in = inputTank.getFluid();
		if (in==null) {
			//Batch is done...?
			setTanksLocked(false);
		} else {
			//Find a recipe, let's go :D
			//For the moment, use Water->Rum
			PotStillRecipe recipe = MachineRecipes.getPotStill(inputTank);
			if (recipe!=null) {
				FluidStack output = recipe.getOutput();
				int filled = outputTank.fillInternal(output, false);
				int extracted = heat.extractHeat(HEAT_REQUIRED, true);
				if (output.amount==filled && extracted==HEAT_REQUIRED) {
					recipe.consumeIngredients(inputTank);
					outputTank.fillInternal(output, true);
					heat.extractHeat(HEAT_REQUIRED, false);
				}
				
			}
		}
	}
	
	lastTickPower = curTickPower;
}
 
开发者ID:elytra,项目名称:Thermionics,代码行数:65,代码来源:TileEntityPotStill.java


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