Setting a block to Granite

So I know this sounds super simple, but for the life of me I can’t find out how to set a BlockType object to granite.

LinkedList<Blockdat> base = new LinkedList<Blockdat>();
		BlockType granite = BlockTypes.STONE;
		// do stuff here to make granite actually granite
		Blockdat pillowBasalt = new Blockdat(granite, 5);//Blockdat is my own class
		base.add(pillowBasalt);
		return base;

From perusing around, I know it has to do with manipulators correct?

Yes, you need to use manipulators. This is how you would change it to granite:

Location block;
// Check that it is indeed a stone type
Optional<StoneData> optional = block.getBlock().getManipulator(StoneData.class);
if (dirtData.isPresent()) {
    StoneData stoneData = optional.get();
    // Change it to granite
    stoneData.setValue(StoneTypes.GRANITE);
    block.offer(stoneData);
}

So in your case, I would recommend that the Blockdat class to accept a StoneType or such.

Also you should not set a BlockType variable, just use it statically.

Blockdat pillowBasalt = new Blockdat(BlockTypes.STONE, 5);
// Or if it accepts a StoneType
Blockdat pillowBasalt = new Blockdat(StoneTypes.GRANITE, 5);

Check [this][1] page for more information on changing blocks.
[1]: https://docs.spongepowered.org/en/plugin/basics/blocks/modifying.html

1 Like

the issue is im using blockdat for both stonetypes and dirt, sandstone, gravel, sand, water etc. I needed a better way to represent a stratigraphy column than is typically used in MC, especially a column that is not necessarily location specific. Let me see if I can make the above work and I’ll get back to you.

1 Like

Ok from what I can tell, there already has to be a block there to place blocks like Granite. The List<Blockdat> is invoked in my code in the generation phase, so it seems redundant and expensive to put a block at a specific coordinate, get it, and change its data. That combined with the fact that I have a generic class Blockdat which contains:

  • The Formation “type” (Any of the stone types, sand, dirt types, ore, sandstone, or clays)

  • The formation “width” (height in y direction)

somewhat confuses me. Maybe I need to design the Blockdat class differently?