-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement bedrock block state and block trait
- Loading branch information
1 parent
94a0967
commit e923476
Showing
19 changed files
with
286 additions
and
70 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/IBlockState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.easecation.bedrockloader.bedrock.block.state | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonParseException | ||
import java.lang.reflect.Type | ||
|
||
sealed interface IBlockState { | ||
class Deserializer : JsonDeserializer<IBlockState> { | ||
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): IBlockState = | ||
when { | ||
json.isJsonObject -> context.deserialize(json, StateRange::class.java) | ||
json.isJsonArray -> json.asJsonArray.let { array -> | ||
when { | ||
!array.isEmpty && array[0].isJsonPrimitive -> array[0].asJsonPrimitive.let { first -> | ||
when { | ||
first.isBoolean -> context.deserialize<StateBoolean>(json, StateBoolean::class.java) | ||
first.isString -> context.deserialize<StateString>(json, StateString::class.java) | ||
first.isNumber -> context.deserialize<StateInt>(json, StateInt::class.java) | ||
else -> throw JsonParseException("Unexpected JSON type for IBlockState") | ||
} | ||
} | ||
else -> throw JsonParseException("Unexpected JSON type for IBlockState") | ||
} | ||
} | ||
else -> throw JsonParseException("Unexpected JSON type for IBlockState") | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateBoolean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.easecation.bedrockloader.bedrock.block.state | ||
|
||
class StateBoolean : IBlockState, ArrayList<Boolean>() |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateInt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.easecation.bedrockloader.bedrock.block.state | ||
|
||
class StateInt : IBlockState, ArrayList<Int>() |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateRange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.easecation.bedrockloader.bedrock.block.state | ||
|
||
data class StateRange(val values: RangeValues) : IBlockState { | ||
data class RangeValues(val min: Int, val max: Int) | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/state/StateString.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.easecation.bedrockloader.bedrock.block.state | ||
|
||
class StateString : IBlockState, ArrayList<String>() |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/BlockTraits.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.easecation.bedrockloader.bedrock.block.traits | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class BlockTraits( | ||
@SerializedName("minecraft:placement_direction") val minecraftPlacementDirection: TraitPlacementDirection?, | ||
@SerializedName("minecraft:placement_position") val minecraftPlacementPosition: TraitPlacementPosition?, | ||
) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/IBlockTrait.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.easecation.bedrockloader.bedrock.block.traits | ||
|
||
interface IBlockTrait { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementDirection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.easecation.bedrockloader.bedrock.block.traits | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class TraitPlacementDirection( | ||
val enabled_states: Set<State>, | ||
val y_rotation_offset: Int | ||
) : IBlockTrait { | ||
enum class State { | ||
@SerializedName("minecraft:cardinal_direction") | ||
MINECRAFT_CARDINAL_DIRECTION, | ||
@SerializedName("minecraft:facing_direction") | ||
MINECRAFT_FACING_DIRECTION | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/net/easecation/bedrockloader/bedrock/block/traits/TraitPlacementPosition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.easecation.bedrockloader.bedrock.block.traits | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class TraitPlacementPosition( | ||
val enabled_states: Set<State> | ||
) : IBlockTrait { | ||
enum class State { | ||
@SerializedName("minecraft:block_face") | ||
MINECRAFT_BLOCK_FACE, | ||
@SerializedName("minecraft:vertical_half") | ||
MINECRAFT_VERTICAL_HALF | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/net/easecation/bedrockloader/block/BedrockBooleanProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.easecation.bedrockloader.block | ||
|
||
import net.minecraft.state.property.Property | ||
import java.util.* | ||
|
||
data class BedrockBooleanProperty( | ||
private val name: String, | ||
private val values: Set<Boolean> | ||
) : Property<Boolean>(name, Boolean::class.java) { | ||
companion object { | ||
fun of(name: String, values: Set<Boolean>): BedrockBooleanProperty { | ||
return BedrockBooleanProperty(name, values) | ||
} | ||
} | ||
|
||
override fun getValues(): Collection<Boolean> = values | ||
|
||
override fun parse(name: String): Optional<Boolean> = Optional.ofNullable(values.find { it.toString() == name }) | ||
|
||
override fun name(value: Boolean): String = value.toString() | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/net/easecation/bedrockloader/block/BedrockIntProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.easecation.bedrockloader.block | ||
|
||
import net.minecraft.state.property.Property | ||
import java.util.* | ||
|
||
data class BedrockIntProperty( | ||
private val name: String, | ||
private val values: Set<Int> | ||
) : Property<Int>(name, Int::class.java) { | ||
companion object { | ||
fun of(name: String, values: Set<Int>): BedrockIntProperty { | ||
return BedrockIntProperty(name, values) | ||
} | ||
} | ||
|
||
override fun getValues(): Collection<Int> = values | ||
|
||
override fun parse(name: String): Optional<Int> = Optional.ofNullable(values.find { it.toString() == name }) | ||
|
||
override fun name(value: Int): String = value.toString() | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/net/easecation/bedrockloader/block/BedrockStringProperty.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.easecation.bedrockloader.block | ||
|
||
import net.minecraft.state.property.Property | ||
import java.util.* | ||
|
||
data class BedrockStringProperty( | ||
private val name: String, | ||
private val values: Set<String> | ||
) : Property<String>(name, String::class.java) { | ||
companion object { | ||
fun of(name: String, values: Set<String>): BedrockStringProperty { | ||
return BedrockStringProperty(name, values) | ||
} | ||
} | ||
|
||
override fun getValues(): Collection<String> = values | ||
|
||
override fun parse(name: String): Optional<String> = Optional.ofNullable(values.find { it == name }) | ||
|
||
override fun name(value: String): String = value.toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.