Skip to content

Commit

Permalink
Fix #431
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Nov 16, 2024
1 parent f76ec9b commit cac7baa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xyz.xenondevs.nova.resources.builder.task.model

import com.google.gson.JsonObject
import org.joml.Matrix4f
import xyz.xenondevs.commons.collections.associateNotNull
import xyz.xenondevs.commons.collections.flatMap
import xyz.xenondevs.commons.gson.fromJson
import xyz.xenondevs.commons.gson.getObjectOrNull
Expand Down Expand Up @@ -60,13 +61,27 @@ class BlockModelContent internal constructor(private val builder: ResourcePackBu
if (file.exists()) {
val blockStateJson = file.parseJson() as JsonObject

if (blockStateJson.has("multipart"))
throw IllegalArgumentException("Block state file $file contains multipart block states, which are not supported")
if (blockStateJson.has("multipart")) {
LOGGER.warning("Block state file $file contains multipart block states, which are not supported. " +
"Block states defined in this file will be ignored and potentially overwritten.")
return@forEach
}

blockStateJson.getObjectOrNull("variants")?.entrySet()
?.forEach { (variantStr, variantOpts) ->
val properties = variantStr.split(',')
.associate { val s = it.split('='); s[0] to s[1] }
val properties = variantStr.split(',').associateNotNull {
val parts = it.split('=')
if (parts.size == 2)
parts[0] to parts[1]
else null
}

if (properties.keys != type.properties) {
LOGGER.warning("Variant '$variantStr' in block state file $file does not specify all properties explicitly " +
"(got ${properties.keys}, expected ${type.properties}). " +
"This variant will be ignored and potentially overwritten.")
return@forEach
}

val config = type.of(properties)
val variant = GSON.fromJson<BlockStateVariantData>(variantOpts)!!
Expand Down Expand Up @@ -212,7 +227,6 @@ class BlockModelContent internal constructor(private val builder: ResourcePackBu
val blockStateFile = getBlockStateFile(type)
blockStateFile.createParentDirectories()
obj.writeToFile(blockStateFile)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal abstract class BackingStateConfigType<T : BackingStateConfig> internal
) {

abstract val blockedIds: Set<Int>
abstract val properties: Set<String>

abstract fun of(id: Int, waterlogged: Boolean = false): T
abstract fun of(properties: Map<String, String>): T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ internal abstract class LeavesBackingStateConfigType<T : LeavesBackingStateConfi

override val defaultStateConfig = ctor(7, true, false)
override val blockedIds = hashSetOf(13)
override val properties = hashSetOf("distance", "persistent", "waterlogged")

override fun of(id: Int, waterlogged: Boolean): T {
return ctor((id shr 1) + 1, (id and 1) == 1, waterlogged)
}

override fun of(properties: Map<String, String>): T {
return ctor(
properties["distance"]?.toInt() ?: 0,
properties["distance"]?.toInt() ?: 1,
properties["persistent"]?.toBoolean() == true,
properties["waterlogged"]?.toBoolean() == true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal data class NoteBackingStateConfig(

companion object : DynamicDefaultingBackingStateConfigType<NoteBackingStateConfig>(1149, "note_block") {

override val properties = hashSetOf("instrument", "note", "powered")

fun getIdOf(instrument: Instrument, note: Int, powered: Boolean): Int {
return instrument.ordinal * NOTE_BASE * POWERED_BASE + note * POWERED_BASE + powered.intValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal abstract class SidedBackingStateConfigType<T : SidedBackingStateConfig>

override val blockedIds = setOf(63)
override val defaultStateConfig = of(63)
override val properties = hashSetOf("north", "east", "south", "west", "up", "down")

final override fun of(id: Int, waterlogged: Boolean): T {
if (waterlogged)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal abstract class TripwireBackingStateConfigType private constructor(
) : BackingStateConfigType<TripwireBackingStateConfig>(63, "tripwire") {

override val blockedIds = IntArraySet((0..15).toIntArray())
override val properties = hashSetOf("north", "east", "south", "west", "disarmed", "powered")

override fun of(id: Int, waterlogged: Boolean): TripwireBackingStateConfig {
if (waterlogged)
Expand Down

0 comments on commit cac7baa

Please sign in to comment.