Esempio n. 1
0
        private void CollectNearbyEntities()
        {
            if (throwStackDelay > 0)
            {
                throwStackDelay--;
                return;
            }

            AxisAlignedBoundingBox collectArea = AABB;

            collectArea.Translate(Position);
            float radius = 0.5f;

            collectArea.Min -= new Vector3(radius, radius, radius);
            collectArea.Max += new Vector3(radius, radius, radius);
            collectArea.CapToWorldBounds();

            PositionChunk minChunk = PositionChunk.CreateFrom(collectArea.Min);
            PositionChunk maxChunk = PositionChunk.CreateFrom(collectArea.Max);
            PositionChunk chunkPos;

            for (int x = minChunk.X; x <= maxChunk.X; x++)
            {
                for (int y = minChunk.Y; y <= maxChunk.Y; y++)
                {
                    for (int z = minChunk.Z; z <= maxChunk.Z; z++)
                    {
                        chunkPos = new PositionChunk(x, y, z);
                        Chunk chunk = World.Instance.GetChunk(chunkPos);
                        foreach (EntityStack stack in chunk.EntitiesInArea(collectArea))
                        {
                            // transfer items
                            Inventory.CollectStack(stack);
                            // if stack is empty remove it
                            if (stack.IsEmpty)
                            {
                                chunk.RemoveEntity(stack);
                            }
                        }
                    }
                }
            }
        }