Fixed the requested changes for Terrain Movement. Tested and working.

This commit is contained in:
Milutinke 2022-08-18 20:58:49 +02:00
parent 9f197d415e
commit af6f655d5e
7 changed files with 60 additions and 72 deletions

View file

@ -18,7 +18,7 @@ namespace MinecraftClient.Commands
if (args.Count < 1)
{
string desc = GetCmdDescTranslated();
string desc = GetCmdDescTranslated();
if (handler.GetTerrainEnabled())
handler.Log.Info(getChunkLoadingStatus(handler.GetWorld()));
@ -64,12 +64,10 @@ namespace MinecraftClient.Commands
case "north": direction = Direction.North; break;
case "south": direction = Direction.South; break;
case "center":
{
Location current = handler.GetCurrentLocation();
Location currentCenter = new Location(Math.Floor(current.X) + 0.5, current.Y, Math.Floor(current.Z) + 0.5);
handler.MoveTo(currentCenter, allowDirectTeleport: true);
return Translations.Get("cmd.move.walk", currentCenter, current);
}
Location current = handler.GetCurrentLocation();
Location currentCenter = new Location(Math.Floor(current.X) + 0.5, current.Y, Math.Floor(current.Z) + 0.5);
handler.MoveTo(currentCenter, allowDirectTeleport: true);
return Translations.Get("cmd.move.walk", currentCenter, current);
case "get": return handler.GetCurrentLocation().ToString();
default: return Translations.Get("cmd.look.unknown", args[0]);
}

View file

@ -20,17 +20,17 @@ namespace MinecraftClient.Mapping
/// <summary>
/// Whether piglins shake and transform to zombified piglins.
/// </summary>
public readonly bool piglinSafe;
public readonly bool piglinSafe = false;
/// <summary>
/// When false, compasses spin randomly. When true, nether portals can spawn zombified piglins.
/// When false, compasses spin randomly. When true, nether portals can spawn zombified piglins.
/// </summary>
public readonly bool natural;
public readonly bool natural = true;
/// <summary>
/// How much light the dimension has.
/// </summary>
public readonly float ambientLight;
public readonly float ambientLight = 0.0f;
/// <summary>
@ -42,35 +42,36 @@ namespace MinecraftClient.Mapping
/// <summary>
/// A resource location defining what block tag to use for infiniburn.
/// Value: "" or minecraft resource "minecraft:...".
/// Value above 1.18.2: "#" or minecraft resource "#minecraft:...".
/// Value below 1.18.1: "" or minecraft resource "minecraft:...".
/// </summary>
public readonly string infiniburn;
public readonly string infiniburn = "#minecraft:infiniburn_overworld";
/// <summary>
/// Whether players can charge and use respawn anchors.
/// </summary>
public readonly bool respawnAnchorWorks;
public readonly bool respawnAnchorWorks = false;
/// <summary>
/// Whether the dimension has skylight access or not.
/// </summary>
public readonly bool hasSkylight;
public readonly bool hasSkylight = true;
/// <summary>
/// Whether players can use a bed to sleep.
/// </summary>
public readonly bool bedWorks;
public readonly bool bedWorks = true;
/// <summary>
/// unknown
/// Values: "minecraft:overworld", "minecraft:the_nether", "minecraft:the_end" or something else.
/// </summary>
public readonly string effects;
public readonly string effects = "minecraft:overworld";
/// <summary>
/// Whether players with the Bad Omen effect can cause a raid.
/// </summary>
public readonly bool hasRaids;
public readonly bool hasRaids = true;
/// <summary>
/// The minimum Y level.
@ -78,7 +79,7 @@ namespace MinecraftClient.Mapping
public readonly int minY = 0;
/// <summary>
/// The minimum Y level.
/// The maximum Y level.
/// </summary>
public readonly int maxY = 256;
@ -90,30 +91,36 @@ namespace MinecraftClient.Mapping
/// <summary>
/// The maximum height to which chorus fruits and nether portals can bring players within this dimension.
/// </summary>
public readonly int logicalHeight;
public readonly int logicalHeight = 256;
/// <summary>
/// The multiplier applied to coordinates when traveling to the dimension.
/// </summary>
public readonly double coordinateScale;
public readonly double coordinateScale = 1.0;
/// <summary>
/// Whether the dimensions behaves like the nether (water evaporates and sponges dry) or not. Also causes lava to spread thinner.
/// </summary>
public readonly bool ultrawarm;
public readonly bool ultrawarm = false;
/// <summary>
/// Whether the dimension has a bedrock ceiling or not. When true, causes lava to spread faster.
/// </summary>
public readonly bool hasCeiling;
public readonly bool hasCeiling = false;
/// <summary>
/// Default value used in version below 1.17
/// </summary>
public Dimension()
{
this.Name = "minecraft:overworld";
}
/// <summary>
/// Create from the "Dimension Codec" NBT Tag Compound
/// </summary>
/// <param name="chunkX">ChunkColumn X</param>
/// <param name="chunkY">ChunkColumn Y</param>
/// <returns>chunk at the given location</returns>
/// <param name="name">Dimension name</param>
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
public Dimension(string name, Dictionary<string, object> nbt)
{
if (name == null)

View file

@ -25,11 +25,6 @@ namespace MinecraftClient.Mapping
/// </summary>
public double Z;
/// <summary>
/// Current world: to get the lowest Y coordinate
/// </summary>
public static World world;
/// <summary>
/// Get location with zeroed coordinates
/// </summary>
@ -84,10 +79,7 @@ namespace MinecraftClient.Mapping
{
get
{
if (world.GetDimension() == null)
return (int)Math.Floor(Y / Chunk.SizeY); // below 1.16.2, Y coordinate always start from zero
else
return (int)Math.Floor((Y - world.GetDimension().minY) / Chunk.SizeY);
return (int)Math.Floor((Y - World.GetDimension().minY) / Chunk.SizeY);
}
}

View file

@ -33,8 +33,7 @@ namespace MinecraftClient.Mapping
}
if (!IsOnGround(world, location) && !IsSwimming(world, location))
{
while (!IsOnGround(world, belowFoots) &&
belowFoots.Y >= 1 + (world.GetDimension() == null ? 0 : world.GetDimension().minY))
while (!IsOnGround(world, belowFoots) && belowFoots.Y >= 1 + World.GetDimension().minY)
belowFoots = Move(belowFoots, Direction.Down);
location = Move2Steps(location, belowFoots, ref motionY, true).Dequeue();
}
@ -62,7 +61,7 @@ namespace MinecraftClient.Mapping
}
else
{
foreach (Direction dir in new []{ Direction.East, Direction.West, Direction.North, Direction.South })
foreach (Direction dir in new[] { Direction.East, Direction.West, Direction.North, Direction.South })
if (CanMove(world, location, dir) && IsOnGround(world, Move(location, dir)) && (allowUnsafe || IsSafe(world, Move(location, dir))))
availableMoves.Add(Move(location, dir));
availableMoves.Add(Move(location, Direction.Down));
@ -193,7 +192,7 @@ namespace MinecraftClient.Mapping
: new KeyValuePair<Location, int>(location, int.MaxValue))
.OrderBy(pair => pair.Value).
// Sort for h-score (f-score - g-score) to get smallest distance to goal if f-scores are equal
ThenBy(pair => f_score[pair.Key]-g_score[pair.Key]).First().Key;
ThenBy(pair => f_score[pair.Key] - g_score[pair.Key]).First().Key;
// Only assert a value if it is of actual use later
if (maxOffset > 0 && ClosedSet.Count > 0)
@ -290,7 +289,7 @@ namespace MinecraftClient.Mapping
public static bool IsSafe(World world, Location location)
{
return
//No block that can harm the player
//No block that can harm the player
!world.GetBlock(location).Type.CanHarmPlayers()
&& !world.GetBlock(Move(location, Direction.Up)).Type.CanHarmPlayers()
&& !world.GetBlock(Move(location, Direction.Down)).Type.CanHarmPlayers()

View file

@ -19,7 +19,7 @@ namespace MinecraftClient.Mapping
/// <summary>
/// The dimension info of the world
/// </summary>
private Dimension dimension;
private static Dimension dimension = new Dimension();
/// <summary>
/// Lock for thread safety
@ -29,8 +29,8 @@ namespace MinecraftClient.Mapping
/// <summary>
/// Chunk data parsing progress
/// </summary>
public uint chunkCnt = 0;
public uint chunkLoadNotCompleted = 0;
public int chunkCnt = 0;
public int chunkLoadNotCompleted = 0;
/// <summary>
/// Read, set or unload the specified chunk column
@ -89,28 +89,24 @@ namespace MinecraftClient.Mapping
}
}
public World()
{
Location.world = this;
}
/// <summary>
/// Set dimension type
/// </summary>
/// <param name="name"> The name of the dimension type</param>
/// <param name="nbt">The dimension type (NBT Tag Compound)</param>
public void SetDimension(string name, Dictionary<string, object> nbt)
public static void SetDimension(string name, Dictionary<string, object> nbt)
{
this.dimension = new Dimension(name, nbt);
// will change in 1.19 and above
dimension = new Dimension(name, nbt);
}
/// <summary>
/// Get dimension type
/// Get current dimension
/// </summary>
/// <returns>The chunk column</returns>
public Dimension GetDimension()
/// <returns>Current dimension</returns>
public static Dimension GetDimension()
{
return this.dimension;
return dimension;
}
/// <summary>
@ -211,7 +207,6 @@ namespace MinecraftClient.Mapping
try
{
chunks = new Dictionary<int, Dictionary<int, ChunkColumn>>();
dimension = null;
}
finally
{

View file

@ -332,7 +332,7 @@ namespace MinecraftClient.Protocol.Handlers
currentDimensionName = dataTypes.ReadNextString(packetData); // Dimension Name (World Name) - 1.16 and above
if (protocolversion >= MC1162Version)
handler.GetWorld().SetDimension(currentDimensionName, currentDimensionType);
World.SetDimension(currentDimensionName, currentDimensionType);
if (protocolversion >= MC115Version)
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
@ -391,10 +391,7 @@ namespace MinecraftClient.Protocol.Handlers
dimensionNameInRespawn = dataTypes.ReadNextString(packetData); // Dimension Name (World Name) - 1.16 and above
if (protocolversion >= MC1162Version)
new Task(() =>
{
handler.GetWorld().SetDimension(dimensionNameInRespawn, dimensionTypeInRespawn);
}).Start();
World.SetDimension(dimensionNameInRespawn, dimensionTypeInRespawn);
if (protocolversion < MC114Version)
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
@ -470,12 +467,13 @@ namespace MinecraftClient.Protocol.Handlers
}
int dataSize = dataTypes.ReadNextVarInt(packetData); // Size
Interlocked.Increment(ref handler.GetWorld().chunkCnt);
Interlocked.Increment(ref handler.GetWorld().chunkLoadNotCompleted);
new Task(() =>
{
handler.GetWorld().chunkCnt++;
handler.GetWorld().chunkLoadNotCompleted++;
pTerrain.ProcessChunkColumnData(chunkX, chunkZ, verticalStripBitmask, packetData);
handler.GetWorld().chunkLoadNotCompleted--;
Interlocked.Decrement(ref handler.GetWorld().chunkLoadNotCompleted);
}).Start();
}
else
@ -752,7 +750,8 @@ namespace MinecraftClient.Protocol.Handlers
int chunkZ = dataTypes.ReadNextInt(packetData);
if (handler.GetWorld()[chunkX, chunkZ] != null)
handler.GetWorld().chunkCnt--;
Interlocked.Decrement(ref handler.GetWorld().chunkCnt);
// Warning: It is legal to include unloaded chunks in the UnloadChunk packet. Since chunks that have not been loaded are not recorded, this may result in loading chunks that should be unloaded and inaccurate statistics.
handler.GetWorld()[chunkX, chunkZ] = null;
}

View file

@ -147,10 +147,8 @@ namespace MinecraftClient.Protocol.Handlers
public void ProcessChunkColumnData(int chunkX, int chunkZ, ulong[] verticalStripBitmask, Queue<byte> cache)
{
var world = handler.GetWorld();
if (world.GetDimension() == null)
return;
int chunkColumnSize = (world.GetDimension().height + 15) / 16;
int chunkColumnSize = (World.GetDimension().height + 15) / 16; // Round up
if (protocolversion >= Protocol18Handler.MC117Version)
{