Example #1
0
    public override void OnRightClick()
    {
        bool isUpper = (WireFrameHelper.data & 0b1000) > 0;

        int  direction = 0;
        bool isOpen    = false;

        if (isUpper)
        {
            NBTHelper.GetBlockData(WireFrameHelper.pos.x, WireFrameHelper.pos.y - 1, WireFrameHelper.pos.z, out byte belowType, out byte belowData);
            if (belowType == 64)
            {
                isOpen    = (belowData & 0b0100) > 0;
                direction = belowData & 0b0011;
            }

            byte newData = (byte)(belowData ^ 0b0100);
            NBTHelper.SetBlockData(WireFrameHelper.pos + Vector3Int.down, WireFrameHelper.type, newData);
        }
        else
        {
            isOpen = (WireFrameHelper.data & 0b0100) > 0;

            byte newData = (byte)(WireFrameHelper.data ^ 0b0100);
            NBTHelper.SetBlockData(WireFrameHelper.pos, WireFrameHelper.type, newData);
        }
        SoundManager.Play2DSound(isOpen ? "Player_Door_Close" : "Player_Door_Open");

        NBTChunk chunk = NBTHelper.GetChunk(WireFrameHelper.pos);

        chunk.RebuildMesh(UpdateFlags.Collidable);
    }
Example #2
0
    public static void SetBlockByte(int x, int y, int z, byte type)
    {
        int chunkX = Mathf.FloorToInt(x / 16f);
        int chunkZ = Mathf.FloorToInt(z / 16f);

        int xInChunk = x - chunkX * 16;
        int zInChunk = z - chunkZ * 16;

        NBTChunk    chunk        = GetChunk(chunkX, chunkZ);
        NBTBlock    oldGenerator = NBTGeneratorManager.GetMeshGenerator(chunk.GetBlockByte(xInChunk, y, zInChunk));
        UpdateFlags updateFlag   = GetUpdateFlags(oldGenerator);

        if (type == 0)
        {
            chunk.GetBlockData(xInChunk, y + 1, zInChunk, out byte topType, out byte topData);
            NBTBlock topGenerator = NBTGeneratorManager.GetMeshGenerator(topType);
            if (topGenerator != null && topGenerator is NBTPlant)
            {
                BreakBlockEffect.Create(topType, topData, new Vector3(x, y + 1, z));
                chunk.SetBlockByte(xInChunk, y + 1, zInChunk, 0);
                updateFlag |= UpdateFlags.NotCollidable;
            }
        }

        chunk.SetBlockByte(xInChunk, y, zInChunk, type);
        if (updateFlag.HasFlag(UpdateFlags.Lighting))
        {
            UpdateLighting(x, y, z);
        }
        chunk.RebuildMesh(updateFlag);

        NBTChunk leftChunk = GetChunk(chunkX - 1, chunkZ);

        if (xInChunk == 0)
        {
            leftChunk.RebuildMesh();
        }

        NBTChunk rightChunk = GetChunk(chunkX + 1, chunkZ);

        if (xInChunk == 15)
        {
            rightChunk.RebuildMesh();
        }

        NBTChunk backChunk = GetChunk(chunkX, chunkZ - 1);

        if (zInChunk == 0)
        {
            backChunk.RebuildMesh();
        }

        NBTChunk frontChunk = GetChunk(chunkX, chunkZ + 1);

        if (zInChunk == 15)
        {
            frontChunk.RebuildMesh();
        }
    }
Example #3
0
    public static void Update()
    {
        UnityEngine.Profiling.Profiler.BeginSample("ChunkRefresher.Update");

        if (PlayerController.isInitialized && refreshChunkList.Count > 0)
        {
            refreshChunkList.Sort(ChunkComparer.instance);
            NBTChunk chunk = refreshChunkList[0];
            if (PlayerController.GetChunkToFrontDot(chunk) > 0 || PlayerController.IsNearByChunk(chunk))
            {
                chunk.RebuildMesh();
                refreshChunkList.RemoveAt(0);
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }
Example #4
0
    public static void Update()
    {
        UnityEngine.Profiling.Profiler.BeginSample("ChunkRefresher.Update");

        if (PlayerController.isInitialized && Time.time - time > interval && refreshChunkList.Count > 0)
        {
            // remove empty
            refreshChunkList.RemoveAll((NBTChunk chunk) => { return(chunk == null); });

            NBTChunk chunk = GetFirstChunk(refreshChunkList);
            if (chunk != null)
            {
                //chunk.RebuildMeshAsync();
                chunk.RebuildMesh();
                refreshChunkList.Remove(chunk);
            }

            time = Time.time;
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }
Example #5
0
    public static void SetBlockData(int x, int y, int z, byte type, byte data)
    {
        int chunkX = Mathf.FloorToInt(x / 16f);
        int chunkZ = Mathf.FloorToInt(z / 16f);

        int xInChunk = x - chunkX * 16;
        int zInChunk = z - chunkZ * 16;

        NBTChunk chunk = GetChunk(chunkX, chunkZ);

        chunk.SetBlockData(xInChunk, y, zInChunk, type, data);
        chunk.RebuildMesh();

        if (type == 0)
        {
            if (xInChunk == 0)
            {
                NBTChunk leftChunk = GetChunk(chunkX - 1, chunkZ);
                leftChunk.RebuildMesh();
            }
            if (xInChunk == 15)
            {
                NBTChunk rightChunk = GetChunk(chunkX + 1, chunkZ);
                rightChunk.RebuildMesh();
            }
            if (zInChunk == 0)
            {
                NBTChunk frontChunk = GetChunk(chunkX, chunkZ - 1);
                frontChunk.RebuildMesh();
            }
            if (zInChunk == 15)
            {
                NBTChunk backChunk = GetChunk(chunkX, chunkZ + 1);
                backChunk.RebuildMesh();
            }
        }
    }