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;
2020-02-26 20:01:57 +01:00
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.math.BlockPos;
2019-10-20 22:30:49 +02:00
import net.minecraft.util.text.StringTextComponent;
2020-02-26 20:01:57 +01:00
public final class CommandAura {
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermissionLevel(2))
.then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
CommandSource source = context.getSource();
BlockPos pos = new BlockPos(source.getPos());
while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(source.getWorld(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getWorld(), spot).storeAura(spot, amount);
}
source.sendFeedback(new StringTextComponent("Added aura to area"), true);
return 0;
})))
.then(Commands.literal("remove").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
CommandSource source = context.getSource();
BlockPos pos = new BlockPos(source.getPos());
while (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(source.getWorld(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getWorld(), spot).drainAura(spot, amount);
}
source.sendFeedback(new StringTextComponent("Removed aura from area"), true);
return 0;
})))
.then(Commands.literal("reset").executes(context -> {
CommandSource source = context.getSource();
BlockPos pos = new BlockPos(source.getPos());
IAuraChunk.getSpotsInArea(source.getWorld(), pos, 35, (spot, amount) -> {
IAuraChunk chunk = IAuraChunk.getAuraChunk(source.getWorld(), spot);
if (amount > 0)
chunk.drainAura(spot, amount);
else
chunk.storeAura(spot, -amount);
});
source.sendFeedback(new StringTextComponent("Reset aura in area"), true);
return 0;
})));
}
}