aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/DaylightDetectorTile.cpp
blob: 1bc9943e4026c7a727d10f5f18f697e458ad0ca2 (plain)
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
106
107
108
109
110
111
112
113
114
#include "stdafx.h"
#include "net.minecraft.h"
#include "net.minecraft.world.level.dimension.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.redstone.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "net.minecraft.world.h"
#include "JavaMath.h"
#include "DaylightDetectorTile.h"

DaylightDetectorTile::DaylightDetectorTile(int id) : BaseEntityTile(id, Material::wood, isSolidRender() )
{
	updateDefaultShape();
}

void DaylightDetectorTile::updateDefaultShape()
{
	setShape(0, 0, 0, 1, 6.0f / 16.0f, 1);
}

void DaylightDetectorTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity)
{
	setShape(0, 0, 0, 1, 6.0f / 16.0f, 1);
}

int DaylightDetectorTile::getSignal(LevelSource *level, int x, int y, int z, int dir)
{
	return level->getData(x, y, z);
}

void DaylightDetectorTile::tick(Level *level, int x, int y, int z, Random *random)
{
	//        updateSignalStrength(level, x, y, z);
}

void DaylightDetectorTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
	//        level.addToTickNextTick(x, y, z, id, getTickDelay());
}

void DaylightDetectorTile::onPlace(Level *level, int x, int y, int z)
{
	//        level.addToTickNextTick(x, y, z, id, getTickDelay());
}

void DaylightDetectorTile::updateSignalStrength(Level *level, int x, int y, int z)
{
	if (level->dimension->hasCeiling) return;

	int current = level->getData(x, y, z);
	int target = level->getBrightness(LightLayer::Sky, x, y, z) - level->skyDarken;
	float sunAngle = level->getSunAngle(1);

	// tilt sunAngle towards zenith (to make the transition to night
	// smoother)
	if (sunAngle < PI)
	{
		sunAngle = sunAngle + (0 - sunAngle) * .2f;
	}
	else
	{
		sunAngle = sunAngle + (PI * 2.0f - sunAngle) * .2f;
	}

	target = Math::round((float) target * Mth::cos(sunAngle));
	if (target < 0)
	{
		target = 0;
	}
	if (target > Redstone::SIGNAL_MAX)
	{
		target = Redstone::SIGNAL_MAX;
	}

	if (current != target)
	{
		level->setData(x, y, z, target, UPDATE_ALL);
	}
}

bool DaylightDetectorTile::isCubeShaped()
{
	return false;
}

bool DaylightDetectorTile::isSolidRender(bool isServerLevel)
{
	return false;
}

bool DaylightDetectorTile::isSignalSource()
{
	return true;
}

shared_ptr<TileEntity> DaylightDetectorTile::newTileEntity(Level *level)
{
	return shared_ptr<DaylightDetectorTileEntity>( new DaylightDetectorTileEntity() );
}

Icon *DaylightDetectorTile::getTexture(int face, int data)
{
	if (face == Facing::UP)
	{
		return icons[0];
	}
	return icons[1];
}

void DaylightDetectorTile::registerIcons(IconRegister *iconRegister)
{
	icons[0] = iconRegister->registerIcon(getIconName() + L"_top");
	icons[1] = iconRegister->registerIcon(getIconName() + L"_side");
}