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


Java ItemStack类代码示例

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


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

示例1: run

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
@Override
public void run() {
    if (!FIRST_GUI_CONTAINERS.containsKey(container)) {
        return;
    }
    for (int i = 10; i < 16; i++) {
        inventory.getSlot(new SlotIndex(i)).get().
                set(inventory.getSlot(new SlotIndex(i + 1)).get().peek().
                        orElse(ItemStack.of(ItemTypes.NONE, 1)));
    }
    if (index == drops.size()) {
        index = 0;
    }
    inventory.getSlot(new SlotIndex(16)).get().
            set(drops.get(index).getDropItem().orElse(ItemStack.of(ItemTypes.NONE, 1)));
    index++;
    Sponge.getScheduler().createTaskBuilder().delayTicks(scroll_delay).execute(this).submit(GWMCrates.getInstance());
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:19,代码来源:FirstGuiPreview.java

示例2: SecondOpenManager

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
public SecondOpenManager(Optional<String> id, Optional<SoundType> open_sound, Optional<Text> display_name,
                         ItemStack hidden_item, boolean increase_hidden_item_quantity,
                         int rows, boolean show_other_drops, int close_delay,
                         boolean forbid_close, boolean give_random_on_close,
                         Optional<SoundType> click_sound) {
    super("SECOND", id, open_sound);
    this.display_name = display_name;
    this.hidden_item = hidden_item;
    this.increase_hidden_item_quantity = increase_hidden_item_quantity;
    if (rows < 1 || rows > 6) {
        GWMCrates.getInstance().getLogger().info("ROWS value more than 6 or less than 1! Force set it to 3!");
        rows = 3;
    }
    this.rows = rows;
    this.show_other_drops = show_other_drops;
    this.close_delay = close_delay;
    if (close_delay <= show_other_drops_delay) {
        GWMCrates.getInstance().getLogger().info("SHOW OTHER DROPS DELAY more or equal to CLOSE DELAY! Force set it to 0!");
        show_other_drops_delay = 0;
    }
    this.forbid_close = forbid_close;
    this.give_random_on_close = give_random_on_close;
    this.click_sound = click_sound;
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:25,代码来源:SecondOpenManager.java

示例3: open

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
@Override
public void open(Player player, Manager manager) {
    PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
    Sponge.getEventManager().post(open_event);
    if (open_event.isCancelled()) return;
    Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
            property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
            property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
            build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
            property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
            build(GWMCrates.getInstance()));
    OrderedInventory ordered = Utils.castToOrdered(inventory);
    int hidden_item_quantity = hidden_item.getQuantity();
    for (int i = 0; i < 9 * rows; i++) {
        int quantity = increase_hidden_item_quantity ? i + 1 : hidden_item_quantity;
        ItemStack copy = hidden_item.copy();
        copy.setQuantity(quantity);
        ordered.getSlot(new SlotIndex(i)).get().set(copy);
    }
    Container container = player.openInventory(inventory).get();
    getOpenSound().ifPresent(open_sound -> player.playSound(open_sound, player.getLocation().getPosition(), 1.));
    SECOND_GUI_INVENTORIES.put(container, new Pair<SecondOpenManager, Manager>(this, manager));
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:24,代码来源:SecondOpenManager.java

示例4: FirstOpenManager

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
public FirstOpenManager(Optional<String> id, Optional<SoundType> open_sound, Optional<Text> display_name,
                        List<ItemStack> decorative_items, List<Integer> scroll_delays,
                        boolean clear_decorative_items, boolean clear_other_drops,
                        int close_delay, Optional<SoundType> scroll_sound,
                        Optional<SoundType> win_sound, Optional<DecorativeItemsChangeMode> decorative_items_change_mode) {
    super("FIRST", id, open_sound);
    this.display_name = display_name;
    if (decorative_items.size() != 20) {
        throw new RuntimeException("DECORATIVE_ITEMS size must be 20 instead of " + decorative_items.size() + "!");
    }
    this.decorative_items = decorative_items;
    this.scroll_delays = scroll_delays;
    this.clear_decorative_items = clear_decorative_items;
    this.clear_other_drops = clear_other_drops;
    this.close_delay = close_delay;
    this.scroll_sound = scroll_sound;
    this.win_sound = win_sound;
    this.decorative_items_change_mode = decorative_items_change_mode;
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:20,代码来源:FirstOpenManager.java

示例5: serializeInventory

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static List<DataView> serializeInventory(Inventory inventory) {
	DataContainer container;
	List<DataView> slots = new LinkedList<>();

	int i = 0;
	Optional<ItemStack> stack;

	for (Inventory inv : inventory.slots()) {
		stack = inv.peek();

		if (stack.isPresent()) {
			container = new org.spongepowered.api.data.MemoryDataContainer();

			container.set(SLOT, i);
			container.set(STACK, serializeItemStack(stack.get()));

			slots.add(container);
		}

		i++;
	}

	return slots;
}
 
开发者ID:AuraDevelopmentTeam,项目名称:InvSync,代码行数:26,代码来源:InventorySerializer.java

示例6: execute

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (!(commandSource instanceof Player)) {
        commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
        return CommandResult.empty();
    }
    Player plr = (Player)commandSource;
    if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
        commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
        return CommandResult.empty();
    }
    ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
    if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
        commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
        return CommandResult.empty();
    }
    VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
    int keyCount = key.getQuantity();
    plr.setItemInHand(HandTypes.MAIN_HAND,null);
    virtualCrate.giveVirtualKeys(plr,keyCount);
    //commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
    commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
            virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
    ));
    return CommandResult.success();
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:26,代码来源:DepositKey.java

示例7: listRewards

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
public void listRewards(Player player, VirtualCrate vc){
    if(!vc.showRewardsOnLeft) return;
    /* Home */
    StateContainer test = new StateContainer();
    Page.PageBuilder rewards = Page.builder();
    rewards.setAutoPaging(true);
    rewards.setTitle(TextSerializers.FORMATTING_CODE.deserialize(vc.displayName + " Rewards"));
    rewards.setEmptyStack(ItemStack.builder()
            .itemType(ItemTypes.STAINED_GLASS_PANE)
            .add(Keys.DYE_COLOR, DyeColors.BLACK)
            .add(Keys.DISPLAY_NAME, Text.of(TextColors.DARK_GRAY, "HuskyCrates")).build());
    for(Object[] e : vc.getItemSet()){
        CrateReward rew = (CrateReward)e[1];
        ItemStack item = rew.getDisplayItem().copy();
        if(vc.showProbability) {
            ArrayList<Text> lore = (ArrayList<Text>) item.getOrElse(Keys.ITEM_LORE, new ArrayList<>());
            lore.add(Text.of());

            lore.add(Text.of(TextColors.GRAY, TextStyles.ITALIC, "Win Probability: " + BigDecimal.valueOf((rew.getChance() / vc.getMaxProb()) * 100d).setScale(1, RoundingMode.HALF_UP).toString() + "%"));
            item.offer(Keys.ITEM_LORE, lore);
        }
        rewards.addElement(new Element(item));
    }
    test.setInitialState(rewards.build("rewards"));
    test.launchFor(player);
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:27,代码来源:HuskyCrates.java

示例8: getCrateKey

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
/***
 * Retrieve the crate item
 * @since 0.10.2
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateKey(int quantity){
    ItemStack key = ItemStack.builder()
            .itemType(keyType)
            .quantity(quantity)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Key")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A key for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }
    String keyUUID = registerKey(quantity);
    if(keyUUID == null){
        HuskyCrates.instance.logger.error("Throwing NullPointerException: Key failed to register.");
        throw new NullPointerException();
    }
    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id).set(DataQuery.of("UnsafeData","keyUUID"),keyUUID)).build();//

}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:26,代码来源:VirtualCrate.java

示例9: getCrateWand

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
/***
 * Retrieve the crate item
 * @since 1.2.1
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateWand(){
    ItemStack key = ItemStack.builder()
            .itemType(ItemTypes.BLAZE_ROD)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Wand")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A wand for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }

    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id)).build();//

}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:21,代码来源:VirtualCrate.java

示例10: getInventory

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
@Override
public Inventory getInventory() {
    Inventory woop = Inventory.builder()
            .property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9,1))
            .property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(Text.of(TextColors.DARK_RED,"INVALID CRATE TYPE!")))
            .listener(InteractInventoryEvent.class, evt ->{
                if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof  InteractInventoryEvent.Close)){
                    evt.setCancelled(true);
                }
                //System.out.println(evt.getClass());
            })
            .build(plugin);
    woop.offer(ItemStack.of(ItemTypes.BARRIER,256*2 + 64));
    for(Inventory e : woop.slots()){
        ItemStack b = e.peek().get();
        b.setQuantity(1);
        e.set(b);
    }
    return woop;
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:21,代码来源:NullCrateView.java

示例11: loadBackpack

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
private void loadBackpack(Player player, VirtualTool vt) {
    if (this.items != null) {
        for (Map.Entry<String, String> entry : this.items.entrySet()) {
            if (entry != null) {
                if (entry.getValue() != null) {
                    final SlotPos sp = SlotPos.of(Integer.parseInt(entry.getKey().split(",")[0].toString()), Integer.parseInt(entry.getKey().split(",")[1].toString()));
                    try {
                        final ItemStack itemst = Tools.Base64ToItemStack(entry.getValue());
                        this.inventory.query(sp).set(itemst);
                    } catch (Exception ex) {
                        VirtualTool.getInstance().getLogger().error("Failed to load a stack data from file for this user: " + player.getName() + " SlotPos: " + sp.getX() + "X," + sp.getY() + "Y");
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
}
 
开发者ID:poqdavid,项目名称:VirtualTool,代码行数:19,代码来源:Backpack.java

示例12: performRemoval

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
private void performRemoval(LookupLine line) {
	World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
	if (w == null) return;
	
	if (line.getTarget() instanceof ItemType) {
		
		Optional<TileEntity> te = w.getTileEntity(line.getPos());
		if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
			TileEntityCarrier c = (TileEntityCarrier) te.get();
			Inventory i = c.getInventory();
			
			Inventory slot = i.query(new SlotIndex(line.getSlot()));
			slot.set(ItemStack.of(ItemTypes.NONE, 0));
		}
		
	} else if (line.getTarget() instanceof BlockType) {
		
		BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
		w.setBlock(line.getPos(), block, Cause.source(container).build());
		
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:23,代码来源:RollbackManager.java

示例13: getAddTrailCommand

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
private static CommandSpec getAddTrailCommand() {
    return CommandSpec.builder()
        .permission("happytrails.command.add")
        .description(Text.of("Adds a new trail"))
        .executor((src, args) -> {
            if (!(src instanceof Player)) {
                return CommandResult.empty();
            }
            final Inventory creator = Inventory.builder()
                .of(InventoryArchetypes.CHEST)
                .property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(Text.of(TextColors.AQUA, "Create a Trail")))
                .listener(ClickInventoryEvent.Primary.class, (event) -> {

                })
                .build(HappyTrails.getInstance());
            creator.offer(ItemStack.of(ItemTypes.FIREWORKS, 1));
            creator.offer(ItemStack.builder().fromBlockState(BlockTypes.REDSTONE_BLOCK.getDefaultState()).build());
            ((Player) src).openInventory(creator);
            return CommandResult.success();
        })
        .build();

}
 
开发者ID:gabizou,项目名称:HappyTrails,代码行数:24,代码来源:TrailCommands.java

示例14: makeSpongeStack

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的package包/类
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
    final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
            .orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
    final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
    final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
            .orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
    final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    view.set(DATA_VALUE, baseItemStack.getData());
    store.deserialize(itemStack, view);
    final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
    if (!enchantments.isEmpty()) {
        itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
                .map(entry -> {
                    final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
                            .orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
                    return new ItemEnchantment(enchantment, entry.getValue());
                })
                .collect(Collectors.toList()));
    }
    return itemStack;
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:23,代码来源:LanternImplAdapter.java

示例15: processCostItem

import org.spongepowered.api.item.inventory.ItemStack; //导入依赖的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


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