Fix xxx.Parse

This commit is contained in:
BruceChen 2022-10-04 11:53:07 +08:00
parent ccb4ce51cc
commit 53898f3446
21 changed files with 71 additions and 44 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using MinecraftClient.Mapping;
@ -30,7 +31,7 @@ namespace MinecraftClient.Commands
{
if (args.Length == 2)
{
if (!int.TryParse(args[1], out int radius))
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int radius))
return CmdUsage;
handler.GetLogger().Info(Translations.TryGet("cmd.bed.searching", radius));

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using MinecraftClient.Mapping;
@ -36,7 +37,10 @@ namespace MinecraftClient.Commands
{
sb.Append("Marked location: ");
if (args.Length == 1 + 3)
sb.Append(String.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}, ", double.Parse(args[1]), double.Parse(args[2]), double.Parse(args[3])));
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)));
sb.Append(String.Format("chunk: ({0}, {1}).\n", markChunkX, markChunkZ));
}
@ -230,14 +234,18 @@ namespace MinecraftClient.Commands
int chunkX, chunkZ;
if (args.Length == 1 + 3)
{
Location pos = new(double.Parse(args[1]), double.Parse(args[2]), double.Parse(args[3]));
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)
);
chunkX = pos.ChunkX;
chunkZ = pos.ChunkZ;
}
else if (args.Length == 1 + 2)
{
chunkX = int.Parse(args[1]);
chunkZ = int.Parse(args[2]);
chunkX = int.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture);
chunkZ = int.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture);
}
else
return null;

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
@ -20,7 +21,7 @@ namespace MinecraftClient.Commands
{
try
{
int entityID = int.Parse(args[0]);
int entityID = int.Parse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture);
if (entityID != 0)
{
if (handler.GetEntities().ContainsKey(entityID))

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using MinecraftClient.Inventory;
@ -24,14 +25,14 @@ namespace MinecraftClient.Commands
{
if (args.Length >= 4)
{
if (!int.TryParse(args[1], out int slot))
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
if (Enum.TryParse(args[2], true, out ItemType itemType))
{
if (handler.GetGamemode() == 1)
{
if (!int.TryParse(args[3], out int count))
if (!int.TryParse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture, out int count))
return GetCmdDescTranslated();
if (handler.DoCreativeGive(slot, itemType, count, null))
@ -52,7 +53,7 @@ namespace MinecraftClient.Commands
{
if (args.Length >= 2)
{
if (!int.TryParse(args[1], out int slot))
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
if (handler.GetGamemode() == 1)
@ -105,7 +106,7 @@ namespace MinecraftClient.Commands
bool shouldUseItemCount = args.Length >= 3;
int itemCount = 0;
if (shouldUseItemCount && !int.TryParse(args[2], out itemCount))
if (shouldUseItemCount && !int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out itemCount))
return GetCmdDescTranslated();
Dictionary<int, Container> inventories = handler.GetInventories();
@ -162,7 +163,7 @@ namespace MinecraftClient.Commands
else
return GetHelp();
}
else if (!int.TryParse(args[0], out inventoryId))
else if (!int.TryParse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture, out inventoryId))
return GetCmdDescTranslated();
Container? inventory = handler.GetInventory(inventoryId);
@ -205,7 +206,7 @@ namespace MinecraftClient.Commands
}
else if (action == "click" && args.Length >= 3)
{
if (!int.TryParse(args[2], out int slot))
if (!int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
WindowActionType actionType = WindowActionType.LeftClick;
@ -224,7 +225,7 @@ namespace MinecraftClient.Commands
}
else if (action == "shiftclick" && args.Length >= 3)
{
if (!int.TryParse(args[2], out int slot))
if (!int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
if (!handler.DoWindowAction(inventoryId, slot, WindowActionType.ShiftClick))
@ -234,7 +235,7 @@ namespace MinecraftClient.Commands
}
else if (action == "drop" && args.Length >= 3)
{
if (!int.TryParse(args[2], out int slot))
if (!int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
// check item exist

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using MinecraftClient.Mapping;
namespace MinecraftClient.Commands
@ -50,8 +51,8 @@ namespace MinecraftClient.Commands
{
try
{
float yaw = float.Parse(args[0]);
float pitch = float.Parse(args[1]);
float yaw = float.Parse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture);
float pitch = float.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture);
handler.UpdateLocation(handler.GetCurrentLocation(), yaw, pitch);
return Translations.Get("cmd.look.at", yaw.ToString("0.00"), pitch.ToString("0.00"));