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

52 lines
2.8 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;
import net.minecraft.network.chat.TextComponent;
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 -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
2021-12-15 16:24:53 +01:00
CommandSourceStack source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition());
2020-02-26 20:01:57 +01:00
while (amount > 0) {
2021-12-04 15:40:09 +01:00
BlockPos spot = IAuraChunk.getLowestSpot(source.getLevel(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).storeAura(spot, amount);
2020-02-26 20:01:57 +01:00
}
2021-12-15 16:24:53 +01:00
source.sendSuccess(new TextComponent("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 -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
2021-12-15 16:24:53 +01:00
CommandSourceStack source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition());
2020-02-26 20:01:57 +01:00
while (amount > 0) {
2021-12-04 15:40:09 +01:00
BlockPos spot = IAuraChunk.getHighestSpot(source.getLevel(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).drainAura(spot, amount);
2020-02-26 20:01:57 +01:00
}
2021-12-15 16:24:53 +01:00
source.sendSuccess(new TextComponent("Removed aura from area"), true);
2020-02-26 20:01:57 +01:00
return 0;
})))
.then(Commands.literal("reset").executes(context -> {
2021-12-15 16:24:53 +01:00
CommandSourceStack source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition());
2021-12-04 15:40:09 +01:00
IAuraChunk.getSpotsInArea(source.getLevel(), pos, 35, (spot, amount) -> {
IAuraChunk 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);
});
2021-12-15 16:24:53 +01:00
source.sendSuccess(new TextComponent("Reset aura in area"), true);
2020-02-26 20:01:57 +01:00
return 0;
})));
}
}