Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit bd0a17e

Browse files
committed
Fix state values property
1 parent c1bea2d commit bd0a17e

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/main/kotlin/org/sandboxpowered/fabric/api/PolyglotStateProperty.kt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ import org.graalvm.polyglot.HostAccess.Export
55

66
class PolyglotStateProperty private constructor(
77
private val property: Property<*>?,
8-
@Export val name: String,
9-
@Export val type: String,
10-
val extra: Array<out Any>
8+
@JvmField @Export val name: String,
9+
@JvmField @Export val type: String,
10+
@JvmField @Export val values: Array<*>
1111
) {
12-
// TODO: Coded : figure out what to do with this
13-
//Int Property
14-
@Export
15-
fun values(): Array<Int> {
16-
if (type == INT) return extra as Array<Int>
17-
throw UnsupportedOperationException("Cannot get minimum value of $type property")
18-
}
19-
2012
companion object {
2113
infix fun from(property: Property<*>) = PolyglotStateProperty(
2214
property = property,
@@ -28,17 +20,17 @@ class PolyglotStateProperty private constructor(
2820
is EnumProperty -> ENUM
2921
else -> error("Unknown Property type: $property")
3022
},
31-
extra = when (property) {
23+
values = when (property) {
3224
is BooleanProperty -> emptyArray()
3325
else -> property.values.toTypedArray()
3426
}
3527
)
3628

37-
fun from(name: String, type: String, extra: Array<out Any> = emptyArray()) = PolyglotStateProperty(
29+
fun from(name: String, type: String, extra: Array<*> = emptyArray<Any>()) = PolyglotStateProperty(
3830
property = null,
3931
name = name,
4032
type = type,
41-
extra = extra
33+
values = extra
4234
)
4335

4436
const val BOOLEAN = "boolean"

src/main/kotlin/org/sandboxpowered/fabric/api/SandboxResourcePolyglotContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SandboxResourcePolyglotContext(private val resource: String, private val s
5858
}
5959

6060
@Export
61-
fun getStateProperty(name: String, type: String, vararg extra: Value): PolyglotStateProperty? {
61+
fun getStateProperty(name: String, type: String, vararg extra: Value): PolyglotStateProperty {
6262
return StateManagement.getStateProperty(name, type, *extra)
6363
}
6464
}

src/main/kotlin/org/sandboxpowered/fabric/api/StateManagement.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.sandboxpowered.fabric.api
22

3-
import com.google.common.hash.Hashing
43
import net.minecraft.state.property.Property
54
import org.graalvm.polyglot.Value
6-
import java.nio.charset.StandardCharsets
5+
import org.sandboxpowered.fabric.util.Hash
6+
import org.sandboxpowered.fabric.util.hash
77

88
object StateManagement {
99
private val stateMap: MutableMap<String, PolyglotStateProperty> = hashMapOf()
@@ -14,7 +14,10 @@ object StateManagement {
1414
stateMap.computeIfAbsent(hash(name, type)) { PolyglotStateProperty.from(name, type) }
1515
}
1616
PolyglotStateProperty.INT -> {
17-
val values = extra.map(Value::asInt).toTypedArray()
17+
require(extra.size == 2) { "Invalid number of arguments specified, expected 2 got ${extra.size}" }
18+
var values = extra.map(Value::asInt).toTypedArray()
19+
20+
values = (values[0]..values[1]).toList().toTypedArray()
1821
stateMap.computeIfAbsent(hash(name, type, values)) {
1922
PolyglotStateProperty.from(name, type, values)
2023
}
@@ -29,9 +32,9 @@ object StateManagement {
2932
}
3033

3134
private fun PolyglotStateProperty.hash(): String =
32-
hash(name, type, extra)
35+
hash(name, type, values)
3336

34-
private fun hash(name: String, type: String, extra: Array<out Any> = emptyArray()): String {
37+
private fun hash(name: String, type: String, extra: Array<*> = emptyArray<Any>()): String {
3538
val compiled = buildString {
3639
append(name)
3740
append(type)

src/main/kotlin/org/sandboxpowered/fabric/util/PolyglotUtil.kt renamed to src/main/kotlin/org/sandboxpowered/fabric/util/polyglot.kt

File renamed without changes.

0 commit comments

Comments
 (0)