Add submodule MinecraftProtocolLibrary

This commit is contained in:
BruceChen 2022-12-23 00:50:20 +08:00
parent 87026e1bfb
commit 3f1de66af3
62 changed files with 1093 additions and 450 deletions

View file

@ -49,7 +49,7 @@ namespace MinecraftClient.Commands
private static int DoAnimation(CmdResult r, bool mainhand)
{
McClient handler = CmdResult.currentHandler!;
return r.SetAndReturn(handler.DoAnimation(mainhand ? 1 : 0).Result);
return r.SetAndReturn(handler.DoAnimationAsync(mainhand ? 1 : 0).Result);
}
}
}

View file

@ -57,7 +57,7 @@ namespace MinecraftClient.Commands
private static int DoLeaveBed(CmdResult r)
{
McClient handler = CmdResult.currentHandler!;
return r.SetAndReturn(Translations.cmd_bed_leaving, handler.SendEntityAction(Protocol.EntityActionType.LeaveBed).Result);
return r.SetAndReturn(Translations.cmd_bed_leaving, handler.SendEntityActionAsync(Protocol.EntityActionType.LeaveBed).Result);
}
private static int DoSleepBedWithRadius(CmdResult r, double radius)
@ -113,7 +113,7 @@ namespace MinecraftClient.Commands
return r.SetAndReturn(Status.FailChunkNotLoad,
string.Format(Translations.cmd_move_chunk_not_loaded, bedLocation.X, bedLocation.Y, bedLocation.Z));
if (handler.MoveTo(bedLocation))
if (handler.MoveToAsync(bedLocation).Result)
{
Task.Factory.StartNew(() =>
{
@ -137,7 +137,7 @@ namespace MinecraftClient.Commands
handler.Log.Info(string.Format(Translations.cmd_bed_moving, bedLocation.X, bedLocation.Y, bedLocation.Z));
bool res = handler.PlaceBlock(bedLocation, Direction.Down).Result;
bool res = handler.PlaceBlockAsync(bedLocation, Direction.Down).Result;
handler.Log.Info(string.Format(
Translations.cmd_bed_trying_to_use,
@ -174,7 +174,7 @@ namespace MinecraftClient.Commands
blockCenter.X,
blockCenter.Y,
blockCenter.Z,
handler.PlaceBlock(block, Direction.Down).Result ? Translations.cmd_bed_in : Translations.cmd_bed_not_in
handler.PlaceBlockAsync(block, Direction.Down).Result ? Translations.cmd_bed_in : Translations.cmd_bed_not_in
));
}
}

View file

@ -44,7 +44,7 @@ namespace MinecraftClient.Commands
if (!handler.GetInventoryEnabled())
return r.SetAndReturn(Status.FailNeedInventory);
if (handler.ChangeSlot((short)(slot - 1)).Result)
if (handler.ChangeSlotAsync((short)(slot - 1)).Result)
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_changeSlot_changed, slot));
else
return r.SetAndReturn(Status.Fail, Translations.cmd_changeSlot_fail);

View file

@ -54,7 +54,7 @@ namespace MinecraftClient.Commands
Block block = handler.GetWorld().GetBlock(blockToBreak);
if (block.Type == Material.Air)
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_no_block);
else if (handler.DigBlock(blockToBreak).Result)
else if (handler.DigBlockAsync(blockToBreak).Result)
{
blockToBreak = blockToBreak.ToCenter();
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_dig_dig, blockToBreak.X, blockToBreak.Y, blockToBreak.Z, block.GetTypeString()));
@ -74,7 +74,7 @@ namespace MinecraftClient.Commands
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_too_far);
else if (block.Type == Material.Air)
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_no_block);
else if (handler.DigBlock(blockLoc, lookAtBlock: false).Result)
else if (handler.DigBlockAsync(blockLoc, lookAtBlock: false).Result)
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_dig_dig, blockLoc.X, blockLoc.Y, blockLoc.Z, block.GetTypeString()));
else
return r.SetAndReturn(Status.Fail, Translations.cmd_dig_fail);

View file

@ -58,7 +58,7 @@ namespace MinecraftClient.Commands
var p = inventories[inventoryId];
int[] targetItems = p.SearchItem(itemType);
foreach (int slot in targetItems)
handler.DoWindowAction(inventoryId, slot, WindowActionType.DropItemStack).Wait();
handler.DoWindowActionAsync(inventoryId, slot, WindowActionType.DropItemStack).Wait();
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_dropItem_dropped, Item.GetTypeString(itemType), inventoryId));
}

View file

@ -5,6 +5,7 @@ using System.Text;
using Brigadier.NET;
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
using MinecraftClient.EntityHandler;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
using static MinecraftClient.CommandHandler.CmdResult;
@ -166,12 +167,12 @@ namespace MinecraftClient.Commands
{
if (action == ActionType.Attack)
{
handler.InteractEntity(entity2.Key, InteractType.Attack).Wait();
handler.InteractEntityAsync(entity2.Key, InteractType.Attack).Wait();
actionst = Translations.cmd_entityCmd_attacked;
}
else if (action == ActionType.Use)
{
handler.InteractEntity(entity2.Key, InteractType.Interact).Wait();
handler.InteractEntityAsync(entity2.Key, InteractType.Interact).Wait();
actionst = Translations.cmd_entityCmd_used;
}
actioncount++;
@ -251,7 +252,7 @@ namespace MinecraftClient.Commands
{
sb.Append($"\n [MCC] {Translations.cmd_entityCmd_latency}: {latency}");
}
else if (type == EntityType.Item || type == EntityType.ItemFrame || type == Mapping.EntityType.EyeOfEnder || type == Mapping.EntityType.Egg || type == Mapping.EntityType.EnderPearl || type == Mapping.EntityType.Potion || type == Mapping.EntityType.Fireball || type == Mapping.EntityType.FireworkRocket)
else if (type == EntityType.Item || type == EntityType.ItemFrame || type == EntityType.EyeOfEnder || type == EntityType.Egg || type == EntityType.EnderPearl || type == EntityType.Potion || type == EntityType.Fireball || type == EntityType.FireworkRocket)
{
string? displayName = item.DisplayName;
if (string.IsNullOrEmpty(displayName))
@ -311,10 +312,10 @@ namespace MinecraftClient.Commands
switch (action)
{
case ActionType.Attack:
handler.InteractEntity(entity.ID, InteractType.Attack).Wait();
handler.InteractEntityAsync(entity.ID, InteractType.Attack).Wait();
return Translations.cmd_entityCmd_attacked;
case ActionType.Use:
handler.InteractEntity(entity.ID, InteractType.Interact).Wait();
handler.InteractEntityAsync(entity.ID, InteractType.Interact).Wait();
return Translations.cmd_entityCmd_used;
case ActionType.List:
return GetEntityInfoDetailed(handler, entity);

View file

@ -159,7 +159,7 @@ namespace MinecraftClient.Commands
if (handler.GetGamemode() == 1)
{
if (handler.DoCreativeGive(slot, itemType, count, null).Result)
if (handler.DoCreativeGiveAsync(slot, itemType, count, null).Result)
return r.SetAndReturn(CmdResult.Status.Done, string.Format(Translations.cmd_inventory_creative_done, itemType, count, slot));
else
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_inventory_creative_fail);
@ -178,7 +178,7 @@ namespace MinecraftClient.Commands
if (handler.GetGamemode() == 1)
{
if (handler.DoCreativeGive(slot, ItemType.Null, 0, null).Result)
if (handler.DoCreativeGiveAsync(slot, ItemType.Null, 0, null).Result)
return r.SetAndReturn(CmdResult.Status.Done, string.Format(Translations.cmd_inventory_creative_delete, slot));
else
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_inventory_creative_fail);
@ -279,7 +279,7 @@ namespace MinecraftClient.Commands
if (inventory == null)
return r.SetAndReturn(CmdResult.Status.Fail, string.Format(Translations.cmd_inventory_not_exist, inventoryId));
if (handler.CloseInventory(inventoryId.Value).Result)
if (handler.CloseInventoryAsync(inventoryId.Value).Result)
return r.SetAndReturn(CmdResult.Status.Done, string.Format(Translations.cmd_inventory_close, inventoryId));
else
return r.SetAndReturn(CmdResult.Status.Fail, string.Format(Translations.cmd_inventory_close_fail, inventoryId));
@ -355,7 +355,7 @@ namespace MinecraftClient.Commands
};
handler.Log.Info(string.Format(Translations.cmd_inventory_clicking, keyName, slot, inventoryId));
var task = handler.DoWindowAction(inventoryId.Value, slot, actionType);
var task = handler.DoWindowActionAsync(inventoryId.Value, slot, actionType);
task.Wait();
return r.SetAndReturn(task.Result);
}
@ -381,7 +381,7 @@ namespace MinecraftClient.Commands
if (!inventory.Items.ContainsKey(slot))
return r.SetAndReturn(CmdResult.Status.Fail, string.Format(Translations.cmd_inventory_no_item, slot));
if (handler.DoWindowAction(inventoryId.Value, slot, actionType).Result)
if (handler.DoWindowActionAsync(inventoryId.Value, slot, actionType).Result)
{
if (actionType == WindowActionType.DropItemStack)
return r.SetAndReturn(CmdResult.Status.Done, string.Format(Translations.cmd_inventory_drop_stack, slot));

View file

@ -145,7 +145,7 @@ namespace MinecraftClient.Commands
Location current = handler.GetCurrentLocation();
Location currentCenter = new(Math.Floor(current.X) + 0.5, current.Y, Math.Floor(current.Z) + 0.5);
handler.MoveTo(currentCenter, allowDirectTeleport: true);
handler.MoveToAsync(currentCenter, allowDirectTeleport: true).Wait();
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_move_walk, currentCenter, current));
}
@ -162,7 +162,7 @@ namespace MinecraftClient.Commands
if (Movement.CanMove(handler.GetWorld(), handler.GetCurrentLocation(), direction))
{
if (handler.MoveTo(goal, allowUnsafe: takeRisk))
if (handler.MoveToAsync(goal, allowUnsafe: takeRisk).Result)
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_move_moving, direction.ToString()));
else
return r.SetAndReturn(Status.Fail, takeRisk ? Translations.cmd_move_dir_fail : Translations.cmd_move_suggestforce);
@ -188,8 +188,8 @@ namespace MinecraftClient.Commands
if (takeRisk || Movement.PlayerFitsHere(handler.GetWorld(), goal))
{
if (current.ToFloor() == goal.ToFloor())
handler.MoveTo(goal, allowDirectTeleport: true);
else if (!handler.MoveTo(goal, allowUnsafe: takeRisk))
handler.MoveToAsync(goal, allowDirectTeleport: true).Wait();
else if (!handler.MoveToAsync(goal, allowUnsafe: takeRisk).Result)
return r.SetAndReturn(Status.Fail, takeRisk ? string.Format(Translations.cmd_move_fail, goal) : string.Format(Translations.cmd_move_suggestforce, goal));
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_move_walk, goal, current));
}

View file

@ -39,7 +39,7 @@ namespace MinecraftClient.Commands
private int DoRespawn(CmdResult r)
{
McClient handler = CmdResult.currentHandler!;
handler.SendRespawnPacket().Wait();
handler.SendRespawnPacketAsync().Wait();
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_respawn_done);
}
}

View file

@ -41,7 +41,7 @@ namespace MinecraftClient.Commands
private int DoExecuteScript(CmdResult r, string command, Dictionary<string, object>? localVars)
{
McClient handler = CmdResult.currentHandler!;
handler.BotLoad(new ChatBots.Script(command.Trim(), null, localVars));
handler.BotLoad(new ChatBots.Script(command.Trim(), null, localVars)).Wait();
return r.SetAndReturn(CmdResult.Status.Done);
}
}

View file

@ -37,7 +37,7 @@ namespace MinecraftClient.Commands
private int DoSendText(CmdResult r, string command)
{
McClient handler = CmdResult.currentHandler!;
handler.SendText(command).Wait();
handler.SendTextAsync(command).Wait();
return r.SetAndReturn(CmdResult.Status.Done);
}
}

View file

@ -42,7 +42,7 @@ namespace MinecraftClient.Commands
McClient handler = CmdResult.currentHandler!;
if (sneaking)
{
var result = handler.SendEntityAction(Protocol.EntityActionType.StopSneaking).Result;
var result = handler.SendEntityActionAsync(Protocol.EntityActionType.StopSneaking).Result;
if (result)
sneaking = false;
if (result)
@ -52,7 +52,7 @@ namespace MinecraftClient.Commands
}
else
{
var result = handler.SendEntityAction(Protocol.EntityActionType.StartSneaking).Result;
var result = handler.SendEntityActionAsync(Protocol.EntityActionType.StartSneaking).Result;
if (result)
sneaking = true;
if (result)

View file

@ -43,7 +43,7 @@ namespace MinecraftClient.Commands
if (!handler.GetInventoryEnabled())
return r.SetAndReturn(Status.FailNeedInventory);
handler.UseItemOnHand().Wait();
handler.UseItemOnHandAsync().Wait();
return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use);
}
}

View file

@ -48,7 +48,7 @@ namespace MinecraftClient.Commands
Location current = handler.GetCurrentLocation();
block = block.ToAbsolute(current).ToFloor();
Location blockCenter = block.ToCenter();
bool res = handler.PlaceBlock(block, Direction.Down).Result;
bool res = handler.PlaceBlockAsync(block, Direction.Down).Result;
return r.SetAndReturn(string.Format(Translations.cmd_useblock_use, blockCenter.X, blockCenter.Y, blockCenter.Z, res ? "succeeded" : "failed"), res);
}
}