-
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.
- Loading branch information
Showing
5 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
57 changes: 42 additions & 15 deletions
57
...main/kotlin/net/easecation/bedrockloader/bedrock/block/component/ComponentCollisionBox.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 |
---|---|---|
@@ -1,24 +1,51 @@ | ||
package net.easecation.bedrockloader.bedrock.block.component | ||
|
||
data class ComponentCollisionBox( | ||
val origin : FloatArray, | ||
val size : FloatArray | ||
) : IBlockComponent { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import java.lang.reflect.Type | ||
|
||
other as ComponentCollisionBox | ||
sealed class ComponentCollisionBox : IBlockComponent { | ||
|
||
if (!origin.contentEquals(other.origin)) return false | ||
if (!size.contentEquals(other.size)) return false | ||
data class ComponentCollisionBoxBoolean( | ||
val value: Boolean | ||
) : ComponentCollisionBox() | ||
|
||
data class ComponentCollisionBoxCustom( | ||
val origin : FloatArray, | ||
val size : FloatArray | ||
) : ComponentCollisionBox() { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as ComponentCollisionBoxCustom | ||
|
||
if (!origin.contentEquals(other.origin)) return false | ||
if (!size.contentEquals(other.size)) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = origin.contentHashCode() | ||
result = 31 * result + size.contentHashCode() | ||
return result | ||
} | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = origin.contentHashCode() | ||
result = 31 * result + size.contentHashCode() | ||
return result | ||
class Deserializer : JsonDeserializer<ComponentCollisionBox> { | ||
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): ComponentCollisionBox { | ||
return if (json.isJsonPrimitive && json.asJsonPrimitive.isBoolean) { | ||
ComponentCollisionBoxBoolean(json.asBoolean) | ||
} else { | ||
val obj = json.asJsonObject | ||
val origin = obj["origin"]?.asJsonArray?.map { it.asFloat }?.toFloatArray() ?: floatArrayOf(0f, 0f, 0f) | ||
val size = obj["size"]?.asJsonArray?.map { it.asFloat }?.toFloatArray() ?: floatArrayOf(0f, 0f, 0f) | ||
ComponentCollisionBoxCustom(origin, size) | ||
} | ||
} | ||
} | ||
|
||
} |
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
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