本文整理汇总了Java中net.minecraft.item.ItemStack.setCount方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.setCount方法的具体用法?Java ItemStack.setCount怎么用?Java ItemStack.setCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.setCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: potionCustomLogic
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void potionCustomLogic(EntityPlayer player, EnumHand hand, ItemStack stack) {
boolean splash = ingredients.removeIf(s -> s.getItem() == Items.GUNPOWDER);
boolean linger = ingredients.removeIf(s -> s.getItem() == Items.DRAGON_BREATH);
NBTTagCompound tag = getBrewData();
if (tag != null) {
Item item = splash && !linger ? ModItems.brew_phial_splash
: linger && !splash ? ModItems.brew_phial_linger : ModItems.brew_phial_drink;
ItemStack brew = new ItemStack(item);
brew.setTagCompound(tag);
brew.setCount(1 + getBrewMultiplier(player));
giveItem(player, hand, stack, brew);
inv.setFluid(null);
onLiquidChange();
}
}
示例2: performWork
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
protected float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
ItemStack stack = getFirstItem();
if (stack.isEmpty()) {
return 0;
}
ItemStack out = stack.copy();
out.setCount(1);
if (stack.isItemEnchanted() || stack.getItem().equals(Items.ENCHANTED_BOOK)) {
if (ItemHandlerHelper.insertItem(outputEnch, out, true).isEmpty()) {
ItemHandlerHelper.insertItem(outputEnch, out, false);
stack.setCount(stack.getCount() - 1);
return 500;
}
} else if (ItemHandlerHelper.insertItem(outputNoEnch, out, true).isEmpty()) {
ItemHandlerHelper.insertItem(outputNoEnch, out, false);
stack.setCount(stack.getCount() - 1);
return 500;
}
return 0;
}
示例3: 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);
}
示例4: importFromChamber
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private void importFromChamber(TileEntityPressureChamberValve core) {
ItemStackHandler chamberStacks = core.getStacksInChamber();
for (ItemStack chamberStack : new ItemStackHandlerIterable(chamberStacks)) {
ItemStack inputStack = inventory.getStackInSlot(0);
if ((inputStack.isEmpty() || inputStack.isItemEqual(chamberStack)) && filterHandler.doesItemMatchFilter(chamberStack)) {
int maxAllowedItems = Math.abs(core.getAirHandler(null).getAir()) / PneumaticValues.USAGE_CHAMBER_INTERFACE;
if (maxAllowedItems > 0) {
if (!inputStack.isEmpty()) {
maxAllowedItems = Math.min(maxAllowedItems, chamberStack.getMaxStackSize() - inputStack.getCount());
}
int transferredItems = Math.min(chamberStack.getCount(), maxAllowedItems);
ItemStack toTransferStack = chamberStack.copy().splitStack(transferredItems);
ItemStack excess = inventory.insertItem(0, toTransferStack, true);
if (excess.getCount() < toTransferStack.getCount()) {
// we can transfer at least some of the items
transferredItems = toTransferStack.getCount() - excess.getCount();
core.addAir((core.getAirHandler(null).getAir() > 0 ? -1 : 1) * transferredItems * PneumaticValues.USAGE_CHAMBER_INTERFACE);
toTransferStack.setCount(transferredItems);
inventory.insertItem(0, toTransferStack, false);
chamberStack.shrink(transferredItems);
}
}
}
}
}
示例5: potionRecipeLogic
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void potionRecipeLogic(EntityPlayer player, EnumHand hand, ItemStack stack) {
List<CauldronBrewRecipe> potions = CauldronRegistry.getBrewRecipes();
Optional<CauldronBrewRecipe> optional = potions.stream().filter(recipe -> recipe.canTake(stack) && recipe.matches(ingredients)).findAny();
if (optional.isPresent()) {
ItemStack potion = optional.get().getResult();
potion.setCount(1 + getBrewMultiplier(player));
giveItem(player, hand, stack, potion);
inv.setFluid(null);
onLiquidChange();
}
}
示例6: protectedUpdate
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void protectedUpdate() {
super.protectedUpdate();
int[] values = {r, g, b};
for (int i = 0; i < 3; ++i) {
ItemStack stack = inputDyes.getStackInSlot(i);
if (!stack.isEmpty() && values[i] + 3 <= 300) {
stack.setCount(stack.getCount() - 1);
values[i] = values[i] + 3;
}
}
r = values[0];
g = values[1];
b = values[2];
}
示例7: getStackInSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Nonnull
@Override
public ItemStack getStackInSlot(int slot) {
if (!storage.getStackInSlot(slot).isEmpty()) {
ItemStack stack = blackHoleUnitBlock.getItemStack(storage.getStackInSlot(slot)).copy();
stack.setCount(blackHoleUnitBlock.getAmount(storage.getStackInSlot(slot)) + output.getStackInSlot(slot).getCount());
return stack;
}
return ItemStack.EMPTY;
}
示例8: getStacksInItem
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void getStacksInItem(ItemStack stack, List<ItemStack> curStacks){
IMEInventoryHandler<IAEItemStack> cellInventoryHandler = cellRegistry.getCellInventory(stack, null, itemChannel);
if (cellInventoryHandler != null) {
IItemList<IAEItemStack> cellItemList = itemChannel.createList();
cellInventoryHandler.getAvailableItems(cellItemList);
for (IAEItemStack aeStack : cellItemList) {
ItemStack st = aeStack.createItemStack();
st.setCount((int) aeStack.getStackSize());
curStacks.add(st);
}
}
}
示例9: performWork
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public float performWork() {
if (WorkUtils.isDisabled(this.getBlockType())) return 0;
if (action > 5) action = 0;
if (action != 0 && outputPotions.getStackInSlot(0).isEmpty() && outputPotions.getStackInSlot(1).isEmpty() && outputPotions.getStackInSlot(2).isEmpty()) {
action = 0;
partialSync(NBT_ACTION, true);
return 1;
}
if (action == 0 && inputGlassBottles.getStackInSlot(0).getCount() >= 3 && ItemHandlerHelper.insertItem(outputPotions, new ItemStack(Items.POTIONITEM, 3), true).isEmpty() && fluidTank.getFluidAmount() >= 3000) { //DUMMY STACK
ItemStack bottles = new ItemStack(Items.POTIONITEM, 3);
NBTTagCompound c = new NBTTagCompound();
c.setString("Potion", "minecraft:water");
bottles.setTagCompound(c);
ItemHandlerHelper.insertItem(outputPotions, bottles, false);
fluidTank.drain(3000, true);
inputGlassBottles.getStackInSlot(0).setCount(inputGlassBottles.getStackInSlot(0).getCount() - 3);
action = 1;
partialSync(NBT_ACTION, true);
return 1;
} else if (action > 0) {
ItemStack ingredient = inputIngredients.getStackInSlot(action - 1);
if (!ingredient.isEmpty()) {
NonNullList<ItemStack> potions = NonNullList.create();
potions.add(outputPotions.getStackInSlot(0));
potions.add(outputPotions.getStackInSlot(1));
potions.add(outputPotions.getStackInSlot(2));
if (BrewingRecipeRegistry.hasOutput(potions.get(0), ingredient)) {
BrewingRecipeRegistry.brewPotions(potions, ingredient, new int[]{0, 1, 2});
for (int i = 0; i < 3; ++i) outputPotions.setStackInSlot(i, potions.get(i));
++action;
ingredient.setCount(ingredient.getCount() - 1);
if (action > 5) action = 0;
partialSync(NBT_ACTION, true);
return 1;
}
}
}
return 0;
}
示例10: setStackInSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void setStackInSlot(int slot, ItemStack stack) {
validateSlotIndex(slot);
stacks.set(slot, stack);
if(!stack.isEmpty() && stack.getCount() > 64) {
stack.setCount(64);
}
onContentsChanged(slot);
}
示例11: export
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean export(BlockPos pos, boolean simulate) {
TileEntity te = drone.world().getTileEntity(pos);
if (te != null) {
for (int i = 0; i < drone.getInv().getSlots(); i++) {
ItemStack droneStack = drone.getInv().getStackInSlot(i);
if (!droneStack.isEmpty()) {
if (widget.isItemValidForFilters(droneStack)) {
for (int side = 0; side < 6; side++) {
if (((ISidedWidget) widget).getSides()[side]) {
droneStack = droneStack.copy();
int oldCount = droneStack.getCount();
if (((ICountWidget) widget).useCount()) {
droneStack.setCount(Math.min(droneStack.getCount(), getRemainingCount()));
}
ItemStack remainder = IOHelper.insert(te, droneStack.copy(), EnumFacing.getFront(side), simulate);
int stackSize = drone.getInv().getStackInSlot(i).getCount() - (remainder.isEmpty() ? droneStack.getCount() : droneStack.getCount() - remainder.getCount());
droneStack.setCount(stackSize);
int exportedItems = oldCount - stackSize;
if (!simulate) {
drone.getInv().setStackInSlot(i, stackSize > 0 ? droneStack : ItemStack.EMPTY);
decreaseCount(exportedItems);
}
if (simulate && exportedItems > 0) return true;
// if (!(inv instanceof ISidedInventory))
// break; //doing it for every side for no side sensitive inventories would be a waste.
}
}
if (droneStack.isEmpty() && !simulate) drone.addAir(null, -PneumaticValues.DRONE_USAGE_INV);
else drone.addDebugEntry("gui.progWidget.inventoryExport.debug.filledToMax", pos);
} else {
drone.addDebugEntry("gui.progWidget.inventoryExport.debug.stackdoesntPassFilter", pos);
}
}
}
} else {
drone.addDebugEntry("gui.progWidget.inventory.debug.noInventory", pos);
}
return false;
}
示例12: copyStackWithSize
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Nonnull
public static ItemStack copyStackWithSize(@Nonnull ItemStack stack, int amount) {
if (stack.isEmpty() || amount <= 0) return ItemStack.EMPTY;
ItemStack s = stack.copy();
s.setCount(amount);
return s;
}
示例13: copyWithSize
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Nonnull
private ItemStack copyWithSize(@Nonnull ItemStack stack, int amount) {
if (stack.isEmpty()|| amount <= 0) return ItemStack.EMPTY;
ItemStack s = stack.copy();
s.setCount(Math.min(amount, stack.getMaxStackSize()));
return s;
}
示例14: addFilteredStackToDankNull
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static boolean addFilteredStackToDankNull(InventoryDankNull inventory, ItemStack filteredStack) {
if (getIndexForStack(inventory, filteredStack) >= 0) {
ItemStack currentStack = getFilteredStack(inventory, filteredStack);
currentStack.grow(filteredStack.getCount());
if (currentStack.getCount() > DankNullUtils.getDankNullMaxStackSize(inventory)) {
currentStack.setCount(DankNullUtils.getDankNullMaxStackSize(inventory));
}
inventory.setInventorySlotContents(getIndexForStack(inventory, filteredStack), currentStack);
//getInventory(dankNull).serializeNBT();
return true;
}
return false;
}
示例15: doEat
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public void doEat(EntityPlayer player, ItemStack is)
{
IExPPlayer p = IExPPlayer.of(player);
float missingCalories = 2000 - p.getCalories();
FoodEntry entry = this.getEntry(is);
float weight = this.getTotalWeight(is);
// Player will not eat rotten food.
float actual_weight = weight * (1 - (this.getTotalRot(is) / entry.getBaseHealth()));
// All that is left is rot.
if (actual_weight <= 0)
{
is.setCount(0);
return;
}
float caloriesConsumed = Math.min(100, missingCalories);
float weightNeeded = Math.min(caloriesConsumed / (entry.getCaloriesRestored() / 100), actual_weight);
caloriesConsumed = weightNeeded * (entry.getCaloriesRestored() / 100);
p.setCalories(p.getCalories() + caloriesConsumed);
if (actual_weight - weightNeeded <= 0)
{
is.setCount(0);
return;
}
this.setTotalWeight(is, weight - weightNeeded);
// Preserve rot values as the player is not eating rotten parts.
float rotValue = weight * this.getTotalRot(is);
float newRotValue = rotValue / (weight - weightNeeded);
this.setTotalRot(is, newRotValue);
}