mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-23 07:36:25 -04:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f2ff91d16 | ||
|
|
432d9ca436 | ||
|
|
27a5d12ed6 | ||
|
|
bf6fc119c4 | ||
|
|
39f383f415 | ||
|
|
2fd65369c3 | ||
|
|
0a2b6f7bf4 |
+26
-7
@@ -21,6 +21,7 @@ import com.cobblemon.mod.common.api.riding.sound.RideSoundSettingsList
|
||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.entity.PoseType
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.util.*
|
||||
import com.cobblemon.mod.common.util.math.geometry.toRadians
|
||||
import net.minecraft.client.Minecraft
|
||||
@@ -74,6 +75,21 @@ class BirdBehaviour : RidingBehaviour<BirdSettings, BirdState> {
|
||||
) {
|
||||
if(vehicle.level().isClientSide) {
|
||||
tickStamina(settings, state, vehicle, driver)
|
||||
checkUpsideDown(state, vehicle, driver)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkUpsideDown(
|
||||
state: BirdState,
|
||||
vehicle: PokemonEntity,
|
||||
driver: Player,
|
||||
) {
|
||||
val controller = (driver as OrientationControllable).orientationController
|
||||
if (cos(controller.roll.toRadians()) < 0.0) {
|
||||
val upsideDownRate = 1.0 / (2.0 * 20.0) // 2 seconds to max out upsideDown force
|
||||
state.currUpsideDownForce.set( min(1.0, state.currUpsideDownForce.get() + upsideDownRate * abs(cos(controller.roll.toRadians()))))
|
||||
} else { // Its right side up so reset it
|
||||
state.currUpsideDownForce.set(0.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +108,8 @@ class BirdBehaviour : RidingBehaviour<BirdSettings, BirdState> {
|
||||
val stamDrainRate = (1.0f / totalStam).toFloat()
|
||||
|
||||
val newStam = if (driver.zza > 0.0) max(0.0f,stam - stamDrainRate)
|
||||
else min(1.0f,stam + stamDrainRate)
|
||||
else if (!state.gliding.get()) max(0.0f,stam - stamDrainRate * 0.5f) // if hovering half the stam drain
|
||||
else min(1.0f,stam + stamDrainRate * 0.2f)
|
||||
|
||||
state.stamina.set(newStam)
|
||||
}
|
||||
@@ -113,8 +130,6 @@ class BirdBehaviour : RidingBehaviour<BirdSettings, BirdState> {
|
||||
driver: Player,
|
||||
input: Vec3
|
||||
): Vec3 {
|
||||
var yVel = 0.0
|
||||
var leftForce = 0.0
|
||||
var upForce = 0.0
|
||||
var forwardForce = 0.0
|
||||
|
||||
@@ -133,7 +148,11 @@ class BirdBehaviour : RidingBehaviour<BirdSettings, BirdState> {
|
||||
forwardForce += sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVelocity.get().y
|
||||
}
|
||||
|
||||
val velocity = Vec3(state.rideVelocity.get().x , upForce, forwardForce)
|
||||
// The downward force used to encourage players to stop flying upside down.
|
||||
val extraDownwardForce = if(state.stamina.get() == 0.0f) -0.3
|
||||
else state.currUpsideDownForce.get().pow(2) * -0.3 // 6 blocks a second downward
|
||||
|
||||
val velocity = Vec3(state.rideVelocity.get().x , upForce + extraDownwardForce, forwardForce)
|
||||
return velocity
|
||||
}
|
||||
|
||||
@@ -228,7 +247,7 @@ class BirdBehaviour : RidingBehaviour<BirdSettings, BirdState> {
|
||||
|
||||
//Check if the ride should be gliding
|
||||
if (driver.isLocalPlayer) {
|
||||
if (activeInput && state.stamina.get() > 0.0) {
|
||||
if ((activeInput && state.stamina.get() > 0.0) || state.rideVelocity.get().z < 0.2) {
|
||||
state.gliding.set(false)
|
||||
} else {
|
||||
state.gliding.set(true)
|
||||
@@ -237,7 +256,7 @@ class BirdBehaviour : RidingBehaviour<BirdSettings, BirdState> {
|
||||
|
||||
//air resistance
|
||||
if( abs(newVelocity.z) > 0) {
|
||||
newVelocity = newVelocity.subtract(0.0, 0.0, min(0.0015 * newVelocity.z.sign, newVelocity.z))
|
||||
newVelocity = newVelocity.subtract(0.0, 0.0, min(0.002 * newVelocity.z.sign, newVelocity.z))
|
||||
}
|
||||
state.rideVelocity.set(newVelocity)
|
||||
}
|
||||
@@ -663,10 +682,10 @@ class BirdState : RidingBehaviourState() {
|
||||
var currRollCorrectionForce = ridingState(0.0, Side.CLIENT)
|
||||
var currPitchCorrectionForce = ridingState(0.0, Side.CLIENT)
|
||||
var noInputTime = ridingState(0.0, Side.CLIENT)
|
||||
var currUpsideDownForce = ridingState(0.0, Side.CLIENT)
|
||||
|
||||
override fun encode(buffer: FriendlyByteBuf) {
|
||||
super.encode(buffer)
|
||||
buffer.writeFloat(stamina.get())
|
||||
buffer.writeBoolean(gliding.get())
|
||||
}
|
||||
|
||||
|
||||
+37
-29
@@ -97,7 +97,31 @@ class HoverBehaviour : RidingBehaviour<HoverSettings, HoverState> {
|
||||
driver: Player,
|
||||
input: Vec3
|
||||
) {
|
||||
tickStamina(settings, state, vehicle)
|
||||
if(vehicle.level().isClientSide) {
|
||||
tickStamina(settings, state, vehicle)
|
||||
checkTooHigh(settings, state, vehicle)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkTooHigh(
|
||||
settings: HoverSettings,
|
||||
state: HoverState,
|
||||
vehicle: PokemonEntity,
|
||||
) {
|
||||
val heightLimit = vehicle.runtime.resolveDouble(settings.jumpExpr)
|
||||
val pos = vehicle.position()
|
||||
val level = Minecraft.getInstance().player?.level() ?: return
|
||||
val hit = level.clip(
|
||||
ClipContext(
|
||||
pos,
|
||||
pos.subtract(0.0, heightLimit, 0.0),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
vehicle
|
||||
)
|
||||
)
|
||||
|
||||
state.tooHigh.set(hit.type == HitResult.Type.MISS)
|
||||
}
|
||||
|
||||
fun tickStamina(
|
||||
@@ -108,7 +132,7 @@ class HoverBehaviour : RidingBehaviour<HoverSettings, HoverState> {
|
||||
val stam = state.stamina.get()
|
||||
val stamDrainRate = (1.0f / vehicle.runtime.resolveDouble(settings.staminaExpr)).toFloat() / 20.0f
|
||||
|
||||
val newStam = min(1.0f,stam + stamDrainRate)
|
||||
val newStam = if (state.tooHigh.get()) max(0.0f, stam - stamDrainRate) else min(1.0f,stam + stamDrainRate)
|
||||
|
||||
state.stamina.set(newStam)
|
||||
}
|
||||
@@ -206,6 +230,7 @@ class HoverBehaviour : RidingBehaviour<HoverSettings, HoverState> {
|
||||
|
||||
// Vertical movement based on driver input.
|
||||
val vertInput = when {
|
||||
state.stamina.get() == 0.0f -> -1.0
|
||||
driver.jumping -> 1.0
|
||||
driver.isShiftKeyDown -> -1.0
|
||||
else -> 0.0
|
||||
@@ -219,28 +244,6 @@ class HoverBehaviour : RidingBehaviour<HoverSettings, HoverState> {
|
||||
driver.zza.sign.toDouble()
|
||||
).normalize()
|
||||
|
||||
/******************************************************
|
||||
* Boosting Logic
|
||||
*****************************************************/
|
||||
if (driver.level().isClientSide) {
|
||||
if(Minecraft.getInstance().options.keySprint.isDown() && state.stamina.get() == 1.0f && !state.isBoosting.get()) {
|
||||
state.isBoosting.set(true)
|
||||
val localBoostVel = if (inputVel.horizontalDistance() == 0.0) Vec3(0.0, 0.0, 1.0) else Vec3(inputVel.x, 0.0, inputVel.z)
|
||||
state.boostVec.set(localBoostVel)
|
||||
state.boostTicks.set(0)
|
||||
state.stamina.set(0.0f)
|
||||
}
|
||||
}
|
||||
val maxBoostTicks = 20
|
||||
val boostPower = (topSpeed * 20) * 0.1 * vehicle.runtime.resolveDouble(settings.jumpExpr)
|
||||
if (state.isBoosting.get() && state.boostTicks.get() < maxBoostTicks) {
|
||||
newVelocity = newVelocity.add(state.boostVec.get().scale(boostPower / maxBoostTicks))
|
||||
state.boostTicks.set(state.boostTicks.get() + 1)
|
||||
} else if (state.isBoosting.get()) {
|
||||
state.isBoosting.set(false)
|
||||
}
|
||||
|
||||
|
||||
// Air Friction/Resistance
|
||||
// When the dot between friction and input is -1 we want to apply none of it.
|
||||
// In short we want to avoid applying friction that opposes our input force.
|
||||
@@ -431,20 +434,20 @@ class HoverSettings : RidingBehaviourSettings {
|
||||
private set
|
||||
|
||||
// Speed in block per second
|
||||
var speedExpr: Expression = "q.get_ride_stats('SPEED', 'AIR', 13.0, 6.0)".asExpression()
|
||||
var speedExpr: Expression = "q.get_ride_stats('SPEED', 'AIR', 9.0, 3.5)".asExpression()
|
||||
private set
|
||||
|
||||
// Acceleration in number of seconds to top speed
|
||||
var accelerationExpr: Expression =
|
||||
"q.get_ride_stats('ACCELERATION', 'AIR', 2.0, 5.0)".asExpression()
|
||||
"q.get_ride_stats('ACCELERATION', 'AIR', 1.0, 3.0)".asExpression()
|
||||
private set
|
||||
|
||||
// Amount of seconds between boosts
|
||||
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 1, 4)".asExpression()
|
||||
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 30.0, 10.0)".asExpression()
|
||||
private set
|
||||
|
||||
// Power of boost as a fraction of top speed
|
||||
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'AIR', 1.2, 0.2)".asExpression()
|
||||
// Blocks before stamina drain
|
||||
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'AIR', 30.0, 10.0)".asExpression()
|
||||
private set
|
||||
|
||||
// Turn rate in degrees per second when stationary
|
||||
@@ -481,17 +484,20 @@ class HoverState : RidingBehaviourState() {
|
||||
var isBoosting = ridingState(false, Side.BOTH)
|
||||
var boostVec = ridingState(Vec3.ZERO, Side.CLIENT)
|
||||
var boostTicks = ridingState(0, Side.CLIENT)
|
||||
var tooHigh = ridingState(false, Side.CLIENT)
|
||||
|
||||
override fun encode(buffer: FriendlyByteBuf) {
|
||||
super.encode(buffer)
|
||||
buffer.writeDouble(speed.get())
|
||||
buffer.writeBoolean(isBoosting.get())
|
||||
buffer.writeBoolean(tooHigh.get())
|
||||
}
|
||||
|
||||
override fun decode(buffer: FriendlyByteBuf) {
|
||||
super.decode(buffer)
|
||||
speed.set(buffer.readDouble(), forced = true)
|
||||
isBoosting.set(buffer.readBoolean(), forced = true)
|
||||
tooHigh.set(buffer.readBoolean(), forced = true)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
@@ -500,6 +506,7 @@ class HoverState : RidingBehaviourState() {
|
||||
isBoosting.set(false, forced = true)
|
||||
boostVec.set(Vec3.ZERO, forced = true)
|
||||
boostTicks.set(0, forced = true)
|
||||
tooHigh.set(false, forced = true)
|
||||
}
|
||||
|
||||
override fun copy() = HoverState().also {
|
||||
@@ -508,6 +515,7 @@ class HoverState : RidingBehaviourState() {
|
||||
it.isBoosting.set(this.isBoosting.get(), forced = true)
|
||||
it.boostVec.set(this.boostVec.get(), forced = true)
|
||||
it.boostTicks.set(this.boostTicks.get(), forced = true)
|
||||
it.tooHigh.set(this.tooHigh.get(), forced = true)
|
||||
}
|
||||
|
||||
override fun shouldSync(previous: RidingBehaviourState): Boolean {
|
||||
|
||||
+25
-9
@@ -114,10 +114,10 @@ class JetBehaviour : RidingBehaviour<JetSettings, JetState> {
|
||||
val stamDrainRate = (1.0f / vehicle.runtime.resolveDouble(settings.staminaExpr)).toFloat() / 20.0f
|
||||
|
||||
if (state.boosting.get()) {
|
||||
newStam = max(0.0f,stam - stamDrainRate)
|
||||
newStam = max(0.0f,stam - stamDrainRate * 1.5f)
|
||||
|
||||
} else {
|
||||
newStam = min(1.0f,stam + stamDrainRate * 0.25f)
|
||||
newStam = max(0.0f,stam - stamDrainRate)
|
||||
}
|
||||
|
||||
state.stamina.set(newStam)
|
||||
@@ -149,11 +149,15 @@ class JetBehaviour : RidingBehaviour<JetSettings, JetState> {
|
||||
|
||||
//Translate ride space velocity to world space velocity.
|
||||
if (controller != null) {
|
||||
upForce = -1.0 * sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVelocity.get().z
|
||||
upForce = if(state.stamina.get() != 0.0f) -1.0 * sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVelocity.get().z
|
||||
else min(0.0, -1.0 * sin(Math.toRadians(controller.pitch.toDouble())) * state.rideVelocity.get().z)
|
||||
forwardForce = cos(Math.toRadians(controller.pitch.toDouble())) * state.rideVelocity.get().z
|
||||
}
|
||||
|
||||
val velocity = Vec3(0.0, upForce, forwardForce)
|
||||
// The downward force used to encourage players to stop flying upside down.
|
||||
val extraDownwardForce = if(state.stamina.get() == 0.0f) -0.3 else 0.0 // 6 blocks a second downward
|
||||
|
||||
val velocity = Vec3(0.0, upForce + extraDownwardForce, forwardForce)
|
||||
|
||||
return velocity
|
||||
}
|
||||
@@ -177,7 +181,17 @@ class JetBehaviour : RidingBehaviour<JetSettings, JetState> {
|
||||
val boostAccel = accel * boostMult
|
||||
|
||||
//speed up and slow down based on input
|
||||
if (state.boosting.get() && speed < boostTopSpeed) {
|
||||
if (state.stamina.get() == 0.0f) {
|
||||
// Decelerate currently always a constant half of max acceleration.
|
||||
state.rideVelocity.set(
|
||||
Vec3(
|
||||
state.rideVelocity.get().x,
|
||||
state.rideVelocity.get().y,
|
||||
max(state.rideVelocity.get().z - ((accel) / 2), minSpeed * 0.5)
|
||||
)
|
||||
)
|
||||
}
|
||||
else if (state.boosting.get() && speed < boostTopSpeed) {
|
||||
state.rideVelocity.set(
|
||||
Vec3(
|
||||
state.rideVelocity.get().x,
|
||||
@@ -305,7 +319,8 @@ class JetBehaviour : RidingBehaviour<JetSettings, JetState> {
|
||||
state.currMouseYForce.set((state.currMouseYForce.get() + (0.0015 * mouseY)).coerceIn(-1.0, 1.0))
|
||||
|
||||
//Get handling in degrees per second
|
||||
var handling = vehicle.runtime.resolveDouble(settings.handlingExpr)
|
||||
val handlingDebuff = if(state.stamina.get() == 0.0f) 0.5 else 1.0
|
||||
var handling = vehicle.runtime.resolveDouble(settings.handlingExpr) * handlingDebuff
|
||||
//convert it to delta time
|
||||
handling *= (cappedDeltaTime)
|
||||
|
||||
@@ -358,7 +373,8 @@ class JetBehaviour : RidingBehaviour<JetSettings, JetState> {
|
||||
state.currMouseYForce.set((state.currMouseYForce.get() + (0.0015 * mouseY)).coerceIn(-1.0, 1.0))
|
||||
|
||||
//Get handling in degrees per second
|
||||
var handling = vehicle.runtime.resolveDouble(settings.handlingExpr)
|
||||
val handlingDebuff = if(state.stamina.get() == 0.0f) 0.5 else 1.0
|
||||
var handling = vehicle.runtime.resolveDouble(settings.handlingExpr) * handlingDebuff
|
||||
|
||||
//convert it to delta time
|
||||
handling *= (cappedDeltaTime)
|
||||
@@ -534,8 +550,8 @@ class JetSettings : RidingBehaviourSettings {
|
||||
var accelerationExpr: Expression =
|
||||
"q.get_ride_stats('ACCELERATION', 'AIR', 5.0, 2.5)".asExpression()
|
||||
private set
|
||||
// Time in seconds to drain full bar of stamina when boosting
|
||||
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 8.0, 4.0)".asExpression()
|
||||
// Time in seconds to drain full bar of stamina flying
|
||||
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 90.0, 30.0)".asExpression()
|
||||
private set
|
||||
|
||||
var rideSounds: RideSoundSettingsList = RideSoundSettingsList()
|
||||
|
||||
+8
-10
@@ -86,7 +86,7 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
// Use this as a "tick" function and check to see if the driver is "boosting"
|
||||
if(vehicle.level().isClientSide) {
|
||||
handleBoosting(settings, state, vehicle, driver)
|
||||
tickStamina(settings, state, vehicle)
|
||||
tickStamina(settings, state, vehicle, driver)
|
||||
}
|
||||
|
||||
return state.rideVelocity.get().length().toFloat()
|
||||
@@ -101,7 +101,6 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
//If the forward key is not held then it cannot be boosting
|
||||
if(Minecraft.getInstance().options.keyUp.isDown() && state.stamina.get() != 0.0f) {
|
||||
val boostKeyPressed = Minecraft.getInstance().options.keySprint.isDown()
|
||||
if (state.stamina.get() >= 0.25f) {
|
||||
//If on the previous tick the boost key was held then don't change if the ride is boosting
|
||||
if(state.boostIsToggleable.get() && boostKeyPressed) {
|
||||
//flip the boosting state if boost key is pressed
|
||||
@@ -109,7 +108,6 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
}
|
||||
//If the boost key is not held then next tick boosting is toggleable
|
||||
state.boostIsToggleable.set(!boostKeyPressed)
|
||||
}
|
||||
} else {
|
||||
//Turn off boost and reset boost params
|
||||
state.boostIsToggleable.set(true)
|
||||
@@ -121,7 +119,8 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
fun tickStamina(
|
||||
settings: RocketSettings,
|
||||
state: RocketState,
|
||||
vehicle: PokemonEntity
|
||||
vehicle: PokemonEntity,
|
||||
driver: Player
|
||||
) {
|
||||
val stam = state.stamina.get()
|
||||
|
||||
@@ -131,8 +130,7 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
val boostTime = vehicle.runtime.resolveDouble(settings.staminaExpr) * 20.0f
|
||||
val stamDrainRate = (1.0f / boostTime).toFloat()
|
||||
|
||||
val newStam = if (state.boosting.get()) max(0.0f,stam - stamDrainRate)
|
||||
else min(1.0f,stam + stamDrainRate)
|
||||
val newStam = if(state.boosting.get() || driver.jumping) max(0.0f,stam - stamDrainRate) else stam
|
||||
|
||||
state.stamina.set(newStam)
|
||||
}
|
||||
@@ -266,7 +264,7 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
|
||||
if(state.canSpeedBurst.get()) {
|
||||
burst = 0.5f
|
||||
state.stamina.set(max(0.0f,state.stamina.get() - 0.1f))
|
||||
state.stamina.set(max(0.0f,state.stamina.get() - 0.05f))
|
||||
state.canSpeedBurst.set(false)
|
||||
}
|
||||
|
||||
@@ -301,7 +299,7 @@ class RocketBehaviour : RidingBehaviour<RocketSettings, RocketState> {
|
||||
} else {
|
||||
if (driver.jumping && !(vehicle.deltaMovement.y > maxVertSpeed && (newVelocity.y.sign.toFloat() > 0.0))) {
|
||||
// More force if traveling downwards to allow for quicker fall stops
|
||||
vertInput = if (newVelocity.y < 0) jump * 3 else jump
|
||||
vertInput = (if (state.stamina.get() == 0.0f) -1.0f else if(newVelocity.y < 0) jump.toFloat() * 3.0f else jump.toFloat()).toDouble()
|
||||
// Reset falldistance if upward motion is detected
|
||||
vehicle.resetFallDistance()
|
||||
newVelocity = Vec3(
|
||||
@@ -509,8 +507,8 @@ class RocketSettings : RidingBehaviourSettings {
|
||||
"q.get_ride_stats('ACCELERATION', 'AIR', (1.0 / (20.0 * 1.5)), (1.0 / (20.0 * 3.0))) * 0.5".asExpression()
|
||||
private set
|
||||
|
||||
// Boost time in seconds
|
||||
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 7.5, 2.5)".asExpression()
|
||||
// air time in seconds
|
||||
var staminaExpr: Expression = "q.get_ride_stats('STAMINA', 'AIR', 20.0, 10.0)".asExpression()
|
||||
private set
|
||||
|
||||
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'AIR', 2.0, 1.0)".asExpression()
|
||||
|
||||
+1
-1
@@ -520,7 +520,7 @@ class HorseSettings : RidingBehaviourSettings {
|
||||
private set
|
||||
|
||||
//Between a one block jump and a six block jump
|
||||
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'LAND', 1.2, 0.45)".asExpression()
|
||||
var jumpExpr: Expression = "q.get_ride_stats('JUMP', 'LAND', 1.0, 0.38)".asExpression()
|
||||
private set
|
||||
|
||||
var handlingExpr: Expression = "q.get_ride_stats('SKILL', 'LAND', 180.0, 40.0)".asExpression()
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
data class RideStatOverrideData(
|
||||
var min: Double,
|
||||
var max: Double,
|
||||
var tier: RidingTier,
|
||||
var boost: Double) {
|
||||
|
||||
fun getTierBoundBoost(): Double {
|
||||
return (((tier.tierRange.last - tier.tierRange.first) / 100) * boost) + tier.tierRange.first
|
||||
}
|
||||
|
||||
fun getCurrStatValue(): Double {
|
||||
return (((max - min) / 100) * getTierBoundBoost()) + min
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import kotlin.math.sin
|
||||
* @since April 7th, 2025
|
||||
*/
|
||||
|
||||
|
||||
class RidingAnimationData(val ride: PokemonEntity)
|
||||
{
|
||||
var prevOrientation: Matrix3f = Matrix3f()
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
/**
|
||||
* Enum to hold the ranges for each riding stat tier
|
||||
*
|
||||
* @author Jackson
|
||||
* @since September 10th, 2025
|
||||
*/
|
||||
enum class RidingTier(val tierRange: IntRange) {
|
||||
S(80..100),
|
||||
A(55..85),
|
||||
B(30..65),
|
||||
C(10..40),
|
||||
D(0..10);
|
||||
}
|
||||
+41
-5
@@ -11,6 +11,8 @@ package com.cobblemon.mod.common.client.gui.debug.riding
|
||||
import com.cobblemon.mod.common.CobblemonNetwork
|
||||
import com.cobblemon.mod.common.api.riding.RidingStyle
|
||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.api.riding.util.RideStatOverrideData
|
||||
import com.cobblemon.mod.common.api.riding.util.RidingTier
|
||||
import com.cobblemon.mod.common.api.text.text
|
||||
import com.cobblemon.mod.common.client.gui.CobblemonRenderable
|
||||
import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
@@ -33,6 +35,8 @@ class RidingStatsDebugGUI(val vehicle: PokemonEntity) : Screen(lang("ui.debug.ri
|
||||
|
||||
var ridingStyle: RidingStyle = RidingStyle.LAND
|
||||
|
||||
val selectedTiers = mutableMapOf<RidingStat, RidingTier>()
|
||||
|
||||
val changeRidingStyle: Button
|
||||
|
||||
val speedSlider: SettingsSlider
|
||||
@@ -88,6 +92,12 @@ class RidingStatsDebugGUI(val vehicle: PokemonEntity) : Screen(lang("ui.debug.ri
|
||||
minStaminaInput = addRenderableWidget(RidingStatInputWidget(getScaledWidth() - 210, 180, "".text()))
|
||||
maxStaminaInput = addRenderableWidget(RidingStatInputWidget(getScaledWidth() - 100, 180, "".text()))
|
||||
|
||||
addTierSelectorRow(RidingStat.SPEED, 60)
|
||||
addTierSelectorRow(RidingStat.ACCELERATION, 90)
|
||||
addTierSelectorRow(RidingStat.SKILL, 120)
|
||||
addTierSelectorRow(RidingStat.JUMP, 150)
|
||||
addTierSelectorRow(RidingStat.STAMINA, 180)
|
||||
|
||||
addRenderableWidget(
|
||||
Button.builder("Save".text()) { button ->
|
||||
saveStatRanges()
|
||||
@@ -113,11 +123,18 @@ class RidingStatsDebugGUI(val vehicle: PokemonEntity) : Screen(lang("ui.debug.ri
|
||||
val jump = jumpSlider.currentValue
|
||||
val stamina = staminaSlider.currentValue
|
||||
|
||||
vehicle.overrideRideStat(ridingStyle, RidingStat.SPEED, speed.toDouble())
|
||||
vehicle.overrideRideStat(ridingStyle, RidingStat.ACCELERATION, acceleration.toDouble())
|
||||
vehicle.overrideRideStat(ridingStyle, RidingStat.SKILL, skill.toDouble())
|
||||
vehicle.overrideRideStat(ridingStyle, RidingStat.JUMP, jump.toDouble())
|
||||
vehicle.overrideRideStat(ridingStyle, RidingStat.STAMINA, stamina.toDouble())
|
||||
for (stat in RidingStat.entries) {
|
||||
// For each stat, try to get the selected tier from the map
|
||||
selectedTiers[stat]?.let { selectedTier ->
|
||||
val overrideData = RideStatOverrideData(
|
||||
min = 0.0,
|
||||
max = 100.0,
|
||||
tier = selectedTier,
|
||||
boost = 0.0
|
||||
)
|
||||
vehicle.overrideRideStat(ridingStyle, stat, overrideData)
|
||||
}
|
||||
}
|
||||
|
||||
CobblemonNetwork.sendToServer(
|
||||
ServerboundUpdateRidingStatsPacket(
|
||||
@@ -203,6 +220,23 @@ class RidingStatsDebugGUI(val vehicle: PokemonEntity) : Screen(lang("ui.debug.ri
|
||||
|
||||
fun getScaledWidth() = Minecraft.getInstance().window.guiScaledWidth
|
||||
|
||||
private fun addTierSelectorRow(stat: RidingStat, y: Int) {
|
||||
val buttonWidth = 38
|
||||
val buttonGap = 2
|
||||
var currentX = 85
|
||||
|
||||
// Iterate directly over all the enum constants. No more hardcoded maps!
|
||||
for (tier in RidingTier.entries) {
|
||||
addRenderableWidget(
|
||||
Button.builder(tier.name.text()) {
|
||||
// When clicked, store the selected tier
|
||||
selectedTiers[stat] = tier
|
||||
}.bounds(currentX, y, buttonWidth, 20).build()
|
||||
)
|
||||
currentX += buttonWidth + buttonGap
|
||||
}
|
||||
}
|
||||
|
||||
override fun render(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {
|
||||
guiGraphics.fill(0, 0, width, height, Color(0, 0, 0, 100).rgb)
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTick)
|
||||
@@ -301,3 +335,5 @@ class RidingStatInputWidget(x: Int, y: Int, val hint: Component) : EditBox(
|
||||
setHint(hint)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ import com.cobblemon.mod.common.api.riding.behaviour.RidingController
|
||||
import com.cobblemon.mod.common.api.riding.events.SelectDriverEvent
|
||||
import com.cobblemon.mod.common.api.riding.sound.RideSoundManager
|
||||
import com.cobblemon.mod.common.api.riding.stats.RidingStat
|
||||
import com.cobblemon.mod.common.api.riding.util.RideStatOverrideData
|
||||
import com.cobblemon.mod.common.api.riding.util.RidingAnimationData
|
||||
import com.cobblemon.mod.common.api.scheduling.Schedulable
|
||||
import com.cobblemon.mod.common.api.scheduling.SchedulingTracker
|
||||
@@ -307,7 +308,7 @@ open class PokemonEntity(
|
||||
val ridingAnimationData: RidingAnimationData = RidingAnimationData(this)
|
||||
var rideSoundManager: RideSoundManager = RideSoundManager(this)
|
||||
|
||||
private val rideStatOverrides = mutableMapOf<RidingStyle, MutableMap<RidingStat, Double>>()
|
||||
private val rideStatOverrides = mutableMapOf<RidingStyle, MutableMap<RidingStat, RideStatOverrideData>>()
|
||||
var ridingController: RidingController? = null
|
||||
private set
|
||||
|
||||
@@ -2064,25 +2065,25 @@ open class PokemonEntity(
|
||||
fun getRideStat(stat: RidingStat, style: RidingStyle, baseMin: Double, baseMax: Double): Double {
|
||||
//TODO: Change from static zero boost once aprijuice is implemented.
|
||||
if (rideStatOverrides[style] != null && rideStatOverrides[style]!![stat] != null) {
|
||||
return (((baseMax - baseMin) / 100) * rideStatOverrides[style]!![stat]!!) + baseMin
|
||||
return rideStatOverrides[style]!![stat]!!.getCurrStatValue()
|
||||
}
|
||||
val stat = this.rideProp.behaviours?.get(style)?.calculate(stat, 0) ?: return 0.0
|
||||
val statVal = (((baseMax - baseMin) / 100) * stat) + baseMin
|
||||
return statVal
|
||||
}
|
||||
|
||||
fun getRawRideStat(stat: RidingStat, style: RidingStyle): Double {
|
||||
fun getRawRideStat(stat: RidingStat, style: RidingStyle): RideStatOverrideData? {
|
||||
if (rideStatOverrides[style] != null && rideStatOverrides[style]!![stat] != null) {
|
||||
return rideStatOverrides[style]!![stat]!!
|
||||
}
|
||||
return this.rideProp.behaviours?.get(style)?.calculate(stat, 0)?.toDouble() ?: 0.0
|
||||
return null
|
||||
}
|
||||
|
||||
internal fun overrideRideStat(style: RidingStyle, stat: RidingStat, value: Double) {
|
||||
internal fun overrideRideStat(style: RidingStyle, stat: RidingStat, rideStatData: RideStatOverrideData) {
|
||||
if (rideStatOverrides[style] == null) {
|
||||
rideStatOverrides[style] = mutableMapOf()
|
||||
}
|
||||
rideStatOverrides[style]!![stat] = value
|
||||
rideStatOverrides[style]!![stat] = rideStatData
|
||||
}
|
||||
|
||||
override fun canAddPassenger(passenger: Entity): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user