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);
}
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;
}
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();
}
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;
}
}
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);
}
Aggregations