示例#1
0
        public static void LoadContainersFromDisk(Chunk chunk)
        {
            string containerPath = Path.Combine(chunk.World.Folder, ChraftConfig.ContainersFolder, "x" + chunk.Coords.ChunkX + "z" + chunk.Coords.ChunkZ);
            if (!Directory.Exists(containerPath))
                return;
            
            string[] files = Directory.GetFiles(containerPath);

            PersistentContainer container;
            UniversalCoords containerCoords;
            BlockData.Blocks containerType;
            string id;
            int x, y, z, startPos, endPos;
            string coordStr;
            foreach (var file in files)
            {
                coordStr = file.Substring(file.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                startPos = coordStr.IndexOf("x") + 1;
                endPos = coordStr.IndexOf("y");
                if (!Int32.TryParse(coordStr.Substring(startPos, endPos - startPos), out x))
                    continue;
                startPos = endPos + 1;
                endPos = coordStr.IndexOf("z");
                if (!Int32.TryParse(coordStr.Substring(startPos, endPos - startPos), out y))
                    continue;
                startPos = endPos + 1;
                endPos = coordStr.IndexOf(".");
                if (!Int32.TryParse(coordStr.Substring(startPos, endPos - startPos), out z))
                    continue;
                containerCoords = UniversalCoords.FromWorld(x, y, z);
                containerType = chunk.GetType(containerCoords);
                switch (containerType)
                {
                    case BlockData.Blocks.Dispenser:
                        container = new DispenserContainer();
                        container.Initialize(chunk.World, containerCoords);
                        break;
                    case BlockData.Blocks.Furnace:
                    case BlockData.Blocks.Burning_Furnace:
                        container = new FurnaceContainer();
                        container.Initialize(chunk.World, containerCoords);
                        (container as FurnaceContainer).StartBurning();
                        break;
                    default:
                        continue;
                }
                chunk.Containers.TryAdd(containerCoords.BlockPackedCoords, container);
            }
        }
示例#2
0
        public Chunk ProvideChunk(int x, int z, Chunk chunk, bool recalculate)
        {
            Rand.setSeed((long)x * 0x4f9939f508L + (long)z * 0x1ef1565bd5L);
            BiomesForGeneration = World.GetWorldChunkManager().GetBlockGeneratorData(BiomesForGeneration, x << 4, z << 4, 16, 16);
            double[] ad = World.GetWorldChunkManager().Temperatures;
            byte[] data = new byte[32768];
            GenerateTerrain(x, z, data, BiomesForGeneration, ad);
            ReplaceBlocksForBiome(x, z, data, BiomesForGeneration);
            CaveGen.GenerateA(this, World, x, z, data);

            for (int bx = 0; bx < 16; bx++)
            {
                for (int by = 0; by < 128; by++)
                {
                    for (int bz = 0; bz < 16; bz++)
                    {
                        if (data[bx << 11 | bz << 7 | by] == 1)
                        {
                            if (Rand.nextInt(100 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Diamond_Ore;
                            else if (Rand.nextInt(100 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Lapis_Lazuli_Ore;
                            else if (Rand.nextInt(40 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Gold_Ore;
                            else if (Rand.nextInt(10 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Redstone_Ore_Glowing;
                            else if (Rand.nextInt(4 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Iron_Ore;
                            else if (Rand.nextInt(2 * by) == 0) data[bx << 11 | bz << 7 | by] = (byte)BlockData.Blocks.Coal_Ore;
                        }
                        chunk.SetAllBlocks(data);
                    }
                }
            }

            World.AddChunk(chunk);

            for (int bx = 0; bx < 16; bx++)
            {
                for (int by = 0; by < 128; by++)
                {
                    for (int bz = 0; bz < 16; bz++)
                    {
                        // TODO: Consider temperature/biome for trees & cacti.
                        UniversalCoords coords = UniversalCoords.FromBlock(x, z, bx, by, bz);
                        if (by > 0 && chunk.GetType(UniversalCoords.FromWorld(coords.WorldX, coords.WorldY - 1, coords.WorldZ)) == BlockData.Blocks.Grass && Rand.nextInt(140) == 0)
                        {
                            switch (Rand.nextInt(3))
                            {
                                case 0: chunk.GrowTree(coords); break;
                                case 1: chunk.GrowTree(coords, 2); break;
                                case 2: chunk.GrowTree(coords, 1); break;
                            }
                        }

                        //if (by > 63 && chunk.GetType(bx, by - 1, bz) == BlockData.Blocks.Sand && Rand.nextInt(80) == 0)
                        //chunk.PlaceCactus(bx, by, bz);
                    }
                }
            }
            if(recalculate)
            chunk.Recalculate();
            chunk.Save();
            return chunk;
        }