Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RideableComponent fix #2

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
package net.easecation.bedrockloader.bedrock.entity.components

data class ComponentRideable(
val controlling_seat: Int?,
val crouching_skip_interact: Boolean?,
val family_types: List<Any>?, // Replace 'Any' with the appropriate type if known
val interact_text: String?,
val passenger_max_width: Double?,
val priority: Int?,
val pull_in_entities: Boolean?,
val rider_can_interact: Boolean?,
val seat_count: Int,
val seats: List<Seat>
import com.google.gson.*
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type

sealed class ComponentRideable(

) : IEntityComponent {
data class Seat(
val lock_rider_rotation: Int?,
val max_rider_count: Int?,
val min_rider_count: Int?,
val position: List<Double>?,
val rotate_rider_by: Any?
)

data class ComponentRideableWithSeat (
val controlling_seat: Int?,
val crouching_skip_interact: Boolean?,
val family_types: List<Any>?, // Replace 'Any' with the appropriate type if known
val interact_text: String?,
val passenger_max_width: Double?,
val priority: Int?,
val pull_in_entities: Boolean?,
val rider_can_interact: Boolean?,
val seat_count: Int,
val seats: Seat
): ComponentRideable()

data class Seat(
val lock_rider_rotation: Int?,
val max_rider_count: Int?,
val min_rider_count: Int?,
val position: List<Double>?,
val rotate_rider_by: Any?
)
data class ComponentRideableWithSeats (
val controlling_seat: Int?,
val crouching_skip_interact: Boolean?,
val family_types: List<Any>?, // Replace 'Any' with the appropriate type if known
val interact_text: String?,
val passenger_max_width: Double?,
val priority: Int?,
val pull_in_entities: Boolean?,
val rider_can_interact: Boolean?,
val seat_count: Int,
val seats: List<Seat>
): ComponentRideable()

class Deserializer : JsonDeserializer<ComponentRideable> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): ComponentRideable {
val seats = json.asJsonObject["seats"]
return if (seats.isJsonArray) {
val type = object :TypeToken<ComponentRideableWithSeats?>() {}.type
context.deserialize<ComponentRideableWithSeats>(json, type)
} else if (seats.isJsonObject){
val type = object :TypeToken<ComponentRideableWithSeat?>() {}.type
context.deserialize<ComponentRideableWithSeat>(json, type)
} else {
throw JsonParseException("Unexpected JSON type for ComponentRideable")
}
}
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/net/easecation/bedrockloader/util/GsonUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.easecation.bedrockloader.bedrock.block.component.ComponentSelectionBo
import net.easecation.bedrockloader.bedrock.pack.SemVersion
import net.easecation.bedrockloader.bedrock.definition.BlockResourceDefinition
import net.easecation.bedrockloader.bedrock.definition.GeometryDefinition
import net.easecation.bedrockloader.bedrock.entity.components.ComponentRideable
import net.minecraft.util.Identifier
import java.lang.reflect.Type
import java.util.UUID
Expand All @@ -28,6 +29,8 @@ object GsonUtil {
.registerTypeAdapter(ComponentSelectionBox::class.java, ComponentSelectionBox.Deserializer())
.registerTypeAdapter(ComponentCollisionBox::class.java, ComponentCollisionBox.Deserializer())
.registerTypeAdapter(ComponentPlacementFilter::class.java, ComponentPlacementFilter.Deserializer())
// entity component
.registerTypeAdapter(ComponentRideable::class.java, ComponentRideable.Deserializer())
// geometry
.registerTypeAdapter(GeometryDefinition.Uv::class.java, GeometryDefinition.Uv.Deserializer())
.create()
Expand Down
Loading