How to set the color of an ItemStack Banner

Hello !

I would like to ask you a question about Banners. I’m trying to give players a Banner (ItemStack) of a specific color. Here is what I do:

ItemStack item = ItemStack.builder().itemType( ItemTypes.BANNER ).build();
item.offer(Keys.DYE_COLOR, DyeColors.RED);

But I always get a black banner (default color). Here is what I also tried:

  • Other keys such as Keys.DISPLAY_NAME, Keys.LORE etc. are perfectly applied to the item
  • The key Keys.DYE_COLOR works on wool blocks
  • The keys Keys.COLOR and Keys.BANNER_BASE_COLOR don’t work either

And what is really strange is that I manage to set a colored banner as a TileEntity:

location.setBlockType(BlockTypes.STANDING_BANNER, ...);
Optional<TileEntity> optBanner = location.getTileEntity();
if(optBanner.isPresent())
{
    Banner banner = (Banner) optBanner.get();
    banner.offer(banner.baseColor().set(DyeColors.RED));
}

Please let me know if I did something wrong :grin: !

Under the hood, banners are largely modified by their block state NBT tag. I am fairly certain that this is intended behaviour, although perhaps undesirable.

I think it should be possible to offer the itemstack BannerData. If it doesn’t work then it could be an issue with spongecommon.
Keys.BANNER_BASE_COLOR should work, maybe setting the data on the itemstack doesn’t work yet (but it should be possible to do)

banner.offer(banner.getOrCreate(BannerData.class).get().baseColor().set(DyeColors.ORANGE));
This is what I’m doing, but I’m getting a NoSuchElementException