/** * Gets whether this item type has a block representation. * * @return If it has a block */ public boolean hasBlockType() { return getBlockType() != null; }
private static ItemCategory register(final String id) { return register(new ItemCategory(id)); }
@Override public String toString() { return getId(); }
/** * Gets the item representation of this block type, if it exists. * * @return The item representation */ @Nullable public ItemType getItemType() { return ItemTypes.get(this.id); }
/** * Set the tool. * * @param item the item type * @param tool the tool to set, which can be {@code null} * @throws InvalidToolBindException if the item can't be bound to that item */ public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException { if (item.hasBlockType()) { throw new InvalidToolBindException(item, "Blocks can't be used"); } else if (item == ItemTypes.get(config.wandItem)) { throw new InvalidToolBindException(item, "Already used for the wand"); } else if (item == ItemTypes.get(config.navigationWand)) { throw new InvalidToolBindException(item, "Already used for the navigation wand"); } this.tools.put(item, tool); }
@Override public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException { final ItemType typeId = getItemInHand(handSide).getType(); if (typeId.hasBlockType()) { return typeId.getBlockType().getDefaultState().toBaseBlock(); } else { throw new NotABlockException(); } }
@ExceptionMatch public void convert(InvalidToolBindException e) throws CommandException { throw new CommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage()); }
public static ItemCategory register(final ItemCategory tag) { return ItemCategory.REGISTRY.register(tag.getId(), tag); }
/** * Checks whether the BaseItem is contained within * this category. * * @param baseItem The item * @return If it's a part of this category */ public boolean contains(BaseItem baseItem) { return this.getAll().contains(baseItem.getType()); } }
public static ItemType register(final ItemType item) { return ItemType.REGISTRY.register(item.getId(), item); }
@Override public BaseItemStack getItemInHand(HandSide handSide) { Optional<ItemStack> is = this.player.getItemInHand(handSide == HandSide.MAIN_HAND ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND); return is.map(itemStack -> new BaseItemStack(ItemTypes.get(itemStack.getType().getId()))).orElse(null); }
/** * Create a Bukkit Material form a WorldEdit ItemType * * @param itemType The WorldEdit ItemType * @return The Bukkit Material */ public static Material adapt(ItemType itemType) { checkNotNull(itemType); if (!itemType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports Minecraft items"); } return Material.getMaterial(itemType.getId().substring(10).toUpperCase()); }
/** * Converts a Material to a ItemType * * @param material The material * @return The itemtype */ public static ItemType asItemType(Material material) { checkNotNull(material); if (!material.isItem()) { throw new IllegalArgumentException(material.getKey().toString() + " is not an item!"); } return ItemTypes.get(material.getKey().toString()); }
@Nullable @Override public String getName(ItemType itemType) { BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId()); return itemEntry != null ? itemEntry.localizedName : null; } }
/** * Create a WorldEdit BaseItemStack from a Bukkit ItemStack * * @param itemStack The Bukkit ItemStack * @return The WorldEdit BaseItemStack */ public static BaseItemStack adapt(ItemStack itemStack) { checkNotNull(itemStack); return new BaseItemStack(ItemTypes.get(itemStack.getType().getKey().toString()), itemStack.getAmount()); }
@Override public void giveItem(BaseItemStack itemStack) { this.player.inventory.addItemStackToInventory( new ItemStack(Item.getByNameOrId(itemStack.getType().getId()), itemStack.getAmount(), 0)); }
@Override public BaseItemStack getItemInHand(HandSide handSide) { ItemStack is = this.player.getHeldItem(handSide == HandSide.MAIN_HAND ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND); return new BaseItemStack(ItemTypes.get(ForgeRegistries.ITEMS.getKey(is.getItem()).toString())); }
public static ItemStack toForgeItemStack(BaseItemStack item) { NBTTagCompound forgeCompound = null; if (item.getNbtData() != null) { forgeCompound = NBTConverter.toNative(item.getNbtData()); } return new ItemStack(Item.getByNameOrId(item.getType().getId()), item.getAmount(), 0, forgeCompound); }
@Command( aliases = { "/wand" }, usage = "", desc = "Get the wand object", min = 0, max = 0 ) @CommandPermissions("worldedit.wand") public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1)); player.print("Left click: select pos #1; Right click: select pos #2"); }