Skip to content

Commit

Permalink
Fixed loadChunk and renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
X-com committed Jan 20, 2022
1 parent a887af4 commit 9cc8927
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
1 change: 1 addition & 0 deletions carpetmodSrc/carpet/commands/CarpetCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static void register(CommandHandler handler) {
handler.registerCommand(new CommandUnload13());
handler.registerCommand(new CommandUpdateCarpet());
handler.registerCommand(new CommandWaypoint());
handler.registerCommand(new CommandChunk());
handler.registerCommand(new CommandLoadedChunks());
handler.registerCommand(new CommandZetBlock());

Expand Down
16 changes: 8 additions & 8 deletions carpetmodSrc/carpet/commands/CommandChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CommandChunk extends CommandCarpetBase

public String getUsage(ICommandSender sender)
{
return "Usage: chunk <X> <Z> <load | info | unload>";
return "Usage: chunk <load | info | unload> <X> <Z>";
}

public String getName()
Expand All @@ -45,12 +45,12 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
throw new WrongUsageException(getUsage(sender));
}

int chunkX = parseChunkPosition(args[0], sender.getPosition().getX());
int chunkZ = parseChunkPosition(args[1], sender.getPosition().getZ());

world = sender.getEntityWorld();
try {
switch (args[2]){
int chunkX = parseChunkPosition(args[1], sender.getPosition().getX());
int chunkZ = parseChunkPosition(args[2], sender.getPosition().getZ());

switch (args[0]){
case "load":
world.getChunk(chunkX, chunkZ);
sender.sendMessage(new TextComponentString("Chunk " + chunkX + ", " + chunkZ + " loaded"));
Expand Down Expand Up @@ -98,11 +98,11 @@ public List<String> getTabCompletions(MinecraftServer server, ICommandSender sen
int chunkZ = sender.getPosition().getZ() >> 4;

if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, Integer.toString(chunkX), "~");
return getListOfStringsMatchingLastWord(args, "info", "load", "unload");
} else if (args.length == 2) {
return getListOfStringsMatchingLastWord(args, Integer.toString(chunkZ), "~");
return getListOfStringsMatchingLastWord(args, Integer.toString(chunkX), "~");
} else if (args.length == 3) {
return getListOfStringsMatchingLastWord(args, "info", "load", "unload");
return getListOfStringsMatchingLastWord(args, Integer.toString(chunkZ), "~");
} else {
return Collections.emptyList();
}
Expand Down
24 changes: 18 additions & 6 deletions carpetmodSrc/carpet/commands/CommandLoadedChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import carpet.CarpetSettings;
import carpet.helpers.CustomHashMap;
import it.unimi.dsi.fastutil.HashCommon;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
Expand Down Expand Up @@ -50,8 +50,6 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
if (args.length == 0) throw new WrongUsageException(getUsage(sender));

world = sender.getEntityWorld();
ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
CustomHashMap<Chunk> loadedChunks = (CustomHashMap<Chunk>) provider.loadedChunks;

try {
switch (args[0]){
Expand All @@ -77,9 +75,10 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
String fileName = "loadedchunks-" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSSS").format(new Date()) + ".csv";
try (PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)))) {
pw.println("index,key,x,z,hash");
long[] keys = loadedChunks.getKey();
Object[] values = loadedChunks.getValues();
for (int i = 0, n = loadedChunks.getHashSize(); i <= n; i++) {
long[] keys = (long[]) getPrivateMethods(world, "key");
Object[] values = (Object[]) getPrivateMethods(world, "value");
int getHashSize = (int) getPrivateMethods(world, "n");
for (int i = 0, n = getHashSize; i <= n; i++) {
long key = keys[i];
Chunk val = (Chunk) values[i];
if (val == null) {
Expand All @@ -102,6 +101,19 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args

}

private Object getPrivateMethods(World world, String name){
ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
Long2ObjectOpenHashMap<Chunk> loadedChunks = (Long2ObjectOpenHashMap<Chunk>) provider.loadedChunks;
try {
Field f = loadedChunks.getClass().getDeclaredField(name);
f.setAccessible(true);
return f.get(loadedChunks);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

protected Long2ObjectOpenHashMap<Chunk> getLoadedChunks (ICommandSender sender){
world = sender.getEntityWorld();
ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
Expand Down
21 changes: 0 additions & 21 deletions carpetmodSrc/carpet/helpers/CustomHashMap.java

This file was deleted.

0 comments on commit 9cc8927

Please sign in to comment.