NaturesAura/src/main/java/de/ellpeck/naturesaura/commands/CommandAura.java

53 lines
2.9 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.commands;
2020-02-26 20:01:57 +01:00
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
2021-12-15 16:24:53 +01:00
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
2022-06-27 15:24:04 +02:00
import net.minecraft.network.chat.Component;
2020-02-26 20:01:57 +01:00
public final class CommandAura {
2021-12-15 16:24:53 +01:00
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermission(2))
2020-02-26 20:01:57 +01:00
.then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
2021-12-15 16:30:22 +01:00
var amount = IntegerArgumentType.getInteger(context, "amount");
var source = context.getSource();
2023-07-08 12:32:27 +02:00
var pos = BlockPos.containing(source.getPosition());
2020-02-26 20:01:57 +01:00
while (amount > 0) {
2021-12-15 16:30:22 +01:00
var spot = IAuraChunk.getLowestSpot(source.getLevel(), pos, 35, pos);
2021-12-04 15:40:09 +01:00
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).storeAura(spot, amount);
2020-02-26 20:01:57 +01:00
}
2023-07-08 12:32:27 +02:00
source.sendSuccess(() -> Component.literal("Added aura to area"), true);
2020-02-26 20:01:57 +01:00
return 0;
})))
.then(Commands.literal("remove").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
2021-12-15 16:30:22 +01:00
var amount = IntegerArgumentType.getInteger(context, "amount");
var source = context.getSource();
2023-07-08 12:32:27 +02:00
var pos = BlockPos.containing(source.getPosition());
2020-02-26 20:01:57 +01:00
while (amount > 0) {
2021-12-15 16:30:22 +01:00
var spot = IAuraChunk.getHighestSpot(source.getLevel(), pos, 35, pos);
2021-12-04 15:40:09 +01:00
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).drainAura(spot, amount);
2020-02-26 20:01:57 +01:00
}
2023-07-08 12:32:27 +02:00
source.sendSuccess(() -> Component.literal("Removed aura from area"), true);
2020-02-26 20:01:57 +01:00
return 0;
})))
.then(Commands.literal("reset").then(Commands.argument("range", IntegerArgumentType.integer(10, 1000)).executes(context -> {
var range = IntegerArgumentType.getInteger(context, "range");
2021-12-15 16:30:22 +01:00
var source = context.getSource();
2023-07-08 12:32:27 +02:00
var pos = BlockPos.containing(source.getPosition());
IAuraChunk.getSpotsInArea(source.getLevel(), pos, range, (spot, amount) -> {
2021-12-15 16:30:22 +01:00
var chunk = IAuraChunk.getAuraChunk(source.getLevel(), spot);
2020-02-26 20:01:57 +01:00
if (amount > 0)
chunk.drainAura(spot, amount);
else
chunk.storeAura(spot, -amount);
});
2023-07-08 12:32:27 +02:00
source.sendSuccess(() -> Component.literal("Reset aura in area"), true);
2020-02-26 20:01:57 +01:00
return 0;
}))));
}
}