public void ModifyVoxel(Vector3Int pos, byte _id) { if (map[pos.x, pos.y, pos.z].id == _id) { return; } VoxelState voxel = map[pos.x, pos.y, pos.z]; BlockType newVoxel = World.Instance.blockTypes[_id]; byte oldOpacity = voxel.properties.opacity; voxel.id = _id; if (voxel.properties.opacity != oldOpacity && (pos.y == VoxelData.ChunkHeight - 1 || map[pos.x, pos.y, pos.z].light == 15)) { Lighting.CastNaturalLight(this, pos.x, pos.z, pos.y + 1); } World.Instance.worldData.AddToModifiedChunkList(this); if (chunk != null) { World.Instance.AddChunkToUpdate(chunk); } }
public void ModifyVoxel(Vector4Int pos, byte id) { VoxelState voxel = getVoxel(pos); if (voxel.blockID == id) { return; } BlockType new_voxel = World.Instance.blockTypes[id]; // Cache old opacity byte oldOpacity = voxel.properties.opacity; voxel.blockID = id; if (voxel.properties.opacity != oldOpacity && (pos.y == ChunkData.cHeight - 1 || getVoxel(pos + Vector4Int.up).light == 15)) { Lighting.CastNaturalLight(this, pos); } World.Instance.worldData.AddToModifieds(this); if (chunk != null) { World.Instance.AddChunkToUpdate(chunk); } }
public void ModifyVoxel(Vector3Int pos, byte _id) { // 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; // 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); } // 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 ModifyVoxel(Vector3Int voxelChunkPosition, byte _id, Vector3 rotation) { if (voxelMap[voxelChunkPosition.x, voxelChunkPosition.y, voxelChunkPosition.z].id == _id) { return; } VoxelData voxel = voxelMap[voxelChunkPosition.x, voxelChunkPosition.y, voxelChunkPosition.z]; //BlockData newVoxel = World.Instance.worldData.blocks[ _id ]; byte oldOpacity = voxel.Properties.GetOpacity(); voxel.id = _id; if (voxel.Properties.GetRotatable()) { voxel.Properties.RotateFaces(rotation); } if (voxel.Properties.GetOpacity() != oldOpacity && (voxelChunkPosition.y == WorldData.chunkHeight - 1 || voxelMap[voxelChunkPosition.x, voxelChunkPosition.y + 1, voxelChunkPosition.z].Light == 15)) { Lighting.CastNaturalLight(this, voxelChunkPosition.x, voxelChunkPosition.z, voxelChunkPosition.y + 1); } World.Instance.worldData.AddToModifiedChunkList(this); if (chunk != null) { World.Instance.AddChunkToUpdate(chunk); } }