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