diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/events/riding/RegisterRidingControllerAdapterEvent.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/events/riding/RegisterRidingControllerAdapterEvent.kt index 6419e0ee87..714dfea288 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/events/riding/RegisterRidingControllerAdapterEvent.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/events/riding/RegisterRidingControllerAdapterEvent.kt @@ -8,13 +8,12 @@ package com.cobblemon.mod.common.api.events.riding -import com.cobblemon.mod.common.api.riding.controller.properties.Deserializer -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties +import com.cobblemon.mod.common.api.riding.controller.RideController import net.minecraft.util.Identifier -data class RegisterRidingControllerAdapterEvent(private val map: MutableMap>) { +data class RegisterRidingControllerAdapterEvent(private val map: MutableMap) { - fun register(key: Identifier, deserializer: Deserializer) { + fun register(key: Identifier, deserializer: RideController.Deserializer) { this.map[key] = deserializer } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingManager.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingManager.kt index 197a3f272c..c2e7091372 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingManager.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingManager.kt @@ -8,10 +8,6 @@ package com.cobblemon.mod.common.api.riding -import com.cobblemon.mod.common.api.riding.capability.RidingCapability -import com.cobblemon.mod.common.api.riding.context.RidingContext -import com.cobblemon.mod.common.api.riding.context.RidingContextBuilder -import com.cobblemon.mod.common.api.riding.controller.RideController import com.cobblemon.mod.common.api.riding.seats.Seat import com.cobblemon.mod.common.entity.pokemon.PokemonEntity import net.minecraft.entity.player.PlayerEntity @@ -20,70 +16,39 @@ import net.minecraft.util.Formatting import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d -data class RidingManager(val entity: () -> PokemonEntity) { - - /** - * Specifies a list of stateful seats which are capable of tracking an occupant. - * - * @since 1.5.0 - */ - var context: RidingContext = RidingContext(RidingContextBuilder()) +data class RidingManager(val entity: PokemonEntity) { // TODO - Seats should realistically be final and manipulated by seat index. // TODO - On the client, these seats are decoded, so setting the variable here // TODO - breaks if final - var seats: List = this.entity().pokemon.riding.seats.map { it.create(this.entity()) } - private lateinit var capabilities: Map - - private var firstTick: Boolean = true + var seats: List = this.entity.pokemon.riding.seats.map { it.create(this.entity) } /** * Responsible for handling riding conditions and transitions amongst controllers. This will tick * whenever the entity receives a tickControlled interaction. */ fun tick(entity: PokemonEntity, driver: PlayerEntity, input: Vec3d) { - if(this.firstTick) { - this.capabilities = this.entity().pokemon.riding.capabilities.associateWith { - RideController.controllers[it.properties.identifier]!! - } - - firstTick = false - } - - val capability = this.capabilities.keys.firstOrNull { it.condition.test(entity) } - val controller = this.capabilities[capability] ?: return - this.context = this.context.apply(capability?.properties ?: return) - - // TODO - We need to figure out a better method for this, as inputs could still be applied when traversal - // TODO - is impossible (consider walls) - entity.dataTracker.set(PokemonEntity.MOVING, input != Vec3d.ZERO) + val controller = entity.pokemon.riding.controllers.firstOrNull { it.condition.invoke(entity) } ?: return val poser = controller.poseProvider entity.dataTracker.set(PokemonEntity.POSE_TYPE, poser.select(entity)) - context.speed = if(input == Vec3d.ZERO) 0F else controller.speed(entity, driver, this.context) - driver.sendMessage(Text.literal("Speed: ").styled { it.withColor(Formatting.GREEN) }.append(Text.literal("${context.speed} b/t")), true) + val speed = controller.speed(entity, driver) + driver.sendMessage(Text.literal("Speed: ").styled { it.withColor(Formatting.GREEN) }.append(Text.literal("$speed b/t")), true) + } + + fun speed(entity: PokemonEntity, driver: PlayerEntity): Float { + val controller = entity.pokemon.riding.controllers.firstOrNull { it.condition.invoke(entity) } + return controller?.speed(entity, driver) ?: 0.05F } fun controlledRotation(entity: PokemonEntity, driver: PlayerEntity): Vec2f { - if(!this::capabilities.isInitialized) { - return Vec2f.ZERO - } - - val capability = this.capabilities.keys.firstOrNull { it.condition.test(entity) } - val controller = this.capabilities[capability] ?: return Vec2f.ZERO - - return controller.rotation(driver) + val controller = entity.pokemon.riding.controllers.firstOrNull { it.condition.invoke(entity) } + return controller?.rotation(driver) ?: Vec2f.ZERO } fun velocity(entity: PokemonEntity, driver: PlayerEntity, input: Vec3d): Vec3d { - if(!this::capabilities.isInitialized) { - return Vec3d.ZERO - } - - val capability = this.capabilities.keys.firstOrNull { it.condition.test(entity) } - val controller = this.capabilities[capability] ?: return Vec3d.ZERO - - return controller.velocity(driver, input) + val controller = entity.pokemon.riding.controllers.firstOrNull { it.condition.invoke(entity) } + return controller?.velocity(driver, input) ?: Vec3d.ZERO } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingProperties.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingProperties.kt index c6df00454a..ad900568c6 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingProperties.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/RidingProperties.kt @@ -8,8 +8,8 @@ package com.cobblemon.mod.common.api.riding -import com.cobblemon.mod.common.api.riding.capability.RidingCapability import com.cobblemon.mod.common.api.riding.conditions.RidingCondition +import com.cobblemon.mod.common.api.riding.controller.RideController import com.cobblemon.mod.common.api.riding.seats.properties.SeatProperties interface RidingProperties { @@ -18,7 +18,7 @@ interface RidingProperties { val conditions: List - val capabilities: List + val controllers: List fun supported(): Boolean diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/LandCapability.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/LandCapability.kt deleted file mode 100644 index fdc4b37d75..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/LandCapability.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.capability - -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties -import com.cobblemon.mod.common.api.tags.CobblemonBlockTags -import com.cobblemon.mod.common.entity.pokemon.PokemonEntity -import com.cobblemon.mod.common.util.blockPositionsAsList -import com.cobblemon.mod.common.util.blockPositionsAsListRounded -import net.minecraft.registry.tag.BlockTags -import net.minecraft.registry.tag.FluidTags -import net.minecraft.util.Identifier -import net.minecraft.util.math.Direction -import net.minecraft.util.math.Vec3i -import net.minecraft.util.shape.VoxelShape -import net.minecraft.util.shape.VoxelShapes -import java.util.function.Predicate - -class LandCapability(override val properties: RideControllerProperties) : RidingCapability { - - override val key: Identifier = RidingCapability.LAND - override val condition: Predicate = Predicate { entity -> - //Are there any blocks under the mon that aren't air or fluid - //Cant just check one block since some mons may be more than one block big - //This should be changed so that the any predicate is only ran on blocks under the mon - VoxelShapes.cuboid(entity.boundingBox).blockPositionsAsListRounded().any { - //Need to check other fluids - if (entity.isTouchingWater || entity.isSubmergedInWater) { - return@any false - } - //This might not actually work, depending on what the yPos actually is. yPos of the middle of the entity? the feet? - if (it.y.toDouble() == (entity.pos.y)) { - val blockState = entity.world.getBlockState(it.down()) - return@any !blockState.isAir && blockState.fluidState.isEmpty - } - false - } - } - -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/LiquidCapability.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/LiquidCapability.kt deleted file mode 100644 index 27e5023875..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/LiquidCapability.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.capability - -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties -import com.cobblemon.mod.common.entity.pokemon.PokemonEntity -import com.cobblemon.mod.common.util.blockPositionsAsListRounded -import net.minecraft.util.Identifier -import net.minecraft.util.shape.VoxelShapes -import java.util.function.Predicate - -class LiquidCapability(override val properties: RideControllerProperties) : RidingCapability { - override val key: Identifier = RidingCapability.LIQUID - //I've tested this with lava, and the pred works properly, but the pokemon sinks in the lava - override val condition: Predicate = Predicate { entity-> - //This could be kinda weird... what if the top of the mon is in a fluid but the bottom isnt? - return@Predicate VoxelShapes.cuboid(entity.boundingBox).blockPositionsAsListRounded().any { - if (entity.isTouchingWater || entity.isSubmergedInWater) { - return@any true - } - val blockState = entity.world.getBlockState(it) - return@any !blockState.fluidState.isEmpty - } - } -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/RidingCapability.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/RidingCapability.kt deleted file mode 100644 index edbed79caa..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/capability/RidingCapability.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.capability - -import com.cobblemon.mod.common.api.net.Encodable -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties -import com.cobblemon.mod.common.entity.pokemon.PokemonEntity -import com.cobblemon.mod.common.util.cobblemonResource -import net.minecraft.network.PacketByteBuf -import net.minecraft.util.Identifier -import java.util.function.Predicate - -interface RidingCapability : Encodable { - - /** A reference key used to denote the individual capability */ - val key: Identifier - - /** Specifies what allows this capability to be applied to the entity */ - val condition: Predicate - - /** Specifies properties relative to a controller configured for this capability */ - val properties: RideControllerProperties - - companion object { - - val LAND = cobblemonResource("land") - val LIQUID = cobblemonResource("liquids") - val FLIGHT = cobblemonResource("flight") - - fun create(key: Identifier, properties: RideControllerProperties): RidingCapability { - return when(key) { - LAND -> LandCapability(properties) - LIQUID -> LiquidCapability(properties) - else -> throw IllegalArgumentException("Invalid key: $key") - } - } - - fun decode(buffer: PacketByteBuf): RidingCapability { - val key = buffer.readIdentifier() - return this.create(key, RideControllerProperties.decode(buffer)) - } - - } - - override fun encode(buffer: PacketByteBuf) { - buffer.writeIdentifier(this.key) - this.properties.encode(buffer) - } - -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/RidingContext.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/RidingContext.kt deleted file mode 100644 index bd9b6ee544..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/RidingContext.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.context - -import com.cobblemon.mod.common.api.reference.Reference -import com.cobblemon.mod.common.api.riding.context.state.RidingStateKey -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerPropertyKey - -@Suppress("UNCHECKED_CAST") -class RidingContext internal constructor(builder: RidingContextBuilder) { - - private val properties: Map, Reference<*>> = builder.properties - var speed: Float = 0.0F - - fun property(key: RideControllerPropertyKey): T? { - return this.properties[key]?.reference as T? - } - - fun propertyOrDefault(key: RideControllerPropertyKey, fallback: T): T { - return this.property(key) ?: fallback - } - - fun apply(properties: RideControllerProperties): RidingContext { - val builder = RidingContextBuilder() - properties.apply(builder) - - val result = builder.finalize() - result.speed = this.speed - return result - } -} - -class RidingContextBuilder { - - internal val properties: MutableMap, Reference<*>> = mutableMapOf() - private val states: MutableMap, Reference<*>> = mutableMapOf() - - fun property(key: RideControllerPropertyKey, value: T): RidingContextBuilder { - this.properties[key] = Reference(value) - return this - } - - fun finalize(): RidingContext { - return RidingContext(this) - } -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/state/RidingStateKey.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/state/RidingStateKey.kt deleted file mode 100644 index 35062911d7..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/state/RidingStateKey.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.context.state - -import net.minecraft.util.Identifier - -data class RidingStateKey(val key: Identifier) \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/state/RidingStateKeys.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/state/RidingStateKeys.kt deleted file mode 100644 index b850316e46..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/context/state/RidingStateKeys.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.context.state - -import com.cobblemon.mod.common.util.cobblemonResource -import net.minecraft.util.Identifier - -object RidingStateKeys { - - val CURRENT_SPEED: RidingStateKey = create(cobblemonResource("current_speed")) - - fun create(key: Identifier) : RidingStateKey { - return RidingStateKey(key) - } - -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideController.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideController.kt index 3185729ff1..d59d1cee6d 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideController.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideController.kt @@ -8,19 +8,16 @@ package com.cobblemon.mod.common.api.riding.controller -import com.cobblemon.mod.common.api.riding.conditions.RidingCondition -import com.cobblemon.mod.common.api.riding.context.RidingContext import com.cobblemon.mod.common.api.riding.controller.posing.PoseProvider import com.cobblemon.mod.common.entity.PoseType import com.cobblemon.mod.common.entity.pokemon.PokemonEntity -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandController -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLiquidController +import com.google.gson.JsonElement import net.minecraft.entity.LivingEntity import net.minecraft.entity.player.PlayerEntity +import net.minecraft.network.PacketByteBuf import net.minecraft.util.Identifier import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d -import java.util.function.Predicate /** * A riding controller is the internal control mechanism for determining how a pokemon @@ -33,16 +30,6 @@ import java.util.function.Predicate */ interface RideController { - companion object { - - val controllers: MutableMap = mutableMapOf() - - init { - controllers[GenericLandController.key] = GenericLandController - controllers[GenericLiquidController.key] = GenericLiquidController - } - } - /** A reference key used to denote the individual controller */ val key: Identifier @@ -73,7 +60,7 @@ interface RideController { /** * Calculates the current speed of the mount. */ - fun speed(entity: PokemonEntity, driver: PlayerEntity, context: RidingContext) : Float + fun speed(entity: PokemonEntity, driver: PlayerEntity) : Float /** * Sets the rotation of the mount. This is typically based on the controlling driver and is manipulated as @@ -88,4 +75,16 @@ interface RideController { */ fun velocity(driver: PlayerEntity, input: Vec3d) : Vec3d + fun encode(buffer: PacketByteBuf) { + buffer.writeIdentifier(this.key) + } + + interface Deserializer { + + fun deserialize(json: JsonElement): RideController + + fun decode(buffer: PacketByteBuf): RideController + + } + } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideControllerDeserializer.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideControllerDeserializer.kt new file mode 100644 index 0000000000..f695e0f339 --- /dev/null +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/RideControllerDeserializer.kt @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2023 Cobblemon Contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package com.cobblemon.mod.common.api.riding.controller + +import com.cobblemon.mod.common.api.events.CobblemonEvents +import com.cobblemon.mod.common.api.events.riding.RegisterRidingControllerAdapterEvent +import com.google.gson.JsonElement +import net.minecraft.network.PacketByteBuf +import net.minecraft.util.Identifier + +object RideControllerDeserializer { + + private val deserializers: MutableMap = mutableMapOf() + + init { + CobblemonEvents.REGISTER_RIDING_CONTROLLER_ADAPTER.emit(RegisterRidingControllerAdapterEvent(this.deserializers)) + } + + fun deserialize(key: Identifier, json: JsonElement): RideController { + val deserializer = this.deserializers[key] + return deserializer?.deserialize(json) ?: throw IllegalArgumentException("Unknown controller: $key") + } + + fun decode(buffer: PacketByteBuf): RideController { + val key = buffer.readIdentifier() + return this.deserializers[key]?.decode(buffer) ?: throw IllegalArgumentException("Unknown controller: $key") + } + + fun register(id: Identifier, deserializer: RideController.Deserializer) { + this.deserializers[id] = deserializer + } + +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/properties/RideControllerProperties.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/properties/RideControllerProperties.kt deleted file mode 100644 index 37f10eeca1..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/properties/RideControllerProperties.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.controller.properties - -import com.cobblemon.mod.common.api.net.Encodable -import com.cobblemon.mod.common.api.riding.context.RidingContextBuilder -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandController -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandControllerAdapter -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLiquidController -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLiquidControllerAdapter -import net.minecraft.network.PacketByteBuf -import net.minecraft.util.Identifier - -interface RideControllerProperties : Encodable { - - val identifier: Identifier - - fun apply(context: RidingContextBuilder) - - companion object { - - val deserializers: Map> - - init { - // TODO - Post registration event - - this.deserializers = mapOf(GenericLandController.key to GenericLandControllerAdapter, GenericLiquidController.key to GenericLiquidControllerAdapter) - } - - fun decode(buffer: PacketByteBuf): RideControllerProperties { - val key = buffer.readIdentifier() - return this.deserializers[key]!!.decode(buffer) - } - - } - -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/properties/RideControllerPropertyDeserializer.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/properties/RideControllerPropertyDeserializer.kt deleted file mode 100644 index 30a42d606e..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/riding/controller/properties/RideControllerPropertyDeserializer.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.api.riding.controller.properties - -import com.cobblemon.mod.common.util.asIdentifier -import com.google.gson.JsonElement -import com.google.gson.JsonParseException -import net.minecraft.network.PacketByteBuf -import net.minecraft.util.Identifier - -object RideControllerPropertyDeserializer { - - fun deserialize(key: Identifier, json: JsonElement): RideControllerProperties { - val data = json.asJsonObject - val controller = data.get("controller").asIdentifier - - return RideControllerProperties.deserializers[controller]?.deserialize( - data.getAsJsonObject("properties") - ) ?: throw JsonParseException("Invalid capability: $controller") - } - -} - -interface Deserializer { - - fun deserialize(json: JsonElement): T - - fun decode(buffer: PacketByteBuf): T - -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/DelayedPokemonRenders.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/DelayedPokemonRenders.kt index 4aaf2446d3..f5db95fc41 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/DelayedPokemonRenders.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/DelayedPokemonRenders.kt @@ -1,3 +1,11 @@ +/* + * Copyright (C) 2023 Cobblemon Contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + package com.cobblemon.mod.common.client.render.pokemon import net.minecraft.client.util.math.MatrixStack diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt b/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt index ecb9d29d0d..ac06a72819 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt @@ -21,7 +21,6 @@ import com.cobblemon.mod.common.api.interaction.PokemonEntityInteraction import com.cobblemon.mod.common.api.net.serializers.PoseTypeDataSerializer import com.cobblemon.mod.common.api.net.serializers.SeatDataSerializer import com.cobblemon.mod.common.api.net.serializers.StringSetDataSerializer -import com.cobblemon.mod.common.api.pokemon.PokemonProperties import com.cobblemon.mod.common.api.pokemon.feature.FlagSpeciesFeature import com.cobblemon.mod.common.api.pokemon.status.Statuses import com.cobblemon.mod.common.api.reactive.ObservableSubscription @@ -31,9 +30,6 @@ import com.cobblemon.mod.common.api.scheduling.SchedulingTracker import com.cobblemon.mod.common.api.storage.InvalidSpeciesException import com.cobblemon.mod.common.api.riding.Rideable import com.cobblemon.mod.common.api.riding.RidingManager -import com.cobblemon.mod.common.api.riding.context.RidingContext -import com.cobblemon.mod.common.api.riding.context.state.RidingStateKeys -import com.cobblemon.mod.common.api.riding.seats.Seat import com.cobblemon.mod.common.api.types.ElementalTypes import com.cobblemon.mod.common.battles.BagItems @@ -64,11 +60,8 @@ import com.cobblemon.mod.common.pokemon.activestate.ShoulderedState import com.cobblemon.mod.common.pokemon.ai.FormPokemonBehaviour import com.cobblemon.mod.common.pokemon.evolution.variants.ItemInteractionEvolution import com.cobblemon.mod.common.pokemon.misc.GimmighoulStashHandler -import com.cobblemon.mod.common.pokemon.riding.RidingState -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandController import com.cobblemon.mod.common.util.* import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules -import net.minecraft.block.Blocks import java.util.EnumSet import java.util.Optional import java.util.UUID @@ -205,7 +198,7 @@ open class PokemonEntity( var blocksTraveled: Double = 0.0 var countsTowardsSpawnCap = true - override val riding: RidingManager = RidingManager { this } + override val riding: RidingManager = RidingManager(this) /** * 0 is do nothing, @@ -1248,7 +1241,7 @@ open class PokemonEntity( } override fun getSaddledSpeed(controller: PlayerEntity): Float { - return this.riding.context.speed + return this.riding.speed(this, controller) } override fun setJumpStrength(strength: Int) { diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/CobblemonRidingProperties.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/CobblemonRidingProperties.kt index 6d23909088..cbea15b68c 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/CobblemonRidingProperties.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/CobblemonRidingProperties.kt @@ -11,7 +11,8 @@ package com.cobblemon.mod.common.pokemon.riding import com.cobblemon.mod.common.api.net.Encodable import com.cobblemon.mod.common.api.riding.conditions.RidingCondition import com.cobblemon.mod.common.api.riding.RidingProperties -import com.cobblemon.mod.common.api.riding.capability.RidingCapability +import com.cobblemon.mod.common.api.riding.controller.RideController +import com.cobblemon.mod.common.api.riding.controller.RideControllerDeserializer import com.cobblemon.mod.common.api.riding.seats.properties.SeatProperties import com.google.gson.annotations.SerializedName import net.minecraft.network.PacketByteBuf @@ -24,7 +25,7 @@ data class CobblemonRidingProperties( override val conditions: List, @SerializedName("capabilities") - override val capabilities: List + override val controllers: List ): RidingProperties, Encodable { companion object { @@ -32,9 +33,9 @@ data class CobblemonRidingProperties( fun decode(buffer: PacketByteBuf): RidingProperties { val seats: List = buffer.readList { _ -> SeatProperties.decode(buffer) } - val capabilities: List = buffer.readList { _ -> RidingCapability.decode(buffer) } + val controllers: List = buffer.readList { _ -> RideControllerDeserializer.decode(buffer) } - return CobblemonRidingProperties(seats, emptyList(), capabilities) + return CobblemonRidingProperties(seats, emptyList(), controllers) } } @@ -44,7 +45,7 @@ data class CobblemonRidingProperties( override fun encode(buffer: PacketByteBuf) { buffer.writeNullable(this.seats) { _, seats -> buffer.writeCollection(seats) { _, seat -> seat.encode(buffer) } } - buffer.writeCollection(this.capabilities) { _, capability -> capability.encode(buffer) } + buffer.writeCollection(this.controllers) { _, controller -> controller.encode(buffer) } } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingModule.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingModule.kt index b6549c1da7..89b67186b6 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingModule.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingModule.kt @@ -9,17 +9,21 @@ package com.cobblemon.mod.common.pokemon.riding import com.cobblemon.mod.common.api.events.CobblemonEvents +import com.cobblemon.mod.common.api.riding.controller.RideControllerDeserializer import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandController -import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandControllerAdapter +import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLandControllerDeserializer import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLiquidController import com.cobblemon.mod.common.pokemon.riding.controllers.GenericLiquidControllerAdapter +import com.cobblemon.mod.common.pokemon.riding.controllers.SwimDashController +import com.cobblemon.mod.common.pokemon.riding.controllers.SwimDashControllerDeserializer object RidingModule { fun configure() { CobblemonEvents.REGISTER_RIDING_CONTROLLER_ADAPTER.subscribe { - it.register(GenericLandController.key, GenericLandControllerAdapter) - it.register(GenericLiquidController.key, GenericLiquidControllerAdapter) + it.register(GenericLandController.KEY, GenericLandControllerDeserializer) + it.register(GenericLiquidController.KEY, GenericLiquidControllerAdapter) + it.register(SwimDashController.KEY, SwimDashControllerDeserializer) } } diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingState.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingState.kt deleted file mode 100644 index 32b7006e33..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/RidingState.kt +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.pokemon.riding - -data class RidingState(var tick: Int, var momentum: Float) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/SpeedCalculator.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/SpeedCalculator.kt deleted file mode 100644 index 97a1348ce7..0000000000 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/SpeedCalculator.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2023 Cobblemon Contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package com.cobblemon.mod.common.pokemon.riding - -import kotlin.math.min - -/** - * Calculates the riding speed of a pokemon based on 5 given variables. The speed of a pokemon when it comes to riding - * is based on 5 factors. These factors are as follows: tick, velocity input, speed, acceleration, and weight. - * - * Tick: This represents the current tick since the start of the movement input, where the input has been non-zero. - * This is effectively meant to be used for time when calculating acceleration. - * - * Input: This represents the movement input specified by the riding entity. This can be used to help model the - * velocity the player is expecting the pokemon to travel in, and can be used to apply different instructions - * based on the direction of the input - * - * Speed: This is a constant value typically between 1 and 5, where 3 acts as the median speed. These factors control - * the max speed allowed for a pokemon. This differs from the pokemon's own speed stat, and is meant to better reflect - * their pokedex entries. - * - * Acceleration: This is a constant value typically between 1 and 5, where 3 acts as the median acceleration. These - * factors control the rate at which a pokemon can get to their max speed from the start of movement input. - * - * Weight: This is a constant variable which describes the pokemon's weight. This can directly affect the acceleration - * capabilities, to allow for greater variance in the resulting time it takes to reach max speed, as defined by the - * speed variable. - * - * @since 1.6.0 - */ -object SpeedCalculator { - - private const val min = 0.2F - private const val max = 2.2F - - fun calculate(tick: Int, speed: Float, acceleration: Float, weight: Float): Float { - val time = min(tick, 100) - val s = ((this.max.coerceAtMost(this.min.coerceAtLeast((this.max - this.min) / 4 * speed - 0.3F)))) - val a = (((1 - (weight / 500)) * 4) + 1) * (acceleration.coerceIn(1.0F, 5.0F) / 5) - - return ((a / weight * time) * (speed / 5)).coerceIn(0F, s) - } - -} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLandController.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLandController.kt index 65a0c8ba7d..1ebfc9a65c 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLandController.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLandController.kt @@ -8,14 +8,9 @@ package com.cobblemon.mod.common.pokemon.riding.controllers -import com.cobblemon.mod.common.api.riding.context.RidingContext -import com.cobblemon.mod.common.api.riding.context.RidingContextBuilder -import com.cobblemon.mod.common.api.riding.controller.properties.Deserializer import com.cobblemon.mod.common.api.riding.controller.posing.PoseOption import com.cobblemon.mod.common.api.riding.controller.posing.PoseProvider import com.cobblemon.mod.common.api.riding.controller.RideController -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerPropertyKeys import com.cobblemon.mod.common.entity.PoseType import com.cobblemon.mod.common.entity.pokemon.PokemonEntity import com.cobblemon.mod.common.util.blockPositionsAsListRounded @@ -28,13 +23,16 @@ import net.minecraft.util.Identifier import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d import net.minecraft.util.shape.VoxelShapes -import java.util.function.Predicate import kotlin.math.max import kotlin.math.min -object GenericLandController : RideController { +data class GenericLandController(val speed: Float, val acceleration: Float) : RideController { - override val key: Identifier = cobblemonResource("land_generic") + companion object { + val KEY: Identifier = cobblemonResource("land/generic") + } + + override val key: Identifier = KEY override val poseProvider: PoseProvider = PoseProvider(PoseType.STAND) .with(PoseOption(PoseType.WALK) { it.dataTracker.get(PokemonEntity.MOVING) }) override val condition: (PokemonEntity) -> Boolean = { entity -> @@ -55,16 +53,12 @@ object GenericLandController : RideController { } } - override fun speed(entity: PokemonEntity, driver: PlayerEntity, context: RidingContext): Float { - val max: Float = context.propertyOrDefault(RideControllerPropertyKeys.SPEED, 0.0F) - val acceleration = this.acceleration(max, context) - - return min(max(context.speed + acceleration, 0.0F), 1.0F) + override fun speed(entity: PokemonEntity, driver: PlayerEntity): Float { + return min(max(this.speed + this.acceleration(), 0.0F), 1.0F) } - private fun acceleration(speed: Float, context: RidingContext): Float { - val acceleration = context.propertyOrDefault(RideControllerPropertyKeys.ACCELERATION, 0.0F) - return (1 / ((300 * speed) + (18.5F - (acceleration * 5.3F)))) * (0.9F * ((acceleration + 1) / 2)) + private fun acceleration(): Float { + return (1 / ((300 * this.speed) + (18.5F - (this.acceleration * 5.3F)))) * (0.9F * ((this.acceleration + 1) / 2)) } override fun rotation(driver: LivingEntity): Vec2f { @@ -81,35 +75,23 @@ object GenericLandController : RideController { return Vec3d(f.toDouble(), 0.0, g.toDouble()) } -} - -data class GenericLandControllerProperties( - val speed: Float, - val acceleration: Float -) : RideControllerProperties { - - override val identifier: Identifier = GenericLandController.key - override fun encode(buffer: PacketByteBuf) { + super.encode(buffer) buffer.writeFloat(this.speed) buffer.writeFloat(this.acceleration) } - override fun apply(context: RidingContextBuilder) { - context.property(RideControllerPropertyKeys.SPEED, this.speed) - context.property(RideControllerPropertyKeys.ACCELERATION, this.acceleration) - } } -object GenericLandControllerAdapter : Deserializer { +object GenericLandControllerDeserializer : RideController.Deserializer { - override fun deserialize(json: JsonElement): GenericLandControllerProperties { + override fun deserialize(json: JsonElement): RideController { val obj = json.asJsonObject - return GenericLandControllerProperties(obj.get("speed").asFloat, obj.get("acceleration").asFloat) + return GenericLandController(obj.get("speed").asFloat, obj.get("acceleration").asFloat) } - override fun decode(buffer: PacketByteBuf): GenericLandControllerProperties { - return GenericLandControllerProperties(buffer.readFloat(), buffer.readFloat()) + override fun decode(buffer: PacketByteBuf): RideController { + return GenericLandController(buffer.readFloat(), buffer.readFloat()) } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLiquidController.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLiquidController.kt index 8f4a9d9ac2..64b011027a 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLiquidController.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/GenericLiquidController.kt @@ -8,14 +8,9 @@ package com.cobblemon.mod.common.pokemon.riding.controllers -import com.cobblemon.mod.common.api.riding.context.RidingContext -import com.cobblemon.mod.common.api.riding.context.RidingContextBuilder import com.cobblemon.mod.common.api.riding.controller.RideController import com.cobblemon.mod.common.api.riding.controller.posing.PoseOption import com.cobblemon.mod.common.api.riding.controller.posing.PoseProvider -import com.cobblemon.mod.common.api.riding.controller.properties.Deserializer -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerPropertyKeys import com.cobblemon.mod.common.entity.PoseType import com.cobblemon.mod.common.entity.pokemon.PokemonEntity import com.cobblemon.mod.common.util.cobblemonResource @@ -26,27 +21,27 @@ import net.minecraft.network.PacketByteBuf import net.minecraft.util.Identifier import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d -import java.util.function.Predicate import kotlin.math.max import kotlin.math.min -object GenericLiquidController : RideController { - override val key: Identifier = cobblemonResource("swim") +data class GenericLiquidController(val speed: Float, val acceleration: Float) : RideController { + + companion object { + val KEY: Identifier = cobblemonResource("swim/generic") + } + + override val key: Identifier = KEY override val poseProvider: PoseProvider = PoseProvider(PoseType.FLOAT) .with(PoseOption(PoseType.SWIM) { it.isSwimming && it.dataTracker.get(PokemonEntity.MOVING) }) override val condition: (PokemonEntity) -> Boolean get() = TODO("Not yet implemented") - override fun speed(entity: PokemonEntity, driver: PlayerEntity, context: RidingContext): Float { - val max: Float = context.propertyOrDefault(RideControllerPropertyKeys.SPEED, 0.0F) - val acceleration = this.acceleration(max, context) - - return min(max(context.speed + acceleration, 0.0F), 1.0F) + override fun speed(entity: PokemonEntity, driver: PlayerEntity): Float { + return min(max(this.speed + this.acceleration(), 0.0F), 1.0F) } - private fun acceleration(speed: Float, context: RidingContext): Float { - val acceleration = context.propertyOrDefault(RideControllerPropertyKeys.ACCELERATION, 0.0F) - return (1 / ((300 * speed) + (18.5F - (acceleration * 5.3F)))) * (0.9F * ((acceleration + 1) / 2)) + private fun acceleration(): Float { + return (1 / ((300 * this.speed) + (18.5F - (this.acceleration * 5.3F)))) * (0.9F * ((this.acceleration + 1) / 2)) } override fun rotation(driver: LivingEntity): Vec2f { @@ -63,35 +58,23 @@ object GenericLiquidController : RideController { return Vec3d(f.toDouble(), 0.0, g.toDouble()) } -} - -data class GenericLiquidControllerProperties( - val speed: Float, - val acceleration: Float -) : RideControllerProperties { - - override val identifier: Identifier = GenericLiquidController.key - override fun encode(buffer: PacketByteBuf) { + super.encode(buffer) buffer.writeFloat(this.speed) buffer.writeFloat(this.acceleration) } - override fun apply(context: RidingContextBuilder) { - context.property(RideControllerPropertyKeys.SPEED, this.speed) - context.property(RideControllerPropertyKeys.ACCELERATION, this.acceleration) - } } -object GenericLiquidControllerAdapter : Deserializer { +object GenericLiquidControllerAdapter : RideController.Deserializer { - override fun deserialize(json: JsonElement): GenericLiquidControllerProperties { + override fun deserialize(json: JsonElement): RideController { val obj = json.asJsonObject - return GenericLiquidControllerProperties(obj.get("speed").asFloat, obj.get("acceleration").asFloat) + return GenericLiquidController(obj.get("speed").asFloat, obj.get("acceleration").asFloat) } - override fun decode(buffer: PacketByteBuf): GenericLiquidControllerProperties { - return GenericLiquidControllerProperties(buffer.readFloat(), buffer.readFloat()) + override fun decode(buffer: PacketByteBuf): RideController { + return GenericLiquidController(buffer.readFloat(), buffer.readFloat()) } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/SwimDashController.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/SwimDashController.kt index bd07ba9880..b0d996b9df 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/SwimDashController.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/riding/controllers/SwimDashController.kt @@ -8,16 +8,14 @@ package com.cobblemon.mod.common.pokemon.riding.controllers -import com.cobblemon.mod.common.api.riding.context.RidingContext -import com.cobblemon.mod.common.api.riding.context.RidingContextBuilder import com.cobblemon.mod.common.api.riding.controller.RideController import com.cobblemon.mod.common.api.riding.controller.posing.PoseOption import com.cobblemon.mod.common.api.riding.controller.posing.PoseProvider -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerProperties import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerPropertyKey import com.cobblemon.mod.common.entity.PoseType import com.cobblemon.mod.common.entity.pokemon.PokemonEntity import com.cobblemon.mod.common.util.cobblemonResource +import com.google.gson.JsonElement import net.minecraft.entity.LivingEntity import net.minecraft.entity.player.PlayerEntity import net.minecraft.network.PacketByteBuf @@ -25,7 +23,14 @@ import net.minecraft.util.Identifier import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d -data class SwimDashController(val properties: SwimDashProperties) : RideController { +data class SwimDashController(val dashSpeed: Float) : RideController { + + companion object { + val KEY: Identifier = cobblemonResource("swim/dash") + const val DASH_TICKS: Int = 60 + + val DASH_SPEED: RideControllerPropertyKey = RideControllerPropertyKey(this.KEY) + } override val key: Identifier = KEY override val poseProvider: PoseProvider = PoseProvider(PoseType.FLOAT) @@ -36,12 +41,7 @@ data class SwimDashController(val properties: SwimDashProperties) : RideControll private var dashing = false private var ticks = 0 - companion object { - val KEY: Identifier = cobblemonResource("swim/dash") - const val DASH_TICKS: Int = 60 - } - - override fun speed(entity: PokemonEntity, driver: PlayerEntity, context: RidingContext): Float { + override fun speed(entity: PokemonEntity, driver: PlayerEntity): Float { if(this.dashing) { if(this.ticks++ >= DASH_TICKS) { this.dashing = false @@ -51,7 +51,7 @@ data class SwimDashController(val properties: SwimDashProperties) : RideControll } this.dashing = true - return context.propertyOrDefault(SwimDashProperties.DASH_SPEED, 0.1F) + return this.dashSpeed } override fun rotation(driver: LivingEntity): Vec2f { @@ -67,23 +67,22 @@ data class SwimDashController(val properties: SwimDashProperties) : RideControll return Vec3d(f.toDouble(), 0.0, g.toDouble()) } -} - -data class SwimDashProperties( - val dashSpeed: Float, -) : RideControllerProperties { - - override val identifier: Identifier = SwimDashController.KEY - - companion object { - val DASH_SPEED: RideControllerPropertyKey = RideControllerPropertyKey(SwimDashController.KEY) - } - - override fun apply(context: RidingContextBuilder) { - context.property(DASH_SPEED, this.dashSpeed) - } override fun encode(buffer: PacketByteBuf) { + super.encode(buffer) buffer.writeFloat(this.dashSpeed) } -} \ No newline at end of file +} + +object SwimDashControllerDeserializer : RideController.Deserializer { + + override fun deserialize(json: JsonElement): RideController { + val obj = json.asJsonObject + return SwimDashController(obj.get("dashSpeed").asFloat) + } + + override fun decode(buffer: PacketByteBuf): RideController { + return SwimDashController(buffer.readFloat()) + } + +} diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/util/adapters/riding/RidingPropertiesAdapter.kt b/common/src/main/kotlin/com/cobblemon/mod/common/util/adapters/riding/RidingPropertiesAdapter.kt index 381d79877f..5bfa035993 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/util/adapters/riding/RidingPropertiesAdapter.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/util/adapters/riding/RidingPropertiesAdapter.kt @@ -9,15 +9,15 @@ package com.cobblemon.mod.common.util.adapters.riding import com.cobblemon.mod.common.api.riding.RidingProperties -import com.cobblemon.mod.common.api.riding.capability.RidingCapability -import com.cobblemon.mod.common.api.riding.controller.properties.RideControllerPropertyDeserializer +import com.cobblemon.mod.common.api.riding.controller.RideControllerDeserializer import com.cobblemon.mod.common.api.riding.seats.properties.SeatProperties import com.cobblemon.mod.common.pokemon.riding.CobblemonRidingProperties import com.cobblemon.mod.common.pokemon.riding.RidingModule -import com.cobblemon.mod.common.util.cobblemonResource +import com.cobblemon.mod.common.util.asIdentifier import com.google.gson.JsonDeserializationContext import com.google.gson.JsonDeserializer import com.google.gson.JsonElement +import com.google.gson.JsonObject import java.lang.reflect.Type object RidingPropertiesAdapter : JsonDeserializer { @@ -29,21 +29,18 @@ object RidingPropertiesAdapter : JsonDeserializer { override fun deserialize(element: JsonElement, type: Type, context: JsonDeserializationContext): RidingProperties { val root = element.asJsonObject val seats = root.getAsJsonArray("seats") - val capabilities = root.getAsJsonObject("capabilities") - .asMap() + val controllers = root.getAsJsonArray("controllers") .map { - val key = cobblemonResource(it.key) - val data: JsonElement = it.value + val controller = it as JsonObject + val key = controller.get("key").asIdentifier - val properties = RideControllerPropertyDeserializer.deserialize(key, data) - RidingCapability.create(key, properties) + RideControllerDeserializer.deserialize(key, controller) } - return CobblemonRidingProperties( seats.map { context.deserialize(it, SeatProperties::class.java) }, emptyList(), - capabilities + controllers ) } diff --git a/common/src/main/resources/data/cobblemon/species/generation1/lapras.json b/common/src/main/resources/data/cobblemon/species/generation1/lapras.json index 4a14912dd7..65d936974c 100644 --- a/common/src/main/resources/data/cobblemon/species/generation1/lapras.json +++ b/common/src/main/resources/data/cobblemon/species/generation1/lapras.json @@ -329,24 +329,6 @@ "aspects": [], "cannotDynamax": false, "riding": { - "capabilities": { - "land": { - "controller": "cobblemon:land_generic", - "properties": { - "speed": 0.1, - "maxBlockSpeed": 0.15, - "acceleration": 0.2 - } - }, - "liquids": { - "controller": "cobblemon:swim", - "properties": { - "speed": 0.4, - "maxBlockSpeed": 0.35, - "acceleration": 0.8 - } - } - }, "controllers": [ { "key": "cobblemon:land/generic", diff --git a/common/src/main/resources/data/cobblemon/species/generation4/bidoof.json b/common/src/main/resources/data/cobblemon/species/generation4/bidoof.json index 19d0b2536a..54423c6356 100644 --- a/common/src/main/resources/data/cobblemon/species/generation4/bidoof.json +++ b/common/src/main/resources/data/cobblemon/species/generation4/bidoof.json @@ -198,24 +198,19 @@ "aspects": [], "cannotDynamax": false, "riding": { - "capabilities": { - "land": { - "controller": "cobblemon:land_generic", - "properties": { - "speed": 0.4, - "maxBlockSpeed": 0.35, - "acceleration": 0.2 - } + "controllers": [ + { + "key": "cobblemon:land/generic", + "speed": 0.1, + "acceleration": 0.2 }, - "liquids": { - "controller": "cobblemon:swim", - "properties": { - "speed": 0.2, - "maxBlockSpeed": 0.4, - "acceleration": 0.2 - } + { + "key": "cobblemon:swim/generic", + "speed": 0.1, + "acceleration": 0.2, + "canDive": false } - }, + ], "seats": [ { "driver": true,