public virtual void HandleMcpeChangeDimension(McpeChangeDimension message) { Thread.Sleep(3000); McpePlayerAction action = McpePlayerAction.CreateObject(); action.runtimeEntityId = Client.EntityId; action.actionId = (int)PlayerAction.DimensionChangeAck; Client.SendPacket(action); }
/// <summary> /// Handles the player action. /// </summary> /// <param name="message">The message.</param> private void HandlePlayerAction(McpePlayerAction message) { Log.DebugFormat("Player action: {0}", message.actionId); Log.DebugFormat("Entity ID: {0}", message.entityId); Log.DebugFormat("Action ID: {0}", message.actionId); Log.DebugFormat("x: {0}", message.x); Log.DebugFormat("y: {0}", message.y); Log.DebugFormat("z: {0}", message.z); Log.DebugFormat("face: {0}", message.face); if (message.entityId != EntityId) { return; } switch (message.actionId) { case 5: // Shoot arrow { if (_itemUseTimer == null) { return; } MetadataSlot itemSlot = Inventory.ItemInHand; Item itemInHand = ItemFactory.GetItem(itemSlot.Value.Id); if (itemInHand == null) { return; // Cheat(?) } _itemUseTimer.Stop(); itemInHand.Release(Level, this, new BlockCoordinates(message.x, message.y, message.z), _itemUseTimer.ElapsedMilliseconds); _itemUseTimer = null; MetadataDictionary metadata = new MetadataDictionary(); metadata[0] = new MetadataByte(0); Level.RelayBroadcast(this, new McpeSetEntityData { entityId = EntityId, metadata = metadata, }); break; } case 7: // Respawn HandleRespawn(null); break; default: return; } }
public void SendPlayerAction(PlayerAction action, BlockCoordinates?coordinates, int?blockFace) { McpePlayerAction packet = McpePlayerAction.CreateObject(); packet.actionId = (int)action; if (coordinates.HasValue) { packet.coordinates = new MiNET.Utils.BlockCoordinates(coordinates.Value.X, coordinates.Value.Y, coordinates.Value.Z); } if (blockFace.HasValue) { packet.face = blockFace.Value; } SendPacket(packet); }
public override void HandleMcpePlayerAction(McpePlayerAction message) { switch (message.actionId) { case (int)PlayerAction.AbortBreak: if (Level is xCoreLevel) { if (((xCoreLevel)Level).Game.Action(message, this)) { base.HandleMcpePlayerAction(message); return; } } break; case (int)PlayerAction.Jump: CooldownTick = 20; break; } base.HandleMcpePlayerAction(message); }
public void HandleMcpePlayerAction(McpePlayerAction message) { }
/// <summary> /// Handles the player action. /// </summary> /// <param name="message">The message.</param> protected virtual void HandlePlayerAction(McpePlayerAction message) { Log.DebugFormat("Player action: {0}", message.actionId); Log.DebugFormat("Entity ID: {0}", message.entityId); Log.DebugFormat("Action ID: {0}", message.actionId); Log.DebugFormat("x: {0}", message.x); Log.DebugFormat("y: {0}", message.y); Log.DebugFormat("z: {0}", message.z); Log.DebugFormat("Face: {0}", message.face); switch ((PlayerAction) message.actionId) { case PlayerAction.StartBreak: break; case PlayerAction.AbortBreak: break; case PlayerAction.StopBreak: break; case PlayerAction.ReleaseItem: if (_itemUseTimer == null) return; Item itemInHand = Inventory.GetItemInHand().Item; if (itemInHand == null) return; // Cheat(?) _itemUseTimer.Stop(); itemInHand.Release(Level, this, new BlockCoordinates(message.x, message.y, message.z), _itemUseTimer.ElapsedMilliseconds); _itemUseTimer = null; break; case PlayerAction.StopSleeping: break; case PlayerAction.Respawn: ThreadPool.QueueUserWorkItem(delegate(object state) { HandleRespawn(null); }); break; case PlayerAction.Jump: break; case PlayerAction.StartSprint: IsSprinting = true; //Speed = 0.15f; //SendSetHealth(); break; case PlayerAction.StopSprint: IsSprinting = false; Speed = 0.1f; SendSetHealth(); break; case PlayerAction.StartSneak: IsSneaking = true; //SendSetHealth(); break; case PlayerAction.StopSneak: IsSneaking = false; //SendSetHealth(); break; case PlayerAction.DimensionChange: break; default: throw new ArgumentOutOfRangeException(); } IsInAction = false; MetadataDictionary metadata = new MetadataDictionary { [0] = GetDataValue() }; var setEntityData = McpeSetEntityData.CreateObject(); setEntityData.entityId = EntityId; setEntityData.metadata = metadata; Level?.RelayBroadcast(this, setEntityData); }
public override void HandleMcpeAddEntity(McpeAddEntity message) { if (Client.IsEmulator) { return; } if (!Client.Entities.ContainsKey(message.entityIdSelf)) { var entity = new Entity(message.entityType, null); entity.EntityId = message.runtimeEntityId; entity.KnownPosition = new PlayerLocation(message.x, message.y, message.z, message.yaw, message.yaw, message.pitch); entity.Velocity = new Vector3(message.speedX, message.speedY, message.speedZ); Client.Entities.TryAdd(entity.EntityId, entity); } Log.DebugFormat("McpeAddEntity Entity ID: {0}", message.entityIdSelf); Log.DebugFormat("McpeAddEntity Runtime Entity ID: {0}", message.runtimeEntityId); Log.DebugFormat("Entity Type: {0}", message.entityType); Log.DebugFormat("X: {0}", message.x); Log.DebugFormat("Y: {0}", message.y); Log.DebugFormat("Z: {0}", message.z); Log.DebugFormat("Yaw: {0}", message.yaw); Log.DebugFormat("Pitch: {0}", message.pitch); Log.DebugFormat("Velocity X: {0}", message.speedX); Log.DebugFormat("Velocity Y: {0}", message.speedY); Log.DebugFormat("Velocity Z: {0}", message.speedZ); Log.DebugFormat("Metadata: {0}", Client.MetadataToCode(message.metadata)); Log.DebugFormat("Links count: {0}", message.links?.Count); if (message.metadata.Contains(0)) { long?value = ((MetadataLong)message.metadata[0])?.Value; if (value != null) { long dataValue = (long)value; Log.Debug($"Bit-array datavalue: dec={dataValue} hex=0x{dataValue:x2}, bin={Convert.ToString(dataValue, 2)}b "); } } if (Log.IsDebugEnabled) { foreach (var attribute in message.attributes) { Log.Debug($"Entity attribute {attribute}"); } } Log.DebugFormat("Links count: {0}", message.links); if (Log.IsDebugEnabled && Client._mobWriter != null) { Client._mobWriter.WriteLine("Entity Type: {0}", message.entityType); Client._mobWriter.Indent++; Client._mobWriter.WriteLine("Metadata: {0}", Client.MetadataToCode(message.metadata)); Client._mobWriter.Indent--; Client._mobWriter.WriteLine(); Client._mobWriter.Flush(); } if (message.entityType == "minecraft:horse") { var id = message.runtimeEntityId; Vector3 pos = new Vector3(message.x, message.y, message.z); Task.Run(BotHelpers.DoWaitForSpawn(Client)) .ContinueWith(t => Task.Delay(3000).Wait()) //.ContinueWith(task => //{ // Log.Warn("Sending jump for player"); // McpeInteract action = McpeInteract.CreateObject(); // action.targetRuntimeEntityId = id; // action.actionId = (int) 3; // SendPackage(action); //}) //.ContinueWith(t => Task.Delay(2000).Wait()) //.ContinueWith(task => //{ // for (int i = 0; i < 10; i++) // { // Log.Warn("Mounting horse"); // McpeInventoryTransaction transaction = McpeInventoryTransaction.CreateObject(); // transaction.transaction = new Transaction() // { // TransactionType = McpeInventoryTransaction.TransactionType.ItemUseOnEntity, // TransactionRecords = new List<TransactionRecord>(), // EntityId = id, // ActionType = 0, // Slot = 0, // Item = new ItemAir(), // //Item = new ItemBlock(new Cobblestone()) { Count = 64 }, // Position = BlockCoordinates.Zero, // FromPosition = CurrentLocation, // ClickPosition = pos, // }; // SendPackage(transaction); // Thread.Sleep(4000); // } //}) .ContinueWith(task => { Log.Warn("Sending sneak for player"); McpePlayerAction action = McpePlayerAction.CreateObject(); action.runtimeEntityId = Client.EntityId; action.actionId = (int)PlayerAction.StartSneak; Client.SendPacket(action); }) .ContinueWith(t => Task.Delay(2000).Wait()) .ContinueWith(task => { Log.Warn("Sending transaction for horse"); var transaction = McpeInventoryTransaction.CreateObject(); transaction.transaction = new ItemUseOnEntityTransaction() { TransactionRecords = new List <TransactionRecord>(), EntityId = id, ActionType = 0, Slot = 0, Item = new ItemAir(), FromPosition = Client.CurrentLocation, ClickPosition = pos, }; Client.SendPacket(transaction); }); } }
public bool Action(McpePlayerAction package, Player player) //готово { return(true); }
/// <summary> /// Handles the player action. /// </summary> /// <param name="message">The message.</param> protected virtual void HandlePlayerAction(McpePlayerAction message) { Log.DebugFormat("Player action: {0}", message.actionId); Log.DebugFormat("Entity ID: {0}", message.entityId); Log.DebugFormat("Action ID: {0}", message.actionId); Log.DebugFormat("x: {0}", message.x); Log.DebugFormat("y: {0}", message.y); Log.DebugFormat("z: {0}", message.z); Log.DebugFormat("Face: {0}", message.face); switch (message.actionId) { case 5: // Shoot arrow { if (_itemUseTimer == null) return; Item itemInHand = Inventory.ItemInHand; if (itemInHand == null) return; // Cheat(?) _itemUseTimer.Stop(); itemInHand.Release(Level, this, new BlockCoordinates(message.x, message.y, message.z), _itemUseTimer.ElapsedMilliseconds); _itemUseTimer = null; MetadataDictionary metadata = new MetadataDictionary(); metadata[0] = new MetadataByte(0); Level.RelayBroadcast(this, new McpeSetEntityData { entityId = EntityId, metadata = metadata, }); break; } case 7: // Respawn ThreadPool.QueueUserWorkItem(delegate(object state) { HandleRespawn(null); }); break; default: return; } }
/// <summary> /// Handles the player action. /// </summary> /// <param name="message">The message.</param> private void HandlePlayerAction(McpePlayerAction message) { Log.DebugFormat("Player action: {0}", message.actionId); Log.DebugFormat("Entity ID: {0}", message.entityId); Log.DebugFormat("Action ID: {0}", message.actionId); Log.DebugFormat("x: {0}", message.x); Log.DebugFormat("y: {0}", message.y); Log.DebugFormat("z: {0}", message.z); Log.DebugFormat("face: {0}", message.face); if (message.entityId != EntityId) return; switch (message.actionId) { case 5: // Shoot arrow { if (_itemUseTimer == null) return; MetadataSlot itemSlot = Inventory.ItemInHand; Item itemInHand = ItemFactory.GetItem(itemSlot.Value.Id); if (itemInHand == null) return; // Cheat(?) _itemUseTimer.Stop(); itemInHand.Release(Level, this, new BlockCoordinates(message.x, message.y, message.z), _itemUseTimer.ElapsedMilliseconds); _itemUseTimer = null; MetadataDictionary metadata = new MetadataDictionary(); metadata[0] = new MetadataByte(0); Level.RelayBroadcast(this, new McpeSetEntityData { entityId = EntityId, metadata = metadata, }); break; } case 7: // Respawn HandleRespawn(null); break; default: return; } }
public void HandleMcpePlayerAction(McpePlayerAction message) { WritePackage(message); }
/// <summary> /// Handles player actions like Start & Stop break /// </summary> /// <param name="message"></param> public override void HandleMcpePlayerAction(McpePlayerAction message) { var action = (PlayerAction)message.actionId; lock (_breakSync) { if (GameMode == GameMode.Creative) { return; } Block block; if (action == PlayerAction.StartBreak) { block = Level.GetBlock(message.coordinates); var inHand = Inventory.GetItemInHand(); var drops = block.GetDrops(inHand); float tooltypeFactor = drops == null || drops.Length == 0 ? 5f : 1.5f; // 1.5 if proper tool var multiplier = 1f; switch (inHand.ItemMaterial) { case ItemMaterial.None: break; case ItemMaterial.Wood: multiplier = 2f; break; case ItemMaterial.Stone: multiplier = 4f; break; case ItemMaterial.Gold: multiplier = 12f; break; case ItemMaterial.Iron: multiplier = 6f; break; case ItemMaterial.Diamond: multiplier = 8f; break; } foreach (var enchantment in inHand.GetEnchantings()) { if (enchantment.Id == EnchantingType.Efficiency && enchantment.Level > 0) { multiplier += MathF.Sqrt(enchantment.Level) + 1; } } if (Effects.TryGetValue(EffectType.Haste, out var effect)) { if (effect is Haste haste && haste.Level > 0f) { multiplier *= 1f + (haste.Level * 0.2f); } } var hardness = block.Hardness; double breakTime = MathF.Ceiling((hardness * tooltypeFactor * 20f)); McpeLevelEvent message1 = McpeLevelEvent.CreateObject(); message1.eventId = 3600; message1.position = message.coordinates; message1.data = (int)((double)ushort.MaxValue / (breakTime / multiplier)); Level.RelayBroadcast(message1); BlockFace face = (BlockFace)message.face; IsBreakingBlock = true; BlockBreakTimer.Restart(); BreakingBlockCoordinates = block.Coordinates; BlockBreakTime = breakTime / multiplier; BreakingFace = face; // Log.Info( // $"Start Breaking block. Hardness: {hardness} | ToolTypeFactor; {tooltypeFactor} | BreakTime: {breakTime} | Multiplier: {multiplier} | BLockBreakTime: {breakTime / multiplier} | IsBreaking: {IsBreakingBlock}"); var blockStartBreak = new BlockStartBreakEvent(this, block); EventDispatcher.DispatchEventAsync(blockStartBreak).Then(result => { if (result.IsCancelled) { SendBlockBreakEnd(block.Coordinates); return; } }); return; } else if (action == PlayerAction.AbortBreak) { var elapsed = BlockBreakTimer.ElapsedMilliseconds; var elapsedTicks = elapsed / 50d; // Log.Info($"!! Abort Break !!! Ticks elapsed: {elapsedTicks} | Required: {BlockBreakTime} | IsBreaking: {IsBreakingBlock}"); block = Level.GetBlock(message.coordinates); if (IsBreakingBlock && BreakingBlockCoordinates == block.Coordinates) { IsBreakingBlock = false; BlockBreakTimer.Reset(); EventDispatcher.DispatchEventAsync(new BlockAbortBreakEvent(this, block)).Then(result => { if (!result.IsCancelled) { SendBlockBreakEnd(block.Coordinates); return; } }); } return; } else if (action == PlayerAction.StopBreak) { var elapsed = BlockBreakTimer.ElapsedMilliseconds; var elapsedTicks = elapsed / 50d; //Log.Info($"## !! Stop Break !!! Ticks elapsed: {elapsedTicks} | Required: {BlockBreakTime} | IsBreaking: {IsBreakingBlock}"); if (IsBreakingBlock) { //BlockFace face = (BlockFace) message.face; if (elapsedTicks >= BlockBreakTime || Math.Abs(elapsedTicks - BlockBreakTime) < 2.5 ) //Give a max time difference of 2.5 ticks. { StopBreak(BreakingBlockCoordinates); } else { } } else { IsBreakingBlock = false; BlockBreakTimer.Reset(); } return; } } base.HandleMcpePlayerAction(message); }