コード例 #1
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            handling = EnumHandHandling.PreventDefault;

            if (api.Side == EnumAppSide.Server)
            {
                var sapi = api as ICoreServerAPI;

                int chunkSize = sapi.WorldManager.ChunkSize;

                int chunkX = (int)byEntity.SidedPos.X / chunkSize;
                int chunkZ = (int)byEntity.SidedPos.Z / chunkSize;

                Vec3d lastOwnedCorpsePos = null;
                int   ownedCorpseCount   = 0;

                int chunksInColum = sapi.WorldManager.MapSizeY / chunkSize;
                for (int i = 0; i < chunksInColum; i++)
                {
                    var chunk = sapi.WorldManager.GetChunk(chunkX, i, chunkZ);
                    foreach (var entity in chunk.Entities)
                    {
                        EntityPlayerCorpse corpseEntity = entity as EntityPlayerCorpse;
                        if (corpseEntity != null)
                        {
                            if (corpseEntity.OwnerUID == (byEntity as EntityPlayer).PlayerUID)
                            {
                                lastOwnedCorpsePos = entity.SidedPos.XYZ;
                                ownedCorpseCount++;
                            }

                            if (byEntity.Controls.Sneak)
                            {
                                string text = corpseEntity.OwnerName + "'s corpse found at " + entity.SidedPos.XYZ;
                                Core.ModLogger.Notification(text);
                                if (Config.Current.DebugMode.Value)
                                {
                                    byEntity.SendMessage(text);
                                }
                            }
                        }
                    }
                }

                if (ownedCorpseCount > 0)
                {
                    particles.MinPos = byEntity.SidedPos.XYZ.Add(0, 1, 0);

                    var relativePos = lastOwnedCorpsePos - byEntity.SidedPos.XYZ.Add(0, 1, 0);
                    particles.MinVelocity = relativePos.ToVec3f() / (particles.LifeLength * 3);
                    particles.AddPos      = particles.MinVelocity.ToVec3d() * 0.1;

                    api.World.SpawnParticles(particles);
                }
                else
                {
                    byEntity.SendMessage(Lang.Get(Code.Domain + ":corpsecompass-corpses-not-found"));
                }
            }
        }