Exemple #1
0
        /// <summary>
        /// 创建特殊复制文件
        /// </summary>
        /// <param name="player"></param>
        /// <param name="directory"></param>
        /// <param name="path"></param>
        /// <param name="Start"></param>
        /// <param name="End"></param>
        public static void CreateSpecialCopy(CreatorAPI creatorAPI, string path, Point3 Start, Point3 End)
        {
            CreatorMain.Math.StartEnd(ref Start, ref End);
            FileStream    fileStream    = new FileStream(path, FileMode.Create);
            List <Entity> blockEntities = new List <Entity>();
            List <Entity> entities      = new List <Entity>();
            string        data          = "";

            data += $"{Start.X - End.X},{Start.Y - End.Y},{Start.Z - End.Z}";
            for (int x = End.X; x <= Start.X; x++)
            {
                for (int y = End.Y; y <= Start.Y; y++)
                {
                    for (int z = End.Z; z <= Start.Z; z++)
                    {
                        if (GameManager.Project.FindSubsystem <SubsystemBlockEntities>().GetBlockEntity(x, y, z) != null)
                        {
                            blockEntities.Add(GameManager.Project.FindSubsystem <SubsystemBlockEntities>().GetBlockEntity(x, y, z).Entity);
                        }
                        data += "|" + GameManager.Project.FindSubsystem <SubsystemTerrain>(true).Terrain.GetCellValueFast(x, y, z);
                    }
                }
            }
            foreach (ComponentCreature current in GameManager.Project.FindSubsystem <SubsystemCreatureSpawn>(true).Creatures)
            {
                if (current.DisplayName != "Male Player" && current.DisplayName != "Female Player")
                {
                    Vector3 vector3 = current.ComponentBody.Position;
                    if (vector3.X <= Start.X && vector3.X >= End.X && vector3.Y <= Start.Y && vector3.Y >= End.Y && vector3.Z <= Start.Z && vector3.Z >= End.Z)
                    {
                        entities.Add(current.Entity);
                    }
                }
            }
            data += "\nBlockEntity";
            foreach (Entity entity in blockEntities)
            {
                ComponentBlockEntity componentBlockEntity = entity.FindComponent <ComponentBlockEntity>();
                if (componentBlockEntity != null)
                {
                    Point3 point3   = componentBlockEntity.Coordinates;
                    string typeName = "Chest";
                    if (entity.FindComponent <ComponentDispenser>() != null)
                    {
                        typeName = "Dispenser";
                    }
                    else if (entity.FindComponent <ComponentFurnace>() != null)
                    {
                        typeName = "Furnace";
                    }
                    else if (entity.FindComponent <ComponentCraftingTable>() != null)
                    {
                        typeName = "CraftingTable";
                    }
                    else
                    {
                        throw new Exception("检测到一个无法识别的方块实体,现在电路元件暂时还不能识别");
                    }
                    data += $"|{typeName}\t{point3.X - End.X},{ point3.Y - End.Y},{point3.Z - End.Z}";
                    ComponentInventoryBase blockEntityInventoryBase = entity.FindComponent <ComponentInventoryBase>();
                    if (blockEntityInventoryBase != null)
                    {
                        for (int i = 0; i < blockEntityInventoryBase.SlotsCount; i++)
                        {
                            int slotValue = blockEntityInventoryBase.GetSlotValue(i);
                            int slotCount = blockEntityInventoryBase.GetSlotCount(i);
                            if (slotValue != 0 && slotCount > 0)
                            {
                                data += $"\t{slotValue}:{slotCount}";
                            }
                        }
                    }
                }
            }
            data += "\nEntity";
            foreach (Entity entity in entities)
            {
                ComponentCreature creature = entity.FindComponent <ComponentCreature>();
                Vector3           vector3  = creature.ComponentBody.Position;
                data += $"|{creature.DisplayName}\t{vector3.X - End.X},{ vector3.Y - End.Y},{vector3.Z - End.Z}";
                ComponentInventoryBase EntityInventoryBase = entity.FindComponent <ComponentInventoryBase>();
                if (EntityInventoryBase != null)
                {
                    for (int i = 0; i < EntityInventoryBase.SlotsCount; i++)
                    {
                        int slotValue = EntityInventoryBase.GetSlotValue(i);
                        int slotCount = EntityInventoryBase.GetSlotCount(i);
                        if (slotValue != 0 && slotCount > 0)
                        {
                            data += $"\t{slotValue}:{slotCount}";
                        }
                    }
                }
            }
            fileStream.Write(Encoding.UTF8.GetBytes(data), 0, Encoding.UTF8.GetBytes(data).Length);
            fileStream.Dispose();
            creatorAPI.componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage($"复制成功", true, true);
        }