mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 01:48:04 -04:00
convert block constructor to primary constructor
This commit is contained in:
parent
cd3c1dd81f
commit
33045040ec
@ -22,16 +22,14 @@ import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.TintColorCalculator
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderer
|
||||
|
||||
open class Block : RegistryItem {
|
||||
override val resourceLocation: ResourceLocation
|
||||
|
||||
open val explosionResistance: Float
|
||||
open val tintColor: RGBColor?
|
||||
open val randomOffsetType: RandomOffsetTypes?
|
||||
open val tint: ResourceLocation?
|
||||
open class Block(override val resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) : RegistryItem {
|
||||
open val explosionResistance: Float = data["explosion_resistance"]?.asFloat ?: 0.0f
|
||||
open val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) }
|
||||
open val randomOffsetType: RandomOffsetTypes? = data["offset_type"]?.asString?.let { RandomOffsetTypes[it] }
|
||||
open val tint: ResourceLocation? = data["tint"]?.asString?.let { ResourceLocation(it) }
|
||||
open val renderOverride: List<BlockLikeRenderer>? = null
|
||||
|
||||
private val itemId: Int
|
||||
private val itemId: Int = data["item"]?.asInt ?: 0
|
||||
|
||||
open lateinit var states: Set<BlockState>
|
||||
protected set
|
||||
@ -40,15 +38,6 @@ open class Block : RegistryItem {
|
||||
open lateinit var item: Item
|
||||
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) {
|
||||
item = versionMapping.itemRegistry.get(itemId)
|
||||
}
|
||||
|
@ -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.FluidRenderer
|
||||
|
||||
class FluidBlock : Block {
|
||||
override val renderOverride: List<BlockLikeRenderer>
|
||||
|
||||
open val stillFluid: Fluid
|
||||
open val flowingFluid: Fluid
|
||||
open class FluidBlock(resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) : Block(resourceLocation, mappings, data) {
|
||||
open val stillFluid: Fluid = mappings.fluidRegistry.get(data["still_fluid"].asInt)
|
||||
open val flowingFluid: Fluid = mappings.fluidRegistry.get(data["flow_fluid"].asInt)
|
||||
|
||||
val fluidRenderer: FluidRenderer
|
||||
|
||||
override val renderOverride: List<BlockLikeRenderer>
|
||||
|
||||
constructor(resourceLocation: ResourceLocation, mappings: VersionMapping, data: JsonObject) : super(resourceLocation, mappings, data) {
|
||||
stillFluid = mappings.fluidRegistry.get(data["still_fluid"].asInt)
|
||||
flowingFluid = mappings.fluidRegistry.get(data["flow_fluid"].asInt)
|
||||
|
||||
fluidRenderer = FluidRenderer(this, stillFluid, flowingFluid)
|
||||
renderOverride = listOf(fluidRenderer)
|
||||
init {
|
||||
also {
|
||||
fluidRenderer = FluidRenderer(it, stillFluid, flowingFluid)
|
||||
renderOverride = listOf(fluidRenderer)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,6 @@ open class BlockItem(
|
||||
resourceLocation: ResourceLocation,
|
||||
data: JsonObject,
|
||||
versionMapping: VersionMapping,
|
||||
) : Item(resourceLocation, data, versionMapping) {
|
||||
) : Item(resourceLocation, versionMapping, data) {
|
||||
val block: Block = versionMapping.blockRegistry.get(data["block"].asInt)
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||
|
||||
open class Item(
|
||||
override val resourceLocation: ResourceLocation,
|
||||
data: JsonObject,
|
||||
versionMapping: VersionMapping,
|
||||
data: JsonObject,
|
||||
) : RegistryItem, Translatable {
|
||||
val rarity: Rarities = data["rarity"]?.asInt?.let { Rarities[it] } ?: Rarities.COMMON
|
||||
val maxStackSize: Int = data["max_stack_size"]?.asInt ?: 64
|
||||
@ -43,10 +43,10 @@ open class Item(
|
||||
check(mappings != null) { "VersionMapping is null!" }
|
||||
return when (data["class"].asString) {
|
||||
"BlockItem" -> BlockItem(resourceLocation, data, mappings)
|
||||
"ArmorItem" -> ArmorItem(resourceLocation, data, mappings)
|
||||
"ArmorItem" -> ArmorItem(resourceLocation, mappings, data)
|
||||
// "Item" -> Item(resourceLocation, data)
|
||||
// else -> TODO("Can not find item class: ${data["class"].asString}")
|
||||
else -> Item(resourceLocation, data, mappings)
|
||||
else -> Item(resourceLocation, mappings, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||
|
||||
open class ArmorItem(
|
||||
resourceLocation: ResourceLocation,
|
||||
data: JsonObject,
|
||||
versionMapping: VersionMapping,
|
||||
) : Item(resourceLocation, data, versionMapping) {
|
||||
data: JsonObject,
|
||||
) : Item(resourceLocation, versionMapping, data) {
|
||||
val protection = data["defense"].asFloat
|
||||
val toughness = data["toughness"].asFloat
|
||||
val equipmentSlot = data["equipment_slot"].asString.let { InventorySlots.EquipmentSlots.NAME_MAP[it]!! }
|
||||
|
Loading…
x
Reference in New Issue
Block a user