-
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.
Merge pull request #2 from linyuzhe210/main
RideableComponent fix
- Loading branch information
Showing
2 changed files
with
55 additions
and
18 deletions.
There are no files selected for viewing
70 changes: 52 additions & 18 deletions
70
src/main/kotlin/net/easecation/bedrockloader/bedrock/entity/components/ComponentRideable.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,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") | ||
} | ||
} | ||
} | ||
} |
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