Implement command completion suggestions.

This commit is contained in:
BruceChen 2022-12-06 15:50:17 +08:00
parent 5d2589b10f
commit 84cf749344
115 changed files with 4684 additions and 2695 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using MinecraftClient.Mapping.BlockPalettes;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Mapping
{
@ -115,7 +116,7 @@ namespace MinecraftClient.Mapping
public string GetTypeString()
{
string typeStr = Type.ToString();
string? trans = Protocol.ChatParser.TranslateString("block.minecraft." + typeStr.ToUnderscoreCase());
string? trans = ChatParser.TranslateString("block.minecraft." + typeStr.ToUnderscoreCase());
return string.IsNullOrEmpty(trans) ? typeStr : trans;
}

View file

@ -139,9 +139,9 @@ namespace MinecraftClient.Mapping
try
{
var monsterSpawnLightLevelObj = nbt["monster_spawn_light_level"];
try
{
monsterSpawnMinLightLevel = monsterSpawnMaxLightLevel = Convert.ToInt32(monsterSpawnLightLevelObj);
try
{
monsterSpawnMinLightLevel = monsterSpawnMaxLightLevel = Convert.ToInt32(monsterSpawnLightLevelObj);
}
catch (Exception)
{

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Inventory;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Mapping
{
@ -158,7 +159,7 @@ namespace MinecraftClient.Mapping
public string GetTypeString()
{
string typeStr = Type.ToString();
string? trans = Protocol.ChatParser.TranslateString("entity.minecraft." + typeStr.ToUnderscoreCase());
string? trans = ChatParser.TranslateString("entity.minecraft." + typeStr.ToUnderscoreCase());
return string.IsNullOrEmpty(trans) ? typeStr : trans;
}
}

View file

@ -26,6 +26,15 @@ namespace MinecraftClient.Mapping
/// </summary>
public double Z;
/// <summary>
/// Identifies whether the coordinates are absolute or relative.
/// true for relative coordinates, false for absolute coordinates.
/// X-axis: ((Status & (1 << 0)) > 0)
/// Y-axis: ((Status & (1 << 1)) > 0)
/// Z-axis: ((Status & (1 << 2)) > 0)
/// </summary>
public byte Status;
/// <summary>
/// Create a new location
/// </summary>
@ -34,6 +43,18 @@ namespace MinecraftClient.Mapping
X = x;
Y = y;
Z = z;
Status = 0;
}
/// <summary>
/// Create a new location
/// </summary>
public Location(double x, double y, double z, byte status)
{
X = x;
Y = y;
Z = z;
Status = status;
}
/// <summary>
@ -44,6 +65,7 @@ namespace MinecraftClient.Mapping
X = loc.X;
Y = loc.Y;
Z = loc.Z;
Status = loc.Status;
}
/// <summary>
@ -60,6 +82,19 @@ namespace MinecraftClient.Mapping
X = chunkX * Chunk.SizeX + blockX;
Y = blockY;
Z = chunkZ * Chunk.SizeZ + blockZ;
Status = 0;
}
public Location ToAbsolute(Location based)
{
if ((Status & (1 << 0)) > 0)
X += based.X;
if ((Status & (1 << 1)) > 0)
Y += based.Y;
if ((Status & (1 << 2)) > 0)
Z += based.Z;
Status = 0;
return this;
}
/// <summary>

View file

@ -36,7 +36,7 @@ namespace MinecraftClient.Mapping
{
if (start == end)
return new(false, Location.Zero, Block.Air);
double start_x = MathHelper.Lerp(-1.0E-7, start.X, end.X);
double start_y = MathHelper.Lerp(-1.0E-7, start.Y, end.Y);
double start_z = MathHelper.Lerp(-1.0E-7, start.Z, end.Z);
@ -87,7 +87,7 @@ namespace MinecraftClient.Mapping
res_location.Z += dz_sign;
z_frac += z_step;
}
block = CheckRaycastResult(world, res_location, includeFluids);
if (block.Type != Material.Air)
return new(true, res_location, block);

View file

@ -153,7 +153,7 @@ namespace MinecraftClient.Mapping
/// <param name="block">Block type</param>
/// <param name="radius">Search radius - larger is slower: O^3 complexity</param>
/// <returns>Block matching the specified block type</returns>
public List<Location> FindBlock(Location from, Material block, int radius)
public List<Location> FindBlock(Location from, Material block, double radius)
{
return FindBlock(from, block, radius, radius, radius);
}
@ -167,7 +167,7 @@ namespace MinecraftClient.Mapping
/// <param name="radiusy">Search radius on the Y axis</param>
/// <param name="radiusz">Search radius on the Z axis</param>
/// <returns>Block matching the specified block type</returns>
public List<Location> FindBlock(Location from, Material block, int radiusx, int radiusy, int radiusz)
public List<Location> FindBlock(Location from, Material block, double radiusx, double radiusy, double radiusz)
{
Location minPoint = new Location(from.X - radiusx, from.Y - radiusy, from.Z - radiusz);
Location maxPoint = new Location(from.X + radiusx, from.Y + radiusy, from.Z + radiusz);