Esempio n. 1
0
    public void ModifyVoxel(Vector3Int pos, byte _id, int direction)
    {
        // If we've somehow tried to change a block for the same block, just return.
        if (map[pos.x, pos.y, pos.z].id == _id)
        {
            return;
        }

        // Cache voxels for easier code.
        VoxelState voxel    = map[pos.x, pos.y, pos.z];
        BlockType  newVoxel = World.Instance.blocktypes[_id];

        // Cache the old opacity value.
        byte oldOpacity = voxel.properties.opacity;

        // Set voxel to new ID.
        voxel.id          = _id;
        voxel.orientation = direction;

        // If the opacity values of the voxel have changed and the voxel above is in direct sunlight
        // (or is above the world) recast light from that voxel downwards.
        if (voxel.properties.opacity != oldOpacity &&
            (pos.y == VoxelData.ChunkHeight - 1 || map[pos.x, pos.y + 1, pos.z].light == 15))
        {
            Lighting.CastNaturalLight(this, pos.x, pos.z, pos.y + 1);
        }

        if (voxel.properties.isActive && BlockBehaviour.Active(voxel))
        {
            voxel.chunkData.chunk.AddActiveVoxel(voxel);
        }
        for (int i = 0; i < 6; i++)
        {
            if (voxel.neighbours[i] != null)
            {
                if (voxel.neighbours[i].properties.isActive && BlockBehaviour.Active(voxel.neighbours[i]))
                {
                    voxel.neighbours[i].chunkData.chunk.AddActiveVoxel(voxel.neighbours[i]);
                }
            }
        }

        // Add this ChunkData to the modified chunks list.
        World.Instance.worldData.AddToModifiedChunkList(this);

        // If we have a chunk attached, add that for updating.
        if (chunk != null)
        {
            World.Instance.AddChunkToUpdate(chunk);
        }
    }
 public void TickUpdate()
 {
     Debug.Log(chunkObject.name + " currently has " + activeVoxels.Count + " active blocks.");
     for (int i = activeVoxels.Count - 1; i > -1; i--)
     {
         if (!BlockBehaviour.Active(activeVoxels[i]))
         {
             RemoveActiveVoxel(activeVoxels[i]);
         }
         else
         {
             BlockBehaviour.Behave(activeVoxels[i]);
         }
     }
 }