diff --git a/carpetmodSrc/carpet/CarpetSettings.java b/carpetmodSrc/carpet/CarpetSettings.java index 281ceccb..28b6dd31 100644 --- a/carpetmodSrc/carpet/CarpetSettings.java +++ b/carpetmodSrc/carpet/CarpetSettings.java @@ -87,6 +87,11 @@ public class CarpetSettings }) public static boolean commandBlockInfo = true; + @Rule(desc = "Enables /loadchunk command", category = COMMANDS, extra = { + "Loads a chunk remotely" + }) + public static boolean commandLoadChunk = true; + @Rule(desc = "Enables /entityinfo command", category = COMMANDS, extra = { "Also enables yellow carpet placement action if 'carpets' rule is turned on as well" }) diff --git a/carpetmodSrc/carpet/commands/CarpetCommands.java b/carpetmodSrc/carpet/commands/CarpetCommands.java index dbd6d666..66af86a9 100644 --- a/carpetmodSrc/carpet/commands/CarpetCommands.java +++ b/carpetmodSrc/carpet/commands/CarpetCommands.java @@ -21,6 +21,7 @@ public static void register(CommandHandler handler) { handler.registerCommand(new CommandGrow()); handler.registerCommand(new CommandLagSpike()); handler.registerCommand(new CommandLight()); + handler.registerCommand(new CommandLoadChunk()); handler.registerCommand(new CommandLog()); handler.registerCommand(new CommandPerimeter()); handler.registerCommand(new CommandPing()); diff --git a/carpetmodSrc/carpet/commands/CommandLoadChunk.java b/carpetmodSrc/carpet/commands/CommandLoadChunk.java new file mode 100644 index 00000000..89a2f563 --- /dev/null +++ b/carpetmodSrc/carpet/commands/CommandLoadChunk.java @@ -0,0 +1,65 @@ +package carpet.commands; + +import carpet.CarpetSettings; +import carpet.utils.BlockInfo; +import carpet.utils.Messenger; +import com.google.common.collect.Lists; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +public class CommandLoadChunk extends CommandCarpetBase +{ + /** + * Gets the name of the command + */ + + public String getUsage(ICommandSender sender) + { + return "Usage: loadchunk "; + } + + public String getName() + { + return "loadchunk"; + } + + /** + * Callback for when the command is executed + */ + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException + { + if (!command_enabled("commandLoadChunk", sender)) return; + + if (args.length != 2) + { + throw new WrongUsageException(getUsage(sender), new Object[0]); + } + int chunkX = parseInt(args[0]); + int chunkZ = parseInt(args[1]); + World world = sender.getEntityWorld(); + world.getChunk(chunkX, chunkZ); + sender.sendMessage(new TextComponentString("Chunk" + chunkX + ", " + chunkZ + " loaded")); + } + + public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos targetPos) { + int chunkX = sender.getPosition().getX() >> 4; + int chunkZ = sender.getPosition().getZ() >> 4; + + if (args.length == 1) { + return getListOfStringsMatchingLastWord(args, Integer.toString(chunkX)); + } else if (args.length == 2) { + return getListOfStringsMatchingLastWord(args, Integer.toString(chunkZ)); + } else { + return Collections.emptyList(); + } + } +}