convert block constructor to primary constructor

This commit is contained in:
Bixilon 2021-05-16 15:49:07 +02:00
parent cd3c1dd81f
commit 33045040ec
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 22 additions and 34 deletions

View File

@ -22,16 +22,14 @@ import de.bixilon.minosoft.data.text.RGBColor
import de.bixilon.minosoft.gui.rendering.TintColorCalculator import de.bixilon.minosoft.gui.rendering.TintColorCalculator
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer
open class Block : RegistryItem { open class Block(override val resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) : RegistryItem {
override val resourceLocation: ResourceLocation open val explosionResistance: Float = data["explosion_resistance"]?.asFloat ?: 0.0f
open val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) }
open val explosionResistance: Float open val randomOffsetType: RandomOffsetTypes? = data["offset_type"]?.asString?.let { RandomOffsetTypes[it] }
open val tintColor: RGBColor? open val tint: ResourceLocation? = data["tint"]?.asString?.let { ResourceLocation(it) }
open val randomOffsetType: RandomOffsetTypes?
open val tint: ResourceLocation?
open val renderOverride: List<BlockLikeRenderer>? = null open val renderOverride: List<BlockLikeRenderer>? = null
private val itemId: Int private val itemId: Int = data["item"]?.asInt ?: 0
open lateinit var states: Set<BlockState> open lateinit var states: Set<BlockState>
protected set protected set
@ -40,15 +38,6 @@ open class Block : RegistryItem {
open lateinit var item: Item open lateinit var item: Item
protected set protected set
constructor(resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) {
resourceLocation.also { this.resourceLocation = it }
(data["explosion_resistance"]?.asFloat ?: 0.0f).also { explosionResistance = it }
data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) }.also { this@Block.tintColor = it }
data["offset_type"]?.asString?.let { RandomOffsetTypes[it] }.also { randomOffsetType = it }
itemId = data["item"]?.asInt ?: 0
data["tint"]?.asString?.let { ResourceLocation(it) }.also { tint = it }
}
override fun postInit(versionMapping: VersionMapping) { override fun postInit(versionMapping: VersionMapping) {
item = versionMapping.itemRegistry.get(itemId) item = versionMapping.itemRegistry.get(itemId)
} }

View File

@ -20,20 +20,19 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.FluidRenderer import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.FluidRenderer
class FluidBlock : Block { open class FluidBlock(resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) : Block(resourceLocation, mappings, data) {
override val renderOverride: List<BlockLikeRenderer> open val stillFluid: Fluid = mappings.fluidRegistry.get(data["still_fluid"].asInt)
open val flowingFluid: Fluid = mappings.fluidRegistry.get(data["flow_fluid"].asInt)
open val stillFluid: Fluid
open val flowingFluid: Fluid
val fluidRenderer: FluidRenderer val fluidRenderer: FluidRenderer
override val renderOverride: List<BlockLikeRenderer>
constructor(resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) : super(resourceLocation, mappings, data) { init {
stillFluid = mappings.fluidRegistry.get(data["still_fluid"].asInt) also {
flowingFluid = mappings.fluidRegistry.get(data["flow_fluid"].asInt) fluidRenderer = FluidRenderer(it, stillFluid, flowingFluid)
renderOverride = listOf(fluidRenderer)
fluidRenderer = FluidRenderer(this, stillFluid, flowingFluid) }
renderOverride = listOf(fluidRenderer)
} }
} }

View File

@ -22,6 +22,6 @@ open class BlockItem(
resourceLocation: ResourceLocation, resourceLocation: ResourceLocation,
data: JsonObject, data: JsonObject,
versionMapping: VersionMapping, versionMapping: VersionMapping,
) : Item(resourceLocation, data, versionMapping) { ) : Item(resourceLocation, versionMapping, data) {
val block: Block = versionMapping.blockRegistry.get(data["block"].asInt) val block: Block = versionMapping.blockRegistry.get(data["block"].asInt)
} }

View File

@ -24,8 +24,8 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping
open class Item( open class Item(
override val resourceLocation: ResourceLocation, override val resourceLocation: ResourceLocation,
data: JsonObject,
versionMapping: VersionMapping, versionMapping: VersionMapping,
data: JsonObject,
) : RegistryItem, Translatable { ) : RegistryItem, Translatable {
val rarity: Rarities = data["rarity"]?.asInt?.let { Rarities[it] } ?: Rarities.COMMON val rarity: Rarities = data["rarity"]?.asInt?.let { Rarities[it] } ?: Rarities.COMMON
val maxStackSize: Int = data["max_stack_size"]?.asInt ?: 64 val maxStackSize: Int = data["max_stack_size"]?.asInt ?: 64
@ -43,10 +43,10 @@ open class Item(
check(mappings != null) { "VersionMapping is null!" } check(mappings != null) { "VersionMapping is null!" }
return when (data["class"].asString) { return when (data["class"].asString) {
"BlockItem" -> BlockItem(resourceLocation, data, mappings) "BlockItem" -> BlockItem(resourceLocation, data, mappings)
"ArmorItem" -> ArmorItem(resourceLocation, data, mappings) "ArmorItem" -> ArmorItem(resourceLocation, mappings, data)
// "Item" -> Item(resourceLocation, data) // "Item" -> Item(resourceLocation, data)
// else -> TODO("Can not find item class: ${data["class"].asString}") // else -> TODO("Can not find item class: ${data["class"].asString}")
else -> Item(resourceLocation, data, mappings) else -> Item(resourceLocation, mappings, data)
} }
} }
} }

View File

@ -21,9 +21,9 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping
open class ArmorItem( open class ArmorItem(
resourceLocation: ResourceLocation, resourceLocation: ResourceLocation,
data: JsonObject,
versionMapping: VersionMapping, versionMapping: VersionMapping,
) : Item(resourceLocation, data, versionMapping) { data: JsonObject,
) : Item(resourceLocation, versionMapping, data) {
val protection = data["defense"].asFloat val protection = data["defense"].asFloat
val toughness = data["toughness"].asFloat val toughness = data["toughness"].asFloat
val equipmentSlot = data["equipment_slot"].asString.let { InventorySlots.EquipmentSlots.NAME_MAP[it]!! } val equipmentSlot = data["equipment_slot"].asString.let { InventorySlots.EquipmentSlots.NAME_MAP[it]!! }