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


Java ItemStackSnapshot类代码示例

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


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

示例1: processCostItem

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
private void processCostItem(Player player, String command, Consumer<CommandResult> callback)
{
    int count = Integer.parseInt(command.replaceFirst("\\s++$", ""));
    ItemStack stackUsed = SpongeUnimplemented.getItemHeldByMouse(player).createStack();
    int stackUsedQuantity = stackUsed.getQuantity();
    if (stackUsedQuantity > count)
    {
        stackUsed.setQuantity(stackUsedQuantity - count);
        SpongeUnimplemented.setItemHeldByMouse(player, stackUsed.createSnapshot());
        callback.accept(CommandResult.success());
    }
    else
    {
        SpongeUnimplemented.setItemHeldByMouse(player, ItemStackSnapshot.NONE);
        callback.accept(CommandResult.empty());
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:18,代码来源:VirtualChestActions.java

示例2: give

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
public void give(Player player) {
	this.checkCache();
	for (ItemStackSnapshot iss : itemStacksCache) {
		InventoryTransactionResult result = player.getInventory().offer(iss.createStack());
		for (ItemStackSnapshot is : result.getRejectedItems()) {
			Item item = (Item) player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
			item.offer(Keys.REPRESENTED_ITEM, is.copy());
			player.getWorld().spawnEntity(item, Cause.of(NamedCause.source(player), NamedCause.owner("BetterKits")));
		}
	}

	for (String command : this.getCommands()) {
		try {
			Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command.replace("%name", player.getName()).replace("%uuid", player.getUniqueId().toString()));
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:20,代码来源:Kit.java

示例3: getDefaultObjectMapper

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
private ObjectMapper getDefaultObjectMapper(boolean xml, boolean details, TreeNode<String, Boolean> perms) {
    if (perms == null) {
        throw new NullPointerException("Permissions may not be null");
    }

    ObjectMapper om = xml ? new XmlMapper() : new ObjectMapper();
    om.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    SimpleModule mod = new SimpleModule();
    for (Map.Entry<Class, BaseSerializer> entry : serializers.entrySet()) {
        mod.addSerializer(entry.getKey(), entry.getValue());
    }
    mod.addDeserializer(ItemStack.class, new ItemStackDeserializer());
    mod.addDeserializer(BlockState.class, new BlockStateDeserializer());
    mod.addDeserializer(ItemStackSnapshot.class, new ItemStackSnapshotDeserializer());
    mod.addDeserializer(Location.class, new LocationDeserializer());
    om.registerModule(mod);

    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter(BaseFilter.ID, new BaseFilter(details, perms));
    om.setFilterProvider(filterProvider);

    om.setAnnotationIntrospector(new AnnotationIntrospector(details));

    return om;
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:27,代码来源:SerializeService.java

示例4: populate

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
private void populate(SimpleCustomInventory inventory) {
    CustomInventoryData data = inventory.getCustomInventoryData();
    val slotIdToItemStack = data.getSlotIdToItemStack();

    inventory.getCustomSlots().forEach(customSlot -> {
        ItemStack itemStack = customSlot.getDefinition().getId()
                .flatMap(slotId -> Optional.ofNullable(slotIdToItemStack.get(slotId)))
                .map(ItemStackSnapshot::createStack)
                .orElseGet(() -> customSlot.getDefinition().createDefaultItemStack());

        customSlot.setItemStack(itemStack);
    });

    val slotIdToFeatureId = data.getSlotIdToFeatureId();

    slotIdToFeatureId.forEach((slotId, featureId) ->
            inventory.getCustomSlot(slotId).ifPresent(customSlot ->
                    customSlot.setFeature(featureId)
            )
    );
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:22,代码来源:SimpleCustomInventoryDefinition.java

示例5: getItemStack

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
public Optional<ItemStack> getItemStack() {
    Optional<Slot> slot = getSlot();

    if(slot.isPresent()) {
        return slot.get().peek();
    }

    if(definition.isPersistent()) {
        CustomInventoryData data = customInventoryDefinition.getCustomInventoryData(dataHolder);
        String definitionId = definition.getId()
                .orElseThrow(() -> new IllegalStateException("Could not access the ID of a persistent CustomSlot."));

        return Optional.ofNullable(data.getSlotIdToItemStack().get(definitionId))
                .map(ItemStackSnapshot::createStack);
    }

    return Optional.ofNullable(definition.createDefaultItemStack());
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:19,代码来源:CustomSlot.java

示例6: output

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
static AffectCustomSlotListener output() {
    return (customSlot, slotTransaction, affectSlotEvent) -> {
        if(slotTransaction.getFinal() == ItemStackSnapshot.NONE)
            return;

        ItemStack finalStackOne = slotTransaction.getFinal().createStack();
        ItemStack originalStackOne = slotTransaction.getOriginal().createStack();

        finalStackOne.setQuantity(1);
        originalStackOne.setQuantity(1);

        if(!finalStackOne.equals(originalStackOne)) {
            affectSlotEvent.setCancelled(true);
            return;
        }

        if(slotTransaction.getFinal().getCount() > slotTransaction.getOriginal().getCount())
            affectSlotEvent.setCancelled(true);
    };
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:21,代码来源:AffectCustomSlotListener.java

示例7: buildContent

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected Optional<CustomInventoryData> buildContent(DataView container) throws InvalidDataException {
    if(!container.contains(CUSTOM_INVENTORY_ID, CUSTOM_INVENTORY_SLOT_ID_TO_ITEMSTACK,
            CUSTOM_INVENTORY_SLOT_ID_TO_FEATURE_ID)) {
        return Optional.empty();
    }

    Optional<String> id = container.getString(CUSTOM_INVENTORY_ID.getQuery());

    if(!id.isPresent())
        throw new InvalidDataException("Could not access the ID of the inventory data.");

    val slotIdToItemStack = (Map<String, ItemStackSnapshot>) container.getMap(
            CUSTOM_INVENTORY_SLOT_ID_TO_ITEMSTACK.getQuery()
    ).orElse(null);

    val slotIdToFeatureId = (Map<String, String>) container.getMap(
            CUSTOM_INVENTORY_SLOT_ID_TO_FEATURE_ID.getQuery()
    ).orElse(null);

    return Optional.of(new CustomInventoryData(id.get(), slotIdToItemStack, slotIdToFeatureId));
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:24,代码来源:CustomInventoryDataBuilder.java

示例8: spawnItem

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
public void spawnItem(Location<World> location, ItemStackSnapshot snapshot, Object notifier) {
    World world = location.getExtent();
    Item rejectedItem = (Item) world.createEntity(EntityTypes.ITEM, location.getPosition());

    Cause cause = Cause.source(
            EntitySpawnCause.builder()
                    .entity(rejectedItem)
                    .type(SpawnTypes.PLUGIN)
                    .build()
            )
            .owner(CustomItemLibrary.getInstance().getPluginContainer())
            .notifier(notifier)
            .build();

    rejectedItem.offer(Keys.REPRESENTED_ITEM, snapshot);
    world.spawnEntity(rejectedItem, cause);
}
 
开发者ID:Limeth,项目名称:CustomItemLibrary,代码行数:18,代码来源:Util.java

示例9: handleOutputClick

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
private void handleOutputClick(SlotTransaction slotTransaction, Transaction<ItemStackSnapshot> cursorTransaction) {
    // Trying to put item in slot
    if (slotTransaction.getFinal() != ItemStackSnapshot.NONE) {
        if (slotTransaction.getOriginal() != cursorTransaction.getFinal()) {
            System.out.println("false positive");
            // False positive
            return;
        }
        System.out.println("put item in output");
        slotTransaction.setValid(false);
        // TODO because Sponge is broken - set custom to original
        cursorTransaction.setCustom(cursorTransaction.getOriginal());
        return;
    }
    if (!canTakeOutput()) {
        System.out.println("take output before ready");
        slotTransaction.setValid(false);
        cursorTransaction.setCustom(cursorTransaction.getOriginal());
        return;
    }
    System.out.println("take output");
    takeOutput();
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:24,代码来源:TileAutoCrafting.java

示例10: onPlayerCombat

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void onPlayerCombat(DamageEntityEvent event) {
  Entity targetEntity = event.getTargetEntity();
  if (!(targetEntity instanceof Living)) {
    return;
  }

  Optional<Clause<Living, ItemStackSnapshot>> optSourceEntity = getSource(event.getCause());
  if (!optSourceEntity.isPresent()) {
    return;
  }

  Living sourceEntity = optSourceEntity.get().getKey();
  ItemStackSnapshot snapshot = optSourceEntity.get().getValue();
  if (!applicabilityTest.test(sourceEntity, snapshot)) {
    return;
  }

  if (cooldownHandler.canUseAbility(sourceEntity)) {
    cooldownHandler.useAbility(sourceEntity);
  } else {
    return;
  }

  rangedCluster.getNextAttackToRun().run(sourceEntity, (Living) targetEntity, event);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:27,代码来源:RangedSpecialAttackClusterListener.java

示例11: getTarget

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@Override
public IInventory getTarget(LanternContainer container, AbstractInventorySlot slot) {
    if (container.getOpenInventory().containsInventory(slot)) {
        return getDefaultTarget(container, slot);
    }
    // The item stack should be present
    final ItemStackSnapshot snapshot = LanternItemStackSnapshot.wrap(slot.peek().get()); // Wrap, peek creates a copy
    // Check if the item can be used as a ingredient
    final Optional<SmeltingRecipe> optSmeltingRecipe = Lantern.getRegistry()
            .getSmeltingRecipeRegistry().findMatchingRecipe(snapshot);
    final List<IInventory> inventories = new ArrayList<>();
    final FurnaceInventory furnaceInventory = (FurnaceInventory) container.getOpenInventory();
    if (optSmeltingRecipe.isPresent()) {
        inventories.add(furnaceInventory.getInputSlot());
    }
    // Check if the item can be used as a fuel
    final Optional<IFuel> optFuel = Lantern.getRegistry()
            .getFuelRegistry().findMatching(snapshot);
    if (optFuel.isPresent()) {
        inventories.add(furnaceInventory.getFuelSlot());
    }
    return inventories.isEmpty() ? getDefaultTarget(container, slot) :
            inventories.size() == 1 ? inventories.get(0) : inventories.get(0).union(inventories.get(1));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:FurnaceShiftClickBehavior.java

示例12: build

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Override
public IShapelessCraftingRecipe build(String id, Object plugin) {
    checkState(this.resultProvider != null, "The result provider is not set.");
    checkState(!this.ingredients.isEmpty(), "The ingredients are not set.");
    checkNotNull(id, "id");
    checkNotNull(id, "plugin");

    final PluginContainer container = checkPlugin(plugin, "plugin");
    final int index = id.indexOf(':');
    if (index != -1) {
        final String pluginId = id.substring(0, index);
        checkState(pluginId.equals(container.getId()), "Plugin ids mismatch, "
                + "found %s in the id but got %s from the container", pluginId, container.getId());
        id = id.substring(index + 1);
    }

    final ItemStackSnapshot exemplary = this.resultProvider.getSnapshot(
            EmptyCraftingMatrix.INSTANCE, EmptyIngredientList.INSTANCE);
    return new LanternShapelessCraftingRecipe(container.getId(), id, exemplary,
            this.groupName, this.resultProvider, ImmutableList.copyOf(this.ingredients));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:LanternShapelessCraftingRecipeBuilder.java

示例13: onBlockCollide

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@Listener
public void onBlockCollide(CollideEvent.Impact event, @First Projectile projectile) {
  ProjectileSource source = projectile.getShooter();
  if (!(source instanceof Living)) {
    return;
  }

  Living sourceEntity = (Living) source;
  ItemStackSnapshot shootingItemStack = projectile.get(SHOOTING_ITEM_DATA_KEY).map(Optional::get).orElse(null);
  if (!applicabilityTest.test(sourceEntity, shootingItemStack)) {
    return;
  }

  if (cooldownHandler.canUseAbility(sourceEntity)) {
    cooldownHandler.useAbility(sourceEntity);
  } else {
    return;
  }

  attackCluster.getNextAbilityToRun().run(sourceEntity, event.getImpactPoint());
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:22,代码来源:PointOfContactClusterListener.java

示例14: init

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@Override
protected void init() {
    super.init();

    // Search for the underlying inventories
    this.output = query(Holder.CRAFTING_OUTPUT_OPERATION).first();
    this.grid = query(Holder.CRAFTING_GRID_OPERATION).first();

    // Add a change listener to update the output slot
    ((AbstractInventory) this.grid).addChangeListener(slot -> {
        final World world = getWorld();
        if (world == null) {
            return;
        }
        final Optional<CraftingResult> optResult = Lantern.getRegistry()
                .getCraftingRecipeRegistry().getResult(this.grid, getWorld());
        this.output.set(optResult
                .map(CraftingResult::getResult)
                .map(ItemStackSnapshot::createStack)
                .orElse(ItemStack.empty()));
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:LanternCraftingInventory.java

示例15: build

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入依赖的package包/类
@Override
public ISmeltingRecipe build() {
    check();

    // Attempt to generate a id for the smelting recipe
    String ingredient = this.exemplaryIngredient.getType().getId();
    ingredient = ingredient.substring(ingredient.indexOf(':') + 1);
    final ItemStackSnapshot exemplaryResult = getResultProvider().get(this.exemplaryIngredient).getResult();
    String result = exemplaryResult.getType().getId();
    result = result.substring(result.indexOf(':') + 1);

    final String id = ingredient + "_to_" + result;
    final int count = idCounters.computeIfAbsent(id, s -> 0) + 1;
    idCounters.put(id, count);

    return build0(id + "_" + count, Lantern.getGame().getImplementationPlugin());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:LanternSmeltingRecipeBuilder.java


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