public static Action <Task, string> DoSendCommand(MiNetClient client) { Action <Task, string> doUseItem = (t, command) => { //McpeCommandRequest commandStep = McpeCommandRequest.CreateObject(); //commandStep.commandName = "fill"; //commandStep.commandOverload = "replace"; //commandStep.unknown1 = 0; //commandStep.currentStep = 0; //commandStep.isOutput = false; //commandStep.clientId = client.ClientId; ////commandStep.commandInputJson = "{\n \"tileName\" : \"dirt\",\n \"from\" : {\n \"x\" : 0,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 0,\n \"zrelative\" : false\n },\n \"to\" : {\n \"x\" : 10,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 10,\n \"zrelative\" : false\n }\n}\n"; //commandStep.commandInputJson = "{\n \"from\" : {\n \"x\" : 0,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 0,\n \"zrelative\" : false\n },\n \"tileName\" : \"dirt\",\n \"to\" : {\n \"x\" : 10,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 10,\n \"zrelative\" : false\n }\n}\n"; //// "commandInputJson": "{\n \"from\" : {\n \"x\" : 0,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 0,\n \"zrelative\" : false\n },\n \"tileName\" : \"dirt\",\n \"to\" : {\n \"x\" : 10,\n \"xrelative\" : false,\n \"y\" : 10,\n \"yrelative\" : false,\n \"z\" : 10,\n \"zrelative\" : false\n }\n}\n", ////commandStep.commandInputJson = "null\n"; //commandStep.commandOutputJson = "null\n"; //commandStep.unknown7 = 0; //commandStep.unknown8 = 0; //commandStep.entityIdSelf = client.NetworkEntityId; ////Log.Error($"Entity ID used={commandStep.entityIdSelf}\n{Package.HexDump(commandStep.Encode())}"); //client.SendPackage(commandStep); McpeCommandRequest request = new McpeCommandRequest(); request.command = command; request.unknownUuid = new UUID(Guid.NewGuid().ToString()); client.SendPacket(request); }; return(doUseItem); }
public static Action <Task, Item, int> DoMobEquipment(MiNetClient client) { Action <Task, Item, int> doMobEquipmentTask = (t, item, selectedSlot) => { McpeMobEquipment message = new McpeMobEquipment(); message.runtimeEntityId = client.EntityId; message.item = item; message.selectedSlot = (byte)selectedSlot; message.slot = (byte)(selectedSlot + 9); client.SendPacket(message); }; return(doMobEquipmentTask); }
public static Action <Task, PlayerLocation> DoMoveTo(MiNetClient client) { Action <Task, PlayerLocation> doMoveTo = (t, loc) => { Vector3 originalPosition = client.CurrentLocation.ToVector3(); Vector3 targetPosition = loc.ToVector3(); PlayerLocation lookAtPos = LookAt(originalPosition + new Vector3(0, 1.62f, 0), targetPosition); { // First just rotate towards target pos McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject(); movePlayerPacket.runtimeEntityId = client.EntityId; movePlayerPacket.x = client.CurrentLocation.X; movePlayerPacket.y = client.CurrentLocation.Y; movePlayerPacket.z = client.CurrentLocation.Z; movePlayerPacket.yaw = lookAtPos.Yaw; movePlayerPacket.pitch = lookAtPos.Pitch; movePlayerPacket.headYaw = lookAtPos.HeadYaw; } float lenght = Math.Abs((originalPosition - targetPosition).Length()); float stepLen = 0.5f; float weight; while (true) { if (Math.Abs((targetPosition - client.CurrentLocation.ToVector3()).Length()) > stepLen) { float lenLeft = Math.Abs((client.CurrentLocation.ToVector3() - targetPosition).Length()); weight = Math.Abs((float)((lenLeft - stepLen) / lenght)); client.CurrentLocation = new PlayerLocation(Vector3.Lerp(originalPosition, targetPosition, 1 - weight)); McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject(); movePlayerPacket.runtimeEntityId = client.EntityId; movePlayerPacket.x = client.CurrentLocation.X; movePlayerPacket.y = client.CurrentLocation.Y; movePlayerPacket.z = client.CurrentLocation.Z; movePlayerPacket.yaw = lookAtPos.Yaw; movePlayerPacket.pitch = lookAtPos.Pitch; movePlayerPacket.headYaw = lookAtPos.HeadYaw; client.SendPacket(movePlayerPacket); Thread.Sleep(50); continue; } { client.CurrentLocation = new PlayerLocation(targetPosition); McpeMovePlayer movePlayerPacket = McpeMovePlayer.CreateObject(); movePlayerPacket.runtimeEntityId = client.EntityId; movePlayerPacket.x = client.CurrentLocation.X; movePlayerPacket.y = client.CurrentLocation.Y; movePlayerPacket.z = client.CurrentLocation.Z; movePlayerPacket.yaw = lookAtPos.Yaw; movePlayerPacket.pitch = lookAtPos.Pitch; movePlayerPacket.headYaw = lookAtPos.HeadYaw; client.SendPacket(movePlayerPacket); } break; } }; return(doMoveTo); }