Skip to content

Commit

Permalink
Finish rotom catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed Dec 27, 2024
1 parent c9d4a2b commit 10445d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import com.cobblemon.mod.common.api.molang.MoLangFunctions
import com.cobblemon.mod.common.api.molang.MoLangFunctions.addFunctions
import com.cobblemon.mod.common.api.molang.ObjectValue
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
import com.cobblemon.mod.common.api.pokemon.feature.ChoiceSpeciesFeatureProvider
import com.cobblemon.mod.common.api.pokemon.feature.SpeciesFeature
import com.cobblemon.mod.common.api.pokemon.feature.SpeciesFeatures
import com.cobblemon.mod.common.api.pokemon.feature.StringSpeciesFeature
import com.cobblemon.mod.common.api.pokemon.feature.*
import com.cobblemon.mod.common.api.properties.CustomPokemonPropertyType
import com.cobblemon.mod.common.api.storage.party.PartyStore
import com.cobblemon.mod.common.pokemon.Pokemon
Expand Down Expand Up @@ -59,23 +56,32 @@ object GenerationsMolangFunctions {
hashMapOf(
"species" to java.util.function.Function { _ -> StringValue(pokemon.species.name) },
"form" to java.util.function.Function { _ -> StringValue(pokemon.form.name) },
"feature" to Function {
"get_feature" to Function {
val featureName = it.getStringOrNull(0) ?: return@Function DoubleValue.ZERO
val feature = pokemon.getOrCreateFeature(featureName) as? StringSpeciesFeature ?: return@Function DoubleValue.ZERO
val feature = pokemon.getFeature<SpeciesFeature>(featureName) ?: return@Function DoubleValue.ZERO

System.out.println("Test: " + featureName)
when (feature) {
is StringSpeciesFeature -> return@Function StringValue(feature.value)
is FlagSpeciesFeature -> return@Function if(feature.enabled) DoubleValue.ONE else DoubleValue.ZERO
is IntSpeciesFeature -> return@Function DoubleValue(feature.value)
else -> return@Function DoubleValue.ZERO
}
},

val value = it.getStringOrNull(1) ?: return@Function StringValue(feature.value)

System.out.println("Tester: " + value)

feature.value = value

pokemon.markFeatureDirty(feature)
pokemon.updateAspects()
pokemon.updateForm()

return@Function DoubleValue.ONE
"set_feature" to Function {
val featureName = it.getStringOrNull(0) ?: return@Function DoubleValue.ZERO
val feature = pokemon.getOrCreateFeature(featureName) ?: return@Function DoubleValue.ZERO

when (feature) {
is StringSpeciesFeature -> it.getStringOrNull(1)?.also {
feature.value = it
}?.also {
feature.apply(pokemon)
} ?: return@Function StringValue(feature.value)
is FlagSpeciesFeature -> it.getBooleanOrNull(1)?.also { feature.enabled = it }?.also { feature.apply(pokemon) }
is IntSpeciesFeature -> it.getIntOrNull(1)?.also { feature.value = it }?.also { feature.apply(pokemon) }
else -> return@Function DoubleValue.ZERO
}
}
)
})
Expand Down Expand Up @@ -149,11 +155,12 @@ object GenerationsMolangFunctions {
return@Function Unit
}
}

}

private fun MoParams.getIntOrNull(index: Int): Int? = this.getDoubleOrNull(index)?.toInt()

private fun Pokemon.getOrCreateFeature(featureName: String): SpeciesFeature? {
var provider = this.getProviderOrNull<CustomPokemonPropertyType<*>>(featureName) ?: return null
val provider = this.getProviderOrNull<CustomPokemonPropertyType<*>>(featureName) ?: return null

when (provider) {
is ChoiceSpeciesFeatureProvider -> return provider.getOrCreate(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public int getBaseZ() {
return 0;
}

protected boolean isAreaClear(Level level, Direction dir, BlockPos pos) {
protected boolean isAreaClear(LevelReader level, Direction dir, BlockPos pos) {

for (int x = 0; x < width + 1; x++) {
for (int z = 0; z < length + 1; z++) {
Expand Down Expand Up @@ -167,7 +167,7 @@ public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
var dir = state.getValue(FACING);
var base = getBaseBlockPos(pos, state);

return isAreaClear((Level) level, dir, base);
return isAreaClear(level, dir, base);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"isVisible": "q.player.has_in_party('cobblemon:rotom', 0)",
"action": [
"v.pokemon = q.player.party.get(0);",
"v.aspect = v.pokemon.get_feature('rotom_form');",
"q.dialogue.set_page('forms');"
]
},
Expand All @@ -32,6 +33,7 @@
"isVisible": "q.player.has_in_party('cobblemon:rotom', 1)",
"action": [
"v.pokemon = q.player.party.get(1);",
"v.aspect = v.pokemon.get_feature('rotom_form');",
"q.dialogue.set_page('forms');"
]
},
Expand All @@ -41,6 +43,7 @@
"isVisible": "q.player.has_in_party('cobblemon:rotom', 2)",
"action": [
"v.pokemon = q.player.party.get(2);",
"v.aspect = v.pokemon.get_feature('rotom_form');",
"q.dialogue.set_page('forms');"
]
},
Expand All @@ -50,6 +53,7 @@
"isVisible": "q.player.has_in_party('cobblemon:rotom', 3)",
"action": [
"v.pokemon = q.player.party.get(3);",
"v.aspect = v.pokemon.get_feature('rotom_form');",
"q.dialogue.set_page('forms');"
]
},
Expand All @@ -59,6 +63,7 @@
"isVisible": "q.player.has_in_party('cobblemon:rotom', 4)",
"action": [
"v.pokemon = q.player.party.get(4);",
"v.aspect = v.pokemon.get_feature('rotom_form');",
"q.dialogue.set_page('forms');"
]
},
Expand All @@ -68,6 +73,7 @@
"isVisible": "q.player.has_in_party('cobblemon:rotom', 5)",
"action": [
"v.pokemon = q.player.party.get(5);",
"v.aspect = v.pokemon.get_feature('rotom_form');",
"q.dialogue.set_page('forms');"
]
},
Expand All @@ -91,54 +97,54 @@
{
"text": "Normal",
"value": "normal",
"isVisible": "v.pokemon.feature('rotom_form') != 'false'",
"isVisible": "v.aspect != 'false' && v.aspect != 0.0",
"action": [
"v.pokemon.feature('rotom_form', 'false');",
"v.pokemon.set_feature('rotom_form', 'false');",
"q.dialogue.close();"
]
},
{
"text": "Heat",
"value": "heat",
"isVisible": "v.pokemon.feature('rotom_form') != 'heat'",
"isVisible": "v.aspect != 'heat'",
"action": [
"v.pokemon.feature('rotom_form', 'heat');",
"v.pokemon.set_feature('rotom_form', 'heat');",
"q.dialogue.close();"
]
},
{
"text": "Wash",
"value": "wash",
"isVisible": "v.pokemon.feature('rotom_form') != 'wash'",
"isVisible": "v.aspect != 'wash'",
"action": [
"v.pokemon.feature('rotom_form', 'wash');",
"v.pokemon.set_feature('rotom_form', 'wash');",
"q.dialogue.close();"
]
},
{
"text": "Frost",
"value": "frost",
"isVisible": "v.pokemon.feature('rotom_form') != 'frost'",
"isVisible": "v.aspect != 'frost'",
"action": [
"v.pokemon.feature('rotom_form', 'frost');",
"v.pokemon.set_feature('rotom_form', 'frost');",
"q.dialogue.close();"
]
},
{
"text": "Fan",
"value": "fan",
"isVisible": "v.pokemon.feature('rotom_form') != 'fan'",
"isVisible": "v.aspect != 'fan'",
"action": [
"v.pokemon.feature('rotom_form', 'fan');",
"v.pokemon.set_feature('rotom_form', 'fan');",
"q.dialogue.close();"
]
},
{
"text": "Mow",
"value": "mow",
"isVisible": "v.pokemon.feature('rotom_form') != 'mow'",
"isVisible": "v.aspect != 'mow'",
"action": [
"v.pokemon.feature('rotom_form', 'mow');",
"v.pokemon.set_feature('rotom_form', 'mow');",
"q.dialogue.close();"
]
}
Expand Down

0 comments on commit 10445d1

Please sign in to comment.