Optimized World.cs

This commit is contained in:
Anon 2026-03-25 23:57:02 +01:00
parent 7da47d36dc
commit a2f7511ef7
3 changed files with 32 additions and 12 deletions

View file

@ -12,9 +12,9 @@ namespace MinecraftClient.Mapping
{ {
/// <summary> /// <summary>
/// The chunks contained into the Minecraft world /// The chunks contained into the Minecraft world
/// Tuple<int, int>: Tuple<chunkX, chunkZ> /// (int ChunkX, int ChunkZ): chunkX, chunkZ
/// </summary> /// </summary>
private ConcurrentDictionary<Tuple<int, int>, ChunkColumn> chunks = new(); private ConcurrentDictionary<(int ChunkX, int ChunkZ), ChunkColumn> chunks = new();
/// <summary> /// <summary>
/// The dimension info of the world /// The dimension info of the world
@ -49,12 +49,12 @@ namespace MinecraftClient.Mapping
{ {
get get
{ {
chunks.TryGetValue(new(chunkX, chunkZ), out ChunkColumn? chunkColumn); chunks.TryGetValue((chunkX, chunkZ), out ChunkColumn? chunkColumn);
return chunkColumn; return chunkColumn;
} }
set set
{ {
Tuple<int, int> chunkCoord = new(chunkX, chunkZ); var chunkCoord = (chunkX, chunkZ);
if (value is null) if (value is null)
chunks.TryRemove(chunkCoord, out _); chunks.TryRemove(chunkCoord, out _);
else else
@ -361,7 +361,7 @@ namespace MinecraftClient.Mapping
/// <param name="loadCompleted">Whether the ChunkColumn has been fully loaded</param> /// <param name="loadCompleted">Whether the ChunkColumn has been fully loaded</param>
public void StoreChunk(int chunkX, int chunkY, int chunkZ, int chunkColumnSize, Chunk? chunk, bool loadCompleted) public void StoreChunk(int chunkX, int chunkY, int chunkZ, int chunkColumnSize, Chunk? chunk, bool loadCompleted)
{ {
ChunkColumn chunkColumn = chunks.GetOrAdd(new(chunkX, chunkZ), (_) => new(chunkColumnSize)); ChunkColumn chunkColumn = chunks.GetOrAdd((chunkX, chunkZ), (_) => new(chunkColumnSize));
chunkColumn[chunkY] = chunk; chunkColumn[chunkY] = chunk;
if (loadCompleted) if (loadCompleted)
chunkColumn.FullyLoaded = true; chunkColumn.FullyLoaded = true;

View file

@ -4,8 +4,6 @@ MCC.LoadBot(new PacketCadenceCaptureBot());
//MCCScript Extensions //MCCScript Extensions
using System.Threading;
public class PacketCadenceCaptureBot : ChatBot public class PacketCadenceCaptureBot : ChatBot
{ {
private const int CaptureDurationSeconds = 5; private const int CaptureDurationSeconds = 5;

View file

@ -19,6 +19,7 @@ EOF
SERVER_DIR="${1:-}" SERVER_DIR="${1:-}"
MC_VERSION="${2:-}" MC_VERSION="${2:-}"
PROFILE="${3:-}" PROFILE="${3:-}"
SERVER_PORT=""
if [[ -z "$SERVER_DIR" || -z "$MC_VERSION" || -z "$PROFILE" ]]; then if [[ -z "$SERVER_DIR" || -z "$MC_VERSION" || -z "$PROFILE" ]]; then
usage >&2 usage >&2
@ -75,6 +76,22 @@ wait_for_server_ready() {
return 1 return 1
} }
wait_for_rcon_port_free() {
local timeout="${1:-30}"
local elapsed=0
while (( elapsed < timeout )); do
if ! ss -ltn '( sport = :25575 )' 2>/dev/null | grep -Fq ':25575'; then
return 0
fi
sleep 1
((elapsed += 1))
done
echo "Timed out waiting for RCON port 25575 to become free" >&2
return 1
}
kill_other_servers() { kill_other_servers() {
local sessions local sessions
sessions="$(tmux list-sessions 2>/dev/null | awk -F: '/^mc-/{print $1}' || true)" sessions="$(tmux list-sessions 2>/dev/null | awk -F: '/^mc-/{print $1}' || true)"
@ -100,16 +117,18 @@ cleanup() {
fi fi
tmux kill-session -t "$SESSION_NAME" 2>/dev/null || true tmux kill-session -t "$SESSION_NAME" 2>/dev/null || true
wait_for_rcon_port_free 30 || true
} }
trap cleanup EXIT trap cleanup EXIT
prepare_config() { prepare_config() {
cp "$REPO_ROOT/MinecraftClient.ini" "$CFG" MCC_TEST_ACCOUNT_TYPE=mojang MCC_TEST_PASSWORD=- \
bash "$REPO_ROOT/.skills/mcc-integration-testing/scripts/prepare_offline_mcc_config.sh" \
"$REPO_ROOT/MinecraftClient.ini" "$CFG" "$MC_VERSION" CursorBot >/dev/null
sed -i \ sed -i \
-e 's/Account = { Login = "test", Password = "-" }/Account = { Login = "CursorBot", Password = "-" }/' \ -e "s#^Server = .*#Server = { Host = \"localhost\", Port = $SERVER_PORT }#" \
-e "s/MinecraftVersion = \"auto\"/MinecraftVersion = \"$MC_VERSION\"/" \
-e 's/TerrainAndMovements = false/TerrainAndMovements = true/' \ -e 's/TerrainAndMovements = false/TerrainAndMovements = true/' \
-e 's/InventoryHandling = false/InventoryHandling = true/' \ -e 's/InventoryHandling = false/InventoryHandling = true/' \
-e 's/EntityHandling = false/EntityHandling = true/' \ -e 's/EntityHandling = false/EntityHandling = true/' \
@ -195,8 +214,8 @@ modern_mob_and_effects() {
run_server_command "effect give CursorBot minecraft:regeneration 10 1 true" run_server_command "effect give CursorBot minecraft:regeneration 10 1 true"
} }
prepare_config
kill_other_servers kill_other_servers
wait_for_rcon_port_free 30 || true
rm -f "$MCC_LOG" "$INPUT_FILE" rm -f "$MCC_LOG" "$INPUT_FILE"
bash "$REPO_ROOT/.skills/mcc-integration-testing/scripts/ensure_offline_server.sh" "$SERVER_DIR" >/dev/null bash "$REPO_ROOT/.skills/mcc-integration-testing/scripts/ensure_offline_server.sh" "$SERVER_DIR" >/dev/null
@ -206,12 +225,15 @@ fi
mc-start "$SERVER_DIR" >/dev/null mc-start "$SERVER_DIR" >/dev/null
wait_for_server_ready || exit 1 wait_for_server_ready || exit 1
SERVER_PORT="$(bash "$REPO_ROOT/.skills/mcc-integration-testing/scripts/get_server_port.sh" "$SERVER_DIR")"
prepare_config
: > "$INPUT_FILE" : > "$INPUT_FILE"
( (
cd "$REPO_ROOT" cd "$REPO_ROOT"
MCC_FILE_INPUT=1 dotnet run --project MinecraftClient -c Release --no-build -- "$CFG" > "$MCC_LOG" 2>&1 MCC_FILE_INPUT=1 dotnet run --project MinecraftClient -c Release --no-build -- \
"$CFG" CursorBot - "localhost:$SERVER_PORT" > "$MCC_LOG" 2>&1
) & ) &
MCC_PID=$! MCC_PID=$!