本文整理汇总了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;
}
示例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;
}
}
示例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();
}
示例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);
}
示例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));
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}