2022-08-27 18:07:26 +02:00
|
|
|
package com.minelittlepony.unicopia.command;
|
|
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2023-09-05 00:42:44 +02:00
|
|
|
import com.minelittlepony.unicopia.USounds;
|
2022-08-27 18:07:26 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.MagicReserves;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
import com.mojang.brigadier.arguments.FloatArgumentType;
|
2023-09-05 00:40:41 +02:00
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
2023-07-29 20:54:49 +02:00
|
|
|
|
|
|
|
import net.minecraft.command.argument.EnumArgumentType;
|
2022-08-27 18:07:26 +02:00
|
|
|
import net.minecraft.server.command.CommandManager;
|
|
|
|
import net.minecraft.server.command.ServerCommandSource;
|
2023-09-05 00:42:44 +02:00
|
|
|
import net.minecraft.sound.SoundCategory;
|
2022-08-27 18:07:26 +02:00
|
|
|
import net.minecraft.text.Text;
|
2023-07-29 20:54:49 +02:00
|
|
|
import net.minecraft.util.StringIdentifiable;
|
2022-08-27 18:07:26 +02:00
|
|
|
|
|
|
|
public class ManaCommand {
|
2023-09-05 00:40:41 +02:00
|
|
|
static LiteralArgumentBuilder<ServerCommandSource> create() {
|
|
|
|
return CommandManager.literal("mana").requires(s -> s.hasPermissionLevel(2))
|
|
|
|
.then(CommandManager.argument("type", ManaType.argument()).executes(source -> {
|
|
|
|
var type = source.getArgument("type", ManaType.class);
|
|
|
|
var pony = Pony.of(source.getSource().getPlayer());
|
|
|
|
var bar = type.getBar(pony.getMagicalReserves());
|
|
|
|
|
|
|
|
source.getSource().getPlayer().sendMessage(Text.literal(type.name() + " is " + bar.get() + "/" + bar.getMax()));
|
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
.then(CommandManager.argument("value", FloatArgumentType.floatArg()).executes(source -> {
|
|
|
|
var type = source.getArgument("type", ManaType.class);
|
|
|
|
var pony = Pony.of(source.getSource().getPlayer());
|
|
|
|
var bar = type.getBar(pony.getMagicalReserves());
|
|
|
|
|
|
|
|
float value = source.getArgument("value", Float.class);
|
2024-02-12 14:27:50 +01:00
|
|
|
if (type == ManaType.LEVEL) {
|
|
|
|
pony.getLevel().set((int)value);
|
|
|
|
value -= (int)value;
|
|
|
|
type = ManaType.XP;
|
|
|
|
}
|
2023-09-05 00:42:44 +02:00
|
|
|
if (type == ManaType.XP) {
|
|
|
|
int currentLevel = pony.getLevel().get();
|
|
|
|
while (type == ManaType.XP && value > 1) {
|
|
|
|
currentLevel++;
|
|
|
|
value -= 1;
|
|
|
|
}
|
|
|
|
pony.getLevel().set(currentLevel);
|
|
|
|
pony.asWorld().playSound(null, pony.getOrigin(), USounds.Vanilla.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1, 2);
|
2023-09-05 00:40:41 +02:00
|
|
|
}
|
|
|
|
bar.set(value);
|
|
|
|
source.getSource().getPlayer().sendMessage(Text.literal("Set " + type.name() + " to " + bar.get() + "/" + bar.getMax()));
|
|
|
|
return 0;
|
|
|
|
})));
|
2022-08-27 18:07:26 +02:00
|
|
|
}
|
|
|
|
|
2023-08-05 16:45:36 +02:00
|
|
|
enum ManaType implements CommandArgumentEnum<ManaType> {
|
2022-08-27 18:07:26 +02:00
|
|
|
EXERTION(MagicReserves::getExertion),
|
|
|
|
EXHAUSTION(MagicReserves::getExhaustion),
|
|
|
|
ENERGY(MagicReserves::getEnergy),
|
|
|
|
MANA(MagicReserves::getMana),
|
2024-02-12 14:27:50 +01:00
|
|
|
XP(MagicReserves::getXp),
|
|
|
|
LEVEL(MagicReserves::getXp);
|
2022-08-27 18:07:26 +02:00
|
|
|
|
|
|
|
private final Function<MagicReserves, MagicReserves.Bar> getter;
|
|
|
|
|
|
|
|
ManaType(Function<MagicReserves, MagicReserves.Bar> getter) {
|
|
|
|
this.getter = getter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public MagicReserves.Bar getBar(MagicReserves reserves) {
|
|
|
|
return getter.apply(reserves);
|
|
|
|
}
|
2023-07-29 20:54:49 +02:00
|
|
|
|
|
|
|
public static EnumArgumentType<ManaType> argument() {
|
|
|
|
return new ArgumentType();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final class ArgumentType extends EnumArgumentType<ManaType> {
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
static final Codec<ManaType> CODEC = StringIdentifiable.createCodec(ManaType::values);
|
|
|
|
|
|
|
|
protected ArgumentType() {
|
|
|
|
super(CODEC, ManaType::values);
|
|
|
|
}
|
|
|
|
}
|
2022-08-27 18:07:26 +02:00
|
|
|
}
|
|
|
|
}
|