Search in sources :

Example 11 with Pattern

use of org.bukkit.block.banner.Pattern 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 12 with Pattern

use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelper_v1_8_R3 method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<CompoundTag>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<String, Tag>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getInstance().getBlockHelper().getNbtData(location.getBlock()).createBuilder().putInt("Base", base.getDyeData()).put("Patterns", new ListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListTag(net.aufdemrand.denizen.nms.util.jnbt.ListTag) CompoundTag(net.aufdemrand.denizen.nms.util.jnbt.CompoundTag)

Example 13 with Pattern

use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelper_v1_11_R1 method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<CompoundTag>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<String, Tag>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getInstance().getBlockHelper().getNbtData(location.getBlock()).createBuilder().putInt("Base", base.getDyeData()).put("Patterns", new ListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListTag(net.aufdemrand.denizen.nms.util.jnbt.ListTag) CompoundTag(net.aufdemrand.denizen.nms.util.jnbt.CompoundTag)

Example 14 with Pattern

use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelper_v1_9_R2 method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<CompoundTag>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<String, Tag>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getInstance().getBlockHelper().getNbtData(location.getBlock()).createBuilder().putInt("Base", base.getDyeData()).put("Patterns", new ListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ListTag(net.aufdemrand.denizen.nms.util.jnbt.ListTag) CompoundTag(net.aufdemrand.denizen.nms.util.jnbt.CompoundTag)

Example 15 with Pattern

use of org.bukkit.block.banner.Pattern in project Glowstone by GlowstoneMC.

the class BlockBanner method fromNBT.

public static List<Pattern> fromNBT(List<CompoundTag> tag) {
    List<Pattern> banner = new ArrayList<>();
    for (CompoundTag layer : tag) {
        PatternType patternType = PatternType.getByIdentifier(layer.getString("Pattern"));
        DyeColor color = DyeColor.getByDyeData((byte) layer.getInt("Color"));
        banner.add(new Pattern(color, patternType));
    }
    return banner;
}
Also used : PatternType(org.bukkit.block.banner.PatternType) Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) DyeColor(org.bukkit.DyeColor) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

Pattern (org.bukkit.block.banner.Pattern)31 ArrayList (java.util.ArrayList)17 DyeColor (org.bukkit.DyeColor)9 HashMap (java.util.HashMap)6 BannerMeta (org.bukkit.inventory.meta.BannerMeta)6 PatternType (org.bukkit.block.banner.PatternType)5 CompoundTag (net.aufdemrand.denizen.nms.util.jnbt.CompoundTag)4 ListTag (net.aufdemrand.denizen.nms.util.jnbt.ListTag)4 CompoundTag (net.glowstone.util.nbt.CompoundTag)4 BookMeta (org.bukkit.inventory.meta.BookMeta)4 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)4 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 SkullMeta (org.bukkit.inventory.meta.SkullMeta)4 CompoundTag (com.denizenscript.denizen.nms.util.jnbt.CompoundTag)3 JNBTListTag (com.denizenscript.denizen.nms.util.jnbt.JNBTListTag)3 MCPattern (com.laytonsmith.abstraction.MCPattern)3 Map (java.util.Map)3 Banner (org.bukkit.block.Banner)3 Enchantment (org.bukkit.enchantments.Enchantment)3