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


Java ItemStackSnapshot.createStack方法代码示例

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


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

示例1: sweepFloor

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
public void sweepFloor() {

    for (Item item : getContained(Item.class)) {

      if (!contains(item)) {
        continue;
      }

      ItemType id = item.getItemType();
      for (ItemType aItem : ITEMS) {
        if (aItem == id) {
          ItemStackSnapshot snapshot = item.get(Keys.REPRESENTED_ITEM).get();
          int newAmt = (int) (snapshot.getCount() * .8);
          if (newAmt < 1) {
            item.remove();
          } else {
            ItemStack newStack = snapshot.createStack();
            newStack.setQuantity(newAmt);
            item.offer(Keys.REPRESENTED_ITEM, newStack.createSnapshot());
          }
          break;
        }
      }
    }
  }
 
开发者ID:Skelril,项目名称:Skree,代码行数:26,代码来源:CursedMineInstance.java

示例2: with

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Override
public IIngredient.Builder with(ItemStackSnapshot... items) {
    checkNotNull(items, "items");
    for (ItemStackSnapshot item : items) {
        checkNotNull(item, "item");
        final ItemStack item1 = item.createStack();
        this.matchers.add(itemStack -> LanternItemStack.areSimilar(itemStack, item1));
    }
    return withDisplay(items);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternIngredientBuilder.java

示例3: giveItems

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
public static Clause<Boolean, List<Clause<ItemStack, Integer>>> giveItems(Player player, Collection<ItemStack> stacks, Cause cause) {
  List<Clause<ItemStack, Integer>> transactions = new ArrayList<>(stacks.size());
  List<ItemStackSnapshot> itemBuffer = new ArrayList<>();
  itemBuffer.addAll(stacks.stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));

  PlayerInventory playerInventory = player.getInventory().query(PlayerInventory.class);
  List<Inventory> inventories = new ArrayList<>();
  inventories.add(playerInventory.getHotbar());
  inventories.add(playerInventory.getMain());

  // Loop through replacing empty space with the requested items
  for (Inventory inventory : inventories) {
    List<ItemStackSnapshot> newBuffer = new ArrayList<>();
    for (ItemStackSnapshot snapshot : itemBuffer) {
      ItemStack stack = snapshot.createStack();

      InventoryTransactionResult result = inventory.offer(stack);
      newBuffer.addAll(result.getRejectedItems());

      transactions.add(new Clause<>(stack, stack.getQuantity()));
    }
    itemBuffer = newBuffer;
  }

  // Drop remaining items
  new ItemDropper(player.getLocation()).dropStackSnapshots(itemBuffer, SpawnTypes.PLUGIN);

  return new Clause<>(true, transactions);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:30,代码来源:MarketImplUtil.java

示例4: ItemStackSnapshotView

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
public ItemStackSnapshotView(ItemStackSnapshot value) {
    super(value);

    this.stack = value.createStack();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:6,代码来源:ItemStackSnapshotView.java

示例5: withRemaining

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Override
public IIngredient.Builder withRemaining(ItemStackSnapshot item) {
    checkNotNull(item, "item");
    this.remainingItemProvider = itemStack -> item.createStack();
    return this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:LanternIngredientBuilder.java

示例6: getMatrixResult

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
/**
 * Gets the {@link MatrixResult}.
 *
 * @return The matrix result
 */
public MatrixResult getMatrixResult(int times) {
    checkArgument(times <= this.maxTimes, "times cannot exceed getMaxTimes");
    final ICraftingMatrix matrix = (ICraftingMatrix) this.matrix.copy();
    final List<ItemStackSnapshot> remaining = this.result.getRemainingItems();
    final List<ItemStack> rest = new ArrayList<>();
    final int w = matrix.width();
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < matrix.height(); y++) {
            ItemStack itemStack = matrix.get(x, y);
            if (!itemStack.isEmpty()) {
                itemStack.setQuantity(itemStack.getQuantity() -
                        (this.itemQuantities == null ? 1 : this.itemQuantities[x][y]) * times);
            }
            final ItemStackSnapshot itemStackSnapshot = remaining.get(y * w + x);
            if (!itemStackSnapshot.isEmpty()) {
                int quantity;
                final boolean flag = LanternItemStack.areSimilar(itemStack, itemStackSnapshot);
                if (itemStack.isEmpty() || flag) {
                    if (!flag) {
                        itemStack = itemStackSnapshot.createStack();
                        matrix.set(x, y, itemStack);
                    }
                    final int max = itemStack.getMaxStackQuantity();
                    quantity = itemStack.getQuantity() * times;
                    if (quantity > max) {
                        itemStack.setQuantity(max);
                        itemStack = itemStack.copy();
                        itemStack.setQuantity(quantity - max);
                    } else {
                        itemStack = null;
                    }
                } else {
                    itemStack = itemStackSnapshot.createStack();
                    itemStack.setQuantity(itemStack.getQuantity() * times);
                }
                if (itemStack != null) {
                    rest.add(itemStack);
                }
            }
        }
    }
    return new MatrixResult(matrix, rest);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:49,代码来源:ExtendedCraftingResult.java

示例7: getResult

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Override
public Optional<SmeltingResult> getResult(ItemStackSnapshot ingredient) {
    final ItemStack itemStack = ingredient.createStack();
    return this.ingredient.test(itemStack) ? Optional.of(this.resultProvider.get(itemStack)) : Optional.empty();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:6,代码来源:LanternSmeltingRecipe.java

示例8: toNullable

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Nullable
public static LanternItemStack toNullable(@Nullable ItemStackSnapshot itemStackSnapshot) {
    return itemStackSnapshot == null || itemStackSnapshot.isEmpty() ? null :  (LanternItemStack) itemStackSnapshot.createStack();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternItemStack.java

示例9: onOreDrop

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Listener
public void onOreDrop(
    DropItemEvent.Destruct event,
    @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause,
    @Named(NamedCause.NOTIFIER) Player player
) {
  if (!Probability.getChance(4)) {
    return;
  }

  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> loc = optLocation.get();
  Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);

  if (!optInst.isPresent()) {
    return;
  }

  CursedMineInstance inst = optInst.get();
  if (!inst.hasrecordForPlayerAt(player, loc)) {
    return;
  }

  List<ItemStackSnapshot> itemStacks = new ArrayList<>();
  Iterator<Entity> entityIterator = event.getEntities().iterator();
  while (entityIterator.hasNext()) {
    Entity entity = entityIterator.next();
    if (entity instanceof Item) {
      ItemStackSnapshot snapshot = ((Item) entity).item().get();
      itemStacks.add(snapshot);
      entityIterator.remove();
    }
  }

  int times = 1;

  Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
  if (optService.isPresent()) {
    ModifierService service = optService.get();
    if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
      times *= 2;
    }
  }

  for (ItemStackSnapshot stackSnapshot : itemStacks) {
    int quantity = Math.min(
        stackSnapshot.getCount() * Probability.getRangedRandom(4, 8),
        stackSnapshot.getType().getMaxStackQuantity()
    );

    for (int i = 0; i < times; ++i) {
      ItemStack stack = stackSnapshot.createStack();
      stack.setQuantity(quantity);
      player.getInventory().offer(stack);
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:64,代码来源:CursedMineListener.java


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