In sponge 7.0 I can set dye color in block/item by use this code.
DyeColor color;
blockEntity.offer(Keys.BANNER_BASE_COLOR, color);
tileEntity.offer(Keys.DYE_COLOR, color);
item.offer(Keys.DYE_COLOR, color);
but In sponge 8.0 It dosen’t work.
How can I set dye color in block/item in sponge 8.0 ?
Please help me.
For clarification? Do you mean dye colour of a block (say wool) or the base colour of a banner?
Banner Base Colour
Keys.DYE_COLOR
or you can use code
banner.baseColor().set(DyeColors.BLACK.get());
Regular blocks/items
As for regular items/blocks its a little different to what it was before.
Minecraft wise, pre 1.13. All the varients of a block (example of wool) were stored under a single id with a sub id being what defined the wool colour
1.13 and onwards. Sub ids were removed and all blocks were given there own id. This means less data is needed to send between the client and server, but it is harder to work with. You can use the Tag
system with BlockTypeTags.WOOL
being one of them (however I have heard a lot of the tag system was removed in API 9 as mods don’t always respect it).
At the end of the day, because blocks and items that are similar are now classed as a complete different block/item. The only way to change from one to another is to treat them as different blocks.
If you want to keep all the same properties on the block, just change the colour (such as if you had stairs in a rotation and oriantation, just wanted to change the wood type) then you could do the following
BlockState originalBlockState;
BlockState newState = BlockState
.builder()
.from(originalBlockState)
.blockType(BlockTypes.BIRCH_STAIRS)
.build();
As the from
takes all the properties (including the type) and then you override the type. But you still need to set the block like it is a new block.
1 Like