-
Notifications
You must be signed in to change notification settings - Fork 27
How to use custom blocks
Benedikt S. Vogler edited this page Sep 28, 2017
·
2 revisions
If you want to use custom blocks you need to override the class CustomBlocks and set it to the maps.
CustomBlocks customBlocks = new YourCustomBlocks();
Map.setBlockConfig(customBlocks);
Wurfel Engine expects that every block type has a unique id or a different value.
@Override
public Block produce(int id, int value, Coordinate coords) {
Block block;
switch (id){
case 70:
block = Block.createBasicInstance(id);
block.setTransparent(true);
block.setNoSides();
break;
case 72:
block = new AnimatedBlock(id, new int[]{1000,1000},true, true);//animation lighting
block.setObstacle(true);
break;
default:
Gdx.app.error("CustomBlockFactory", "Block "+id+"not defined.");
block = Block.createBasicInstance(id);;
}
return block;
}
}
To use this class and register it as your block factory class set it
public class CustomConfiguration extends Configuration {
private CustomBlockFactory factory = new CustomBlockFactory();
@Override
public BlockFactory getBlockFactoy() {
return factory;
}
}
Then you can use non-default blocks as usual via
Block.getInstance(id)