make block properties not an enum

Long needed refactor
This commit is contained in:
Bixilon 2023-09-28 20:43:22 +02:00
parent 8600d2d8f3
commit bf84b99df3
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
58 changed files with 370 additions and 433 deletions

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.assets.meta.MinosoftMeta
import de.bixilon.minosoft.assets.properties.version.AssetsVersionProperties
import de.bixilon.minosoft.data.registries.fallback.FallbackRegistries
import de.bixilon.minosoft.data.registries.fallback.tags.FallbackTags
import de.bixilon.minosoft.datafixer.DataFixer
import de.bixilon.minosoft.protocol.versions.VersionLoader
import de.bixilon.minosoft.test.IT
import de.bixilon.minosoft.test.ITUtil
@ -37,6 +38,7 @@ internal object MinosoftSIT {
disableGC()
Log.log(LogMessageType.OTHER, LogLevels.INFO) { "Setting up integration tests...." }
initAssetsManager()
DataFixer.load()
loadVersionsJson()
loadAssetsProperties()
loadDefaultRegistries()

View File

@ -18,7 +18,6 @@ import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.createPlayer
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.runTicks
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
import de.bixilon.minosoft.data.registries.blocks.types.stone.StoneTest0
import de.bixilon.minosoft.data.world.World
@ -31,14 +30,14 @@ import kotlin.math.abs
abstract class FlowingFluidIT {
protected val levels by lazy {
arrayOf(
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 6),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 5),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 4),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 3),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 2),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 1),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0),
block!!.states.withProperties(FluidBlock.LEVEL to 7),
block!!.states.withProperties(FluidBlock.LEVEL to 6),
block!!.states.withProperties(FluidBlock.LEVEL to 5),
block!!.states.withProperties(FluidBlock.LEVEL to 4),
block!!.states.withProperties(FluidBlock.LEVEL to 3),
block!!.states.withProperties(FluidBlock.LEVEL to 2),
block!!.states.withProperties(FluidBlock.LEVEL to 1),
block!!.states.withProperties(FluidBlock.LEVEL to 0),
)
}

View File

@ -21,7 +21,6 @@ import de.bixilon.minosoft.data.physics.PhysicsTestUtil.assertPosition
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.assertVelocity
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.createPlayer
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.runTicks
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
import de.bixilon.minosoft.data.registries.blocks.types.stone.StoneTest0
import de.bixilon.minosoft.data.registries.fluid.fluids.LavaFluid
@ -44,9 +43,9 @@ class MixedFluidIT {
}
private fun World.fill() {
this[Vec3i(10, 2, 3)] = lava!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
this[Vec3i(10, 2, 3)] = lava!!.states.withProperties(FluidBlock.LEVEL to 0)
this[Vec3i(10, 1, 3)] = StoneTest0.state
this[Vec3i(10, 2, 4)] = water!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
this[Vec3i(10, 2, 4)] = water!!.states.withProperties(FluidBlock.LEVEL to 0)
this[Vec3i(10, 1, 4)] = StoneTest0.state
}
@ -78,7 +77,7 @@ class MixedFluidIT {
fun stillLavaAndLava2() {
val player = createPlayer(createConnection(3))
player.connection.world.fill()
player.connection.world[Vec3i(10, 2, 4)] = lava!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
player.connection.world[Vec3i(10, 2, 4)] = lava!!.states.withProperties(FluidBlock.LEVEL to 0)
player.forceTeleport(Vec3d(10.0, 2.0, 3.8))
player.input = PlayerMovementInput(forward = true)
@ -92,8 +91,8 @@ class MixedFluidIT {
fun mixedHeight1() {
val player = createPlayer(createConnection(3))
player.connection.world[Vec3i(10, 1, 4)] = StoneTest0.state
player.connection.world[Vec3i(10, 2, 4)] = lava!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = water!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 2, 4)] = lava!!.states.withProperties(FluidBlock.LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = water!!.states.withProperties(FluidBlock.LEVEL to 7)
player.forceTeleport(Vec3d(10.0, 2.0, 3.8))
player.runTicks(2)
player.input = PlayerMovementInput(jump = true, forward = true)
@ -106,8 +105,8 @@ class MixedFluidIT {
fun mixedHeight2() {
val player = createPlayer(createConnection(3))
player.connection.world[Vec3i(10, 1, 4)] = StoneTest0.state
player.connection.world[Vec3i(10, 2, 4)] = lava!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = water!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 2, 4)] = lava!!.states.withProperties(FluidBlock.LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = water!!.states.withProperties(FluidBlock.LEVEL to 7)
player.forceTeleport(Vec3d(10.0, 2.0, 3.8))
player.runTicks(2)
player.input = PlayerMovementInput(jump = true, forward = true)
@ -120,8 +119,8 @@ class MixedFluidIT {
fun mixedHeight3() {
val player = createPlayer(createConnection(3))
player.connection.world[Vec3i(10, 1, 4)] = StoneTest0.state
player.connection.world[Vec3i(10, 2, 4)] = water!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = lava!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 2, 4)] = water!!.states.withProperties(FluidBlock.LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = lava!!.states.withProperties(FluidBlock.LEVEL to 7)
player.forceTeleport(Vec3d(10.0, 2.0, 3.8))
player.runTicks(2)
player.input = PlayerMovementInput(jump = true, forward = true)
@ -134,8 +133,8 @@ class MixedFluidIT {
fun mixedHeight4() {
val player = createPlayer(createConnection(3))
player.connection.world[Vec3i(10, 1, 4)] = StoneTest0.state
player.connection.world[Vec3i(10, 2, 4)] = water!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = lava!!.states.withProperties(BlockProperties.FLUID_LEVEL to 7)
player.connection.world[Vec3i(10, 2, 4)] = water!!.states.withProperties(FluidBlock.LEVEL to 7)
player.connection.world[Vec3i(10, 3, 4)] = lava!!.states.withProperties(FluidBlock.LEVEL to 7)
player.forceTeleport(Vec3d(10.0, 2.0, 3.8))
player.runTicks(2)
player.input = PlayerMovementInput(jump = true, forward = true)

View File

@ -18,7 +18,6 @@ import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.createPlayer
import de.bixilon.minosoft.data.physics.PhysicsTestUtil.runTicks
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
import de.bixilon.minosoft.data.registries.blocks.types.stone.StoneTest0
import de.bixilon.minosoft.data.world.WorldTestUtil.fill
@ -32,7 +31,7 @@ abstract class StillFluidIT {
connection.world.fill(
Vec3i(-10, 16, -10),
Vec3i(20, 16, 20),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
block!!.states.withProperties(FluidBlock.LEVEL to 0)
)
connection.world.fill(Vec3i(-10, 15, -10), Vec3i(20, 15, 20), StoneTest0.state)
@ -43,7 +42,7 @@ abstract class StillFluidIT {
connection.world.fill(
Vec3i(-10, 16, -10),
Vec3i(20, 20, 20),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
block!!.states.withProperties(FluidBlock.LEVEL to 0)
)
connection.world.fill(Vec3i(-10, 15, -10), Vec3i(20, 15, 20), StoneTest0.state)
@ -60,7 +59,7 @@ abstract class StillFluidIT {
player.connection.world.fill(
Vec3i(4, 5, 7),
Vec3i(4, 16, 7),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
block!!.states.withProperties(FluidBlock.LEVEL to 0)
)
player.forceTeleport(Vec3d(4.0, 18.0, 7.0))
player.runTicks(10)
@ -72,7 +71,7 @@ abstract class StillFluidIT {
player.connection.world.fill(
Vec3i(4, 5, 7),
Vec3i(4, 16, 7),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
block!!.states.withProperties(FluidBlock.LEVEL to 0)
)
player.forceTeleport(Vec3d(4.0, 30.0, 7.0))
player.runTicks(35)
@ -100,7 +99,7 @@ abstract class StillFluidIT {
connection.world.fill(
Vec3i(-10, 16, -10),
Vec3i(20, 17, 20),
block!!.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
block!!.states.withProperties(FluidBlock.LEVEL to 0)
)
connection.world.fill(Vec3i(-10, 15, -10), Vec3i(20, 15, 20), StoneTest0.state)

View File

@ -36,22 +36,22 @@ class WaterFluidTest {
}
fun heightLevel0() {
val state = block.states.withProperties(BlockProperties.FLUID_LEVEL to 0)
val state = block.states.withProperties(FluidBlock.LEVEL to 0)
assertEquals(this.water.getHeight(state), 0.8888889f)
}
fun heightLevel2() {
val state = block.states.withProperties(BlockProperties.FLUID_LEVEL to 2)
val state = block.states.withProperties(FluidBlock.LEVEL to 2)
assertEquals(this.water.getHeight(state), 0.6666667f)
}
fun heightLevel8() {
val state = block.states.withProperties(BlockProperties.FLUID_LEVEL to 8)
val state = block.states.withProperties(FluidBlock.LEVEL to 8)
assertEquals(this.water.getHeight(state), 0.8888889f)
}
fun heightLevel12() {
val state = block.states.withProperties(BlockProperties.FLUID_LEVEL to 12)
val state = block.states.withProperties(FluidBlock.LEVEL to 12)
assertEquals(this.water.getHeight(state), 0.8888889f)
}

View File

@ -24,7 +24,7 @@ abstract class PixLyzerLoadingTest(version: String) : RegistryLoadingTest(versio
@Test(priority = 100000)
open fun loadRegistries() {
throw SkipException("temp")
throw SkipException("temp") // TODO: remove
this._registries = ITUtil.loadPixlyzerData(version)
}

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.variant
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.exception.Broken
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
@ -46,7 +47,7 @@ class PropertyVariantBlockModelTest {
mapOf(BlockProperties.FACING to Directions.WEST, BlockProperties.LIT to false) to B,
mapOf(BlockProperties.FACING to Directions.SOUTH) to C,
mapOf(BlockProperties.LIT to false) to D,
))
).unsafeCast())
assertEquals(model.choose(PropertyBlockState(DummyBlock, mapOf(BlockProperties.FACING to Directions.EAST, BlockProperties.LIT to true), 0)), A)
assertEquals(model.choose(PropertyBlockState(DummyBlock, mapOf(BlockProperties.FACING to Directions.WEST, BlockProperties.LIT to false), 0)), B)
assertNull(model.choose(PropertyBlockState(DummyBlock, mapOf(BlockProperties.FACING to Directions.WEST, BlockProperties.LIT to true), 0)))

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Axes {
X {
@ -35,7 +34,7 @@ enum class Axes {
abstract fun next(): Axes
abstract fun previous(): Axes
companion object : ValuesEnum<Axes>, BlockPropertiesSerializer {
companion object : ValuesEnum<Axes> {
override val VALUES: Array<Axes> = values()
override val NAME_MAP: Map<String, Axes> = EnumUtil.getEnumValues(VALUES)
@ -46,9 +45,5 @@ enum class Axes {
Directions.NORTH, Directions.SOUTH -> Z
}
}
override fun deserialize(value: Any): Axes {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -16,17 +16,12 @@ import de.bixilon.kotlinglm.mat4x4.Mat4
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kotlinglm.vec3.swizzle.xy
import de.bixilon.kotlinglm.vec3.swizzle.xz
import de.bixilon.kotlinglm.vec3.swizzle.yz
import de.bixilon.kotlinglm.vec3.swizzle.zy
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.minosoft.data.Axes
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.world.chunk.ChunkSection
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.get
@ -134,7 +129,7 @@ enum class Directions(
}
companion object : BlockPropertiesSerializer, ValuesEnum<Directions> {
companion object : ValuesEnum<Directions> {
const val O_DOWN = 0 // Directions.DOWN.ordinal
const val O_UP = 1 // Directions.UP.ordinal
const val O_NORTH = 2 // Directions.NORTH.ordinal
@ -157,10 +152,6 @@ enum class Directions(
val XYZ = arrayOf(WEST, EAST, DOWN, UP, NORTH, SOUTH)
override fun deserialize(value: Any): Directions {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
private const val MIN_ERROR = 0.0001f
@Deprecated("outsource")

View File

@ -23,8 +23,8 @@ import de.bixilon.minosoft.data.container.ItemStackUtil
import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.direction.DirectionUtil.rotateY
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.isLit
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.isLit
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.entity.CampfireBlock
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft

View File

@ -20,7 +20,7 @@ import de.bixilon.kutil.json.JsonObject
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.blocks.factory.BlockFactories
import de.bixilon.minosoft.data.registries.blocks.factory.BlockFactory
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.state.AdvancedBlockState
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
@ -58,7 +58,7 @@ class BlockRegistry(
}
val properties: MutableMap<BlockProperties, MutableSet<Any>> = mutableMapOf()
val properties: MutableMap<BlockProperty<*>, MutableSet<Any>> = mutableMapOf()
val states: MutableSet<BlockState> = ObjectOpenHashSet()
for (stateJson in statesData) {
@ -83,7 +83,7 @@ class BlockRegistry(
}
fun flattened(block: Block, data: JsonObject, registries: Registries) {
val properties: MutableMap<BlockProperties, MutableSet<Any>> = mutableMapOf()
val properties: MutableMap<BlockProperty<*>, MutableSet<Any>> = mutableMapOf()
val states: MutableSet<BlockState> = ObjectOpenHashSet()
for ((stateId, stateJson) in data["states"].asAnyMap()) {

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Attachments {
FLOOR,
@ -25,13 +24,8 @@ enum class Attachments {
DOUBLE_WALL,
;
companion object : BlockPropertiesSerializer, ValuesEnum<Attachments> {
companion object : ValuesEnum<Attachments> {
override val VALUES: Array<Attachments> = values()
override val NAME_MAP: Map<String, Attachments> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): Attachments {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class BambooLeaves {
NONE,
@ -23,12 +22,8 @@ enum class BambooLeaves {
LARGE,
;
companion object : BlockPropertiesSerializer, ValuesEnum<BambooLeaves> {
companion object : ValuesEnum<BambooLeaves> {
override val VALUES = values()
override val NAME_MAP: Map<String, BambooLeaves> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): BambooLeaves {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,19 +15,14 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class BedParts {
HEAD,
FOOT,
;
companion object : BlockPropertiesSerializer, ValuesEnum<BedParts> {
companion object : ValuesEnum<BedParts> {
override val VALUES = values()
override val NAME_MAP: Map<String, BedParts> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): BedParts {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -15,165 +15,158 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.minosoft.data.Axes
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BooleanBlockPropertiesSerializer
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.IntBlockPropertiesSerializer
import de.bixilon.minosoft.data.registries.blocks.properties.primitives.BooleanProperty
import de.bixilon.minosoft.data.registries.blocks.properties.primitives.IntProperty
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import java.util.*
@Deprecated("Will be split and refactored")
enum class BlockProperties {
POWERED(BooleanBlockPropertiesSerializer),
TRIGGERED(BooleanBlockPropertiesSerializer),
INVERTED(BooleanBlockPropertiesSerializer),
LIT(BooleanBlockPropertiesSerializer),
WATERLOGGED(BooleanBlockPropertiesSerializer),
STAIR_DIRECTIONAL("shape", Shapes),
STAIR_HALF("half", Halves),
SLAB_TYPE("type", Halves),
MOISTURE_LEVEL("moisture", IntBlockPropertiesSerializer),
FLUID_LEVEL("level", IntBlockPropertiesSerializer),
HONEY_LEVEL("honey_level", IntBlockPropertiesSerializer),
PISTON_EXTENDED("extended", BooleanBlockPropertiesSerializer),
PISTON_TYPE("type", PistonTypes),
PISTON_SHORT("short", BooleanBlockPropertiesSerializer),
RAILS_SHAPE("shape", Shapes),
SNOWY(BooleanBlockPropertiesSerializer),
STAGE(IntBlockPropertiesSerializer),
DISTANCE(IntBlockPropertiesSerializer),
LEAVES_PERSISTENT("persistent", BooleanBlockPropertiesSerializer),
BED_PART("part", BedParts),
BED_OCCUPIED("occupied", BooleanBlockPropertiesSerializer),
TNT_UNSTABLE("unstable", BooleanBlockPropertiesSerializer),
DOOR_HINGE("hinge", Sides),
DOOR_OPEN("open", BooleanBlockPropertiesSerializer),
AGE(IntBlockPropertiesSerializer),
INSTRUMENT(Instruments),
NOTE(IntBlockPropertiesSerializer),
REDSTONE_POWER("power", IntBlockPropertiesSerializer),
MULTIPART_NORTH("north", MultipartDirectionParser),
MULTIPART_WEST("west", MultipartDirectionParser),
MULTIPART_SOUTH("south", MultipartDirectionParser),
MULTIPART_EAST("east", MultipartDirectionParser),
MULTIPART_UP("up", MultipartDirectionParser),
MULTIPART_DOWN("down", MultipartDirectionParser),
SNOW_LAYERS("layers", IntBlockPropertiesSerializer),
FENCE_IN_WALL("in_wall", BooleanBlockPropertiesSerializer),
SCAFFOLDING_BOTTOM("bottom", BooleanBlockPropertiesSerializer),
TRIPWIRE_DISARMED("disarmed", BooleanBlockPropertiesSerializer),
TRIPWIRE_IN_AIR("in_air", BooleanBlockPropertiesSerializer),
TRIPWIRE_ATTACHED("attached", BooleanBlockPropertiesSerializer),
STRUCTURE_BLOCK_MODE("mode", StructureBlockModes),
COMMAND_BLOCK_CONDITIONAL("conditional", BooleanBlockPropertiesSerializer),
BUBBLE_COLUMN_DRAG("drag", BooleanBlockPropertiesSerializer),
BELL_ATTACHMENT("attachment", Attachments),
LANTERN_HANGING("hanging", BooleanBlockPropertiesSerializer),
SEA_PICKLE_PICKLES("pickles", IntBlockPropertiesSerializer),
LECTERN_BOOK("has_book", BooleanBlockPropertiesSerializer),
BREWING_STAND_BOTTLE_0("has_bottle_0", BooleanBlockPropertiesSerializer),
BREWING_STAND_BOTTLE_1("has_bottle_1", BooleanBlockPropertiesSerializer),
BREWING_STAND_BOTTLE_2("has_bottle_2", BooleanBlockPropertiesSerializer),
CHEST_TYPE("type", ChestTypes),
CAKE_BITES("bites", IntBlockPropertiesSerializer),
BAMBOO_LEAVES("leaves", BambooLeaves),
REPEATER_LOCKED("locked", BooleanBlockPropertiesSerializer),
REPEATER_DELAY("delay", IntBlockPropertiesSerializer),
PORTAL_FRAME_EYE("eye", BooleanBlockPropertiesSerializer),
JUKEBOX_HAS_RECORD("has_record", BooleanBlockPropertiesSerializer),
CAMPFIRE_SIGNAL_FIRE("signal_fire", BooleanBlockPropertiesSerializer),
TURTLE_EGS_EGGS("eggs", IntBlockPropertiesSerializer),
TURTLE_EGGS_HATCH("hatch", IntBlockPropertiesSerializer),
RESPAWN_ANCHOR_CHARGES("charges", IntBlockPropertiesSerializer),
CANDLES(IntBlockPropertiesSerializer),
FACE("face", Attachments),
HOPPER_ENABLED("enabled", BooleanBlockPropertiesSerializer),
DRIPSTONE_THICKNESS("thickness", Thicknesses),
@Deprecated("Fallback data")
object BlockProperties {
private val list: MutableList<BlockProperty<*>> = mutableListOf()
LEGACY_BLOCK_UPDATE("block_update", BooleanBlockPropertiesSerializer),
LEGACY_SMOOTH("smooth", BooleanBlockPropertiesSerializer),
SCULK_SENSOR_PHASE("sculk_sensor_phase", SensorPhases),
DRIPSTONE_TILT("tilt", Tilts),
CAVE_VINES_BERRIES("berries", BooleanBlockPropertiesSerializer),
val POWERED = BooleanProperty("powered").register()
val TRIGGERED = BooleanProperty("triggered").register()
val INVERTED = BooleanProperty("inverted").register()
val LIT = BooleanProperty("lit").register()
val WATERLOGGED = BooleanProperty("waterlogged").register()
val STAIR_DIRECTIONAL = EnumProperty("shape", Shapes).register()
val STAIR_HALF = EnumProperty("half", Halves).register()
val SLAB_TYPE = EnumProperty("type", Halves).register()
val FLUID_LEVEL = IntProperty("level", 0..15).register()
val MOISTURE_LEVEL = IntProperty("moisture").register()
val HONEY_LEVEL = IntProperty("honey_level").register()
val PISTON_EXTENDED = BooleanProperty("extended").register()
val PISTON_TYPE = EnumProperty("type", PistonTypes).register()
val PISTON_SHORT = BooleanProperty("short").register()
val RAILS_SHAPE = EnumProperty("shape", Shapes).register()
val SNOWY = BooleanProperty("snowy").register()
val STAGE = IntProperty("stage").register()
val DISTANCE = IntProperty("distance").register()
val LEAVES_PERSISTENT = BooleanProperty("persistent").register()
val BED_PART = EnumProperty("part", BedParts).register()
val BED_OCCUPIED = BooleanProperty("occupied").register()
val TNT_UNSTABLE = BooleanProperty("unstable").register()
val DOOR_HINGE = EnumProperty("hinge", Sides).register()
val DOOR_OPEN = BooleanProperty("open").register()
val AGE = IntProperty("age").register()
val INSTRUMENT = EnumProperty("instrument", Instruments).register()
val NOTE = IntProperty("note").register()
val REDSTONE_POWER = IntProperty("power").register()
val MULTIPART_NORTH = EnumProperty("north", MultipartDirections).register()
val MULTIPART_WEST = EnumProperty("west", MultipartDirections).register()
val MULTIPART_SOUTH = EnumProperty("south", MultipartDirections).register()
val MULTIPART_EAST = EnumProperty("east", MultipartDirections).register()
val MULTIPART_UP = EnumProperty("up", MultipartDirections).register()
val MULTIPART_DOWN = EnumProperty("down", MultipartDirections).register()
val SNOW_LAYERS = IntProperty("layers").register()
val FENCE_IN_WALL = BooleanProperty("in_wall").register()
val SCAFFOLDING_BOTTOM = BooleanProperty("bottom").register()
val TRIPWIRE_DISARMED = BooleanProperty("disarmed").register()
val TRIPWIRE_IN_AIR = BooleanProperty("in_air").register()
val TRIPWIRE_ATTACHED = BooleanProperty("attached").register()
val STRUCTURE_BLOCK_MODE = EnumProperty("mode", StructureBlockModes).register()
val COMMAND_BLOCK_CONDITIONAL = BooleanProperty("conditional").register()
val BUBBLE_COLUMN_DRAG = BooleanProperty("drag").register()
val BELL_ATTACHMENT = EnumProperty("attachment", Attachments).register()
val LANTERN_HANGING = BooleanProperty("hanging").register()
val SEA_PICKLE_PICKLES = IntProperty("pickles").register()
val LECTERN_BOOK = BooleanProperty("has_book").register()
val BREWING_STAND_BOTTLE_0 = BooleanProperty("has_bottle_0").register()
val BREWING_STAND_BOTTLE_1 = BooleanProperty("has_bottle_1").register()
val BREWING_STAND_BOTTLE_2 = BooleanProperty("has_bottle_2").register()
val CHEST_TYPE = EnumProperty("type", ChestTypes).register()
val CAKE_BITES = IntProperty("bites").register()
val BAMBOO_LEAVES = EnumProperty("leaves", BambooLeaves).register()
val REPEATER_LOCKED = BooleanProperty("locked").register()
val REPEATER_DELAY = IntProperty("delay").register()
val PORTAL_FRAME_EYE = BooleanProperty("eye").register()
val JUKEBOX_HAS_RECORD = BooleanProperty("has_record").register()
val CAMPFIRE_SIGNAL_FIRE = BooleanProperty("signal_fire").register()
val TURTLE_EGS_EGGS = IntProperty("eggs").register()
val TURTLE_EGGS_HATCH = IntProperty("hatch").register()
val RESPAWN_ANCHOR_CHARGES = IntProperty("charges").register()
val CANDLES = IntProperty("candles").register()
val FACE = EnumProperty("face", Attachments).register()
val HOPPER_ENABLED = BooleanProperty("enabled").register()
val DRIPSTONE_THICKNESS = EnumProperty("thickness", Thicknesses).register()
VERTICAL_DIRECTION("vertical_direction", VerticalDirections),
val LEGACY_BLOCK_UPDATE = BooleanProperty("block_update").register()
val LEGACY_SMOOTH = BooleanProperty("smooth").register()
val SCULK_SENSOR_PHASE = EnumProperty("sculk_sensor_phase", SensorPhases).register()
val DRIPSTONE_TILT = EnumProperty("tilt", Tilts).register()
val CAVE_VINES_BERRIES = BooleanProperty("berries").register()
LEGACY_CHECK_DECAY("check_decay", BooleanBlockPropertiesSerializer),
LEGACY_DECAYABLE("decayable", BooleanBlockPropertiesSerializer),
LEGACY_NODROP("nodrop", BooleanBlockPropertiesSerializer),
val VERTICAL_DIRECTION = EnumProperty("vertical_direction", VerticalDirections).register()
AXIS("axis", Axes),
FACING("facing", Directions),
ROTATION("rotation", IntBlockPropertiesSerializer),
ORIENTATION("orientation", Orientations),
BLOOM("bloom", BooleanBlockPropertiesSerializer),
val LEGACY_CHECK_DECAY = BooleanProperty("check_decay").register()
val LEGACY_DECAYABLE = BooleanProperty("decayable").register()
val LEGACY_NODROP = BooleanProperty("nodrop").register()
SHRIEKING("shrieking", BooleanBlockPropertiesSerializer),
CAN_SUMMON("can_summon", BooleanBlockPropertiesSerializer),
val AXIS = EnumProperty("axis", Axes).register()
val FACING = EnumProperty("facing", Directions).register()
val ROTATION = IntProperty("rotation").register()
val ORIENTATION = EnumProperty("orientation", Orientations).register()
val BLOOM = BooleanProperty("bloom").register()
val SHRIEKING = BooleanProperty("shrieking").register()
val CAN_SUMMON = BooleanProperty("can_summon").register()
// ToDo: used in models
MAP("map", BooleanBlockPropertiesSerializer),
val MAP = BooleanProperty("map").register()
BOOKS_STORED("books_stored", IntBlockPropertiesSerializer),
LAST_INTERACTION_BOOK_SLOT("last_interaction_book_slot", IntBlockPropertiesSerializer),
val BOOKS_STORED = IntProperty("books_stored").register()
val LAST_INTERACTION_BOOK_SLOT = IntProperty("last_interaction_book_slot").register()
BOOK_SLOT_OCCUPIED_0("slot_0_occupied", BooleanBlockPropertiesSerializer),
BOOK_SLOT_OCCUPIED_1("slot_1_occupied", BooleanBlockPropertiesSerializer),
BOOK_SLOT_OCCUPIED_2("slot_2_occupied", BooleanBlockPropertiesSerializer),
BOOK_SLOT_OCCUPIED_3("slot_3_occupied", BooleanBlockPropertiesSerializer),
BOOK_SLOT_OCCUPIED_4("slot_4_occupied", BooleanBlockPropertiesSerializer),
BOOK_SLOT_OCCUPIED_5("slot_5_occupied", BooleanBlockPropertiesSerializer),
val BOOK_SLOT_OCCUPIED_0 = BooleanProperty("slot_0_occupied").register()
val BOOK_SLOT_OCCUPIED_1 = BooleanProperty("slot_1_occupied").register()
val BOOK_SLOT_OCCUPIED_2 = BooleanProperty("slot_2_occupied").register()
val BOOK_SLOT_OCCUPIED_3 = BooleanProperty("slot_3_occupied").register()
val BOOK_SLOT_OCCUPIED_4 = BooleanProperty("slot_4_occupied").register()
val BOOK_SLOT_OCCUPIED_5 = BooleanProperty("slot_5_occupied").register()
DUSTED("dusted", IntBlockPropertiesSerializer),
FLOWER_AMOUNT("flower_amount", IntBlockPropertiesSerializer),
val DUSTED = IntProperty("dusted").register()
val FLOWER_AMOUNT = IntProperty("flower_amount").register()
CRACKED("cracked", BooleanBlockPropertiesSerializer),
;
val CRACKED = BooleanProperty("cracked").register()
val group: String
val serializer: BlockPropertiesSerializer
constructor(group: String, serializer: BlockPropertiesSerializer) {
this.group = group
this.serializer = serializer
}
constructor(serializer: BlockPropertiesSerializer) {
this.group = name.lowercase(Locale.getDefault())
this.serializer = serializer
@Deprecated("should not exist")
fun <T : BlockProperty<*>> T.register(): T {
list += this
return this
}
companion object {
val PROPERTIES: Map<String, List<BlockProperties>> = run {
val map: MutableMap<String, MutableList<BlockProperties>> = mutableMapOf()
val PROPERTIES: Map<String, List<BlockProperty<*>>> = run {
val map: MutableMap<String, MutableList<BlockProperty<*>>> = mutableMapOf()
for (value in values()) {
map.getOrPut(value.group) { mutableListOf() } += value
for (value in list) {
map.getOrPut(value.name) { mutableListOf() } += value
}
return@run map
}
fun parseProperty(group: String, value: Any): Pair<BlockProperties, Any> {
fun parseProperty(group: String, value: Any): Pair<BlockProperty<*>, Any> {
val properties = PROPERTIES[group] ?: throw IllegalArgumentException("Can not find group: $group, expected value $value")
var property: BlockProperties? = null
var property: BlockProperty<*>? = null
var retValue: Any? = null
for (blockProperty in properties) {
retValue = try {
blockProperty.serializer.deserialize(value)
blockProperty.parse(value)
} catch (exception: Throwable) {
continue
}
@ -197,5 +190,4 @@ enum class BlockProperties {
fun BlockState.isLit(): Boolean {
return this[LIT]
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,9 +11,12 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.blocks.properties.serializer
package de.bixilon.minosoft.data.registries.blocks.properties
interface BlockPropertiesSerializer {
fun deserialize(value: Any): Any
abstract class BlockProperty<T>(
val name: String,
) {
abstract fun parse(value: Any): T
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class ChestTypes {
SINGLE,
@ -23,12 +22,8 @@ enum class ChestTypes {
RIGHT,
;
companion object : BlockPropertiesSerializer, ValuesEnum<ChestTypes> {
companion object : ValuesEnum<ChestTypes> {
override val VALUES = values()
override val NAME_MAP: Map<String, ChestTypes> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): ChestTypes {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -0,0 +1,32 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.ValuesEnum
class EnumProperty<T : Enum<*>>(
name: String,
private val values: ValuesEnum<T>,
private val allowed: Set<T>? = null,
) : BlockProperty<T>(name) {
override fun parse(value: Any): T {
val value = values[value] ?: throw IllegalArgumentException("Invalid enum value: $value")
if (allowed != null && value !in allowed) {
throw IllegalArgumentException("Enum value not allowed: $value")
}
return value
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -13,35 +13,23 @@
package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
import java.util.*
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.enums.AliasableEnum
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
enum class Halves(
vararg val aliases: Any,
) {
vararg names: String,
) : AliasableEnum {
UPPER("top"),
LOWER("bottom"),
DOUBLE,
;
companion object : BlockPropertiesSerializer {
private val NAME_MAP: Map<Any, Halves>
override val names: Array<String> = names.unsafeCast()
init {
val names: MutableMap<Any, Halves> = mutableMapOf()
for (value in values()) {
names[value.name.lowercase(Locale.getDefault())] = value
for (alias in value.aliases) {
names[alias] = value
}
}
NAME_MAP = names
}
override fun deserialize(value: Any): Halves {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
companion object : ValuesEnum<Halves> {
override val VALUES = values()
override val NAME_MAP = EnumUtil.getEnumValues(VALUES)
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -13,12 +13,14 @@
package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
import java.util.*
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.enums.AliasableEnum
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
enum class Instruments(
vararg val aliases: String,
) {
vararg names: String,
) : AliasableEnum {
HARP,
BASE_DRUM("basedrum"),
SNARE,
@ -45,24 +47,11 @@ enum class Instruments(
CUSTOM_HEAD,
;
companion object : BlockPropertiesSerializer {
private val NAME_MAP: Map<Any, Instruments>
override val names: Array<String> = names.unsafeCast()
init {
val names: MutableMap<Any, Instruments> = mutableMapOf()
for (value in values()) {
names[value.name.lowercase(Locale.getDefault())] = value
for (alias in value.aliases) {
names[alias] = value
}
}
NAME_MAP = names
}
override fun deserialize(value: Any): Instruments {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
companion object : ValuesEnum<Instruments> {
override val VALUES = values()
override val NAME_MAP = EnumUtil.getEnumValues(VALUES)
}
}

View File

@ -1,49 +0,0 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
import java.util.*
enum class MultipartDirectionParser(
vararg val aliases: Any,
) {
NONE(false, "false"),
LOW,
UP,
SIDE(true, "true"),
TALL,
;
companion object : BlockPropertiesSerializer {
private val NAME_MAP: Map<Any, MultipartDirectionParser>
init {
val names: MutableMap<Any, MultipartDirectionParser> = mutableMapOf()
for (value in values()) {
names[value.name.lowercase(Locale.getDefault())] = value
for (alias in value.aliases) {
names[alias] = value
}
}
NAME_MAP = names
}
override fun deserialize(value: Any): MultipartDirectionParser {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -0,0 +1,44 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.enums.AliasableEnum
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
enum class MultipartDirections(
vararg names: String,
) : AliasableEnum {
NONE("false"),
LOW,
UP,
SIDE("true"),
TALL,
;
override val names: Array<String> = names.unsafeCast()
companion object : ValuesEnum<MultipartDirections> {
override val VALUES: Array<MultipartDirections> = values()
override val NAME_MAP = EnumUtil.getEnumValues(VALUES)
override fun get(any: Any): MultipartDirections? {
if (any is Boolean) {
return if (any) SIDE else NONE
}
return super.get(any)
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Orientations {
DOWN_EAST,
@ -32,12 +31,8 @@ enum class Orientations {
SOUTH_UP,
;
companion object : ValuesEnum<Orientations>, BlockPropertiesSerializer {
companion object : ValuesEnum<Orientations> {
override val VALUES: Array<Orientations> = values()
override val NAME_MAP: Map<String, Orientations> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): Orientations {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,19 +15,14 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class PistonTypes {
NORMAL,
STICKY,
;
companion object : BlockPropertiesSerializer, ValuesEnum<PistonTypes> {
companion object : ValuesEnum<PistonTypes> {
override val VALUES = values()
override val NAME_MAP: Map<String, PistonTypes> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): PistonTypes {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class SensorPhases {
INACTIVE,
@ -23,12 +22,8 @@ enum class SensorPhases {
COOLDOWN,
;
companion object : BlockPropertiesSerializer, ValuesEnum<SensorPhases> {
companion object : ValuesEnum<SensorPhases> {
override val VALUES = values()
override val NAME_MAP: Map<String, SensorPhases> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): SensorPhases {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Shapes {
STRAIGHT,
@ -35,12 +34,8 @@ enum class Shapes {
ASCENDING_SOUTH,
;
companion object : BlockPropertiesSerializer, ValuesEnum<Shapes> {
companion object : ValuesEnum<Shapes> {
override val VALUES = values()
override val NAME_MAP: Map<String, Shapes> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): Shapes {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,19 +15,14 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Sides {
LEFT,
RIGHT,
;
companion object : BlockPropertiesSerializer, ValuesEnum<Sides> {
companion object : ValuesEnum<Sides> {
override val VALUES = values()
override val NAME_MAP: Map<String, Sides> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): Sides {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class StructureBlockModes {
SAVE,
@ -26,12 +25,8 @@ enum class StructureBlockModes {
SUBTRACT,
;
companion object : BlockPropertiesSerializer, ValuesEnum<StructureBlockModes> {
companion object : ValuesEnum<StructureBlockModes> {
override val VALUES = values()
override val NAME_MAP: Map<String, StructureBlockModes> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): StructureBlockModes {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Thicknesses {
TIP_MERGE,
@ -27,12 +26,8 @@ enum class Thicknesses {
DOWN,
;
companion object : BlockPropertiesSerializer, ValuesEnum<Thicknesses> {
companion object : ValuesEnum<Thicknesses> {
override val VALUES = values()
override val NAME_MAP: Map<String, Thicknesses> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): Thicknesses {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class Tilts {
NONE,
@ -24,12 +23,8 @@ enum class Tilts {
FULL,
;
companion object : BlockPropertiesSerializer, ValuesEnum<Tilts> {
companion object : ValuesEnum<Tilts> {
override val VALUES = values()
override val NAME_MAP: Map<String, Tilts> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): Tilts {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -15,19 +15,14 @@ package de.bixilon.minosoft.data.registries.blocks.properties
import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.minosoft.data.registries.blocks.properties.serializer.BlockPropertiesSerializer
enum class VerticalDirections {
UP,
DOWN,
;
companion object : BlockPropertiesSerializer, ValuesEnum<VerticalDirections> {
companion object : ValuesEnum<VerticalDirections> {
override val VALUES = values()
override val NAME_MAP: Map<String, VerticalDirections> = EnumUtil.getEnumValues(VALUES)
override fun deserialize(value: Any): VerticalDirections {
return NAME_MAP[value] ?: throw IllegalArgumentException("No such property: $value")
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,13 +11,14 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.blocks.properties.serializer
package de.bixilon.minosoft.data.registries.blocks.properties.primitives
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
object BooleanBlockPropertiesSerializer : BlockPropertiesSerializer {
class BooleanProperty(name: String) : BlockProperty<Boolean>(name) {
override fun deserialize(value: Any): Boolean {
override fun parse(value: Any): Boolean {
return value.toBoolean()
}
}

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2021 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -11,13 +11,21 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.registries.blocks.properties.serializer
package de.bixilon.minosoft.data.registries.blocks.properties.primitives
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
object IntBlockPropertiesSerializer : BlockPropertiesSerializer {
class IntProperty(
name: String,
val range: IntRange? = null,
) : BlockProperty<Int>(name) {
override fun deserialize(value: Any): Int {
return value.toInt()
override fun parse(value: Any): Int {
val value = value.toInt()
if (range != null && value !in range) throw IllegalArgumentException("Value out of range: $value (expected=$range)")
return value
}
}

View File

@ -14,14 +14,14 @@
package de.bixilon.minosoft.data.registries.blocks.state
import de.bixilon.minosoft.data.registries.blocks.light.LightProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.state.builder.BlockStateSettings
import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape
open class AdvancedBlockState(
block: Block,
properties: Map<BlockProperties, Any>,
properties: Map<BlockProperty<*>, Any>,
luminance: Int,
val collisionShape: AbstractVoxelShape?,
val outlineShape: AbstractVoxelShape?,

View File

@ -12,7 +12,7 @@
*/
package de.bixilon.minosoft.data.registries.blocks.state
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.state.builder.BlockStateSettings
import de.bixilon.minosoft.data.registries.blocks.state.error.StatelessBlockError
import de.bixilon.minosoft.data.registries.blocks.types.Block
@ -42,17 +42,18 @@ open class BlockState(
return block.toString()
}
open fun withProperties(vararg properties: Pair<BlockProperties, Any>): BlockState {
open fun withProperties(vararg properties: Pair<BlockProperty<*>, Any>): BlockState {
if (properties.isEmpty()) return this
throw StatelessBlockError(this)
}
open fun withProperties(properties: Map<BlockProperties, Any>): BlockState {
open fun withProperties(properties: Map<BlockProperty<*>, Any>): BlockState {
if (properties.isEmpty()) return this
throw StatelessBlockError(this)
}
open fun cycle(property: BlockProperties): BlockState = throw StatelessBlockError(this)
open fun cycle(property: BlockProperty<*>): BlockState = throw StatelessBlockError(this)
open operator fun <T> get(property: BlockProperties): T = throw StatelessBlockError(this)
open operator fun <T> get(property: BlockProperty<T>): T = throw StatelessBlockError(this)
open fun <T> getOrNull(property: BlockProperty<T>): T? = throw StatelessBlockError(this)
}

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.data.registries.blocks.state
import com.google.common.base.Objects
import de.bixilon.kutil.array.ArrayUtil.next
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.state.builder.BlockStateSettings
import de.bixilon.minosoft.data.registries.blocks.state.manager.PropertyStateManager
import de.bixilon.minosoft.data.registries.blocks.types.Block
@ -25,7 +25,7 @@ import de.bixilon.minosoft.data.text.BaseComponent
open class PropertyBlockState(
block: Block,
val properties: Map<BlockProperties, Any>,
val properties: Map<BlockProperty<*>, Any>,
luminance: Int,
) : BlockState(block, luminance) {
private val hash = Objects.hashCode(block, properties)
@ -45,7 +45,7 @@ open class PropertyBlockState(
}
override fun withProperties(vararg properties: Pair<BlockProperties, Any>): BlockState {
override fun withProperties(vararg properties: Pair<BlockProperty<*>, Any>): BlockState {
val nextProperties = this.properties.toMutableMap()
for ((key, value) in properties) {
@ -55,7 +55,7 @@ open class PropertyBlockState(
return getStateWith(nextProperties)
}
override fun withProperties(properties: Map<BlockProperties, Any>): BlockState {
override fun withProperties(properties: Map<BlockProperty<*>, Any>): BlockState {
val nextProperties = this.properties.toMutableMap()
for ((key, value) in properties) {
@ -65,7 +65,7 @@ open class PropertyBlockState(
return getStateWith(nextProperties)
}
private fun getStateWith(properties: Map<BlockProperties, Any>): BlockState {
private fun getStateWith(properties: Map<BlockProperty<*>, Any>): BlockState {
for (state in this.block.states) {
if (state !is PropertyBlockState) continue
@ -79,16 +79,20 @@ open class PropertyBlockState(
throw IllegalArgumentException("Can not find ${this.block} with properties: $properties")
}
override fun cycle(property: BlockProperties): BlockState {
val value: Any = this[property]
override fun cycle(property: BlockProperty<*>): BlockState {
val value: Any = this[property]!!
return withProperties(property to block.states.unsafeCast<PropertyStateManager>().properties[property]!!.next(value))
}
override fun <T> get(property: BlockProperties): T {
override fun <T> get(property: BlockProperty<T>): T {
val value = this.properties[property] ?: throw IllegalArgumentException("$this has not property $property")
return value.unsafeCast()
}
override fun <T> getOrNull(property: BlockProperty<T>): T? {
return this.properties[property]?.unsafeCast()
}
fun withProperties(): BaseComponent {
val component = BaseComponent()

View File

@ -19,14 +19,14 @@ import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.blocks.light.*
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.shapes.ShapeRegistry
import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape
import de.bixilon.minosoft.data.registries.shapes.voxel.AbstractVoxelShape.Companion.deserialize
import java.util.*
class BlockStateSettings(
val properties: Map<BlockProperties, Any>?,
val properties: Map<BlockProperty<*>, Any>?,
val luminance: Int,
val collisionShape: AbstractVoxelShape?,
val outlineShape: AbstractVoxelShape?,
@ -57,11 +57,11 @@ class BlockStateSettings(
return AbstractVoxelShape.EMPTY
}
private fun JsonObject.getProperties(): Map<BlockProperties, Any>? {
private fun JsonObject.getProperties(): Map<BlockProperty<*>, Any>? {
val data = this["properties"]?.toJsonObject() ?: return null
if (data.isEmpty()) return null
val properties: MutableMap<BlockProperties, Any> = EnumMap(BlockProperties::class.java)
val properties: MutableMap<BlockProperty<*>, Any> = HashMap()
for ((group, json) in data) {
try {

View File

@ -13,18 +13,18 @@
package de.bixilon.minosoft.data.registries.blocks.state.manager
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
interface BlockStateManager : Iterable<BlockState> {
val default: BlockState
fun withProperties(vararg properties: Pair<BlockProperties, Any>): BlockState {
fun withProperties(vararg properties: Pair<BlockProperty<*>, Any>): BlockState {
return this.default.withProperties(*properties)
}
fun withProperties(properties: Map<BlockProperties, Any>): BlockState {
fun withProperties(properties: Map<BlockProperty<*>, Any>): BlockState {
return this.default.withProperties(properties)
}
}

View File

@ -13,11 +13,11 @@
package de.bixilon.minosoft.data.registries.blocks.state.manager
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
class PropertyStateManager(
val properties: Map<BlockProperties, Array<Any>>,
val properties: Map<BlockProperty<*>, Array<Any>>,
val states: Set<BlockState>,
override val default: BlockState,
) : BlockStateManager {

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.registries.blocks.types
import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.minosoft.data.language.LanguageUtil.translation
import de.bixilon.minosoft.data.language.translate.Translatable
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.state.manager.BlockStateManager
@ -50,7 +50,7 @@ abstract class Block(
}
fun updateStates(states: Set<BlockState>, default: BlockState, properties: Map<BlockProperties, Array<Any>>) {
fun updateStates(states: Set<BlockState>, default: BlockState, properties: Map<BlockProperty<*>, Array<Any>>) {
val manager = when {
states.size == 1 -> SimpleStateManager(default)
else -> PropertyStateManager(properties, states, default)

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.data.registries.blocks.types.fluid
import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kutil.exception.Broken
import de.bixilon.minosoft.data.registries.blocks.light.CustomLightProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.Block
@ -47,5 +48,6 @@ abstract class FluidBlock(identifier: ResourceLocation, settings: BlockSettings)
companion object {
val LIGHT_PROPERTIES = CustomLightProperties(true, false, true)
val LEVEL = BlockProperties.FLUID_LEVEL
}
}

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.registries.blocks.types.pixlyzer
import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.minosoft.data.registries.blocks.factory.PixLyzerBlockFactory
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.isLit
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.isLit
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.properties.rendering.RandomDisplayTickable
import de.bixilon.minosoft.data.registries.identified.ResourceLocation

View File

@ -19,7 +19,7 @@ import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.data.registries.blocks.factory.PixLyzerBlockFactory
import de.bixilon.minosoft.data.registries.blocks.handler.entity.Climbable
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries

View File

@ -17,7 +17,7 @@ import de.bixilon.minosoft.camera.target.targets.BlockTarget
import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.entities.entities.player.Hands
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.isPowered
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.isPowered
import de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.PixLyzerBlock
import de.bixilon.minosoft.data.registries.blocks.types.properties.InteractBlockHandler
import de.bixilon.minosoft.data.registries.identified.ResourceLocation

View File

@ -21,7 +21,7 @@ import de.bixilon.kutil.random.RandomUtil.chance
import de.bixilon.minosoft.data.entities.block.CampfireBlockEntity
import de.bixilon.minosoft.data.registries.blocks.factory.PixLyzerBlockFactory
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.isLit
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.isLit
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.state.PropertyBlockState
import de.bixilon.minosoft.data.registries.blocks.types.properties.LitBlock

View File

@ -21,8 +21,8 @@ import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.entities.entities.player.Hands
import de.bixilon.minosoft.data.registries.blocks.factory.PixLyzerBlockFactory
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.isPowered
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.isPowered
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.properties.InteractBlockHandler
import de.bixilon.minosoft.data.registries.blocks.types.properties.rendering.RandomDisplayTickable

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.wall
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.properties.Attachments
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.state.PropertyBlockState
import de.bixilon.minosoft.data.registries.blocks.state.error.StatelessBlockError

View File

@ -15,8 +15,8 @@ package de.bixilon.minosoft.data.registries.fluid
import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidFilled
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidHolder
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
@ -130,7 +130,7 @@ abstract class Fluid(override val identifier: ResourceLocation) : RegistryItem()
if (state.block is FluidFilled && state.block.fluid == this) {
return MAX_LEVEL
}
val level = state.get<Int?>(BlockProperties.FLUID_LEVEL) ?: return 0.0f
val level = state[FluidBlock.LEVEL]
if (level <= 0 || level >= 8) {
return MAX_LEVEL
}

View File

@ -23,7 +23,7 @@ import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.entities.block.sign.SignBlockEntity
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.state.PropertyBlockState
import de.bixilon.minosoft.data.registries.blocks.types.pixlyzer.entity.sign.StandingSignBlock

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.entities.renderer.storage
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.time.DateUtil
import de.bixilon.minosoft.data.entities.block.container.storage.StorageBlockEntity
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderContext

View File

@ -16,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.entities.renderer.storage
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.time.DateUtil
import de.bixilon.minosoft.data.entities.block.container.storage.StorageBlockEntity
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.Companion.getFacing
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties.getFacing
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.RenderContext

View File

@ -15,13 +15,13 @@ package de.bixilon.minosoft.gui.rendering.models.block.state.builder.condition
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.json.JsonObject
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
class AndCondition(
val conditions: Set<BuilderCondition>,
) : BuilderCondition {
override fun matches(properties: Map<BlockProperties, Any>): Boolean {
override fun matches(properties: Map<BlockProperty<*>, Any>): Boolean {
for (condition in conditions) {
if (!condition.matches(properties)) return false
}

View File

@ -13,9 +13,9 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.builder.condition
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
interface BuilderCondition {
fun matches(properties: Map<BlockProperties, Any>): Boolean
fun matches(properties: Map<BlockProperty<*>, Any>): Boolean
}

View File

@ -14,13 +14,13 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.builder.condition
import de.bixilon.kutil.json.JsonObject
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
class OrCondition(
val conditions: Set<BuilderCondition>,
) : BuilderCondition {
override fun matches(properties: Map<BlockProperties, Any>): Boolean {
override fun matches(properties: Map<BlockProperty<*>, Any>): Boolean {
for (condition in conditions) {
if (condition.matches(properties)) return true
}

View File

@ -13,11 +13,11 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.builder.condition
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
class PrimitiveCondition private constructor(val matches: Boolean) : BuilderCondition {
override fun matches(properties: Map<BlockProperties, Any>) = matches
override fun matches(properties: Map<BlockProperty<*>, Any>) = matches
companion object {

View File

@ -16,12 +16,13 @@ package de.bixilon.minosoft.gui.rendering.models.block.state.builder.condition
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.json.JsonObject
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
class PropertyCondition(
val conditions: Map<BlockProperties, Any>,
val conditions: Map<BlockProperty<*>, Any>,
) : BuilderCondition {
override fun matches(properties: Map<BlockProperties, Any>): Boolean {
override fun matches(properties: Map<BlockProperty<*>, Any>): Boolean {
for ((property, value) in this.conditions) {
val target = properties[property] ?: return false
if (value is Set<*>) {
@ -36,13 +37,13 @@ class PropertyCondition(
companion object {
private fun deserializeOr(property: String, list: List<String>): Pair<BlockProperties, Any> {
private fun deserializeOr(property: String, list: List<String>): Pair<BlockProperty<*>, Any> {
if (list.size == 1) {
return BlockProperties.parseProperty(property, list.first())
}
val values: MutableSet<Any> = mutableSetOf()
var blockProperty: BlockProperties? = null
var blockProperty: BlockProperty<*>? = null
for (entry in list) {
val (entryProperty, entryValue) = BlockProperties.parseProperty(property, entry)
@ -59,7 +60,7 @@ class PropertyCondition(
}
fun deserialize(data: JsonObject): PropertyCondition? {
val properties: MutableMap<BlockProperties, Any> = mutableMapOf()
val properties: MutableMap<BlockProperty<*>, Any> = mutableMapOf()
for ((key, value) in data) {
if (key == OrCondition.KEY) continue

View File

@ -13,6 +13,6 @@
package de.bixilon.minosoft.gui.rendering.models.block.state.variant
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
typealias BlockVariant = Map<BlockProperties, Any>
typealias BlockVariant = Map<BlockProperty<*>, Any>

View File

@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.models.block.state.variant
import de.bixilon.kutil.json.JsonObject
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
import de.bixilon.minosoft.gui.rendering.models.block.state.DirectBlockModel
import de.bixilon.minosoft.gui.rendering.models.block.state.apply.BlockStateApply
import de.bixilon.minosoft.gui.rendering.models.loader.BlockLoader
@ -27,7 +28,7 @@ interface VariantBlockModel : DirectBlockModel {
companion object {
private fun parseVariant(variant: String): BlockVariant {
val properties: MutableMap<BlockProperties, Any> = mutableMapOf()
val properties: MutableMap<BlockProperty<*>, Any> = mutableMapOf()
for (pair in variant.split(',')) {
val (key, rawValue) = pair.split('=', limit = 2)