summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockIce.h
blob: 12505b3fde506bf33d244d16d081b41657bf13d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

#pragma once

#include "BlockHandler.h"





class cBlockIceHandler :
	public cBlockHandler
{
	using Super = cBlockHandler;

public:

	using Super::Super;

private:

	virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override
	{
		// Only drop self when using silk-touch:
		if (ToolHasSilkTouch(a_Tool))
		{
			return cItem(m_BlockType);
		}

		return {};
	}

	virtual void OnUpdate(
		cChunkInterface & a_ChunkInterface,
		cWorldInterface & a_WorldInterface,
		cBlockPluginInterface & a_PluginInterface,
		cChunk & a_Chunk,
		const Vector3i a_RelPos
	) const override
	{
		// Disappears instantly in nether:
		if (a_WorldInterface.GetDimension() == dimNether)
		{
			a_Chunk.SetBlock(a_RelPos, E_BLOCK_AIR, 0);
			return;
		}

		// Artificial light on any of the surrounding block > 11 leads to melting the ice.
		static const std::array<Vector3i, 7> Adjacents
		{
			{
				{ 1, 0, 0 }, { -1, 0, 0 },
				{ 0, 1, 0 }, { 0, -1, 0 },
				{ 0, 0, 1 }, { 0, 0, -1 }
			}
		};

		for (const auto Offset : Adjacents)
		{
			auto Position = a_RelPos + Offset;
			const auto Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(Position);

			if ((Chunk == nullptr) || !Chunk->IsValid())
			{
				continue;
			}

			if (!Chunk->IsLightValid())
			{
				Chunk->GetWorld()->QueueLightChunk(Chunk->GetPosX(), Chunk->GetPosZ());
				continue;
			}

			if (Chunk->GetBlockLight(Position) > 11)
			{
				a_Chunk.SetBlock(a_RelPos, E_BLOCK_STATIONARY_WATER, 0);
				return;
			}
		}
	}

	virtual void OnBroken(
		cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
		Vector3i a_BlockPos,
		BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
	) const override
	{
		// If there's a solid block or a liquid underneath, convert to water, rather than air
		if (a_BlockPos.y <= 0)
		{
			return;
		}

		const auto Below = a_ChunkInterface.GetBlock(a_BlockPos.addedY(-1));
		if (cBlockInfo::FullyOccupiesVoxel(Below) || IsBlockLiquid(Below))
		{
			a_ChunkInterface.SetBlock(a_BlockPos, E_BLOCK_WATER, 0);
		}
	}

	virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
	{
		UNUSED(a_Meta);
		return 5;
	}
} ;