mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +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.ModLoadingContext;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -92,8 +91,4 @@ public final class NaturesAura {
|
||||||
proxy.postInit(event);
|
proxy.postInit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void serverStarting(FMLServerStartingEvent event) {
|
|
||||||
// TODO event.registerServerCommand(new CommandAura());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,87 +1,51 @@
|
||||||
/* TODO commands
|
|
||||||
package de.ellpeck.naturesaura.commands;
|
package de.ellpeck.naturesaura.commands;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import de.ellpeck.naturesaura.NaturesAura;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||||
import net.minecraft.command.*;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
public final class CommandAura {
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommandAura extends Command {
|
public static void register(CommandDispatcher<CommandSource> dispatcher) {
|
||||||
@Override
|
dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermissionLevel(2))
|
||||||
public String getName() {
|
.then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
|
||||||
return "naaura";
|
int amount = IntegerArgumentType.getInteger(context, "amount");
|
||||||
}
|
CommandSource source = context.getSource();
|
||||||
|
BlockPos pos = new BlockPos(source.getPos());
|
||||||
@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) {
|
while (amount > 0) {
|
||||||
BlockPos spot = IAuraChunk.getLowestSpot(world, pos, range, pos);
|
BlockPos spot = IAuraChunk.getLowestSpot(source.getWorld(), pos, 35, pos);
|
||||||
amount -= IAuraChunk.getAuraChunk(world, spot).storeAura(spot, amount);
|
amount -= IAuraChunk.getAuraChunk(source.getWorld(), spot).storeAura(spot, amount);
|
||||||
}
|
}
|
||||||
sender.sendMessage(new StringTextComponent("Stored Aura successfully"));
|
source.sendFeedback(new StringTextComponent("Added aura to area"), true);
|
||||||
} else if ("drain".equals(action)) {
|
return 0;
|
||||||
int amount = parse(args, 1, -1);
|
})))
|
||||||
int range = parse(args, 2, 35);
|
.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) {
|
while (amount > 0) {
|
||||||
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, range, pos);
|
BlockPos spot = IAuraChunk.getHighestSpot(source.getWorld(), pos, 35, pos);
|
||||||
amount -= IAuraChunk.getAuraChunk(world, spot).drainAura(spot, amount);
|
amount -= IAuraChunk.getAuraChunk(source.getWorld(), spot).drainAura(spot, amount);
|
||||||
}
|
}
|
||||||
sender.sendMessage(new StringTextComponent("Drained Aura successfully"));
|
source.sendFeedback(new StringTextComponent("Removed aura from area"), true);
|
||||||
} else if ("reset".equals(action)) {
|
return 0;
|
||||||
int range = parse(args, 1, -1);
|
})))
|
||||||
IAuraChunk.getSpotsInArea(world, pos, range, (spot, amount) -> {
|
.then(Commands.literal("reset").executes(context -> {
|
||||||
IAuraChunk chunk = IAuraChunk.getAuraChunk(world, spot);
|
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)
|
if (amount > 0)
|
||||||
chunk.drainAura(spot, amount);
|
chunk.drainAura(spot, amount);
|
||||||
else
|
else
|
||||||
chunk.storeAura(spot, -amount);
|
chunk.storeAura(spot, -amount);
|
||||||
});
|
});
|
||||||
sender.sendMessage(new StringTextComponent("Reset Aura successfully"));
|
source.sendFeedback(new StringTextComponent("Reset aura in area"), true);
|
||||||
} else {
|
return 0;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||||
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
||||||
import de.ellpeck.naturesaura.chunk.AuraChunkProvider;
|
import de.ellpeck.naturesaura.chunk.AuraChunkProvider;
|
||||||
|
import de.ellpeck.naturesaura.commands.CommandAura;
|
||||||
import de.ellpeck.naturesaura.misc.WorldData;
|
import de.ellpeck.naturesaura.misc.WorldData;
|
||||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
@ -19,6 +20,7 @@ import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.event.world.ChunkWatchEvent;
|
import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||||
|
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -85,4 +87,9 @@ public class CommonEvents {
|
||||||
PacketHandler.sendTo(event.getPlayer(), auraChunk.makePacket());
|
PacketHandler.sendTo(event.getPlayer(), auraChunk.makePacket());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onServerAboutToStartEvent(FMLServerStartingEvent event) {
|
||||||
|
CommandAura.register(event.getCommandDispatcher());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue