Esempio n. 1
0
        public override void GenerateLandscape(Chunk chunk, BlockOffset blockOffset)
        {
            Vector3 coord = chunk.GetAbsPosition(blockOffset);

            float height = _landScapeHeight - _noiseLandscape.GetSimplexFractal(coord.X, coord.Z) * (_heightGain.GetSimplexFractal(coord.X, coord.Z) * 50);

            IBlock block = new BlockAir();

            if (coord.Y <= height)
            {
                block = new BlockGrass();
            }

            if ((coord.Y <= height - 1) && (coord.Y > height - 5))
            {
                block = new BlockDirt();
            }

            if (coord.Y <= height - 5)
            {
                block = new BlockStone();
            }

            chunk.SetBlock(blockOffset, block);
        }
Esempio n. 2
0
    public override Block BuildBlock(Vector3Int pos)
    {
        Block newBlock = null;


        float noise = (MyUtil.Get3DNoise(pos.x, pos.y, pos.z, frequency,
                                         octave, persistence) + 1.0f) * 0.5f;

        noise = Mathf.Clamp01(noise);

        if (noise <= blockRate)
        {
            newBlock = new Block();
        }
        else if (noise <= desertRate)
        {
            newBlock = new BlockDesert();
        }
        else if (noise <= grassRate)
        {
            newBlock = new BlockGrass();
        }
        else if (noise <= cloudRate)
        {
            newBlock = new BlockCloud();
        }
        else
        {
            newBlock = new BlockAir();
        }

        return(newBlock);
    }
Esempio n. 3
0
    void Start()
    {
        filter = gameObject.GetComponent<MeshFilter>();
        coll = gameObject.GetComponent<MeshCollider>();

        //past here is just to set up an example chunk
        blocks = new Block[chunkSize, chunkSize, chunkSize];

        for (int x = 0; x < chunkSize; x++)
        {
            for (int y = 0; y < chunkSize; y++)
            {
                for (int z = 0; z < chunkSize; z++)
                {
                    blocks[x, y, z] = new BlockAir();
                }
            }
        }

        blocks[1, 1, 1] = new Block();
        blocks[1, 2, 1] = new Block();
        blocks[1, 2, 2] = new Block();
        blocks[2, 2, 2] = new Block();

        UpdateChunk();
    }
Esempio n. 4
0
    public override Block BuildBlock(Vector3Int pos)
    {
        Block newBlock = null;

        if (blockType == FillArea.BlockType.BLOCK)
        {
            newBlock = new Block();
        }
        else if (blockType == FillArea.BlockType.GRASS)
        {
            newBlock = new BlockGrass();
        }
        else if (blockType == FillArea.BlockType.DESERT)
        {
            newBlock = new BlockDesert();
        }
        else if (blockType == FillArea.BlockType.CLOUD)
        {
            newBlock = new BlockCloud();
        }
        else if (blockType == FillArea.BlockType.WATER)
        {
            newBlock = new BlockWater();
        }
        else
        {
            newBlock = new BlockAir();
        }

        return(newBlock);
    }
Esempio n. 5
0
    /** Instantiate all block types and store them in the array */
    static Block()
    {
        blocks          = new Block[ushort.MaxValue + 1];
        blocks[AIR]     = new BlockAir();
        blocks[BEDROCK] = new BlockBedrock();
        for (uint i = 0; i < STONE.Length; i++)
        {
            blocks[STONE[i]] = new BlockStone(i);
        }
        blocks[DIRT]       = new BlockDirt();
        blocks[GRASS]      = new BlockGrass();
        blocks[ROCKY_DIRT] = new BlockDirtStone();
        blocks[SAND]       = new BlockSand();
        for (uint i = 0; i < WATER.Length; i++)
        {
            blocks[WATER[i]] = new BlockWater(i);
        }

        for (int i = 0; i < blocks.Length; i++)
        {
            if (blocks[i] != null)
            {
                blocks[i].id = (ushort)i;
            }
        }
    }
Esempio n. 6
0
    /**
     *  @brief  구름 블럭을 생성한다.
     *  @return 만들어진 지형을 반환한다.
     */
    private Block CreateBlock(Vector3Int worldPos)
    {
        Block newBlock = null;
        var   info     = planetInfo.cloudInfo;

        //구름의 높이 밀도
        float heightDensity = info.radius;

        heightDensity -= info.chunkSize * (1 - info.densityHeight);

        //heightDensity 내인 경우 노이즈 함수를 이용해 구름 생성
        if (MyUtil.IsCubeInRange(worldPos, 1, heightDensity) != 0)
        {
            float noise = (MyUtil.Get3DNoise(worldPos.x, worldPos.y, worldPos.z, info.frequency,
                                             info.octave, info.persistence) + 1.0f) * 0.5f;

            //구름의 너비 밀도
            if (noise < info.densityWidth)
            {
                newBlock = new BlockCloud();
            }
        }

        if (newBlock == null)
        {
            newBlock = new BlockAir();
        }

        return(newBlock);
    }
Esempio n. 7
0
    /**
     *  @brief  지형 블럭을 생성한다.
     *  @return 만들어진 지형을 반환한다.
     */
    private Block CreateBlock(Vector3Int worldPos)
    {
        Block newBlock = null;
        var   info     = planetInfo.terrainInfo;

        float coreRange = info.radius * info.coreRate;

        //코어의 표면은 블럭으로 생성
        int isInVertCnt = MyUtil.IsCubeInRange(worldPos, 1, coreRange);

        if (isInVertCnt > 0 && isInVertCnt < 8)
        {
            newBlock        = new Block();
            newBlock.isLock = true;
        }
        //코어 외부는 Mode에 따라 함수를 통해 생성
        else if (isInVertCnt == 0)
        {
            if (MyUtil.GetSNoise(worldPos.x, worldPos.y, worldPos.z, 0.05f, 50) > 20)
            {
                float noise = (MyUtil.Get3DNoise(worldPos.x, worldPos.y, worldPos.z, info.frequency,
                                                 info.octave, info.persistence) + 1.0f) * 0.5f;
                //int holeChance = MyUtil.GetSNoise(worldPos.x, worldPos.y, worldPos.z, 0.05f, 50);

                noise = Mathf.Clamp01(noise);

                if (noise <= info.blockRate)
                {
                    newBlock = new Block();
                }
                else if (noise <= info.desertRate)
                {
                    newBlock = new BlockDesert();
                }
                else if (noise <= info.grassRate)
                {
                    newBlock = new BlockGrass();
                }
            }
        }

        //Ocean BLock
        if (newBlock == null)
        {
            float height = Mathf.Max(Mathf.Abs(worldPos.x + 0.5f), Mathf.Abs(worldPos.y + 0.5f), Mathf.Abs(worldPos.z + 0.5f));

            if (height <= info.oceanHeight && height > info.oceanHeight - info.oceanDepth)
            {
                newBlock        = new BlockWater();
                newBlock.isLock = true;
            }
        }

        if (newBlock == null)
        {
            newBlock = new BlockAir();
        }

        return(newBlock);
    }
 public void Init()
 {
     //seed = UnityEngine.Random.Range(0, int.MaxValue);
     BLOCK_AIR   = new BlockAir();
     BLOCK_STONE = new BlockStone();
     BLOCK_DIRT  = new BlockDirt();
     BLOCK_GRASS = new BlockGrass();
     BLOCK_LEAF  = new BlockLeaf();
     BLOCK_WOOD  = new BlockWood();
 }
Esempio n. 9
0
    void Start()
    {
        _filter   = gameObject.GetComponent <MeshFilter>();
        _collider = gameObject.GetComponent <MeshCollider>();

        _blocks = new Block[ChunkSize, ChunkSize, ChunkSize];

        for (var x = 0; x < ChunkSize; x++)
        {
            for (var y = 0; y < ChunkSize; y++)
            {
                for (var z = 0; z < ChunkSize; z++)
                {
                    _blocks[x, y, z] = new BlockAir();
                }
            }
        }

        _blocks[3, 5, 2] = new Block();
        _blocks[4, 5, 2] = new BlockGrass();
        UpdateChunk();
    }
Esempio n. 10
0
    //Gets a block at the given world position
    public Block GetBlock(int x, int y, int z)
    {
        Block retBlock       = null;
        Chunk containerChunk = GetChunk(x, y, z);

        //if no chunk is found, the block is assumed to be air
        if (containerChunk != null)
        {
            Block block = containerChunk.GetBlock(
                x - containerChunk.pos.x,
                y - containerChunk.pos.y,
                z - containerChunk.pos.z);

            retBlock = block;
        }
        else
        {
            retBlock = new BlockAir();
        }

        return(retBlock);
    }
Esempio n. 11
0
        public void HandleWorldAction(MinecraftPacket packet)
        {
            switch (packet)
            {
            case CP1BPlayerDigging digging:
                bool IsLegal(double x1, double y1, double z1, double x2, double y2, double z2)
                {
                    return(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2) + Math.Pow(z2 - z1, 2)) <= 6.0);
                }

                BlockBase block = Parent.GetBlock(digging.Location.X, digging.Location.Y, digging.Location.Z);
                SP07AcknowledgePlayerDigging acknowledgePlayerDigging;

                if (block == null)
                {
                    acknowledgePlayerDigging = new SP07AcknowledgePlayerDigging(Client, digging.Location, 0,
                                                                                (SP07AcknowledgePlayerDigging.ActionType)digging.Status, false);
                    Client.Send(acknowledgePlayerDigging);
                    break;
                }

                if (!IsLegal(X, Y + 1.5, Z, digging.Location.X, digging.Location.Y, digging.Location.Z))
                {
                    acknowledgePlayerDigging = new SP07AcknowledgePlayerDigging(Client, digging.Location, block.State,
                                                                                (SP07AcknowledgePlayerDigging.ActionType)digging.Status, false);
                    Client.Send(acknowledgePlayerDigging);
                    break;
                }

                acknowledgePlayerDigging = new SP07AcknowledgePlayerDigging(Client, digging.Location, block.State,
                                                                            (SP07AcknowledgePlayerDigging.ActionType)digging.Status, true);
                Client.Send(acknowledgePlayerDigging);

                // TODO block break animation

                CP1BPlayerDigging.ActionType requiredAction;

                if (Gamemode == Gamemode.Creative)
                {
                    requiredAction = CP1BPlayerDigging.ActionType.StartedDigging;
                }
                else
                {
                    requiredAction = CP1BPlayerDigging.ActionType.FinishedDigging;
                }

                if (digging.Status == requiredAction)
                {
                    BlockBase air = new BlockAir();

                    Parent.SetBlock(air, digging.Location.X, digging.Location.Y, digging.Location.Z);

                    SP0BBlockChange blockChange = new(null, digging.Location, air.State);
                    Client.Server.MulticastAsync(blockChange, Client, Parent.GetClientsWithChunkLoaded(
                                                     (int)Math.Floor((double)digging.Location.X / Chunk.X_SIZE),
                                                     (int)Math.Floor((double)digging.Location.Z / Chunk.Z_SIZE)).ToArray());
                }
                break;

            case CP2EPlayerBlockPlacement playerBlockPlacement:
                Position.Int pos = new(playerBlockPlacement.Location);

                switch (playerBlockPlacement.Face)
                {
                case Face.Top:
                    pos.Y++;
                    break;

                case Face.Bottom:
                    pos.Y--;
                    break;

                case Face.North:
                    pos.Z--;
                    break;

                case Face.East:
                    pos.X++;
                    break;

                case Face.South:
                    pos.Z++;
                    break;

                case Face.West:
                    pos.X--;
                    break;
                }

                // TODO check for collisions here

                if (Parent.GetBlock(pos.X, pos.Y, pos.Z) == null)
                {
                    Inventory.Slot held = Inventory.Slots[Inventory.HeldSlot];

                    if (!held.IsEmpty() && held.Item is BlockItem item)
                    {
                        block = BlockRepository.Create(item.BlockProtocolId);

                        if (block == null || block.State == 0)
                        {
                            break;
                        }

                        if (pos.Y < 0 || pos.Y >= Chunk.Y_SIZE)
                        {
                            return;
                        }

                        Parent.SetBlock(block, pos.X, pos.Y, pos.Z);

                        SP0BBlockChange _blockChange = new(null, pos, block.State);
                        Client.Server.MulticastAsync(_blockChange, Client, Parent.GetClientsWithChunkLoaded(
                                                         (int)Math.Floor((double)pos.X / Chunk.X_SIZE),
                                                         (int)Math.Floor((double)pos.Z / Chunk.Z_SIZE)).ToArray());
                    }
                }
                break;

            case CP1CEntityAction:
                break;
            }
        }
Esempio n. 12
0
    Block CreateBlock(string name)
    {
        Block block;

        switch (name)
        {
        case "Apple":
            block = new BlockApple();
            break;

        case "Alphabet":
            block = new BlockAlphabet();
            break;

        case "Amazon":
            block = new BlockAmazon();
            break;

        case "Facebook":
            block = new BlockFacebook();
            break;

        case "IBM":
            block = new BlockIBM();
            break;

        case "Intel":
            block = new BlockIntel();
            break;

        case "Microsoft":
            block = new BlockMicrosoft();
            break;

        case "Netflix":
            block = new BlockNetflix();
            break;

        case "Twitter":
            block = new BlockTwitter();
            break;

        case "Yahoo":
            block = new BlockYahoo();
            break;

        case "Walmart":
            block = new BlockWalmart();
            break;

        case "Chipotle":
            block = new BlockChipotle();
            break;

        case "Costco":
            block = new BlockCostco();
            break;

        case "Pepsi":
            block = new BlockPepsi();
            break;

        case "Symantec":
            block = new BlockSymantec();
            break;

        case "Garmin":
            block = new BlockGarmin();
            break;

        default:
            block = new BlockAir();
            break;
        }
        return(block);
    }
Esempio n. 13
0
    Block CreateBlock()
    {
        string blockType = GetComponent <PrefabBlockTexture>().blockType;
        Block  block;

        switch (blockType)
        {
        case "Stone":
            block = new Block();
            break;

        case "Grass":
            block = new BlockGrass();
            break;

        case "BrownWood":
            block = new BlockBrownWood();
            break;

        case "Lava":
            block = new BlockLava();
            break;

        case "GreenLeaves":
            block = new BlockGreenLeaves();
            break;

        case "OrangeLeaves":
            block = new BlockOrangeLeaves();
            break;

        case "StoneSnow":
            block = new BlockStoneSnow();
            break;

        case "Ice":
            block = new BlockIce();
            break;

        case "Glass":
            block = new BlockGlass();
            break;

        case "WhiteWood":
            block = new BlockWhiteWood();
            break;

        case "Apple":
            block = new BlockApple();
            break;

        case "Alphabet":
            block = new BlockAlphabet();
            break;

        case "Amazon":
            block = new BlockAmazon();
            break;

        case "Facebook":
            block = new BlockFacebook();
            break;

        case "IBM":
            block = new BlockIBM();
            break;

        case "Intel":
            block = new BlockIntel();
            break;

        case "Microsoft":
            block = new BlockMicrosoft();
            break;

        case "Netflix":
            block = new BlockNetflix();
            break;

        case "Twitter":
            block = new BlockTwitter();
            break;

        case "Yahoo":
            block = new BlockYahoo();
            break;

        default:
            block = new BlockAir();
            break;
        }
        block.upsideDown = GetComponent <PrefabBlockTexture>().upsideDown;
        return(block);
    }
Esempio n. 14
0
    public virtual Block.Tile TexturePosition(Block.Direction direction)
    {
        Block.Tile tile = new Block.Tile();

        switch (blockType)
        {
        case "Stone":
            Block blockStone = new Block();
            blockStone.upsideDown = upsideDown;
            tile = blockStone.TexturePosition(direction);
            return(tile);

        case "Grass":
            BlockGrass blockGrass = new BlockGrass();
            blockGrass.upsideDown = upsideDown;
            tile = blockGrass.TexturePosition(direction);
            return(tile);

        case "BrownWood":
            BlockBrownWood blockBrownWood = new BlockBrownWood();
            blockBrownWood.upsideDown = upsideDown;
            tile = blockBrownWood.TexturePosition(direction);
            return(tile);

        case "Lava":
            BlockLava blockLava = new BlockLava();
            blockLava.upsideDown = upsideDown;
            tile = blockLava.TexturePosition(direction);
            return(tile);

        case "GreenLeaves":
            BlockGreenLeaves blockGreenLeaves = new BlockGreenLeaves();
            blockGreenLeaves.upsideDown = upsideDown;
            tile = blockGreenLeaves.TexturePosition(direction);
            return(tile);

        case "OrangeLeaves":
            BlockOrangeLeaves blockOrangeLeaves = new BlockOrangeLeaves();
            blockOrangeLeaves.upsideDown = upsideDown;
            tile = blockOrangeLeaves.TexturePosition(direction);
            return(tile);

        case "StoneSnow":
            BlockStoneSnow blockStoneSnow = new BlockStoneSnow();
            blockStoneSnow.upsideDown = upsideDown;
            tile = blockStoneSnow.TexturePosition(direction);
            return(tile);

        case "Ice":
            BlockIce blockIce = new BlockIce();
            blockIce.upsideDown = upsideDown;
            tile = blockIce.TexturePosition(direction);
            return(tile);

        case "Glass":
            BlockGlass blockGlass = new BlockGlass();
            blockGlass.upsideDown = upsideDown;
            tile = blockGlass.TexturePosition(direction);
            return(tile);

        case "WhiteWood":
            BlockWhiteWood blockWhiteWood = new BlockWhiteWood();
            blockWhiteWood.upsideDown = upsideDown;
            tile = blockWhiteWood.TexturePosition(direction);
            return(tile);

        case "Apple":
            BlockApple blockApple = new BlockApple();
            blockApple.upsideDown = upsideDown;
            tile = blockApple.TexturePosition(direction);
            return(tile);

        case "Alphabet":
            BlockAlphabet blockAlphabet = new BlockAlphabet();
            blockAlphabet.upsideDown = upsideDown;
            tile = blockAlphabet.TexturePosition(direction);
            return(tile);

        case "Amazon":
            BlockAmazon blockAmazon = new BlockAmazon();
            blockAmazon.upsideDown = upsideDown;
            tile = blockAmazon.TexturePosition(direction);
            return(tile);

        case "Facebook":
            BlockFacebook blockFacebook = new BlockFacebook();
            blockFacebook.upsideDown = upsideDown;
            tile = blockFacebook.TexturePosition(direction);
            return(tile);

        case "IBM":
            BlockIBM blockIBM = new BlockIBM();
            blockIBM.upsideDown = upsideDown;
            tile = blockIBM.TexturePosition(direction);
            return(tile);

        case "Intel":
            BlockIntel blockIntel = new BlockIntel();
            blockIntel.upsideDown = upsideDown;
            tile = blockIntel.TexturePosition(direction);
            return(tile);

        case "Microsoft":
            BlockMicrosoft blockMicrosoft = new BlockMicrosoft();
            blockMicrosoft.upsideDown = upsideDown;
            tile = blockMicrosoft.TexturePosition(direction);
            return(tile);

        case "Netflix":
            BlockNetflix blockNetflix = new BlockNetflix();
            blockNetflix.upsideDown = upsideDown;
            tile = blockNetflix.TexturePosition(direction);
            return(tile);

        case "Twitter":
            BlockTwitter blockTwitter = new BlockTwitter();
            blockTwitter.upsideDown = upsideDown;
            tile = blockTwitter.TexturePosition(direction);
            return(tile);

        case "Yahoo":
            BlockYahoo blockYahoo = new BlockYahoo();
            blockYahoo.upsideDown = upsideDown;
            tile = blockYahoo.TexturePosition(direction);
            return(tile);

        case "Leaves0":
            BlockLeaves0 blockLeaves0 = new BlockLeaves0();
            blockLeaves0.upsideDown = upsideDown;
            tile = blockLeaves0.TexturePosition(direction);
            return(tile);

        case "Leaves1":
            BlockLeaves1 blockLeaves1 = new BlockLeaves1();
            blockLeaves1.upsideDown = upsideDown;
            tile = blockLeaves1.TexturePosition(direction);
            return(tile);

        case "Leaves2":
            BlockLeaves2 blockLeaves2 = new BlockLeaves2();
            blockLeaves2.upsideDown = upsideDown;
            tile = blockLeaves2.TexturePosition(direction);
            return(tile);

        case "Leaves3":
            BlockLeaves3 blockLeaves3 = new BlockLeaves3();
            blockLeaves3.upsideDown = upsideDown;
            tile = blockLeaves3.TexturePosition(direction);
            return(tile);

        case "Leaves4":
            BlockLeaves4 blockLeaves4 = new BlockLeaves4();
            blockLeaves4.upsideDown = upsideDown;
            tile = blockLeaves4.TexturePosition(direction);
            return(tile);
        }
        //just in case it's not registered
        Block blockAir = new BlockAir();

        tile = blockAir.TexturePosition(direction);
        return(tile);
    }
Esempio n. 15
0
    //Use this for initialization
    void Start()
    {
        filter = gameObject.GetComponent<MeshFilter>();
        coll = gameObject.GetComponent<MeshCollider>();

        //past here is just to set up an example chunk
        blocks = new Block[chunkSize, chunkSize, chunkSize];

        for (int x = 0; x < chunkSize; x++){
            for (int y = 0; y < chunkSize; y++){
                for (int z = 0; z < chunkSize; z++){
                    blocks[x, y, z] = new BlockAir();
                }
            }
        }

        //testing
        //blocks[1, 5, 2] = new Block();
        //blocks[1, 5, 1] = new Block();
        //blocks[2, 5, 2] = new Block();
        //blocks[3, 5, 2] = new Block();
        //blocks[4, 5, 2] = new Block();
        //blocks[5, 5, 2] = new Block();
        //blocks[3, 6, 2] = new BlockYellow();
        for(int z = 1; z<=5; z++){
            for(int y = 11; y<=15 ;y++ ){
                blocks[1,y,z] = new Block();

            }
            for(int y = 4; y <=16 ; y++){
                blocks[2,y,z] = new Block();
            }
            for(int y =3; y <= 16; y++){
                blocks[3,y,z]= new Block();
            }
            for(int y=2; y <= 17; y++){
                blocks[4,y,z] =new Block();
            }
            for(int y = 2; y <= 17; y++){
                blocks[5,y,z] = new Block();
            }
            for(int y = 2; y <= 17; y++){
                blocks[6,y,z] = new Block();
            }
            for(int y = 2; y <= 17; y++){
                blocks[7,y,z] = new Block();
            }
            for(int y = 2; y <= 17; y++){
                blocks[8,y,z] = new Block();
            }
            for(int y = 1; y <= 18; y++){
                blocks[9,y,z] = new Block();
            }
            for(int y = 1; y <= 18; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 2; y <= 17; y++){
                blocks[11,y,z] = new Block();
            }
            for(int y = 3; y <= 17; y++){
                blocks[12,y,z] = new Block();
            }
            for(int y = 5; y <= 15; y++){
                blocks[13,y,z] = new Block();
            }
            for(int y = 6; y <= 12; y++){
                blocks[14,y,z] = new Block();
            }
        }

        for(int z = 6; z <=6 ; z++){
            for(int y = 6; y <= 7; y++){
                blocks[2,y,z] = new Block();
            }
            for(int y = 12; y <= 13; y++){
                blocks[2,y,z] = new Block();
            }
            for(int y = 4; y <= 8; y++){
                blocks[3,y,z] = new Block();
            }
            for(int y = 11; y <= 15; y++){
                blocks[3,y,z] = new Block();
            }
            for(int y = 3; y <= 9; y++){
                blocks[4,y,z] = new Block();
            }
            for(int y = 11; y <= 15; y++){
                blocks[4,y,z] = new Block();
            }
            for(int y = 3; y <= 9; y++){
                blocks[5,y,z] = new Block();
            }
            for(int y = 11; y <= 14; y++){
                blocks[5,y,z] = new Block();
            }
            for(int y = 4; y <= 9; y++){
                blocks[6,y,z] = new Block();
            }
            for(int y = 11; y <= 12; y++){
                blocks[6,y,z] = new Block();
            }
            for(int y = 6; y <= 7; y++){
                blocks[7,y,z] = new Block();
            }
            for(int y = 13; y <= 15; y++){
                blocks[8,y,z] = new Block();
            }
            for(int y = 3; y <= 5; y++){
                blocks[9,y,z] = new Block();
            }
            for(int y = 8; y <= 10; y++){
                blocks[9,y,z] = new Block();
            }
            for(int y = 13; y <= 16; y++){
                blocks[9,y,z] = new Block();
            }
            for(int y = 3; y <= 5; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 8; y <= 10; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 14; y <= 16; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 4; y <= 5; y++){
                blocks[11,y,z] = new Block();
            }
            for(int y = 7; y <= 11; y++){
                blocks[11,y,z] = new Block();
            }
            for(int y = 14; y <= 16; y++){
                blocks[11,y,z] = new Block();
            }
            for(int y = 7; y <= 11; y++){
                blocks[12,y,z] = new Block();
            }
            for(int y = 14; y <= 15; y++){
                blocks[12,y,z] = new Block();
            }
            for(int y = 7; y <= 11; y++){
                blocks[13,y,z] = new Block();
            }
        }

        for (int z = 7; z <= 7; z++) {
            for(int y = 7; y <= 7; y++){
                blocks[3,y,z] = new Block();
            }
            for(int y = 12; y <= 13; y++){
                blocks[3,y,z] = new Block();
            }
            for(int y = 5; y <= 8; y++){
                blocks[4,y,z] = new Block();
            }
            for(int y = 12; y <= 14; y++){
                blocks[4,y,z] = new Block();
            }
            for(int y = 5; y <= 8; y++){
                blocks[5,y,z] = new Block();
            }
            for(int y = 12; y <= 13; y++){
                blocks[5,y,z] = new Block();
            }
            for(int y = 6; y <= 7; y++){
                blocks[6,y,z] = new Block();
            }
            for(int y = 14; y <= 15; y++){
                blocks[9,y,z] = new Block();
            }
            for(int y = 4; y <= 4; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 9; y <= 10; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 15; y <= 15; y++){
                blocks[10,y,z] = new Block();
            }
            for(int y = 8; y <= 10; y++){
                blocks[11,y,z] = new Block();
            }
            for(int y = 15; y <= 15; y++){
                blocks[11,y,z] = new Block();
            }
            for(int y = 8; y <= 10; y++){
                blocks[12,y,z] = new Block();
            }
        }

        /*for (int z=8; z<=8; z++) {
            for(int y = 6; y <= 6; y++){
                blocks[4,y,z] = new Block();
            }
            for(int y = 13; y <= 13; y++){
                blocks[4,y,z] = new Block();
            }
            for(int y = 6; y <= 7; y++){
                blocks[5,y,z] = new Block();
            }
            for(int y = 9; y <= 9; y++){
                blocks[11,y,z] = new Block();
            }
        }*/

        UpdateChunk();
    }
Esempio n. 16
0
	// set to true if a light source affects surrounding chunks lights
	// then only the lights are updated!
    // Updates the chunk based on the blocks mesh data
	// i should add in a render pass here
	void UpdateChunk() {
		MyMonsterSpawns.Clear ();
		RefreshLights ();
        for (int x = 0; x < chunkSize; x++)
        {
            for (int y = 0; y < chunkSize; y++)
            {
                for (int z = 0; z < chunkSize; z++)
				{
					if (blocks[x,y,z].TileIndex == 16) {
						MyMonsterSpawns.Add (new Vector3(x,y,z));
						blocks[x,y,z] = new BlockAir();
					} 

					if (blocks[x, y, z] == null)
						Debug.LogError("Huge issues in chunk! doesn't have block iniitialized :O");
					MyMeshData = blocks[x, y, z].Blockdata(this, x, y, z, MyMeshData,0);
					MyWaterMeshData = blocks[x, y, z].Blockdata(this, x, y, z, MyWaterMeshData,1);
                }
            }
        }
		CanUpdateRenderer = true;
    }
Esempio n. 17
0
    public bool Load()
    {
        string saveFile = "construction/Town/";

        //saveFile += "Town1.bin";
        saveFile += "Towndemo.bin";

        if (!File.Exists(saveFile))
        {
            return(false);
        }

        IFormatter formatter = new BinaryFormatter();
        FileStream stream    = new FileStream(saveFile, FileMode.Open);

        //chunk.blocks = (Block[,,])formatter.Deserialize (stream);

        /*Block[,,] save = (Block[,,])formatter.Deserialize (stream);
         * for (int x = 0; x < 320; x++) {
         *      for (int y = 0; y < 50; y++) {
         *              for (int z = 0; z < 320; z++) {
         *                      //blocksTown [x,y,z] = save[x,y+7,z];
         *                      if (save[x,y+7,z] is BlockStoneBricks)
         *                              blocksTown[x,y,z] = new BlockStoneBricks();
         *                      else if(save[x,y+7,z] is BlockAir)
         *                              blocksTown[x,y,z] = new BlockAir();
         *                      else if(save[x,y+7,z] is BlockGrass)
         *                              blocksTown[x,y,z] = new BlockGrass();
         *                      else if(save[x,y+7,z] is BlockDirt)
         *                              blocksTown[x,y,z] = new BlockDirt();
         *                      else if(save[x,y+7,z] is BlockGlass)
         *                              blocksTown[x,y,z] = new BlockGlass();
         *                      else if(save[x,y+7,z] is BlockWood)
         *                              blocksTown[x,y,z] = new BlockWood();
         *                      else if(save[x,y+7,z] is BlockLeaves)
         *                              blocksTown[x,y,z] = new BlockLeaves();
         *                      else if(save[x,y+7,z] is BlockWater)
         *                              blocksTown[x,y,z] = new BlockWater();
         *                      else if(save[x,y+7,z] is BlockTile)
         *                              blocksTown[x,y,z] = new BlockTile();
         *                      else if(save[x,y+7,z] is BlockWoodPlanks)
         *                              blocksTown[x,y,z] = new BlockWoodPlanks();
         *                      else if(save[x,y+7,z] is Block)
         *                              blocksTown[x,y,z] = new Block();
         *              }
         *      }
         * }*/

        int[,,] save = (int[, , ])formatter.Deserialize(stream);

        for (int x = 0; x < 320; x++)
        {
            for (int y = 0; y < 40; y++)
            {
                for (int z = 0; z < 320; z++)
                {
                    if (save[x, y, z] == 0)
                    {
                        blocksTown[x, y, z] = new BlockAir();
                    }
                    else if (save[x, y, z] == 8)
                    {
                        blocksTown[x, y, z] = new BlockStoneBricks();
                    }
                    else if (save[x, y, z] == 7)
                    {
                        blocksTown[x, y, z] = new BlockWoodPlanks();
                    }
                    else
                    {
                        blocksTown[x, y, z] = new BlockAir();
                    }
                }
            }
        }
        stream.Close();
        return(true);
    }