Search in sources :

Example 1 with BannerMeta

use of org.bukkit.inventory.meta.BannerMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemPatterns method setPatterns.

private void setPatterns(List<Pattern> patterns) {
    ItemStack itemStack = item.getItemStack();
    ItemMeta itemMeta = itemStack.getItemMeta();
    if (itemMeta instanceof BlockStateMeta) {
        Banner banner = (Banner) ((BlockStateMeta) itemMeta).getBlockState();
        banner.setPatterns(patterns);
        banner.update();
        ((BlockStateMeta) itemMeta).setBlockState(banner);
    } else {
        ((BannerMeta) itemMeta).setPatterns(patterns);
    }
    itemStack.setItemMeta(itemMeta);
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Banner(org.bukkit.block.Banner) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 2 with BannerMeta

use of org.bukkit.inventory.meta.BannerMeta in project Glowstone by GlowstoneMC.

the class GlowBannerMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    DyeColor color = null;
    Pattern texture = null;
    ItemStack banner = null;
    for (ItemStack item : matrix) {
        if (item == null) {
            continue;
        }
        if (Tag.BANNERS.isTagged(item.getType())) {
            if (banner != null) {
                // Multiple banners found
                return null;
            }
            banner = item;
            continue;
        }
        if (MaterialTags.DYES.isTagged(item.getType())) {
            DyeColor itemColor = ((Dye) item.getData()).getColor();
            if (color != null && itemColor != color) {
                // Can't have multiple colors
                return null;
            }
            color = itemColor;
        }
    }
    if (banner == null) {
        // Couldn't found a banner to alter
        return null;
    }
    recipe: for (LayerRecipe recipe : LayerRecipe.values()) {
        if (recipe.hasItem()) {
            boolean foundDye = false;
            for (ItemStack item : matrix) {
                if (item == null) {
                    // Ignore blanks
                    continue;
                }
                if (Tag.BANNERS.isTagged(item.getType())) {
                    // Banner is already checked
                    continue;
                }
                if (MaterialTags.DYES.isTagged(item.getType())) {
                    if (foundDye) {
                        // Can't have multiple dyes
                        continue recipe;
                    }
                    foundDye = true;
                    continue;
                }
                if (item.getType() == recipe.getType() && item.getDurability() == recipe.getData()) {
                    if (texture != null) {
                        // Can't have multiple of same item
                        return null;
                    }
                    // Matches texture type
                    texture = recipe.getPattern();
                    continue;
                }
                // Non-recipe item in grid
                continue recipe;
            }
            if (texture == null) {
                // No item type for this recipe found
                continue;
            }
            if (color == null) {
                color = DyeColor.BLACK;
            }
            // Recipe matches
            break;
        } else {
            if (matrix.length != 9) {
                // Non-item recipes only work on 3x3
                return null;
            }
            for (int i = 0; i < 9; i++) {
                boolean hasValue = recipe.getValues()[i] == '#';
                ItemStack item = matrix[i];
                if (hasValue && item != null && MaterialTags.DYES.isTagged(item.getType())) {
                    continue;
                }
                if (!hasValue && (item == null || Tag.BANNERS.isTagged(item.getType()))) {
                    // Allow banner and blanks
                    continue;
                }
                // Non-recipe item found or no dye where dye should be
                continue recipe;
            }
            texture = recipe.getPattern();
            // Recipe matches
            break;
        }
    }
    if (texture == null) {
        // No texture found
        return null;
    }
    // Create result banner
    BannerMeta meta = (BannerMeta) banner.getItemMeta();
    List<Pattern> layers = meta.getPatterns();
    meta.setPatterns(layers);
    result = banner.clone();
    result.setItemMeta(meta);
    return result;
}
Also used : Pattern(org.bukkit.block.banner.Pattern) Dye(org.bukkit.material.Dye) BannerMeta(org.bukkit.inventory.meta.BannerMeta) DyeColor(org.bukkit.DyeColor) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with BannerMeta

use of org.bukkit.inventory.meta.BannerMeta in project Glowstone by GlowstoneMC.

the class GlowBannerCopyMatcher method getResult.

/*
    - Must be exactly two banners
    - 1 with no pattern, and 1 with at least one layer
    - Must be same colour
    - No other items allowed in matrix
     */
@Override
public ItemStack getResult(ItemStack[] matrix) {
    ArrayList<ItemStack> banners = new ArrayList<>();
    for (ItemStack item : matrix) {
        if (item == null) {
            continue;
        }
        // TODO: handle all new banner types
        if (item.getType() == Material.LEGACY_BANNER) {
            banners.add(item);
            continue;
        }
        // Non-banner item in matrix
        return null;
    }
    if (banners.size() != 2) {
        // Must have 2 banners only
        return null;
    }
    if (banners.get(0).getDurability() != banners.get(1).getDurability()) {
        // Not same color
        return null;
    }
    ItemStack original = null;
    ItemStack blank = null;
    for (ItemStack banner : banners) {
        BannerMeta meta = (BannerMeta) banner.getItemMeta();
        if (meta.getPatterns().isEmpty()) {
            if (blank != null) {
                // More than 1 blank
                return null;
            }
            blank = banner;
        } else {
            if (original != null) {
                // More than 1 original
                return null;
            }
            original = banner;
        }
    }
    if (original == null || blank == null) {
        // Haven't got both needed banners
        return null;
    }
    return original.clone();
}
Also used : BannerMeta(org.bukkit.inventory.meta.BannerMeta) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with BannerMeta

use of org.bukkit.inventory.meta.BannerMeta in project Glowstone by GlowstoneMC.

the class BlockCauldron method bleachBanner.

private boolean bleachBanner(GlowPlayer player, GlowBlock block) {
    // fired when a player bleaches a banner using the cauldron
    if (player.getGameMode() == GameMode.CREATIVE) {
        return false;
    }
    if (block.getData() > LEVEL_EMPTY) {
        ItemStack inHand = player.getItemInHand();
        BannerMeta meta = (BannerMeta) inHand.getItemMeta();
        List<Pattern> layers = meta.getPatterns();
        if (layers.isEmpty()) {
            return false;
        }
        if (!setCauldronLevel(block, block.getData() - 1, player, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
            return false;
        }
        meta.setPatterns(layers);
        inHand.setItemMeta(meta);
        return true;
    } else {
        return false;
    }
}
Also used : BannerMeta(org.bukkit.inventory.meta.BannerMeta) Pattern(org.bukkit.block.banner.Pattern) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with BannerMeta

use of org.bukkit.inventory.meta.BannerMeta in project Denizen-For-Bukkit by DenizenScript.

the class ItemBaseColor method setBaseColor.

private void setBaseColor(DyeColor color, TagContext context) {
    if (color == null && item.getBukkitMaterial() == Material.SHIELD) {
        ItemRawNBT property = ItemRawNBT.getFrom(item);
        MapTag nbt = property.getFullNBTMap();
        nbt.putObject("BlockEntityTag", null);
        property.setFullNBT(item, nbt, context, false);
        return;
    }
    ItemMeta itemMeta = item.getItemMeta();
    if (itemMeta instanceof BlockStateMeta) {
        Banner banner = (Banner) ((BlockStateMeta) itemMeta).getBlockState();
        banner.setBaseColor(color);
        banner.update();
        ((BlockStateMeta) itemMeta).setBlockState(banner);
    } else {
        ((BannerMeta) itemMeta).setBaseColor(color);
    }
    item.setItemMeta(itemMeta);
}
Also used : BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Banner(org.bukkit.block.Banner) MapTag(com.denizenscript.denizencore.objects.core.MapTag) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

BannerMeta (org.bukkit.inventory.meta.BannerMeta)15 ItemMeta (org.bukkit.inventory.meta.ItemMeta)8 ItemStack (org.bukkit.inventory.ItemStack)7 Banner (org.bukkit.block.Banner)6 Pattern (org.bukkit.block.banner.Pattern)6 BlockStateMeta (org.bukkit.inventory.meta.BlockStateMeta)6 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)5 SkullMeta (org.bukkit.inventory.meta.SkullMeta)5 BookMeta (org.bukkit.inventory.meta.BookMeta)4 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 DyeColor (org.bukkit.DyeColor)3 Enchantment (org.bukkit.enchantments.Enchantment)3 PotionData (org.bukkit.potion.PotionData)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GlowBanner (net.glowstone.block.entity.state.GlowBanner)2 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)2 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)2 MapMeta (org.bukkit.inventory.meta.MapMeta)2