diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/blocks/properties/list/MapPropertyListTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/blocks/properties/list/MapPropertyListTest.kt
new file mode 100644
index 000000000..21efb2f17
--- /dev/null
+++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/registries/blocks/properties/list/MapPropertyListTest.kt
@@ -0,0 +1,58 @@
+/*
+ * 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 .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.data.registries.blocks.properties.list
+
+import de.bixilon.minosoft.data.direction.Directions
+import de.bixilon.minosoft.data.registries.blocks.properties.EnumProperty
+import de.bixilon.minosoft.data.registries.blocks.properties.primitives.BooleanProperty
+import org.testng.Assert.assertEquals
+import org.testng.annotations.Test
+
+@Test(groups = ["blocks"])
+class MapPropertyListTest {
+
+ fun `unpacking single boolean property`() {
+ val list = MapPropertyList()
+ val property = BooleanProperty("test")
+ list += property
+ assertEquals(list.unpack().toSet(), setOf(mapOf(property to false), mapOf(property to true)))
+ }
+
+ fun `unpacking single enum property`() {
+ val list = MapPropertyList()
+ val property = EnumProperty("test", Directions)
+ list += property
+ assertEquals(list.unpack().toSet(), setOf(
+ mapOf(property to Directions.DOWN),
+ mapOf(property to Directions.UP),
+ mapOf(property to Directions.NORTH),
+ mapOf(property to Directions.SOUTH),
+ mapOf(property to Directions.WEST),
+ mapOf(property to Directions.EAST),
+ ))
+ }
+
+ fun `unpacking 2 boolean properties`() {
+ val list = MapPropertyList()
+ val a = BooleanProperty("a")
+ val b = BooleanProperty("b")
+ list += a; list += b
+ assertEquals(list.unpack().toSet(), setOf(
+ mapOf(a to false, b to false),
+ mapOf(a to false, b to true),
+ mapOf(a to true, b to false),
+ mapOf(a to true, b to true),
+ ))
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperties.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperties.kt
index a714320a6..15b1f2291 100644
--- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperties.kt
+++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperties.kt
@@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.blocks.types.building.dirt.SnowyBlock
import de.bixilon.minosoft.data.registries.blocks.types.building.snow.SnowLayerBlock
import de.bixilon.minosoft.data.registries.blocks.types.fluid.FluidBlock
+import java.util.*
@Deprecated("Fallback data")
object BlockProperties {
@@ -117,6 +118,7 @@ object BlockProperties {
val AXIS = EnumProperty("axis", Axes).register()
val FACING = EnumProperty("facing", Directions).register()
+ val FACING_HORIZONTAL = EnumProperty("facing", Directions, EnumSet.of(Directions.NORTH, Directions.SOUTH, Directions.WEST, Directions.EAST))
val ROTATION = IntProperty("rotation").register()
val ORIENTATION = EnumProperty("orientation", Orientations).register()
diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperty.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperty.kt
index 414ecbabc..4317a52ae 100644
--- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperty.kt
+++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/BlockProperty.kt
@@ -16,7 +16,7 @@ package de.bixilon.minosoft.data.registries.blocks.properties
abstract class BlockProperty(
val name: String,
-) {
+) : Iterable {
override fun toString(): String {
return name
diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/EnumProperty.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/EnumProperty.kt
index d9c7cbed6..5b29a94db 100644
--- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/EnumProperty.kt
+++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/EnumProperty.kt
@@ -17,8 +17,8 @@ import de.bixilon.kutil.enums.ValuesEnum
class EnumProperty>(
name: String,
- private val values: ValuesEnum,
- private val allowed: Set? = null,
+ val values: ValuesEnum,
+ val allowed: Set? = null,
) : BlockProperty(name) {
override fun parse(value: Any): T {
@@ -36,4 +36,8 @@ class EnumProperty>(
if (other.name != name) return false
return other.values == values && allowed == other.allowed
}
+
+ override fun iterator(): Iterator {
+ return allowed?.iterator() ?: values.iterator()
+ }
}
diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/list/BlockPropertyList.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/list/BlockPropertyList.kt
index 9ff72b7bf..8c0a7fa81 100644
--- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/list/BlockPropertyList.kt
+++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/properties/list/BlockPropertyList.kt
@@ -18,8 +18,10 @@ import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperty
interface BlockPropertyList {
operator fun get(name: String): BlockProperty<*>?
+ fun unpack(): List