Esempio n. 1
0
        public static PersistentContainer Instance(WorldManager world, UniversalCoords coords)
        {
            PersistentContainer container;
            Chunk chunk = world.GetChunk(coords) as Chunk;
            if (chunk == null)
                return null; 
            BlockData.Blocks block = chunk.GetType(coords);
            if (!chunk.Containers.ContainsKey(coords.BlockPackedCoords))
            {
                switch (block)
                {
                    case BlockData.Blocks.Furnace:
                    case BlockData.Blocks.Burning_Furnace:
                        container = new FurnaceContainer();
                        container.Initialize(world, coords);
                        (container as FurnaceContainer).StartBurning();
                        break;
                    case BlockData.Blocks.Dispenser:
                        container = new DispenserContainer();
                        container.Initialize(world, coords);
                        break;
                    case BlockData.Blocks.Chest:
                        // Double chest?
                        if (IsDoubleChest(chunk, coords))
                        {
                            UniversalCoords[] doubleChestCoords = GetDoubleChestCoords(world, coords);
                            if (doubleChestCoords == null)
                                return null;
                            chunk.Containers.TryRemove(doubleChestCoords[0].BlockPackedCoords, out container);
                            chunk.Containers.TryRemove(doubleChestCoords[1].BlockPackedCoords, out container);

                            container = new LargeChestContainer(doubleChestCoords[1]);
                            container.Initialize(world, doubleChestCoords[0]);
                            chunk.Containers.TryAdd(doubleChestCoords[0].BlockPackedCoords, container);
                            chunk.Containers.TryAdd(doubleChestCoords[1].BlockPackedCoords, container);
                        }
                        else
                        {
                            container = new SmallChestContainer();
                            container.Initialize(world, coords);
                        }
                        break;
                    default:
                        return null;
                }
                chunk.Containers.TryAdd(coords.BlockPackedCoords, container);
            }
            else
            {
                chunk.Containers.TryGetValue(coords.BlockPackedCoords, out container);
            }
            return container;
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        public static PersistentContainer Instance(WorldManager world, UniversalCoords coords)
        {
            PersistentContainer container;
            Chunk chunk = world.GetChunk(coords) as Chunk;

            if (chunk == null)
            {
                return(null);
            }
            BlockData.Blocks block = chunk.GetType(coords);
            if (!chunk.Containers.ContainsKey(coords.BlockPackedCoords))
            {
                switch (block)
                {
                case BlockData.Blocks.Furnace:
                case BlockData.Blocks.Burning_Furnace:
                    container = new FurnaceContainer();
                    container.Initialize(world, coords);
                    (container as FurnaceContainer).StartBurning();
                    break;

                case BlockData.Blocks.Dispenser:
                    container = new DispenserContainer();
                    container.Initialize(world, coords);
                    break;

                case BlockData.Blocks.Chest:
                    // Double chest?
                    if (IsDoubleChest(chunk, coords))
                    {
                        UniversalCoords[] doubleChestCoords = GetDoubleChestCoords(world, coords);
                        if (doubleChestCoords == null)
                        {
                            return(null);
                        }
                        chunk.Containers.TryRemove(doubleChestCoords[0].BlockPackedCoords, out container);
                        chunk.Containers.TryRemove(doubleChestCoords[1].BlockPackedCoords, out container);

                        container = new LargeChestContainer(doubleChestCoords[1]);
                        container.Initialize(world, doubleChestCoords[0]);
                        chunk.Containers.TryAdd(doubleChestCoords[0].BlockPackedCoords, container);
                        chunk.Containers.TryAdd(doubleChestCoords[1].BlockPackedCoords, container);
                    }
                    else
                    {
                        container = new SmallChestContainer();
                        container.Initialize(world, coords);
                    }
                    break;

                default:
                    return(null);
                }
                chunk.Containers.TryAdd(coords.BlockPackedCoords, container);
            }
            else
            {
                chunk.Containers.TryGetValue(coords.BlockPackedCoords, out container);
            }
            return(container);
        }