@@ -4,15 +4,11 @@ import com.bedrockk.molang.runtime.MoParams
44import com.cobblemon.mod.common.api.molang.ObjectValue
55import com.cobblemon.mod.common.client.ClientMoLangFunctions
66import com.cobblemon.mod.common.client.render.models.blockbench.PosableModel
7- import com.cobblemon.mod.common.client.render.models.blockbench.PosableState
8- import com.cobblemon.mod.common.client.render.models.blockbench.PoseableEntityState
97import com.cobblemon.mod.common.client.render.models.blockbench.animation.ActiveAnimation
108import com.cobblemon.mod.common.client.render.models.blockbench.animation.PrimaryAnimation
11- import com.cobblemon.mod.common.client.render.models.blockbench.repository.RenderContext
129import com.cobblemon.mod.common.client.render.models.blockbench.wavefunction.WaveFunction
1310import com.cobblemon.mod.common.util.asResource
1411import com.cobblemon.mod.common.util.getBooleanOrNull
15- import generations.gg.generations.core.generationscore.common.client.render.CobblemonInstanceProvider
1612import generations.gg.generations.core.generationscore.common.client.render.rarecandy.CobblemonInstance
1713import generations.gg.generations.core.generationscore.common.client.render.rarecandy.ModelRegistry
1814import gg.generations.rarecandy.renderer.animation.Animation
@@ -22,18 +18,8 @@ import java.util.function.Function
2218import java.util.function.Supplier
2319
2420object RareCandyAnimationFactory {
25- data class ActiveRareCandyAnimation (private val animation : RareCandyAnimation ): ActiveAnimation {
26- private var startedSeconds = - 1F
27- override val isTransition: Boolean = false
28- override var enduresPrimaryAnimations: Boolean = false
2921
30- override val duration: Float
31- get() = animation.duration
32-
33-
34- }
35-
36- fun <T : Entity > stateful (loc : String , name : String , transforms : Boolean ): RareCandyAnimation <T > {
22+ fun <T : Entity > PosableModel.pkStateful (model : String , name : String ) {
3723 val location = loc.asResource().withPrefix(" bedrock/pokemon/models/" )
3824
3925 return RareCandyAnimation (Supplier <Animation ?> {
@@ -47,16 +33,13 @@ object RareCandyAnimationFactory {
4733
4834 fun stateless (model : PosableModel , loc : String , name : String ): ActiveAnimation {
4935 val location = loc.asResource().withPrefix(" bedrock/pokemon/models/" )
50- return RareCandyAnimation (
51- {
52- val objects = ModelRegistry [location]?.renderObject
53- if (objects != null && objects.isReady) {
54- (objects.objects[0 ] as AnimatedMeshObject ).animations[name]
55- }
56- null
57- },
58- { ModelRegistry [location]?.guiInstance },
59- )
36+ return RareCandyAnimation {
37+ val objects = ModelRegistry [location]?.renderObject
38+ if (objects != null && objects.isReady) {
39+ (objects.objects[0 ] as AnimatedMeshObject ).animations[name]
40+ }
41+ null
42+ }
6043 }
6144
6245 fun function (function : (PosableModel , MoParams ) -> Any ): Function <PosableModel , Function <MoParams , Any >> {
@@ -68,20 +51,21 @@ object RareCandyAnimationFactory {
6851
6952 var map = ClientMoLangFunctions .animationFunctions
7053
71- map[" pk_stateful" ] = function { model, params ->
72- val group = params.getString(0 )
73- val animation = params.getString(1 )
74- val anim = stateful<T >(group, animation, params.getBooleanOrNull(2 ) ? : false )
75- ObjectValue (anim)
76- }
77-
7854 map[" pk_primary" ] = function { model, params ->
7955 val group = params.getString(0 )
8056 val animation = params.getString(1 )
8157 val anim = stateful<T >(group, animation, params.getBooleanOrNull(2 ) ? : false )
8258
8359 val excludedLabels = mutableSetOf<String >()
84- val curve: WaveFunction = { 2F }
60+ var curve: WaveFunction = { t ->
61+ if (t < 0.1 ) {
62+ t * 10
63+ } else if (t < 0.9 ) {
64+ 1F
65+ } else {
66+ 1F
67+ }
68+ }
8569
8670 for (index in 2 until params.params.size) {
8771 val label = params.getString(index) ? : continue
@@ -91,70 +75,23 @@ object RareCandyAnimationFactory {
9175 ObjectValue (PrimaryAnimation (animation = anim, excludedLabels = excludedLabels, curve = curve))
9276 }
9377
94- map[" pk " ] = function { model, params ->
78+ map[" pk_stateful " ] = function { model, params ->
9579 val group = params.getString(0 )
9680 val animation = params.getString(1 )
97- val anim = stateless(model, group, animation)
81+ val anim = stateful< T >( group, animation, params.getBooleanOrNull( 2 ) ? : false )
9882 ObjectValue (anim)
9983 }
100- }
101-
102-
103- class RareCandyAnimation (
104- private val animationSuppler : Supplier <Animation ?>,
105- private val instanceProvider : Supplier <CobblemonInstance ?>,
106- ) {
107-
108-
109- fun run (
110- context : RenderContext ,
111- model : PosableModel ,
112- state : PosableState ,
113- limbSwing : Float ,
114- limbSwingAmount : Float ,
115- ageInTicks : Float ,
116- headYaw : Float ,
117- headPitch : Float ,
118- intensity : Float
119- ): Boolean {
120- if (startedSeconds == - 1F ) {
121- startedSeconds = state.animationSeconds
122- }
123-
124-
125- val instance = model.context.request(
126- RenderContext .ENTITY
127- )?.takeIf { it is CobblemonInstanceProvider }?.let { it as CobblemonInstanceProvider }?.instance
128- ? : instanceProvider.get()
129- val animation = animationSuppler.get()
130-
131- if (animation != null ) {
132- val currentSeconds = state.animationSeconds - startedSeconds
133- val animationLength = animation.animationDuration / animation.ticksPerSecond
134-
135- if (currentSeconds > animationLength) {
136- return false
137- }
138-
139- if (instance != null ) {
140- instance.setAnimation(animation)
141-
142- instance.matrixTransforms = animation.getFrameTransform((currentSeconds).toDouble())
143- animation.getFrameOffset(instance.currentAnimation!! )
144- }
14584
146- return true
147- }
14885
149- return false
15086
87+ map[" pk" ] = function { model, params ->
88+ val group = params.getString(0 )
89+ val animation = params.getString(1 )
90+ val anim = stateless(model, group, animation)
91+ ObjectValue (anim)
15192 }
93+ }
15294
15395
154-
155- override fun applyEffects (entity : T , state : PoseableEntityState <T >, previousSeconds : Float , newSeconds : Float ) = run { }
156-
157- fun asMolang () = ObjectValue (this )
158- }
15996}
16097
0 commit comments