Example #1
0
        public virtual List <IStructBlock> GetNearbyBlocks()
        {
            BoundingBox touchCheckBoundingBox = this.BoundingBox.Contract(new Vector3(0.001, 0.001, 0.001));

            List <IStructBlock> touchedBlocks = new List <IStructBlock>();

            // Notify blocks of collisions with an entity
            UniversalCoords minCoords = UniversalCoords.FromAbsWorld(touchCheckBoundingBox.Minimum.X, touchCheckBoundingBox.Minimum.Y, touchCheckBoundingBox.Minimum.Z);
            UniversalCoords maxCoords = UniversalCoords.FromAbsWorld(touchCheckBoundingBox.Maximum.X, touchCheckBoundingBox.Maximum.Y, touchCheckBoundingBox.Maximum.Z);

            if (this.World.ChunkExists(minCoords) && this.World.ChunkExists(maxCoords))
            {
                for (int x = minCoords.WorldX; x <= maxCoords.WorldX; x++)
                {
                    for (int y = minCoords.WorldY; y <= maxCoords.WorldY; y++)
                    {
                        for (int z = minCoords.WorldZ; z <= maxCoords.WorldZ; z++)
                        {
                            var block = (StructBlock)this.World.GetBlock(x, y, z);
                            touchedBlocks.Add(block);
                        }
                    }
                }
            }
            return(touchedBlocks);
        }
Example #2
0
        protected override void DoDeath(EntityBase killedBy)
        {
            var             killedByMob = killedBy as Mob;
            UniversalCoords coords      = UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z);

            if (killedByMob != null && killedByMob.Type == MobType.Skeleton)
            {
                // If killed by a skeleton drop a music disc
                sbyte count = 1;
                short item;
                if (Server.Rand.Next(2) > 1)
                {
                    item = (short)BlockData.Items.Disc13;
                }
                else
                {
                    item = (short)BlockData.Items.DiscCat;
                }
                Server.DropItem(World, coords, new Interfaces.ItemStack(item, count, 0));
            }
            else
            {
                sbyte count = (sbyte)Server.Rand.Next(2);
                if (count > 0)
                {
                    Server.DropItem(World, coords, new Interfaces.ItemStack((short)BlockData.Items.Gunpowder, count, 0));
                }
            }
            base.DoDeath(killedBy);
        }
Example #3
0
        protected override void DoInteraction(IClient client, IItemInventory item)
        {
            base.DoInteraction(client, item);

            if (client != null && item != null && !ItemHelper.IsVoid(item))
            {
                if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop Red mushroom when sheared
                    sbyte count = 5;

                    var drop = ItemHelper.GetInstance(BlockData.Blocks.Red_Mushroom);
                    drop.Count = count;
                    Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), drop);

                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)BlockData.Items.Bowl)
                {
                    short slot = (short)item.Slot;
                    client.GetOwner().GetInventory().RemoveItem(slot);
                    client.GetOwner().GetInventory().AddItem((short)BlockData.Items.Mushroom_Soup, 1, 0);
                }
                else if (item.Type == (short)BlockData.Items.Bucket)
                {
                    short slot = (short)item.Slot;
                    client.GetOwner().GetInventory().RemoveItem(slot);
                    client.GetOwner().GetInventory().AddItem((short)BlockData.Items.Milk_Bucket, 1, 0);
                }
            }
        }
Example #4
0
        protected override void DoInteraction(IClient client, IItemStack item)
        {
            base.DoInteraction(client, item);

            if (client != null && item != null && !item.IsVoid())
            {
                if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared)
                {
                    // Drop wool when sheared
                    sbyte count = (sbyte)Server.Rand.Next(2, 4);
                    if (count > 0)
                    {
                        Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), new Interfaces.ItemStack((short)BlockData.Blocks.Wool, count, (short)Data.WoolColor));
                    }
                    Data.Sheared = true;

                    SendMetadataUpdate();
                }
                else if (item.Type == (short)BlockData.Items.Ink_Sack)
                {
                    // Set the wool colour of this Sheep based on the item.Durability
                    // Safety check. Values of 16 and higher (color do not exist) may crash the client v1.8.1 and below
                    if (item.Durability >= 0 && item.Durability <= 15)
                    {
                        //this.Data.WoolColor = (WoolColor)Enum.ToObject(typeof(WoolColor), (15 - item.Durability));
                        Data.WoolColor = DyeColorToWoolColor((MetaData.Dyes)Enum.ToObject(typeof(MetaData.Dyes), item.Durability));
                        SendMetadataUpdate();
                    }
                }
            }
        }
Example #5
0
        protected override void DoDeath(EntityBase killedBy)
        {
            var             killedByMob = killedBy as Mob;
            UniversalCoords coords      = UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z);
            ItemInventory   item;

            if (killedByMob != null && killedByMob.Type == MobType.Skeleton)
            {
                // If killed by a skeleton drop a music disc
                sbyte count = 1;

                if (Server.Rand.Next(2) > 1)
                {
                    item = ItemHelper.GetInstance(BlockData.Items.Disc13);
                }
                else
                {
                    item = ItemHelper.GetInstance(BlockData.Items.DiscCat);
                }
                item.Count      = count;
                item.Durability = 0;
                Server.DropItem(World, coords, item);
            }
            else
            {
                sbyte count = (sbyte)Server.Rand.Next(2);
                if (count > 0)
                {
                    item       = ItemHelper.GetInstance(BlockData.Items.Gunpowder);
                    item.Count = count;
                    Server.DropItem(World, coords, item);
                }
            }
            base.DoDeath(killedBy);
        }
Example #6
0
 protected override void DoDeath(EntityBase killedBy)
 {
     Inventory.DropAll(UniversalCoords.FromAbsWorld(Position));
     StopFireBurnTimer();
     StopSuffocationTimer();
     StopDrowningTimer();
 }
Example #7
0
        protected override void OnStop()
        {
            UniversalCoords currentBlockCoords = UniversalCoords.FromAbsWorld(Position);
            byte?           blockId            = World.GetBlockId(currentBlockCoords);

            if (blockId == null)
            {
                return;
            }

            if (BlockHelper.Instance.IsAir((byte)blockId))
            {
                World.Server.DropItem(World, currentBlockCoords, new ItemStack(BlockId, 1));
            }
            else
            {
                UniversalCoords aboveBlockCoords = UniversalCoords.FromWorld(currentBlockCoords.WorldX,
                                                                             currentBlockCoords.WorldY + 1,
                                                                             currentBlockCoords.WorldZ);
                StructBlock aboveBlock = new StructBlock(aboveBlockCoords, BlockId, 0, World);
                BlockHelper.Instance.CreateBlockInstance(BlockId).Spawn(aboveBlock);

                foreach (LivingEntity living in World.Server.GetNearbyLivings(World, aboveBlockCoords))
                {
                    if (Math.Abs(living.Position.X - aboveBlockCoords.WorldX) < 2 &&
                        Math.Abs(living.Position.Z - aboveBlockCoords.WorldZ) < 2 &&
                        Math.Abs(living.Position.Y + living.Height - aboveBlockCoords.WorldY) < 2)
                    {
                        living.CheckSuffocation();
                    }
                }
            }
            base.OnStop();
        }
Example #8
0
        public List <PathCoordinate> CreatePathToCoordinate(EntityBase entityFrom, AbsWorldCoords coordinate, double maxDistance = 24.0)
        {
            PathCoordinate start = GetCoordinateFromCacheOrAdd(entityFrom.BlockPosition);
            PathCoordinate end   = GetCoordinateFromCacheOrAdd(UniversalCoords.FromAbsWorld(coordinate.X - (entityFrom.Width * 0.5), coordinate.Y, coordinate.Z - (entityFrom.Width * 0.5)));
            Size           size  = new Size((int)Math.Floor(entityFrom.Width + 1.0), (int)Math.Floor(entityFrom.Height + 1.0));

            return(GeneratePath(start, end, size, maxDistance));
        }
Example #9
0
 protected override void DoDeath(EntityBase killedBy)
 {
     if (!Data.Sheared)
     {
         Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), new Interfaces.ItemStack((short)BlockData.Blocks.Wool, 1, (short)Data.WoolColor));
     }
     base.DoDeath(killedBy);
 }
Example #10
0
        protected override void DoDeath(EntityBase killedBy)
        {
            sbyte count = (sbyte)Server.Rand.Next(2);

            if (count > 0)
            {
                Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), new Interfaces.ItemStack((short)BlockData.Items.Leather, count, 0));
            }
            base.DoDeath(killedBy);
        }
Example #11
0
 protected override void DoDeath(EntityBase killedBy)
 {
     if (!Data.Sheared)
     {
         var item = ItemHelper.GetInstance(BlockData.Blocks.Wool);
         item.Count      = 1;
         item.Durability = (short)Data.WoolColor;
         Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), item);
     }
     base.DoDeath(killedBy);
 }
Example #12
0
        internal virtual void OnMoveRotateTo(sbyte x, sbyte y, sbyte z)
        {
            UniversalCoords coords = UniversalCoords.FromAbsWorld(Position);

            foreach (Client c in Server.GetNearbyPlayersInternal(World, coords))
            {
                if (!ToSkip(c))
                {
                    c.SendMoveRotateBy(this, x, y, z, PackedYaw, PackedPitch);
                }
            }
        }
Example #13
0
        internal virtual void OnTeleportTo(AbsWorldCoords absCoords)
        {
            UniversalCoords coords = UniversalCoords.FromAbsWorld(absCoords);

            foreach (Client c in Server.GetNearbyPlayersInternal(World, coords))
            {
                if (!ToSkip(c))
                {
                    c.SendTeleportTo(this);
                }
            }
        }
Example #14
0
        protected override void DoDeath(EntityBase killedBy)
        {
            sbyte count = (sbyte)Server.Rand.Next(2);

            if (count > 0)
            {
                var item = ItemHelper.GetInstance(BlockData.Items.Bow_String);
                item.Count = count;
                Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), item);
            }
            base.DoDeath(killedBy);
        }
Example #15
0
        protected override void DoDeath(EntityBase killedBy)
        {
            sbyte count = (sbyte)Server.Rand.Next(2);

            if (count > 0)
            {
                var item = ItemHelper.GetInstance(BlockData.Items.Raw_Porkchop);
                item.Count = count;
                Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), item);
            }
            base.DoDeath(killedBy);
            // TODO: if death by fire drop cooked pork
        }
Example #16
0
        protected override void DoClose()
        {
            base.DoClose();

            // Drop all items from the workbench
            if (_useProvidedDropCoordinates)
            {
                base.DropAll(_DropCoords);
            }
            else
            {
                base.DropAll(UniversalCoords.FromAbsWorld(Owner.Position));
            }
        }
Example #17
0
        protected BaseFallingPhysics(WorldManager world, AbsWorldCoords pos)
        {
            World    = world;
            Position = pos;
            EntityId = world.Server.AllocateEntity();

            CreateEntityPacket entity = new CreateEntityPacket {
                EntityId = EntityId
            };

            World.Server.SendPacketToNearbyPlayers(World,
                                                   UniversalCoords.FromAbsWorld(Position),
                                                   entity);
        }
Example #18
0
        protected override void DoDeath(EntityBase killedBy)
        {
            var             killedByMob = killedBy as Mob;
            UniversalCoords coords      = UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z);
            sbyte           count       = (sbyte)Server.Rand.Next(2);

            if (count > 0)
            {
                ItemInventory itm = ItemHelper.GetInstance(BlockData.Items.EnderPearl);
                itm.Count = count;
                Server.DropItem(World, coords, itm);
            }
            base.DoDeath(killedBy);
        }
Example #19
0
        protected void SendMetadataUpdate(bool notifyYourself = true)
        {
            UniversalCoords coords = UniversalCoords.FromAbsWorld(Position);

            foreach (
                Client c in World.Server.GetNearbyPlayersInternal(World, coords)
                )
            {
                if (ToSkip(c) && !notifyYourself)
                {
                    continue;
                }
                c.SendEntityMetadata(this);
            }
        }
Example #20
0
        public virtual void CheckDrowning()
        {
            if (!CanDrown || IsDead)
            {
                return;
            }
            byte?headBlockId = World.GetBlockId(UniversalCoords.FromAbsWorld(Position.X, Position.Y + Height, Position.Z));

            if (headBlockId != null && BlockHelper.Instance.IsLiquid((byte)headBlockId))
            {
                if (DrowningTimer == null)
                {
                    DrowningTimer = new Timer(Drown, null, 50, 50);
                }
            }
        }
Example #21
0
        protected virtual void Drown(object state)
        {
            byte?headBlockId = World.GetBlockId(UniversalCoords.FromAbsWorld(Position.X, Position.Y + Height, Position.Z));

            if (headBlockId == null || IsDead || !BlockHelper.Instance.IsLiquid((byte)headBlockId) || !CanDrown)
            {
                StopDrowningTimer();
                return;
            }

            if (TicksDrowning >= 240 && TicksDrowning % 20 == 0) // 10+ Seconds underwater
            {
                Damage(DamageCause.Drowning, 2);
            }
            TicksDrowning++;
        }
Example #22
0
        public virtual void CheckSuffocation()
        {
            if (!CanSuffocate || IsDead)
            {
                return;
            }
            byte?headBlockId = World.GetBlockId(UniversalCoords.FromAbsWorld(Position.X, Position.Y + EyeHeight, Position.Z));

            if (headBlockId != null && BlockHelper.Instance.IsOpaque((byte)headBlockId))
            {
                if (SuffocationTimer == null)
                {
                    SuffocationTimer = new Timer(Suffocate, null, 0, 50);
                }
            }
        }
Example #23
0
        protected virtual void Suffocate(object state)
        {
            byte?headBlockId = World.GetBlockId(UniversalCoords.FromAbsWorld(Position.X, Position.Y + EyeHeight, Position.Z));

            if (headBlockId == null || IsDead || !BlockHelper.Instance.IsOpaque((byte)headBlockId) || !CanSuffocate)
            {
                StopSuffocationTimer();
                return;
            }

            if (TicksSuffocating % 10 == 0)
            {
                Damage(DamageCause.Suffocation, 1);
            }
            TicksSuffocating++;
        }
Example #24
0
        internal void UpdatePosition()
        {
            this.Position = new AbsWorldCoords(this.Position.ToVector() + Velocity);
            EntityTeleportPacket et = new EntityTeleportPacket
            {
                EntityId = this.EntityId,
                X        = this.Position.X,
                Y        = this.Position.Y,
                Z        = this.Position.Z,
                Yaw      = this.PackedYaw,
                Pitch    = this.PackedPitch
            };

            World.Server.SendPacketToNearbyPlayers(World,
                                                   UniversalCoords.FromAbsWorld(Position),
                                                   et);
        }
Example #25
0
        private void PickupItem(ItemEntity item)
        {
            if (Server.GetEntityById(item.EntityId) == null)
            {
                return;
            }

            Server.SendPacketToNearbyPlayers(item.World, UniversalCoords.FromAbsWorld(item.Position), new CollectItemPacket
            {
                EntityId = item.EntityId,
                PlayerId = EntityId
            });

            Server.RemoveEntity(item);

            Inventory.AddItem(item.ItemId, item.Count, item.Durability);
        }
Example #26
0
        private void PickupExpOrb(ExpOrbEntity orb)
        {
            if (Server.GetEntityById(orb.EntityId) == null)
            {
                return;
            }

            Server.SendPacketToNearbyPlayers(orb.World, UniversalCoords.FromAbsWorld(orb.Position), new CollectItemPacket
            {
                EntityId = orb.EntityId,
                PlayerId = EntityId
            });

            Server.RemoveEntity(orb);

            AddExperience(orb.Experience);
        }
Example #27
0
        public void Use(IClient iClient, string commandName, string[] tokens)
        {
            Client  client = iClient as Client;
            Vector3 facing = new Vector3(client.Owner.Yaw, client.Owner.Pitch);

            Vector3 start = new Vector3(client.Owner.Position.X, client.Owner.Position.Y + client.Owner.EyeHeight, client.Owner.Position.Z);
            Vector3 end   = facing * 100 + start;

            if (end.Y < 0)
            {
                end   = end * (Math.Abs(end.Y) / start.Y);
                end.Y = 0;
            }

            RayTraceHitBlock hit = client.Owner.World.RayTraceBlocks(new AbsWorldCoords(start), new AbsWorldCoords(end));

            if (hit != null)
            {
                if (tokens.Length == 0)
                {
                }
                else
                {
                    MobType mobType;
                    if (Enum.TryParse <MobType>(tokens[0], true, out mobType))
                    {
                        Mob theMob = MobFactory.Instance.CreateMob(client.Owner.World, client.Server, mobType, null) as Mob;
                        theMob.Position = new AbsWorldCoords(client.Owner.World.FromFace(hit.TargetBlock, hit.FaceHit));
                        client.Server.AddEntity(theMob);
                    }
                    else if (tokens[0] == "update")
                    {
                        UniversalCoords coords = UniversalCoords.FromAbsWorld(client.Owner.Position);
                        foreach (EntityBase entity in client.Server.GetNearbyEntitiesInternal(client.Owner.World, coords))
                        {
                            entity.TeleportTo(entity.Position);
                        }
                    }
                    else
                    {
                        client.SendMessage(String.Format("Unrecognised mob type: '{0}'", tokens[0]));
                    }
                }
            }
        }
Example #28
0
        public virtual void Stop(bool forceStop = false)
        {
            IsPlaying = false;
            BaseFallingPhysics unused = null;

            World.PhysicsBlocks.TryRemove(EntityId, out unused);
            DestroyEntityPacket entity = new DestroyEntityPacket {
                EntitiesCount = 1, EntitiesId = new [] { EntityId }
            };

            World.Server.SendPacketToNearbyPlayers(World,
                                                   UniversalCoords.FromAbsWorld(Position),
                                                   entity);
            if (!forceStop)
            {
                OnStop();
            }
        }
Example #29
0
        /// <summary>
        /// Inaccurate check whether the player is in water. Should use the bounding box.
        /// </summary>
        /// <returns></returns>
        public bool IsInWater()
        {
            var feetBlock = World.GetBlockId(UniversalCoords.FromAbsWorld(Position));
            var headBlock = World.GetBlockId(UniversalCoords.FromAbsWorld(Position.X, Position.Y + 1, Position.Z));

            if (feetBlock == null || headBlock == null)
            {
                return(false);
            }

            if (feetBlock == (byte)BlockData.Blocks.Water || feetBlock == (byte)BlockData.Blocks.Still_Water ||
                feetBlock == (byte)BlockData.Blocks.Lava || feetBlock == (byte)BlockData.Blocks.Still_Lava ||
                headBlock == (byte)BlockData.Blocks.Water || headBlock == (byte)BlockData.Blocks.Still_Water ||
                headBlock == (byte)BlockData.Blocks.Lava || headBlock == (byte)BlockData.Blocks.Still_Lava)
            {
                return(true);
            }
            return(false);
        }
Example #30
0
        public static void HandlePacketAnimation(Client client, AnimationPacket packet)
        {
            Player p = client.Owner;

            UniversalCoords coords = UniversalCoords.FromAbsWorld(p.Position);

            foreach (Client c in p.Server.GetNearbyPlayersInternal(p.World, coords))
            {
                if (c == client)
                {
                    continue;
                }
                c.SendPacket(new AnimationPacket
                {
                    Animation = packet.Animation,
                    PlayerId  = p.EntityId
                });
            }
        }