mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-19 06:38:53 -05:00
Learnset query command for command block/mcfunction use
This commit is contained in:
1 parent
5c60f2634d
commit
7cf46baa98
5 files changed
+59
-1
No files matched your search
+2
-1
@@ -1,7 +1,8 @@
|
||||
# Changelog
|
||||
## [1.4.0](#1-4-0)
|
||||
## Additions
|
||||
- Added the `/teststore` command allowing command block/mcfunction users to query a party, PC or both for Pokémon matching specific properties and returning the match count, this will be a cheat command in the Minecraft permission system or use the permission `cobblemon.command.teststore` if a permission mod is present.
|
||||
- Added the `/teststore <player> <store> <properties>` command allowing command block/mcfunction users to query a party, PC or both for Pokémon matching specific properties and returning the match count, this will be a cheat command in the Minecraft permission system or use the permission `cobblemon.command.teststore` if a permission mod is present.
|
||||
- Added the `/querylearnset <player> <slot> <move>` command allowing command block/mcfunction users to query a party slot and check if the Pokémon can learn a specific move returning a 1 if yes otherwise 0, this will be a cheat command in the Minecraft permission system or use the permission `cobblemon.command.querylearnset` if a permission mod is present.
|
||||
|
||||
## [1.3.1 (March 31st, 2023)](#1-3-1)
|
||||
|
||||
|
||||
@@ -39,5 +39,6 @@ object CobblemonCommands {
|
||||
SpawnPokemonFromPool.register(dispatcher)
|
||||
PokeboxCommand.register(dispatcher)
|
||||
TestStoreCommand.register(dispatcher)
|
||||
QueryLearnsetCommand.register(dispatcher)
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,8 @@ object CobblemonPermissions {
|
||||
|
||||
val TEST_STORE = this.create("${COMMAND_PREFIX}teststore", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||
|
||||
val QUERY_LEARNSET = this.create("${COMMAND_PREFIX}querylearnset", PermissionLevel.CHEAT_COMMANDS_AND_COMMAND_BLOCKS)
|
||||
|
||||
fun all(): Iterable<Permission> = this.permissions
|
||||
|
||||
private fun create(node: String, level: PermissionLevel): Permission {
|
||||
|
||||
@@ -29,6 +29,7 @@ fun interface LearnsetQuery {
|
||||
|| learnset.tutorMoves.contains(move)
|
||||
|| learnset.tmMoves.contains(move)
|
||||
|| learnset.formChangeMoves.contains(move)
|
||||
|| learnset.evolutionMoves.contains(move)
|
||||
}
|
||||
|
||||
fun level(level: Int) = LearnsetQuery { move, learnset -> learnset.getLevelUpMovesUpTo(level).contains(move) }
|
||||
@@ -43,6 +44,8 @@ fun interface LearnsetQuery {
|
||||
|
||||
val FORM_CHANGE = LearnsetQuery { move, learnset -> learnset.formChangeMoves.contains(move) }
|
||||
|
||||
val EVOLUTION = LearnsetQuery { move, learnset -> learnset.evolutionMoves.contains(move) }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.pokemon.moves.LearnsetQuery
|
||||
import com.cobblemon.mod.common.command.argument.MoveArgumentType
|
||||
import com.cobblemon.mod.common.command.argument.PartySlotArgumentType
|
||||
import com.cobblemon.mod.common.util.permission
|
||||
import com.cobblemon.mod.common.util.player
|
||||
import com.mojang.brigadier.Command
|
||||
import com.mojang.brigadier.CommandDispatcher
|
||||
import com.mojang.brigadier.context.CommandContext
|
||||
import net.minecraft.command.argument.EntityArgumentType
|
||||
import net.minecraft.server.command.CommandManager.argument
|
||||
import net.minecraft.server.command.CommandManager.literal
|
||||
import net.minecraft.server.command.ServerCommandSource
|
||||
|
||||
object QueryLearnsetCommand {
|
||||
|
||||
private const val NAME = "querylearnset"
|
||||
private const val PLAYER = "player"
|
||||
private const val SLOT = "slot"
|
||||
private const val MOVE = "move"
|
||||
private const val NO_SUCCESS = 0
|
||||
|
||||
fun register(dispatcher : CommandDispatcher<ServerCommandSource>) {
|
||||
dispatcher.register(
|
||||
literal(NAME)
|
||||
.permission(CobblemonPermissions.QUERY_LEARNSET)
|
||||
.then(argument(PLAYER, EntityArgumentType.player())
|
||||
.then(argument(SLOT, PartySlotArgumentType.partySlot())
|
||||
.then(argument(MOVE, MoveArgumentType.move())
|
||||
.executes(this::execute))))
|
||||
)
|
||||
}
|
||||
|
||||
private fun execute(context: CommandContext<ServerCommandSource>): Int {
|
||||
val player = context.player(PLAYER)
|
||||
val pokemon = PartySlotArgumentType.getPokemonOf(context, SLOT, player)
|
||||
val move = MoveArgumentType.getMove(context, MOVE)
|
||||
return if (LearnsetQuery.ANY.canLearn(move, pokemon.form.moves)) Command.SINGLE_SUCCESS else NO_SUCCESS
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user