2022-09-06 14:54:49 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-10-04 11:53:07 +08:00
|
|
|
|
using System.Globalization;
|
2022-09-06 14:54:49 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using MinecraftClient.Mapping;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Chunk : Command
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string CmdName { get { return "chunk"; } }
|
2022-09-06 15:25:27 +08:00
|
|
|
|
public override string CmdUsage { get { return "chunk status [chunkX chunkZ|locationX locationY locationZ]"; } }
|
2022-09-06 14:54:49 +08:00
|
|
|
|
public override string CmdDesc { get { return "cmd.chunk.desc"; } }
|
|
|
|
|
|
|
|
|
|
|
|
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
|
|
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
|
if (HasArg(command))
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
|
string[] args = GetArgs(command);
|
2022-09-06 14:54:49 +08:00
|
|
|
|
if (args.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args[0] == "status")
|
|
|
|
|
|
{
|
|
|
|
|
|
World world = handler.GetWorld();
|
|
|
|
|
|
Location current = handler.GetCurrentLocation();
|
2022-09-06 15:25:27 +08:00
|
|
|
|
|
|
|
|
|
|
Tuple<int, int>? markedChunkPos = ParseChunkPos(args);
|
2022-09-06 16:10:34 +08:00
|
|
|
|
(int markChunkX, int markChunkZ) = markedChunkPos ?? (new(current.ChunkX, current.ChunkZ));
|
2022-09-06 15:25:27 +08:00
|
|
|
|
|
2022-09-06 14:54:49 +08:00
|
|
|
|
StringBuilder sb = new();
|
|
|
|
|
|
|
2022-10-02 18:31:08 +08:00
|
|
|
|
sb.Append(World.GetChunkLoadingStatus(handler.GetWorld()));
|
2022-09-06 14:54:49 +08:00
|
|
|
|
sb.Append('\n');
|
|
|
|
|
|
|
2022-10-07 21:49:05 +08:00
|
|
|
|
sb.AppendLine(Translations.Get("cmd.chunk.current", current, current.ChunkX, current.ChunkZ));
|
2022-09-06 16:10:34 +08:00
|
|
|
|
if (markedChunkPos != null)
|
|
|
|
|
|
{
|
2022-10-07 21:49:05 +08:00
|
|
|
|
sb.Append(Translations.Get("cmd.chunk.marked"));
|
2022-09-06 16:10:34 +08:00
|
|
|
|
if (args.Length == 1 + 3)
|
2022-10-04 11:53:07 +08:00
|
|
|
|
sb.Append(String.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}, ",
|
|
|
|
|
|
double.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture),
|
|
|
|
|
|
double.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture),
|
|
|
|
|
|
double.Parse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture)));
|
2022-10-07 21:49:05 +08:00
|
|
|
|
sb.AppendLine(Translations.Get("cmd.chunk.chunk_pos", markChunkX, markChunkZ));;
|
2022-09-06 16:10:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-07 03:04:07 +08:00
|
|
|
|
int consoleHeight = Math.Max(Console.BufferHeight - 2, 25);
|
|
|
|
|
|
if (consoleHeight % 2 == 0)
|
|
|
|
|
|
--consoleHeight;
|
2022-09-06 16:10:34 +08:00
|
|
|
|
|
2022-09-07 03:04:07 +08:00
|
|
|
|
int consoleWidth = Math.Max(Console.BufferWidth / 2, 17);
|
|
|
|
|
|
if (consoleWidth % 2 == 0)
|
|
|
|
|
|
--consoleWidth;
|
2022-09-06 23:21:14 +08:00
|
|
|
|
|
2022-09-07 03:04:07 +08:00
|
|
|
|
int startZ = current.ChunkZ - consoleHeight, endZ = current.ChunkZ + consoleHeight;
|
|
|
|
|
|
int startX = current.ChunkX - consoleWidth, endX = current.ChunkX + consoleWidth;
|
2022-09-06 23:39:45 +08:00
|
|
|
|
|
2022-09-06 23:21:14 +08:00
|
|
|
|
int leftMost = endX, rightMost = startX, topMost = endZ, bottomMost = startZ;
|
2022-09-07 03:04:07 +08:00
|
|
|
|
for (int z = startZ; z <= endZ; z++)
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
2022-09-07 03:04:07 +08:00
|
|
|
|
for (int x = startX; x <= endX; ++x)
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
2022-09-07 03:04:07 +08:00
|
|
|
|
if (world[x, z] != null)
|
2022-09-06 23:21:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
leftMost = Math.Min(leftMost, x);
|
|
|
|
|
|
rightMost = Math.Max(rightMost, x);
|
|
|
|
|
|
topMost = Math.Min(topMost, z);
|
|
|
|
|
|
bottomMost = Math.Max(bottomMost, z);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-07 03:04:07 +08:00
|
|
|
|
// Include the player's location
|
|
|
|
|
|
topMost = Math.Min(topMost, current.ChunkZ);
|
|
|
|
|
|
bottomMost = Math.Max(bottomMost, current.ChunkZ);
|
|
|
|
|
|
leftMost = Math.Min(leftMost, current.ChunkX);
|
|
|
|
|
|
rightMost = Math.Max(rightMost, current.ChunkX);
|
|
|
|
|
|
|
|
|
|
|
|
// Empty one row and one column each
|
|
|
|
|
|
--leftMost; ++rightMost; --topMost; ++bottomMost;
|
|
|
|
|
|
|
|
|
|
|
|
// Resize according to limitations
|
|
|
|
|
|
if ((bottomMost - topMost + 1) > consoleHeight)
|
2022-09-06 23:21:14 +08:00
|
|
|
|
{
|
2022-09-07 03:04:07 +08:00
|
|
|
|
int delta = (bottomMost - topMost + 1) - consoleHeight;
|
|
|
|
|
|
if (bottomMost - (delta + 1) / 2 < current.ChunkZ + 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int bottomReduce = bottomMost - (current.ChunkZ + 1);
|
|
|
|
|
|
bottomMost -= bottomReduce;
|
|
|
|
|
|
topMost += delta - bottomReduce;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (topMost + delta / 2 > current.ChunkZ - 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int topAdd = topMost - (current.ChunkZ - 1);
|
|
|
|
|
|
topMost += topAdd;
|
|
|
|
|
|
bottomMost -= delta - topAdd;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
topMost += delta / 2;
|
|
|
|
|
|
bottomMost -= (delta + 1) / 2;
|
|
|
|
|
|
}
|
2022-09-06 23:21:14 +08:00
|
|
|
|
}
|
2022-09-07 03:04:07 +08:00
|
|
|
|
if ((rightMost - leftMost + 1) > consoleWidth)
|
|
|
|
|
|
{
|
|
|
|
|
|
int delta = (rightMost - leftMost + 1) - consoleWidth;
|
|
|
|
|
|
if (rightMost - (delta + 1) / 2 < current.ChunkX + 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int rightReduce = rightMost - (current.ChunkX + 1);
|
|
|
|
|
|
rightMost -= rightReduce;
|
|
|
|
|
|
leftMost += delta - rightReduce;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (leftMost + delta / 2 > current.ChunkX - 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int leftAdd = leftMost - (current.ChunkX - 1);
|
|
|
|
|
|
leftMost += leftAdd;
|
|
|
|
|
|
rightMost -= delta - leftAdd;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
leftMost += delta / 2;
|
|
|
|
|
|
rightMost -= (delta + 1) / 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try to include the marker chunk
|
|
|
|
|
|
if (markedChunkPos != null &&
|
|
|
|
|
|
(((Math.Max(bottomMost, markChunkZ) - Math.Min(topMost, markChunkZ) + 1) > consoleHeight) ||
|
|
|
|
|
|
((Math.Max(rightMost, markChunkX) - Math.Min(leftMost, markChunkX) + 1) > consoleWidth)))
|
2022-10-07 21:49:05 +08:00
|
|
|
|
sb.AppendLine(Translations.Get("cmd.chunk.outside"));
|
2022-09-06 23:39:45 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-09-07 03:04:07 +08:00
|
|
|
|
topMost = Math.Min(topMost, markChunkZ);
|
|
|
|
|
|
bottomMost = Math.Max(bottomMost, markChunkZ);
|
|
|
|
|
|
leftMost = Math.Min(leftMost, markChunkX);
|
|
|
|
|
|
rightMost = Math.Max(rightMost, markChunkX);
|
2022-09-06 23:39:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-08 14:55:41 +08:00
|
|
|
|
|
|
|
|
|
|
// \ud83d\udd33: 🔳, \ud83d\udfe8: 🟨, \ud83d\udfe9: 🟩, \u25A1: □, \u25A3: ▣, \u25A0: ■
|
2022-10-05 15:02:30 +08:00
|
|
|
|
string[] chunkStatusStr = Settings.Config.Main.Advanced.EnableEmoji ?
|
2022-09-08 14:55:41 +08:00
|
|
|
|
new string[] { "\ud83d\udd33", "\ud83d\udfe8", "\ud83d\udfe9" } : new string[] { "\u25A1", "\u25A3", "\u25A0" };
|
|
|
|
|
|
|
2022-09-06 23:39:45 +08:00
|
|
|
|
// Output
|
2022-09-06 23:21:14 +08:00
|
|
|
|
for (int z = topMost; z <= bottomMost; ++z)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int x = leftMost; x <= rightMost; ++x)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (z == current.ChunkZ && x == current.ChunkX)
|
2022-09-07 03:04:07 +08:00
|
|
|
|
sb.Append("§z"); // Player Location: background gray
|
2022-09-06 23:21:14 +08:00
|
|
|
|
else if (z == markChunkZ && x == markChunkX)
|
2022-09-07 03:04:07 +08:00
|
|
|
|
sb.Append("§w"); // Marked chunk: background red
|
|
|
|
|
|
|
|
|
|
|
|
ChunkColumn? chunkColumn = world[x, z];
|
|
|
|
|
|
if (chunkColumn == null)
|
2022-09-08 14:55:41 +08:00
|
|
|
|
sb.Append(chunkStatusStr[0]);
|
2022-09-07 03:04:07 +08:00
|
|
|
|
else if (chunkColumn.FullyLoaded)
|
2022-09-08 14:55:41 +08:00
|
|
|
|
sb.Append(chunkStatusStr[2]);
|
2022-09-07 03:04:07 +08:00
|
|
|
|
else
|
2022-09-08 14:55:41 +08:00
|
|
|
|
sb.Append(chunkStatusStr[1]);
|
2022-09-07 03:04:07 +08:00
|
|
|
|
|
2022-09-06 23:21:14 +08:00
|
|
|
|
if ((z == current.ChunkZ && x == current.ChunkX) || (z == markChunkZ && x == markChunkX))
|
2022-09-07 03:04:07 +08:00
|
|
|
|
sb.Append("§r"); // Reset background color
|
2022-09-06 14:54:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
sb.Append('\n');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-07 21:49:05 +08:00
|
|
|
|
sb.AppendLine(Translations.Get("cmd.chunk.icon", "§z §r", "§w §r", chunkStatusStr[0], chunkStatusStr[1], chunkStatusStr[2]));
|
2022-09-06 14:54:49 +08:00
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
2022-09-06 21:40:44 +08:00
|
|
|
|
else if (args[0] == "setloading") // For debugging
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
Tuple<int, int>? chunkPos = ParseChunkPos(args);
|
|
|
|
|
|
if (chunkPos != null)
|
|
|
|
|
|
{
|
2022-10-07 21:49:05 +08:00
|
|
|
|
handler.Log.Info(Translations.Get("cmd.chunk.for_debug"));
|
2022-09-06 14:54:49 +08:00
|
|
|
|
World world = handler.GetWorld();
|
|
|
|
|
|
(int chunkX, int chunkZ) = chunkPos;
|
|
|
|
|
|
ChunkColumn? chunkColumn = world[chunkX, chunkZ];
|
|
|
|
|
|
if (chunkColumn != null)
|
|
|
|
|
|
chunkColumn.FullyLoaded = false;
|
2022-10-02 18:31:08 +08:00
|
|
|
|
return (chunkColumn == null) ? "Fail: chunk dosen't exist!" :
|
2022-09-06 14:54:49 +08:00
|
|
|
|
String.Format("Successfully marked chunk ({0}, {1}) as loading.", chunkX, chunkZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
|
}
|
2022-09-06 21:40:44 +08:00
|
|
|
|
else if (args[0] == "setloaded") // For debugging
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
Tuple<int, int>? chunkPos = ParseChunkPos(args);
|
|
|
|
|
|
if (chunkPos != null)
|
|
|
|
|
|
{
|
2022-10-07 21:49:05 +08:00
|
|
|
|
handler.Log.Info(Translations.Get("cmd.chunk.for_debug"));
|
2022-09-06 14:54:49 +08:00
|
|
|
|
World world = handler.GetWorld();
|
|
|
|
|
|
(int chunkX, int chunkZ) = chunkPos;
|
|
|
|
|
|
ChunkColumn? chunkColumn = world[chunkX, chunkZ];
|
|
|
|
|
|
if (chunkColumn != null)
|
|
|
|
|
|
chunkColumn.FullyLoaded = true;
|
2022-10-02 18:31:08 +08:00
|
|
|
|
return (chunkColumn == null) ? "Fail: chunk dosen't exist!" :
|
2022-09-06 14:54:49 +08:00
|
|
|
|
String.Format("Successfully marked chunk ({0}, {1}) as loaded.", chunkX, chunkZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
|
}
|
2022-09-06 21:40:44 +08:00
|
|
|
|
else if (args[0] == "delete") // For debugging
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
Tuple<int, int>? chunkPos = ParseChunkPos(args);
|
|
|
|
|
|
if (chunkPos != null)
|
|
|
|
|
|
{
|
2022-10-07 21:49:05 +08:00
|
|
|
|
handler.Log.Info(Translations.Get("cmd.chunk.for_debug"));
|
2022-09-06 14:54:49 +08:00
|
|
|
|
World world = handler.GetWorld();
|
|
|
|
|
|
(int chunkX, int chunkZ) = chunkPos;
|
|
|
|
|
|
world[chunkX, chunkZ] = null;
|
|
|
|
|
|
return String.Format("Successfully deleted chunk ({0}, {1}).", chunkX, chunkZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
|
}
|
2022-10-02 18:31:08 +08:00
|
|
|
|
else
|
2022-09-06 14:54:49 +08:00
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-02 18:31:08 +08:00
|
|
|
|
private static Tuple<int, int>? ParseChunkPos(string[] args)
|
2022-09-06 14:54:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
int chunkX, chunkZ;
|
|
|
|
|
|
if (args.Length == 1 + 3)
|
|
|
|
|
|
{
|
2022-10-04 11:53:07 +08:00
|
|
|
|
Location pos = new(
|
|
|
|
|
|
double.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture),
|
|
|
|
|
|
double.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture),
|
|
|
|
|
|
double.Parse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture)
|
|
|
|
|
|
);
|
2022-09-06 14:54:49 +08:00
|
|
|
|
chunkX = pos.ChunkX;
|
|
|
|
|
|
chunkZ = pos.ChunkZ;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (args.Length == 1 + 2)
|
|
|
|
|
|
{
|
2022-10-04 11:53:07 +08:00
|
|
|
|
chunkX = int.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture);
|
|
|
|
|
|
chunkZ = int.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture);
|
2022-09-06 14:54:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return null;
|
|
|
|
|
|
return new(chunkX, chunkZ);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|