Compare commits

...
12 changed files with 221 additions and 86 deletions

No files matched your search

+2
View File
@@ -13,6 +13,8 @@
- Added `visibility/hidden`, `visibility/hat` and `visibility/face` tags to control where and how certain items are rendered.
- Added Pokémon markings, toggleable within the summary.
- Added `/boxcount` command to change PC boxes amount
- Added `/transformmodelpart (position|rotation|scale) <modelPart> <transform: x y z>` command that can add transformations to a pokemon's model part.
- The player executing the command must be facing the target pokemon entity. Transformations are not persistent and will revert when resources are reloaded.
### Changes
- Renamed `chargeGainedPerTick` config to `secondsToChargeHealingMachine`.
@@ -563,6 +563,8 @@ object Cobblemon {
this.implementation.registerCommandArgument(cobblemonResource("npc_class"), NPCClassArgumentType::class, SingletonArgumentInfo.contextFree(NPCClassArgumentType::npcClass))
this.implementation.registerCommandArgument(cobblemonResource("wallpaper"), UnlockablePCBoxWallpaperArgumentType::class, SingletonArgumentInfo.contextFree(UnlockablePCBoxWallpaperArgumentType::wallpaper))
this.implementation.registerCommandArgument(cobblemonResource("mark"), MarkArgumentType::class, SingletonArgumentInfo.contextFree(MarkArgumentType::mark))
this.implementation.registerCommandArgument(cobblemonResource("transform_type"), TransformTypeArgumentType::class, SingletonArgumentInfo.contextFree(TransformTypeArgumentType::transformType))
this.implementation.registerCommandArgument(cobblemonResource("model_part"), ModelPartArgumentType::class, SingletonArgumentInfo.contextFree(ModelPartArgumentType::modelPart))
}
}
@@ -23,7 +23,7 @@ object CobblemonCommands {
ChangeEyeHeight.register(dispatcher)
ChangeScaleAndSize.register(dispatcher)
ChangeWalkSpeed.register(dispatcher)
ChangeJointScaleCommand.register(dispatcher)
TransformModelPartCommand.register(dispatcher)
TestCommand.register(dispatcher)
ReloadShowdownCommand.register(dispatcher)
ClickTextCommand.register(dispatcher)
@@ -20,7 +20,7 @@ object CobblemonPermissions {
@JvmStatic
val CHANGE_WALK_SPEED = this.create("${COMMAND_PREFIX}changewalkspeed", PermissionLevel.ALL_COMMANDS)
@JvmStatic
val CHANGE_JOINT_SCALE = this.create("${COMMAND_PREFIX}changejointscale", PermissionLevel.ALL_COMMANDS)
val TRANSFORM_MODEL_PART = this.create("${COMMAND_PREFIX}transformmodelpart", PermissionLevel.ALL_COMMANDS)
@JvmStatic
val CHECKSPAWNS = this.create("${COMMAND_PREFIX}checkspawns", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
@JvmStatic
@@ -78,8 +78,15 @@ class JsonPose(model: PosableModel, json: JsonObject) {
it[2].asDouble
)
} ?: Vec3.ZERO
val scale = it.get("scale")?.asJsonArray?.let {
Vec3(
it[0].asDouble,
it[1].asDouble,
it[2].asDouble
)
} ?: Vec3(1.0,1.0,1.0)
val isVisible = it.get("isVisible")?.asString?.asExpressionLike()
return@map part.withPosition(position.x, position.y, position.z).withRotationDegrees(rotation.x, rotation.y, rotation.z).also { if (isVisible != null) it.withVisibility(isVisible) }
return@map part.withPosition(position.x, position.y, position.z).withRotationDegrees(rotation.x, rotation.y, rotation.z).withScale(scale.x, scale.y, scale.z).also { if (isVisible != null) it.withVisibility(isVisible) }
}?.toTypedArray() ?: arrayOf()
val idleAnimations = (json.get("animations")?.asJsonArray ?: JsonArray()).asJsonArray.mapNotNull {
@@ -532,7 +532,7 @@ open class PosableModel(@Transient override val rootPart: Bone) : ModelFrame {
/** Puts the model back to its original location and rotations. */
fun setDefault() {
defaultPositions.forEach { it.set() }
transformedParts.forEach { it.set() }
transformedParts.forEach { it.apply() }
}
/**
@@ -46,7 +46,7 @@ class ModelPartTransformation(val modelPart: ModelPart) {
var visibility: ExpressionLike? = null
/** Applies the transformation to the model part. */
fun apply(state: PosableState, intensity: Float) {
fun apply(state: PosableState? = null, intensity: Float = 1f) {
modelPart.x += position[0] * intensity
modelPart.y += position[1] * intensity
modelPart.z += position[2] * intensity
@@ -56,7 +56,7 @@ class ModelPartTransformation(val modelPart: ModelPart) {
modelPart.xScale *= ((1 - scale[0]).absoluteValue * intensity) * (scale[0] - 1).sign + 1
modelPart.yScale *= ((1 - scale[1]).absoluteValue * intensity) * (scale[1] - 1).sign + 1
modelPart.zScale *= ((1 - scale[2]).absoluteValue * intensity) * (scale[2] - 1).sign + 1
visibility?.let { modelPart.visible = state.runtime.resolveBoolean(it) }
visibility?.let { modelPart.visible = state?.runtime?.resolveBoolean(it)?: defaultRuntime.resolveBoolean(it) }
}
fun set() {
@@ -1,79 +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.command
import com.cobblemon.mod.common.api.permission.CobblemonPermissions
import com.cobblemon.mod.common.api.text.red
import com.cobblemon.mod.common.api.text.text
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
import com.cobblemon.mod.common.client.render.models.blockbench.createTransformation
import com.cobblemon.mod.common.client.render.models.blockbench.repository.VaryingModelRepository
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
import com.cobblemon.mod.common.util.permission
import com.cobblemon.mod.common.util.traceFirstEntityCollision
import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.FloatArgumentType
import com.mojang.brigadier.arguments.StringArgumentType
import com.mojang.brigadier.context.CommandContext
import net.minecraft.commands.CommandSourceStack
import net.minecraft.commands.Commands
object ChangeJointScaleCommand {
fun register(dispatcher : CommandDispatcher<CommandSourceStack>) {
val command = Commands.literal("changejointscale")
.permission(CobblemonPermissions.CHANGE_JOINT_SCALE)
.then(
Commands.argument("joint", StringArgumentType.string())
.then(
Commands.argument("x", FloatArgumentType.floatArg())
.then(Commands.argument("y", FloatArgumentType.floatArg())
.then(
Commands.argument("z", FloatArgumentType.floatArg())
.executes(::execute)
)
)
)
.executes(::execute))
dispatcher.register(command)
}
private fun execute(context: CommandContext<CommandSourceStack>) : Int {
val jointName = StringArgumentType.getString(context, "joint")
val x = FloatArgumentType.getFloat(context, "x")
val y = FloatArgumentType.getFloat(context, "y")
val z = FloatArgumentType.getFloat(context, "z")
val player = context.source.playerOrException
val targetEntity = player.traceFirstEntityCollision(entityClass = PokemonEntity::class.java)
if (targetEntity == null) {
player.sendSystemMessage("No pokemon".red())
return 0
}
val state = FloatingState()
state.currentAspects = targetEntity.aspects
val model = VaryingModelRepository.getPoser(name = targetEntity.exposedSpecies.resourceIdentifier, state = state)
val part = model.relevantPartsByName[jointName]
?: run {
player.sendSystemMessage("No joint named $jointName".red())
return 0
}
val existing = model.transformedParts.find { it.modelPart == part }
if (existing == null) {
model.transformedParts = model.transformedParts + part.createTransformation().withScale(x, y, z)
} else {
existing.withScale(x, y, z)
}
player.sendSystemMessage("Changed scale of $jointName to $x, $y, $z".text())
return Command.SINGLE_SUCCESS
}
}
@@ -0,0 +1,72 @@
/*
* 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.command
import com.cobblemon.mod.common.api.permission.CobblemonPermissions
import com.cobblemon.mod.common.api.text.text
import com.cobblemon.mod.common.client.render.models.blockbench.createTransformation
import com.cobblemon.mod.common.command.argument.ModelPartArgumentType
import com.cobblemon.mod.common.command.argument.TransformTypeArgumentType
import com.cobblemon.mod.common.command.argument.TransformTypeArgumentType.Companion.TransformType
import com.cobblemon.mod.common.util.permission
import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.FloatArgumentType
import com.mojang.brigadier.context.CommandContext
import net.minecraft.commands.CommandSourceStack
import net.minecraft.commands.Commands
object TransformModelPartCommand {
fun register(dispatcher : CommandDispatcher<CommandSourceStack>) {
val command = Commands.literal("transformmodelpart")
.permission(CobblemonPermissions.TRANSFORM_MODEL_PART)
.then(Commands.argument("transform", TransformTypeArgumentType.transformType())
.then(Commands.argument("part", ModelPartArgumentType.modelPart())
.then(Commands.argument("x", FloatArgumentType.floatArg())
.then(Commands.argument("y", FloatArgumentType.floatArg())
.then(Commands.argument("z", FloatArgumentType.floatArg())
.executes(::execute)
)
)
)
.executes(::execute))
.executes(::execute))
dispatcher.register(command)
}
private fun execute(context: CommandContext<CommandSourceStack>) : Int {
val transformType = TransformTypeArgumentType.getTransform(context, "transform")
val targetModelPart = ModelPartArgumentType.getModelPart(context, "part")?: return 0
val x = FloatArgumentType.getFloat(context, "x")
val y = FloatArgumentType.getFloat(context, "y")
val z = FloatArgumentType.getFloat(context, "z")
val model = ModelPartArgumentType.getModel(context)?: return 0
val existing = model.transformedParts.find { it.modelPart == targetModelPart }
when (transformType) {
TransformType.POSITION -> {
if (existing != null) existing.withPosition(x, y, z)
else model.transformedParts += targetModelPart.createTransformation().withPosition(x, y, z)
}
TransformType.ROTATION -> {
if (existing != null) existing.withRotation(x, y, z)
else model.transformedParts += targetModelPart.createTransformation().withRotation(x, y, z)
}
TransformType.SCALE -> {
if (existing != null) existing.withScale(x, y, z)
else model.transformedParts += targetModelPart.createTransformation().withScale(x, y, z)
}
}
context.source.playerOrException.sendSystemMessage("Changed ${transformType.name.lowercase()} of ${context.getArgument("part", String::class.java )} to $x, $y, $z".text())
return Command.SINGLE_SUCCESS
}
}
@@ -0,0 +1,75 @@
/*
* 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.command.argument
import com.cobblemon.mod.common.api.text.red
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
import com.cobblemon.mod.common.client.render.models.blockbench.PosableModel
import com.cobblemon.mod.common.client.render.models.blockbench.repository.VaryingModelRepository
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
import com.mojang.brigadier.StringReader
import com.mojang.brigadier.arguments.ArgumentType
import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.suggestion.Suggestions
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import net.minecraft.client.Minecraft
import net.minecraft.client.model.geom.ModelPart
import net.minecraft.commands.CommandSourceStack
import net.minecraft.commands.SharedSuggestionProvider
import net.minecraft.world.phys.EntityHitResult
import net.minecraft.world.phys.HitResult.Type
import java.util.concurrent.CompletableFuture
class ModelPartArgumentType(): ArgumentType<String> {
override fun parse(reader: StringReader): String {
return reader.readString()
}
override fun <S : Any> listSuggestions(
context: CommandContext<S>,
builder: SuggestionsBuilder
): CompletableFuture<Suggestions> {
return SharedSuggestionProvider.suggest(getModelParts(context).keys.toList(),builder)
}
companion object {
fun modelPart() = ModelPartArgumentType()
fun <S: Any> getModel(context: CommandContext<S> ): PosableModel? {
if (context.source is SharedSuggestionProvider) {
val targetEntity = (Minecraft.getInstance().hitResult as? EntityHitResult)
?.takeIf { it.type == Type.ENTITY }
?.entity
//Could probably work for NPCs too with some changes
if (targetEntity is PokemonEntity) {
val state = FloatingState()
state.currentAspects = targetEntity.aspects
return VaryingModelRepository.getPoser(name = targetEntity.exposedSpecies.resourceIdentifier, state = state)
}
}
return null
}
private fun <S: Any> getModelParts(context: CommandContext<S>): MutableMap<String, ModelPart> {
val modelParts = getModel(context)?.relevantPartsByName?:mutableMapOf()
return modelParts
}
fun getModelPart(context: CommandContext<CommandSourceStack>, name: String): ModelPart? {
val partName = context.getArgument(name, String::class.java )
val part = getModelParts(context)[partName]
?: run {
context.source.playerOrException.sendSystemMessage("No joint named $partName".red())
return null
}
return part
}
}
}
@@ -0,0 +1,49 @@
/*
* 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.command.argument
import com.mojang.brigadier.StringReader
import com.mojang.brigadier.arguments.ArgumentType
import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.exceptions.CommandSyntaxException
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import net.minecraft.commands.CommandSourceStack
import net.minecraft.commands.SharedSuggestionProvider
class TransformTypeArgumentType: ArgumentType<TransformTypeArgumentType.Companion.TransformType>
{
override fun parse(reader: StringReader): TransformType {
try {
reader.readString()?.let { return TransformType.valueOf(it.uppercase()) }
}
catch (_: Exception) { }
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherParseException().create(reader)
}
override fun getExamples() = EXAMPLES
override fun <S : Any> listSuggestions(context: CommandContext<S>, builder: SuggestionsBuilder) = SharedSuggestionProvider.suggest(EXAMPLES, builder)
companion object {
enum class TransformType {
POSITION,
ROTATION,
SCALE
}
fun transformType() = TransformTypeArgumentType()
fun getTransform(context: CommandContext<CommandSourceStack>, name: String): TransformType {
return context.getArgument(name, TransformType::class.java )
}
private val EXAMPLES = TransformType.entries.map { it.name.lowercase() }
}
}
@@ -43,7 +43,14 @@ object ModelPartTransformationAdapter : JsonDeserializer<ModelPartTransformation
it[2].asDouble
)
} ?: Vec3.ZERO
val scale = json.get("scale")?.asJsonArray?.let {
Vec3(
it[0].asDouble,
it[1].asDouble,
it[2].asDouble
)
} ?: Vec3(1.0,1.0,1.0)
val isVisible = json.get("isVisible")?.asString?.asExpressionLike()
return part.withPosition(position.x, position.y, position.z).withRotationDegrees(rotation.x, rotation.y, rotation.z).also { if (isVisible != null) it.withVisibility(isVisible) }
return part.withPosition(position.x, position.y, position.z).withRotationDegrees(rotation.x, rotation.y, rotation.z).withScale(scale.x, scale.y, scale.z).also { if (isVisible != null) it.withVisibility(isVisible) }
}
}