Skip to content

Commit

Permalink
add load chunk command (#141)
Browse files Browse the repository at this point in the history
* add load chunk command

/loadchunk x z would tirgger chunk loading

* fix random shit my ide add, upsi did an xcom
  • Loading branch information
kerbaras authored Jan 6, 2021
1 parent 78f4f2e commit 7a3726c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions carpetmodSrc/carpet/CarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
Expand Down
1 change: 1 addition & 0 deletions carpetmodSrc/carpet/commands/CarpetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
65 changes: 65 additions & 0 deletions carpetmodSrc/carpet/commands/CommandLoadChunk.java
Original file line number Diff line number Diff line change
@@ -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 <X> <Z>";
}

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<String> 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();
}
}
}

0 comments on commit 7a3726c

Please sign in to comment.