本文整理匯總了Java中org.spongepowered.api.item.inventory.ItemStack.offer方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemStack.offer方法的具體用法?Java ItemStack.offer怎麽用?Java ItemStack.offer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.spongepowered.api.item.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.offer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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();//
}
示例3: 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();//
}
示例4: 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);
}
示例5: commandItemLoreAdd
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private CompletableFuture<Boolean> commandItemLoreAdd(final EPlayer player, final String name) {
if(!player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
EAMessages.EMPTY_ITEM_IN_HAND.sender()
.prefix(EEMessages.PREFIX)
.sendTo(player);
return CompletableFuture.completedFuture(false);
}
ItemStack item = player.getItemInHand(HandTypes.MAIN_HAND).get();
List<Text> lore = new ArrayList<Text>();
if(item.get(Keys.ITEM_LORE).isPresent()){
lore = item.get(Keys.ITEM_LORE).get();
}
lore.add(EChat.of(name));
item.offer(Keys.ITEM_LORE, lore);
EEMessages.ITEM_LORE_ADD_LORE.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.ITEM_LORE_ADD_COLOR.getColor()))
.sendTo(player);
item.offer(Keys.ITEM_LORE, lore);
player.setItemInHand(HandTypes.MAIN_HAND, item);
return CompletableFuture.completedFuture(true);
}
示例6: createItem
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public CustomMaterial createItem(Cause cause) {
CustomMaterialRegistry registry = CustomMaterialRegistry.getInstance();
ItemStack itemStack = itemStackSnapshot.createStack();
SkinRecord skin = registry.getSkin(getPluginContainer(), getDefaultModel())
.orElseThrow(() -> new IllegalStateException("Models are not prepared."));
skin.apply(itemStack);
itemStack.offer(createDefaultCustomFeatureData());
CustomMaterial material = new CustomMaterial(itemStack, this);
CustomItemCreationEvent event = new CustomItemCreationEvent(material, cause);
Sponge.getEventManager().post(event);
return material;
}
示例7: createItem
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public CustomTool createItem(Cause cause) {
PluginContainer plugin = getPluginContainer();
ItemStack itemStack = itemStackSnapshot.createStack();
ItemType itemType = itemStack.getItem();
int durability = DurabilityRegistry.getInstance().getDurability(itemType, plugin, getDefaultModel())
.orElseThrow(() -> new IllegalStateException("Could not get the durability for the default models."));
itemStack.offer(Keys.UNBREAKABLE, true);
itemStack.offer(Keys.ITEM_DURABILITY, durability);
itemStack.offer(Keys.HIDE_UNBREAKABLE, true);
itemStack.offer(Keys.HIDE_ATTRIBUTES, true);
itemStack.offer(createDefaultCustomFeatureData());
CustomTool tool = new CustomTool(itemStack, this);
CustomItemCreationEvent event = new CustomItemCreationEvent(tool, cause);
Sponge.getEventManager().post(event);
return tool;
}
示例8: getCrateKey
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public ItemStack getCrateKey(String id,int quantity){
VirtualCrate vc = plugin.crateUtilities.getVirtualCrate(id);
if(vc != null){
ItemStack key = ItemStack.builder()
.itemType(ItemTypes.NETHER_STAR)
.quantity(quantity)
.add(Keys.DISPLAY_NAME, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(vc.displayName + " Key")).build();
ArrayList<Text> bb = new ArrayList<>();
bb.add(Text.of(TextColors.WHITE,"A key for a ", TextSerializers.LEGACY_FORMATTING_CODE.deserialize(vc.displayName) , TextColors.WHITE,"."));
bb.add(Text.of(TextColors.WHITE,"crate_" + id));
key.offer(Keys.ITEM_LORE,bb);
return key;
}
return null;
}
示例9: getCrateItem
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/***
* Retrieve the crate chest.
* @since 0.10.2
* @param quantity the quantity of chests you want.
* @return the ItemStack with the chest.
*/
public ItemStack getCrateItem(int quantity) {
ItemStack stacky = ItemStack.builder()
.itemType(crateBlockItemType)
.quantity(quantity)
.add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName)).build();
stacky = ItemStack.builder()
.fromContainer(stacky.toContainer().set(DataQuery.of("UnsafeDamage"),crateBlockDamage)) //OVERRIDE DAMAGE VAL! :)
.build();
ArrayList<Text> itemLore = new ArrayList<>();
itemLore.add(Text.of(TextColors.WHITE, "A placeable ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, " crate."));
itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
stacky.offer(Keys.ITEM_LORE, itemLore);
return ItemStack.builder().fromContainer(stacky.toContainer().set(DataQuery.of("UnsafeData","crateID"),id)).build();
}
示例10: confetti
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private ItemStack confetti(){
DyeColor[] colors = {DyeColors.BLUE,DyeColors.CYAN,DyeColors.LIME,DyeColors.LIGHT_BLUE,DyeColors.MAGENTA,DyeColors.ORANGE,DyeColors.PINK,DyeColors.PURPLE,DyeColors.RED,DyeColors.YELLOW};
ItemStack g =ItemStack.builder()
.itemType(ItemTypes.STAINED_GLASS_PANE)
.add(Keys.DYE_COLOR,colors[(int)Math.floor(Math.random() * colors.length)])
.build();
if(!outOfTime) {
g.offer(Keys.DISPLAY_NAME, Text.of(TextStyles.RESET, "Your prize awaits..."));
}else{
g.offer(Keys.DISPLAY_NAME, Text.of(TextStyles.RESET,TextColors.RED, "Ran out of time!"));
}
return g;
}
示例11: confetti
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private ItemStack confetti(){
DyeColor[] colors = {DyeColors.BLUE,DyeColors.CYAN,DyeColors.LIME,DyeColors.LIGHT_BLUE,DyeColors.MAGENTA,DyeColors.ORANGE,DyeColors.PINK,DyeColors.PURPLE,DyeColors.RED,DyeColors.YELLOW};
ItemStack g =ItemStack.builder()
.itemType(ItemTypes.STAINED_GLASS_PANE)
.add(Keys.DYE_COLOR,colors[(int)Math.floor(Math.random() * colors.length)])
.build();
g.offer(Keys.DISPLAY_NAME, Text.of("HuskyCrates"));
return g;
}
示例12: confettiBorder
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private ItemStack confettiBorder(){
DyeColor[] colors = {DyeColors.BLUE,DyeColors.CYAN,DyeColors.LIGHT_BLUE,DyeColors.LIME,DyeColors.MAGENTA,DyeColors.ORANGE,DyeColors.PINK,DyeColors.PURPLE,DyeColors.RED,DyeColors.YELLOW};
ItemStack g =ItemStack.builder()
.itemType(ItemTypes.STAINED_GLASS_PANE)
.add(Keys.DYE_COLOR,colors[(int)Math.floor(Math.random() * colors.length)])
.build();
g.offer(Keys.DISPLAY_NAME,Text.of(TextStyles.RESET,"You won an item!"));
return g;
}
示例13: repairInventory
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static ItemStack repairInventory(final ItemStack stack) {
Optional<Integer> data = stack.get(Keys.ITEM_DURABILITY);
if (data.isPresent()) {
stack.offer(Keys.ITEM_DURABILITY, Integer.MAX_VALUE);
}
return stack;
}
示例14: 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();
}
示例15: commandRepair
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private CompletableFuture<Boolean> commandRepair(final EPlayer player) {
Optional<ItemStack> optItem = player.getItemInMainHand();
if (!optItem.isPresent()) {
EAMessages.EMPTY_ITEM_IN_HAND.sendTo(player);
return CompletableFuture.completedFuture(false);
}
ItemStack item = optItem.get();
Optional<Integer> durability = item.get(Keys.ITEM_DURABILITY);
if (!durability.isPresent()) {
EEMessages.REPAIR_HAND_ERROR.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
.sendTo(player);
return CompletableFuture.completedFuture(false);
}
item.offer(Keys.ITEM_DURABILITY, Integer.MAX_VALUE);
if (item.get(Keys.ITEM_DURABILITY).get() == durability.get()) {
EEMessages.REPAIR_HAND_MAX_DURABILITY.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
.sendTo(player);
return CompletableFuture.completedFuture(false);
}
player.setItemInMainHand(item);
EEMessages.REPAIR_HAND_PLAYER.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
.sendTo(player);
return CompletableFuture.completedFuture(true);
}