當前位置: 首頁>>代碼示例>>Java>>正文


Java ItemStack.of方法代碼示例

本文整理匯總了Java中org.spongepowered.api.item.inventory.ItemStack.of方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemStack.of方法的具體用法?Java ItemStack.of怎麽用?Java ItemStack.of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongepowered.api.item.inventory.ItemStack的用法示例。


在下文中一共展示了ItemStack.of方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFor

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static ItemTag getFor(Action<String> error, String text) {
    List<String> split = CoreUtilities.split(text, '/', 3);
    ItemTypeTag type = ItemTypeTag.getFor(error, split.get(0));
    int q = 1;
    if (split.size() > 1) {
        q = (int) IntegerTag.getFor(error, split.get(1)).getInternal();
    }
    ItemStack its = ItemStack.of(type.getInternal(), q);
    if (split.size() > 2) {
        MapTag toApply = MapTag.getFor(error, split.get(2));
        for (Map.Entry<String, AbstractTagObject> a : toApply.getInternal().entrySet()) {
            DataKeys.tryApply(its, DataKeys.getKeyForName(a.getKey()), a.getValue(), error);
        }
    }
    return new ItemTag(its);
}
 
開發者ID:DenizenScript,項目名稱:Denizen2Sponge,代碼行數:17,代碼來源:ItemTag.java

示例2: commandBook

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private CompletableFuture<Boolean> commandBook(EPlayer player) {
    // Si le joueur a bien un item dans la main
    if (player.getItemInMainHand().isPresent()) {
        ItemStack item = player.getItemInMainHand().get();
        if (item.getType().equals(ItemTypes.WRITTEN_BOOK) && item.get(Keys.BOOK_PAGES).isPresent()) {
            // Nouveau livre
            ItemStack book = ItemStack.of(ItemTypes.WRITABLE_BOOK, 1);
            
            // Ajoute les pages
            book.offer(Keys.BOOK_PAGES, item.get(Keys.BOOK_PAGES).get());
            
            // Remplace le livre
            player.setItemInMainHand(book);
            
            EEMessages.BOOK_WRITABLE.sendTo(player);
        } else {
            EEMessages.BOOK_NO_WRITTEN.sendTo(player);
        }
    // Le joueur a aucun item dans la main
    } else {
        EAMessages.EMPTY_ITEM_IN_HAND.sender()
            .prefix(EEMessages.PREFIX)
            .sendTo(player);
    }
    return CompletableFuture.completedFuture(true);
}
 
開發者ID:EverCraft,項目名稱:EverEssentials,代碼行數:27,代碼來源:EEBook.java

示例3: PipeBlock

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public PipeBlock() {
    this.pane = ItemStack.of(ItemTypes.STAINED_GLASS_PANE, 1);
    Vector3d rotX = new Vector3d(90, 0, 0);
    Vector3d rotY = new Vector3d(0, 90, 0);
    this.entityStruct = new MultiEntityStructure.Builder()
            .define(Direction.DOWN.name(), EntityTypes.ARMOR_STAND,
                    armorStandOffset(true, Axis.Z, new Vector3f(0.5, 0.2, 0.5)),
                    ArmorStand.class, stand -> setupArmorStand(stand, rotX))
            .define(Direction.UP.name(), EntityTypes.ARMOR_STAND,
                    armorStandOffset(true, Axis.Z, new Vector3f(0.5, 0.7375, 0.5)),
                    ArmorStand.class, stand -> setupArmorStand(stand, rotX))
            .define(Direction.NORTH.name(), EntityTypes.ARMOR_STAND,
                    armorStandOffset(false, Axis.Z, new Vector3f(0.5, 0.2, 0.2)),
                    ArmorStand.class, stand -> setupArmorStand(stand, null))
            .define(Direction.SOUTH.name(), EntityTypes.ARMOR_STAND,
                    armorStandOffset(false, Axis.Z, new Vector3f(0.5, 0.2, 0.8)),
                    ArmorStand.class, stand -> setupArmorStand(stand, null))
            .define(Direction.EAST.name(), EntityTypes.ARMOR_STAND,
                    armorStandOffset(false, Axis.X, new Vector3f(0.8, 0.2, 0.5)),
                    ArmorStand.class, stand -> setupArmorStand(stand, rotY))
            .define(Direction.WEST.name(), EntityTypes.ARMOR_STAND,
                    armorStandOffset(false, Axis.X, new Vector3f(0.2, 0.2, 0.5)),
                    ArmorStand.class, stand -> setupArmorStand(stand, rotY))
            .build();
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:26,代碼來源:PipeBlock.java

示例4: create

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/**
 * @return A player head with this skin
 */
public ItemStack create(int quantity) {
    ItemStack result = ItemStack.of(ItemTypes.SKULL, quantity);

    apply(result);

    return result;
}
 
開發者ID:Limeth,項目名稱:MineskinSponge,代碼行數:11,代碼來源:SkinRecord.java

示例5: createPlayerHead

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static ItemStack createPlayerHead(GameProfile profile) {
    ItemStack skull = ItemStack.of(ItemTypes.SKULL, 1);
    skull.offer(Keys.SKULL_TYPE, SkullTypes.PLAYER);
    skull.offer(Keys.REPRESENTED_PLAYER, profile);
    return ItemStack.builder()
            .itemType(ItemTypes.SKULL)
            .keyValue(Keys.SKULL_TYPE, SkullTypes.PLAYER)
            .keyValue(Keys.REPRESENTED_PLAYER, profile)
            .build();
}
 
開發者ID:EverCraft,項目名稱:EverAPI,代碼行數:11,代碼來源:UtilsItemStack.java

示例6: getSellDisplayItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/** create a Item with custom description adding the sell-price for a stack with the present size */
public ItemStack getSellDisplayItem(int patchedSlot, UUID player) {
    if (sellprice == null) return ItemStack.of(FieldResolver.emptyHandItem(), 1); //nothing
    Text cs = currency.getSymbol();
    ItemStack dis = item.copy();
    List<Text> desc = dis.get(Keys.ITEM_LORE).orElse(new LinkedList<Text>());
    desc.add(Text.of(TextColors.GREEN, (item.getQuantity()>1
            ? VillagerShops.getTranslator().localText("shop.item.sell.stack")
                .replace("%price%", String.format("%.2f", buyprice))
                .replace("%itemprice%", Text.of(String.format("%.2f", buyprice/(double)item.getQuantity())))
                .replace("%currency%", cs)
                .resolve(player).orElse(
                    Text.of(TextColors.GREEN, "Sell for: ", TextColors.WHITE, String.format("%.2f", buyprice), cs, String.format(" (� %.2f", buyprice/(double)item.getQuantity()), cs, ')')
                    )
            : VillagerShops.getTranslator().localText("shop.item.sell.one")
            .replace("%price%", String.format("%.2f", buyprice))
            .replace("%currency%", cs)
            .resolve(player).orElse(
                Text.of(TextColors.GREEN, "Sell for: ", TextColors.WHITE, String.format("%.2f", buyprice), cs)
                )
            )));
    if (maxStock>0) 
        desc.add(Text.of(TextColors.GRAY, 
                VillagerShops.getTranslator().localText("shop.item.stock")
                    .replace("%amount%", getStocked())
                    .replace("%max%", maxStock)
                    .resolve(player).orElse(
                        Text.of(String.format("In Stock: %d/%d", getStocked(), maxStock))
                        ))); 
    
    dis.offer(Keys.ITEM_LORE, desc);
    
    return ItemStack.builder().fromContainer(
               dis.toContainer().set(DataQuery.of("UnsafeData", "vShopSlotNum"), patchedSlot) ).build();
}
 
開發者ID:DosMike,項目名稱:VillagerShops,代碼行數:36,代碼來源:StockItem.java

示例7: getBuyDisplayItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/** create a Item with custom description adding the buy-price for a stack with the present size */
public ItemStack getBuyDisplayItem(int patchedSlot, UUID player) {
    if (buyprice == null) return ItemStack.of(FieldResolver.emptyHandItem(), 1); //nothing
    Text cs = currency.getSymbol();
    ItemStack dis = item.copy();
    List<Text> desc = dis.get(Keys.ITEM_LORE).orElse(new LinkedList<Text>());
    desc.add(Text.of(TextColors.RED, (item.getQuantity()>1
            ? VillagerShops.getTranslator().localText("shop.item.buy.stack")
                .replace("%price%", String.format("%.2f", buyprice))
                .replace("%itemprice%", Text.of(String.format("%.2f", buyprice/(double)item.getQuantity())))
                .replace("%currency%", cs)
                .resolve(player).orElse(
                    Text.of(TextColors.RED, "Buy for: ", TextColors.WHITE, String.format("%.2f", buyprice), cs, String.format(" (� %.2f", buyprice/(double)item.getQuantity()), cs, ')')
                    )
            : VillagerShops.getTranslator().localText("shop.item.buy.one")
            .replace("%price%", String.format("%.2f", buyprice))
            .replace("%currency%", cs)
            .resolve(player).orElse(
                Text.of(TextColors.RED, "Buy for: ", TextColors.WHITE, String.format("%.2f", buyprice), cs)
                )
            )));
    if (maxStock>0) 
        desc.add(Text.of(TextColors.GRAY, 
            VillagerShops.getTranslator().localText("shop.item.stock")
                .replace("%amount%", getStocked())
                .replace("%max%", maxStock)
                .resolve(player).orElse(
                    Text.of(String.format("In Stock: %d/%d", getStocked(), maxStock))
                    )));
    
    dis.offer(Keys.ITEM_LORE, desc);

    return ItemStack.builder().fromContainer(
               dis.toContainer().set(DataQuery.of("UnsafeData", "vShopSlotNum"), patchedSlot) ).build();
}
 
開發者ID:DosMike,項目名稱:VillagerShops,代碼行數:36,代碼來源:StockItem.java

示例8: createItemUnsafe

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public ItemStack createItemUnsafe(ItemType itemType, PluginContainer pluginContainer, String model) {
    int durability = getDurability(itemType, pluginContainer, model)
            .orElseThrow(() -> new IllegalStateException("The model should have been registered by now, is the definition actually being registered?"));

    ItemStack itemStack = ItemStack.of(itemType, 1);

    itemStack.offer(Keys.UNBREAKABLE, true);
    itemStack.offer(Keys.ITEM_DURABILITY, durability);

    return itemStack;
}
 
開發者ID:Limeth,項目名稱:CustomItemLibrary,代碼行數:12,代碼來源:DurabilityRegistry.java

示例9: createItemStack

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public ItemStack createItemStack() {
    ItemStack stack = ItemStack.of(getVanillaItem(), 1);
    CustomItemData customData = stack.getOrCreate(CustomItemData.class).get();
    applyItemStackData(customData.getData());
    stack.tryOffer(customData);
    applyItemStackModifiers(stack);
    return stack;
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:9,代碼來源:CustomItem.java

示例10: onPreInitialization

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Listener
public void onPreInitialization(GamePreInitializationEvent event) {
    instance = this;

    try {
        loadStrings();
    } catch (IOException ex) {
        throw new RuntimeException("Failed to load strings!", ex);
    }

    if (FlintCore.getApiRevision() < MIN_FLINT_VERSION) {
        getLogger().error(getString("log.error.flint-version", MIN_FLINT_VERSION + ""));
        return;
    }

    // general plugin initialization
    Sponge.getEventManager().registerListeners(this, new BlockListener());
    Sponge.getEventManager().registerListeners(this, new PlayerListener());

    registerCommands();

    //MIN_PLAYERS = getConfig().getInt("min-prep-players"); //TODO
    MIN_PLAYERS = 2;

    //int shovelType = getConfig().getInt("shovel-type"); //TODO
    int shovelType = 3;
    ItemType shovelItem = shovelType >= 0 && shovelType < SHOVELS.size()
            ? SHOVELS.get(shovelType)
            : SHOVELS.get(3);
    SHOVEL = ItemStack.of(shovelItem, 1);

    // Flint initialization
    mg = FlintCore.registerPlugin("infernospleef");
    mg.getEventBus().register(new MinigameListener());

    ImmutableSet<LifecycleStage> stages = ImmutableSet.copyOf(new LifecycleStage[]{
            new LifecycleStage(WAITING_STAGE_ID, -1),
            //new LifecycleStage(PREPARING_STAGE_ID, getConfig().getInt("prep-time")), //TODO
            new LifecycleStage(PREPARING_STAGE_ID, 10),
            //new LifecycleStage(PLAYING_STAGE_ID, getConfig().getInt("round-time")) //TODO
            new LifecycleStage(PLAYING_STAGE_ID, 30)
    });
    mg.setConfigValue(ConfigNode.DEFAULT_LIFECYCLE_STAGES, stages);
    //mg.setConfigValue(ConfigNode.MAX_PLAYERS, getConfig().getInt("arena-size")); //TODO
    mg.setConfigValue(ConfigNode.MAX_PLAYERS, 32);
}
 
開發者ID:caseif,項目名稱:InfernoSpleef,代碼行數:47,代碼來源:Main.java

示例11: commandItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private CompletableFuture<Boolean> commandItem(final EPlayer player, String type_string, String value) {
    Optional<ItemType> type = UtilsItemType.getItemType(type_string);
    
    // Le type n'existe pas
    if (!type.isPresent()) {
        EEMessages.ITEM_ERROR_ITEM_NOT_FOUND.sender()
            .replace("{item}", type_string)
            .sendTo(player);
        return CompletableFuture.completedFuture(false);
    }
    
    // L'item est dans la BlackList
    if (this.blacklist.contains(type.get())) {
        EEMessages.ITEM_ERROR_ITEM_BLACKLIST.sendTo(player);
        return CompletableFuture.completedFuture(false);
    }
    
    ItemStack item = ItemStack.of(type.get(), 1);
    int quantity = type.get().getMaxStackQuantity();
    Optional<ItemStack> item_data = UtilsItemType.getCatalogType(item, value);
    
    // Si la valeur est une data
    if (item_data.isPresent()){
        return this.commandGive(player, item_data.get(), quantity);
    }
    
    // La quantité n'est pas un nombre
    try {
        quantity = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        EAMessages.IS_NOT_NUMBER.sender()
            .prefix(EEMessages.PREFIX)
            .replace("{number}", value)
            .sendTo(player);
        return CompletableFuture.completedFuture(false);
    }
        
    // La valeur n'est pas correcte
    if (quantity < 1 && quantity > type.get().getMaxStackQuantity()) {
        EEMessages.ITEM_ERROR_QUANTITY.sender()
            .replace("{amount}", String.valueOf(type.get().getMaxStackQuantity()))
            .sendTo(player);
        return CompletableFuture.completedFuture(false);
    }
    
    return this.commandGive(player, item, quantity);
}
 
開發者ID:EverCraft,項目名稱:EverEssentials,代碼行數:48,代碼來源:EEItem.java

示例12: getParamFromJson

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private static Tuple<Class, Object> getParamFromJson(JsonNode node) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    if (!node.isObject())
        throw new ClassNotFoundException(node.toString());

    String type = node.get("type").asText().toLowerCase();
    JsonNode e = node.get("value");

    switch (type) {
        case "int":
        case "integer":
            return new Tuple<>(Integer.class, e.asInt());
        case "float":
            return new Tuple<>(Float.class, (float)e.asDouble());
        case "double":
            return new Tuple<>(Double.class, e.asDouble());
        case "bool":
        case "boolean":
            return new Tuple<>(Boolean.class, e.asBoolean());
        case "byte":
            return new Tuple<>(Byte.class, (byte)e.asInt());
        case "char":
            return new Tuple<>(Character.class, e.asText().charAt(0));
        case "long":
            return new Tuple<>(Long.class, e.asLong());
        case "short":
            return new Tuple<>(Short.class, (short)e.asInt());
        case "string":
            return new Tuple<>(String.class, e.asText());
        case "class":
            return new Tuple<>(Class.class, Class.forName(type));
        case "enum":
            Class c = Class.forName(e.get("type").asText());
            String name = e.get("value").asText();
            return new Tuple<Class, Object>(c, Enum.valueOf(c, name));

        case "vector3d":
            return new Tuple<>(Vector3d.class, new Vector3d(e.get("x").asDouble(), e.get("y").asDouble(), e.get("z").asDouble()));

        case "vector3i":
            return new Tuple<>(Vector3i.class, new Vector3i(e.get("x").asInt(), e.get("y").asInt(), e.get("z").asInt()));

        case "text":
            return new Tuple<>(Text.class, Text.of(e.asText()));

        case "world":
            Optional<World> w = Sponge.getServer().getWorld(UUID.fromString(e.asText()));
            return new Tuple<>(World.class, w.orElse(null));

        case "player":
            Optional<Player> p = Sponge.getServer().getPlayer(UUID.fromString(e.asText()));
            return new Tuple<>(Player.class, p.orElse(null));

        case "itemstack":
            String cName = e.get("itemType").asText();
            Optional<ItemType> t = Sponge.getRegistry().getType(ItemType.class, cName);
            int amount = e.get("amount").asInt();

            if (!t.isPresent())
                throw new ClassNotFoundException(cName);

            return new Tuple<>(ItemStack.class, ItemStack.of(t.get(), amount));

        case "static":
            Class clazz = Class.forName(e.get("class").asText());
            Field f = clazz.getField(e.get("field").asText());
            return new Tuple<>(f.getType(), f.get(null));

        default:
            return null;
    }
}
 
開發者ID:Valandur,項目名稱:Web-API,代碼行數:72,代碼來源:Util.java


注:本文中的org.spongepowered.api.item.inventory.ItemStack.of方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。