Suffix block classes with "Block"
This commit is contained in:
parent
e35c46b408
commit
ac5132feda
2 changed files with 16 additions and 13 deletions
|
@ -68,16 +68,16 @@ class BlocksAndMaterialGenerator(
|
||||||
.writeTo(outputDir)
|
.writeTo(outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
val materialLines = listOf("%L", "%S", "%L", "%Lf", "%L", "%L", "%L", "BLOCK_COLLISION_SHAPES[%L]")
|
private val materialLines = listOf("%L", "%S", "%L", "%Lf", "%L", "%L", "%L", "BLOCK_COLLISION_SHAPES[%L]")
|
||||||
|
|
||||||
private fun generateBlockStubs(blocks: List<JsonAny>, collisionShapes: Map<String, JsonAny>) {
|
private fun generateBlockStubs(blocks: List<JsonAny>, collisionShapes: Map<String, JsonAny>) {
|
||||||
for (block in blocks) {
|
for (block in blocks) {
|
||||||
val lowerUnderscoreName = block.get("name").toString()
|
val lowerUnderscoreName = block.get("name").toString()
|
||||||
if (BLOCK_BLACKLIST.contains(lowerUnderscoreName)) continue
|
if (BLOCK_BLACKLIST.contains(lowerUnderscoreName)) continue
|
||||||
|
|
||||||
val upperCamelName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, lowerUnderscoreName)
|
val className = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, lowerUnderscoreName) + "Block"
|
||||||
|
|
||||||
val filePathRelativeToSourceRoot = "./${BLOCK_PACKAGE.replace(".", "/")}/$upperCamelName.kt"
|
val filePathRelativeToSourceRoot = "./${BLOCK_PACKAGE.replace(".", "/")}/$className.kt"
|
||||||
if (sourcesDir.resolve(filePathRelativeToSourceRoot).exists()) continue
|
if (sourcesDir.resolve(filePathRelativeToSourceRoot).exists()) continue
|
||||||
|
|
||||||
val materialArgs = arrayOf(
|
val materialArgs = arrayOf(
|
||||||
|
@ -91,7 +91,7 @@ class BlocksAndMaterialGenerator(
|
||||||
collisionShapes.getValue(lowerUnderscoreName).toInt()
|
collisionShapes.getValue(lowerUnderscoreName).toInt()
|
||||||
)
|
)
|
||||||
|
|
||||||
val type = TypeSpec.classBuilder(upperCamelName)
|
val type = TypeSpec.classBuilder(className)
|
||||||
.apply {
|
.apply {
|
||||||
if (block.get("states").asList().isNotEmpty()) {
|
if (block.get("states").asList().isNotEmpty()) {
|
||||||
addModifiers(KModifier.DATA)
|
addModifiers(KModifier.DATA)
|
||||||
|
@ -107,14 +107,17 @@ class BlocksAndMaterialGenerator(
|
||||||
.addType(
|
.addType(
|
||||||
TypeSpec.companionObjectBuilder()
|
TypeSpec.companionObjectBuilder()
|
||||||
.addSuperinterface(
|
.addSuperinterface(
|
||||||
MATERIAL_TYPE.parameterizedBy(ClassName(BLOCK_PACKAGE, upperCamelName)),
|
MATERIAL_TYPE.parameterizedBy(ClassName(BLOCK_PACKAGE, className)),
|
||||||
CodeBlock.of("material(\n${materialLines.joinToString(",\n") { " $it" }}\n)", *materialArgs)
|
CodeBlock.of(
|
||||||
|
"material(\n${materialLines.joinToString(",\n") { " $it" }}\n)",
|
||||||
|
*materialArgs
|
||||||
|
)
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
FileSpec.builder(BLOCK_PACKAGE, upperCamelName)
|
FileSpec.builder(BLOCK_PACKAGE, className)
|
||||||
.addType(type)
|
.addType(type)
|
||||||
.build()
|
.build()
|
||||||
.writeTo(outputDir)
|
.writeTo(outputDir)
|
||||||
|
@ -125,7 +128,7 @@ class BlocksAndMaterialGenerator(
|
||||||
val names = blocks
|
val names = blocks
|
||||||
.map { it.get("name").toString() }
|
.map { it.get("name").toString() }
|
||||||
.filter { !BLOCK_BLACKLIST.contains(it) }
|
.filter { !BLOCK_BLACKLIST.contains(it) }
|
||||||
.map { CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, it) }
|
.map { CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, it) + "Block" }
|
||||||
|
|
||||||
val property = PropertySpec.builder(
|
val property = PropertySpec.builder(
|
||||||
"GENERATED_BLOCKS",
|
"GENERATED_BLOCKS",
|
||||||
|
|
|
@ -16,9 +16,9 @@ import space.uranos.testplugin.anvil.AnvilWorld
|
||||||
import space.uranos.world.Dimension
|
import space.uranos.world.Dimension
|
||||||
import space.uranos.world.VoxelLocation
|
import space.uranos.world.VoxelLocation
|
||||||
import space.uranos.world.WorldAndLocationWithRotation
|
import space.uranos.world.WorldAndLocationWithRotation
|
||||||
import space.uranos.world.block.CraftingTable
|
import space.uranos.world.block.CraftingTableBlock
|
||||||
import space.uranos.world.block.GreenWool
|
import space.uranos.world.block.GreenWoolBlock
|
||||||
import space.uranos.world.block.RedWool
|
import space.uranos.world.block.RedWoolBlock
|
||||||
|
|
||||||
class TestPlugin: Plugin("Test", "1.0.0") {
|
class TestPlugin: Plugin("Test", "1.0.0") {
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
|
@ -33,10 +33,10 @@ class TestPlugin: Plugin("Test", "1.0.0") {
|
||||||
|
|
||||||
val world = AnvilWorld(dimension, true)
|
val world = AnvilWorld(dimension, true)
|
||||||
world.getVoxelsInCube(VoxelLocation.of(16, 0, 16), VoxelLocation.of(-16, 0, -16)).forEach {
|
world.getVoxelsInCube(VoxelLocation.of(16, 0, 16), VoxelLocation.of(-16, 0, -16)).forEach {
|
||||||
it.block = if (it.location.x % 16 == 0 || it.location.z % 16 == 0) GreenWool() else RedWool()
|
it.block = if (it.location.x % 16 == 0 || it.location.z % 16 == 0) GreenWoolBlock() else RedWoolBlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
world.getVoxel(VoxelLocation.of(-1, 2, -1)).block = CraftingTable()
|
world.getVoxel(VoxelLocation.of(-1, 2, -1)).block = CraftingTableBlock()
|
||||||
|
|
||||||
Uranos.eventBus.on<ServerListInfoRequestEvent> { event ->
|
Uranos.eventBus.on<ServerListInfoRequestEvent> { event ->
|
||||||
event.response = ServerListInfo("1.16.4", 754, TextComponent of "Test", 10, 0, emptyList())
|
event.response = ServerListInfo("1.16.4", 754, TextComponent of "Test", 10, 0, emptyList())
|
||||||
|
|
Reference in a new issue