예제 #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;
        }
예제 #2
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);
        }