From ac5132fedacea95419e3f63ec897753be14d7493 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Sun, 3 Jan 2021 16:07:58 +0100 Subject: [PATCH] Suffix block classes with "Block" --- .../generator/BlocksAndMaterialGenerator.kt | 19 +++++++++++-------- .../space/uranos/testplugin/TestPlugin.kt | 10 +++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/kotlin/space/uranos/mdsp/generator/BlocksAndMaterialGenerator.kt b/buildSrc/src/main/kotlin/space/uranos/mdsp/generator/BlocksAndMaterialGenerator.kt index ca140fe..5a78e8d 100644 --- a/buildSrc/src/main/kotlin/space/uranos/mdsp/generator/BlocksAndMaterialGenerator.kt +++ b/buildSrc/src/main/kotlin/space/uranos/mdsp/generator/BlocksAndMaterialGenerator.kt @@ -68,16 +68,16 @@ class BlocksAndMaterialGenerator( .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, collisionShapes: Map) { for (block in blocks) { val lowerUnderscoreName = block.get("name").toString() 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 val materialArgs = arrayOf( @@ -91,7 +91,7 @@ class BlocksAndMaterialGenerator( collisionShapes.getValue(lowerUnderscoreName).toInt() ) - val type = TypeSpec.classBuilder(upperCamelName) + val type = TypeSpec.classBuilder(className) .apply { if (block.get("states").asList().isNotEmpty()) { addModifiers(KModifier.DATA) @@ -107,14 +107,17 @@ class BlocksAndMaterialGenerator( .addType( TypeSpec.companionObjectBuilder() .addSuperinterface( - MATERIAL_TYPE.parameterizedBy(ClassName(BLOCK_PACKAGE, upperCamelName)), - CodeBlock.of("material(\n${materialLines.joinToString(",\n") { " $it" }}\n)", *materialArgs) + MATERIAL_TYPE.parameterizedBy(ClassName(BLOCK_PACKAGE, className)), + CodeBlock.of( + "material(\n${materialLines.joinToString(",\n") { " $it" }}\n)", + *materialArgs + ) ) .build() ) .build() - FileSpec.builder(BLOCK_PACKAGE, upperCamelName) + FileSpec.builder(BLOCK_PACKAGE, className) .addType(type) .build() .writeTo(outputDir) @@ -125,7 +128,7 @@ class BlocksAndMaterialGenerator( val names = blocks .map { it.get("name").toString() } .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( "GENERATED_BLOCKS", diff --git a/test-plugin/src/main/kotlin/space/uranos/testplugin/TestPlugin.kt b/test-plugin/src/main/kotlin/space/uranos/testplugin/TestPlugin.kt index cecec8f..cd5cc98 100644 --- a/test-plugin/src/main/kotlin/space/uranos/testplugin/TestPlugin.kt +++ b/test-plugin/src/main/kotlin/space/uranos/testplugin/TestPlugin.kt @@ -16,9 +16,9 @@ import space.uranos.testplugin.anvil.AnvilWorld import space.uranos.world.Dimension import space.uranos.world.VoxelLocation import space.uranos.world.WorldAndLocationWithRotation -import space.uranos.world.block.CraftingTable -import space.uranos.world.block.GreenWool -import space.uranos.world.block.RedWool +import space.uranos.world.block.CraftingTableBlock +import space.uranos.world.block.GreenWoolBlock +import space.uranos.world.block.RedWoolBlock class TestPlugin: Plugin("Test", "1.0.0") { override fun onEnable() { @@ -33,10 +33,10 @@ class TestPlugin: Plugin("Test", "1.0.0") { val world = AnvilWorld(dimension, true) 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 { event -> event.response = ServerListInfo("1.16.4", 754, TextComponent of "Test", 10, 0, emptyList())