mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Convert switch statements to expressions and adopt collection expressions
- DirectionExtensions.cs: Convert GetOpposite() to switch expression, use file-scoped namespace, use collection expression for HORIZONTAL - McClient.cs: Convert InteractType switch to expression, use collection expressions for array literals - Protocol18.cs: Replace Array.Empty<byte>() with [], use collection expressions for byte/int array literals - DataTypes.cs: Use collection expression for TAG_End byte array - ChatBot.cs: Use collection expressions for string/char arrays - Location.cs: Use collection expressions and modernize null check Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/milutinke/Minecraft-Console-Client/sessions/4e9bd25b-22c5-47c2-98f9-6025d927b1d6
This commit is contained in:
parent
c5df6a49c6
commit
2ae31e269f
6 changed files with 66 additions and 92 deletions
|
|
@ -1,63 +1,42 @@
|
|||
using System;
|
||||
|
||||
namespace MinecraftClient.Mapping
|
||||
namespace MinecraftClient.Mapping;
|
||||
|
||||
public static class DirectionExtensions
|
||||
{
|
||||
public static class DirectionExtensions
|
||||
public static Direction GetOpposite(this Direction direction) => direction switch
|
||||
{
|
||||
public static Direction GetOpposite(this Direction direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.SouthEast:
|
||||
return Direction.NorthEast;
|
||||
case Direction.SouthWest:
|
||||
return Direction.NorthWest;
|
||||
Direction.SouthEast => Direction.NorthEast,
|
||||
Direction.SouthWest => Direction.NorthWest,
|
||||
Direction.NorthEast => Direction.SouthEast,
|
||||
Direction.NorthWest => Direction.SouthWest,
|
||||
Direction.West => Direction.East,
|
||||
Direction.East => Direction.West,
|
||||
Direction.North => Direction.South,
|
||||
Direction.South => Direction.North,
|
||||
Direction.Down => Direction.Up,
|
||||
Direction.Up => Direction.Down,
|
||||
_ => Direction.Up,
|
||||
};
|
||||
|
||||
case Direction.NorthEast:
|
||||
return Direction.SouthEast;
|
||||
case Direction.NorthWest:
|
||||
return Direction.SouthWest;
|
||||
public static Direction[] HORIZONTAL =
|
||||
[
|
||||
Direction.South,
|
||||
Direction.West,
|
||||
Direction.North,
|
||||
Direction.East,
|
||||
];
|
||||
|
||||
case Direction.West:
|
||||
return Direction.East;
|
||||
case Direction.East:
|
||||
return Direction.West;
|
||||
public static Direction FromRotation(double rotation)
|
||||
{
|
||||
double floor = Math.Floor((rotation / 90.0) + 0.5);
|
||||
int value = (int)floor & 3;
|
||||
|
||||
case Direction.North:
|
||||
return Direction.South;
|
||||
case Direction.South:
|
||||
return Direction.North;
|
||||
return FromHorizontal(value);
|
||||
}
|
||||
|
||||
case Direction.Down:
|
||||
return Direction.Up;
|
||||
case Direction.Up:
|
||||
return Direction.Down;
|
||||
default:
|
||||
return Direction.Up;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Direction[] HORIZONTAL =
|
||||
{
|
||||
Direction.South,
|
||||
Direction.West,
|
||||
Direction.North,
|
||||
Direction.East
|
||||
};
|
||||
|
||||
public static Direction FromRotation(double rotation)
|
||||
{
|
||||
double floor = Math.Floor((rotation / 90.0) + 0.5);
|
||||
int value = (int)floor & 3;
|
||||
|
||||
return FromHorizontal(value);
|
||||
}
|
||||
|
||||
public static Direction FromHorizontal(int value)
|
||||
{
|
||||
return HORIZONTAL[Math.Abs(value % HORIZONTAL.Length)];
|
||||
}
|
||||
public static Direction FromHorizontal(int value)
|
||||
{
|
||||
return HORIZONTAL[Math.Abs(value % HORIZONTAL.Length)];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue