public override void OnTick(Entity[] entities) { if (!_horse.IsTamed) { //Log.Debug($"Riding untamed horse {_rideTime}"); if (_rideTime > 100 && !_horse.IsRearing) { _horse.IsRearing = true; _horse.BroadcastSetEntityData(); } else if (_rideTime > 120) { McpeEntityEvent entityEvent = McpeEntityEvent.CreateObject(); entityEvent.runtimeEntityId = _horse.EntityId; entityEvent.eventId = 6; entityEvent.data = 0; _horse.Level.RelayBroadcast(entityEvent); _horse.Unmount(_horse.Rider); } _rideTime++; } else { if (_horse.IsRearing && _horse.IsOnGround) { _horse.IsRearing = false; _horse.BroadcastSetEntityData(); } } }
public bool ShouldStart() { if (_entity.Level.Random.Next(1000) != 0) { return(false); } var coordinates = _entity.KnownPosition; var direction = Vector3.Normalize(coordinates.GetHeadDirection()); BlockCoordinates coord = new Vector3(coordinates.X + direction.X, coordinates.Y, coordinates.Z + direction.Z); var shouldStart = _entity.Level.GetBlock(coord + BlockCoordinates.Down) is Grass || _entity.Level.GetBlock(coord) is TallGrass; if (!shouldStart) { return(false); } _duration = 40; _entity.Velocity *= new Vector3(0, 1, 0); McpeEntityEvent entityEvent = McpeEntityEvent.CreateObject(); entityEvent.entityId = _entity.EntityId; entityEvent.eventId = 10; _entity.Level.RelayBroadcast(entityEvent); return(true); }
public virtual void Kill(Player player) { var msg = McpeEntityEvent.CreateObject(); msg.runtimeEntityId = EntityId; msg.eventId = (byte)3; player.SendPackage(msg); }
public virtual void BroadcastEntityEvent() { var entityEvent = McpeEntityEvent.CreateObject(); entityEvent.runtimeEntityId = EntityId; entityEvent.eventId = (byte)(HealthManager.Health <= 0 ? 3 : 2); Level.RelayBroadcast(entityEvent); }
public virtual void Kill(Level level) { var msg = McpeEntityEvent.CreateObject(); msg.runtimeEntityId = EntityId; msg.eventId = (byte)3; level.RelayBroadcast(msg); }
protected override void OnHitBlock(Block blockCollided) { IsCritical = false; BroadcastSetEntityData(); McpeEntityEvent entityEvent = McpeEntityEvent.CreateObject(); entityEvent.runtimeEntityId = EntityId; entityEvent.eventId = 39; entityEvent.data = 14; Level.RelayBroadcast(entityEvent); }
public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown) { var player = Entity as Player; if (player != null && player.GameMode != GameMode.Survival) { return; } if (CooldownTick > 0) { return; } LastDamageSource = source; LastDamageCause = cause; Health -= damage * 10; if (Health < 0) { OnPlayerTakeHit(new HealthEventArgs(this, source, Entity)); Health = 0; Kill(); return; } if (player != null) { player.HungerManager.IncreaseExhaustion(0.3f); player.SendUpdateAttributes(); player.BroadcastEntityEvent(); } else { var msg = McpeEntityEvent.CreateObject(); msg.entityId = Entity.EntityId; msg.eventId = (byte)(Health <= 0 ? 3 : 2); Entity.Level.RelayBroadcast(msg); } if (source != null) { DoKnockback(source); } CooldownTick = 10; OnPlayerTakeHit(new HealthEventArgs(this, source, Entity)); }
public override void DespawnEntity() { McpeEntityEvent entityEvent = McpeEntityEvent.CreateObject(); entityEvent.runtimeEntityId = EntityId; entityEvent.eventId = 25; entityEvent.data = 0; Level.RelayBroadcast(entityEvent); base.DespawnEntity(); McpeLevelSoundEvent sound = McpeLevelSoundEvent.CreateObject(); sound.soundId = 56; sound.blockId = -1; sound.entityType = 1; sound.position = KnownPosition; Level.RelayBroadcast(sound); }
private void HandleEntityEvent(McpeEntityEvent message) { Log.Debug("Entity Id:" + message.entityId); Log.Debug("Entity Event:" + message.eventId); //if (message.eventId != 0) return; // Should probably broadcast?! switch (message.eventId) { case 9: // Eat food if (GameMode == GameMode.Survival) { FoodItem foodItem = Inventory.GetItemInHand().Item as FoodItem; if (foodItem != null) { foodItem.Consume(this); Inventory.GetItemInHand().Count--; SendPlayerInventory(); } } break; } }
public override void HandleMcpeEntityEvent(McpeEntityEvent message) { UnhandledPackage(message); }
public abstract void HandleMcpeEntityEvent(McpeEntityEvent message);
public override void HandleMcpeEntityEvent(McpeEntityEvent message) { }
public virtual void TakeHit(Entity source, int damage = 1, DamageCause cause = DamageCause.Unknown) { var player = Entity as Player; if (player != null && player.GameMode != GameMode.Survival) { return; } if (CooldownTick > 0) { return; } LastDamageSource = source; LastDamageCause = cause; Health -= damage * 10; if (Health < 0) { Health = 0; } if (player != null) { player.HungerManager.IncreaseExhaustion(0.3f); player.SendUpdateAttributes(); player.BroadcastEntityEvent(); } else { var msg = McpeEntityEvent.CreateObject(); msg.entityId = Entity.EntityId; msg.eventId = (byte)(Health <= 0 ? 3 : 2); Entity.Level.RelayBroadcast(msg); } if (source != null) { double dx = source.KnownPosition.X - Entity.KnownPosition.X; Random rand = new Random(); double dz; for (dz = source.KnownPosition.Z - Entity.KnownPosition.Z; dx *dx + dz *dz < 0.00010; dz = (rand.NextDouble() - rand.NextDouble()) * 0.01D) { dx = (rand.NextDouble() - rand.NextDouble()) * 0.01D; } double knockbackForce = Math.Sqrt(dx * dx + dz * dz); float knockbackMultiplier = 0.4F; //this.motX /= 2.0D; //this.motY /= 2.0D; //this.motZ /= 2.0D; double motX = 0; motX -= dx / knockbackForce * knockbackMultiplier; double motY = knockbackMultiplier; double motZ = 0; motZ -= dz / knockbackForce * knockbackMultiplier; if (motY > 0.4) { motY = 0.4; } Entity.Knockback(new Vector3(motX, motY, motZ)); } CooldownTick = 10; OnPlayerTakeHit(new HealthEventArgs(this, source, Entity)); }
public void HandleMcpeEntityEvent(McpeEntityEvent message) { WritePackage(message); }
public override void DoInteraction(int actionId, Player player) { if (player.IsSneaking) { Inventory.Open(player); return; } var inHand = player.Inventory.GetItemInHand(); if (inHand is ItemSugar || inHand is ItemWheat || inHand is ItemApple || inHand is ItemGoldenCarrot || inHand is ItemGoldenApple || inHand.Id == 170) { // Feeding // Increase temper if (inHand is ItemSugar) { Temper += 3; HealthManager.Regen(1); } else if (inHand is ItemWheat) { Temper += 3; HealthManager.Regen(2); } else if (inHand is ItemApple) { Temper += 3; HealthManager.Regen(3); } else if (inHand is ItemGoldenCarrot) { Temper += 5; HealthManager.Regen(4); } else if (inHand is ItemGoldenApple) { Temper += 10; HealthManager.Regen(10); } else if (inHand.Id == 170) { //Temper += 3; HealthManager.Regen(20); } } else if (IsTamed && !IsSaddled && inHand is ItemSaddle) { // Saddle horse if (!IsSaddled) { Inventory.SetSlot(0, inHand); player.Inventory.RemoveItems(inHand.Id, 1); // Wrong. Should really be item in hand } } else { // Riding if (!IsTamed) { Random random = new Random(); if (random.Next(100) < Temper || player.GameMode == GameMode.Creative) { // Tamed Temper = 100; IsTamed = true; BroadcastSetEntityData(); McpeEntityEvent entityEvent = McpeEntityEvent.CreateObject(); entityEvent.runtimeEntityId = EntityId; entityEvent.eventId = 7; entityEvent.data = 0; Level.RelayBroadcast(entityEvent); } else { Temper += 5; } } Mount(player); } }
public void HandleMcpeEntityEvent(McpeEntityEvent message) { }