[Solved] Glass Block Color

Hello Everyone,

I wish to implement a color onto my STAINED_GLASS line:

BlockState stainedGlassW = BlockState.builder().blockType(BlockTypes.STAINED_GLASS).build();

but I can not figure out how to do so. I’ve been hearing the terms Keys.COLOR, Keys.DYE_COLOR, Color.RED, on the internet, but it is still not clear to me where I am to use these in my line of code. It’s probably a simple task for experienced sponge plugin developers, but I am just learning the Sponge 4.2.0 API. Any help would be great. Thanks!

DyeableData dyeableData = Sponge.getDataManager().getManipulatorBuilder(DyeableData.class).get().create(); dyeableData.type().set(DyeColors.BLACK); itemStack.offer(dyeableData);

I believe this is the Keys.DYE_COLOR equivalent

blockState.offer(Keys.DYE_COLOR, DyeColors.RED)

2 Likes

@TrenTech Thank you for the quick reply!

I tried to enter the raw code provided, but I received the error message “Cannot make a static reference to the non-static method offer(DataManipulator<?,?>) from the type CompositeValueStore<DataHolder,DataManipulator<?,?>>” I made the method a static method, but that did not seemed to fix the issue. Any thoughts?

Oh I’m thinking ItemStack. I believe you need to offer it to the Location of the BlockState.

Sorry I’m on my cellphone so I’m pulling this off the top of my head

1 Like

I have tried to implement the code into my line, but I’m having no luck. I must be doing something wrong, but thank you for help thus far.

@TrenTech was correct, but he just used the wrong method name. For BlockStates, which are immutable, you’ll need to use with:

state = state.with(Keys.DYE_COLOR, DyeColors.RED).get()

Alternatively, you can use add on the Builder you get from BlockState.builder()

2 Likes

It worked! Thank you both @Aaron1011 and @TrenTech

1 Like