Beispiel #1
0
    public Block CreateBlockInOtherChunk(string blockType, int chunkX, int chunkY, int chunkZ)
    {
        if (isInBlocksBounds(chunkX, chunkY, chunkZ))
        {
            return(CreateBlock(blockType, chunkX, chunkY, chunkZ));
        }

        Vector3 worldPosition = new Vector3(worldOffset.x + chunkX, worldOffset.y + chunkY, worldOffset.z + chunkZ);
        Vector3 chunkPosition = HelperMethods.worldPositionToChunkPosition(worldPosition);
        Vector3 blockPosition = HelperMethods.vectorDifference(worldPosition, chunkPosition);

        Chunk chunk = generator.getChunk(chunkPosition);

        if (chunk == null)
        {
            //Debug.Log ("Cant create block, chunk doesnt exist "+chunkPosition);
            return(null);
        }

        Block block = chunk.getBlock(blockPosition);

        if (block != null)
        {
            //Debug.Log ("Cant create block, block already there");
            return(null);
        }

        return(chunk.CreateBlock(blockType, (int)blockPosition.x, (int)blockPosition.y, (int)blockPosition.z));
    }
Beispiel #2
0
    bool avoidCollision(Vector3 collider)
    {
        Vector3 forward = transform.forward;

        Vector3 botPos = this.gameObject.transform.position;

        botPos += collider;
        botPos += forward * 3.0f;

        /*if (cube == null) {
         *      cube = GameObject.CreatePrimitive (PrimitiveType.Cube);
         *      cube.transform.localScale = new Vector3 (0.1f, 0.1f, 0.1f);
         *
         *      Physics.IgnoreCollision (cube.GetComponent<Collider> (), GetComponent<Collider> ());
         * }
         *
         * cube.transform.position = botPos;*/

        Vector3 chunkPos = HelperMethods.worldPositionToChunkPosition(botPos);
        Vector3 blockPos = HelperMethods.vectorDifference(chunkPos, botPos);

        Chunk chunk = pg.getChunk(chunkPos);

        if (chunk == null)
        {
            return(false);
        }

        Block block = chunk.getBlock(blockPos);

        if (block == null)
        {
            return(false);
        }

        if (block.resourceString == "WaterBlock")
        {
            return(false);
        }

        return(true);
    }
    private void drawAdjacentBlock(float x, float y, float z)
    {
        Vector3 deletedPos = new Vector3(x, y, z);
        Vector3 chunkPos   = HelperMethods.worldPositionToChunkPosition(deletedPos);
        Vector3 blockPos   = HelperMethods.vectorDifference(chunkPos, deletedPos);

        Chunk chunk = pg.getChunk(chunkPos);

        if (chunk == null)
        {
            return;
        }

        Block block = chunk.getBlock(blockPos);

        if (block == null)
        {
            return;
        }

        block.draw();
    }