mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-22 14:59:22 +01:00
finally added back the aura command
This commit is contained in:
parent
74d4e9cab5
commit
cb928c5bbf
3 changed files with 49 additions and 83 deletions
|
@ -24,7 +24,6 @@ import net.minecraftforge.fml.DistExecutor;
|
|||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -92,8 +91,4 @@ public final class NaturesAura {
|
|||
proxy.postInit(event);
|
||||
}
|
||||
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
// TODO event.registerServerCommand(new CommandAura());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,87 +1,51 @@
|
|||
/* TODO commands
|
||||
package de.ellpeck.naturesaura.commands;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import net.minecraft.command.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
public final class CommandAura {
|
||||
|
||||
public class CommandAura extends Command {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "naaura";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSource sender) {
|
||||
return "command." + NaturesAura.MOD_ID + ".aura.usage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSource sender, String[] args) throws CommandException {
|
||||
if (args.length < 2)
|
||||
throw new WrongUsageException(this.getUsage(sender));
|
||||
World world = sender.getEntityWorld();
|
||||
BlockPos pos = sender.getPosition();
|
||||
|
||||
String action = args[0];
|
||||
if ("store".equals(action)) {
|
||||
int amount = parse(args, 1, -1);
|
||||
int range = parse(args, 2, 35);
|
||||
while (amount > 0) {
|
||||
BlockPos spot = IAuraChunk.getLowestSpot(world, pos, range, pos);
|
||||
amount -= IAuraChunk.getAuraChunk(world, spot).storeAura(spot, amount);
|
||||
}
|
||||
sender.sendMessage(new StringTextComponent("Stored Aura successfully"));
|
||||
} else if ("drain".equals(action)) {
|
||||
int amount = parse(args, 1, -1);
|
||||
int range = parse(args, 2, 35);
|
||||
while (amount > 0) {
|
||||
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, range, pos);
|
||||
amount -= IAuraChunk.getAuraChunk(world, spot).drainAura(spot, amount);
|
||||
}
|
||||
sender.sendMessage(new StringTextComponent("Drained Aura successfully"));
|
||||
} else if ("reset".equals(action)) {
|
||||
int range = parse(args, 1, -1);
|
||||
IAuraChunk.getSpotsInArea(world, pos, range, (spot, amount) -> {
|
||||
IAuraChunk chunk = IAuraChunk.getAuraChunk(world, spot);
|
||||
if (amount > 0)
|
||||
chunk.drainAura(spot, amount);
|
||||
else
|
||||
chunk.storeAura(spot, -amount);
|
||||
});
|
||||
sender.sendMessage(new StringTextComponent("Reset Aura successfully"));
|
||||
} else {
|
||||
throw new SyntaxErrorException("Invalid action " + action);
|
||||
}
|
||||
}
|
||||
|
||||
private static int parse(String[] args, int argNum, int def) throws NumberInvalidException {
|
||||
try {
|
||||
return Integer.parseInt(args[argNum]);
|
||||
} catch (Exception e) {
|
||||
if (def < 0)
|
||||
throw new NumberInvalidException("Invalid number " + args[argNum]);
|
||||
else
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) {
|
||||
if (args.length == 1) {
|
||||
return getListOfStringsMatchingLastWord(args, "store", "drain", "reset");
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
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;
|
||||
})));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
||||
import de.ellpeck.naturesaura.chunk.AuraChunkProvider;
|
||||
import de.ellpeck.naturesaura.commands.CommandAura;
|
||||
import de.ellpeck.naturesaura.misc.WorldData;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
@ -19,6 +20,7 @@ import net.minecraftforge.event.TickEvent;
|
|||
import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -85,4 +87,9 @@ public class CommonEvents {
|
|||
PacketHandler.sendTo(event.getPlayer(), auraChunk.makePacket());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerAboutToStartEvent(FMLServerStartingEvent event) {
|
||||
CommandAura.register(event.getCommandDispatcher());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue