aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/EnderChestTileEntity.cpp
blob: 8169c0292248a11003a678966e8b2ad88530bbac (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
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "EnderChestTileEntity.h"

EnderChestTileEntity::EnderChestTileEntity()
{
	openness = oOpenness = 0.0f;
	openCount = 0;
	tickInterval = 0;
}

void EnderChestTileEntity::tick()
{
	TileEntity::tick();

	if (++tickInterval % 20 * 4 == 0)
	{
		level->tileEvent(x, y, z, Tile::enderChest_Id, ChestTile::EVENT_SET_OPEN_COUNT, openCount);
	}

	oOpenness = openness;

	float speed = 0.10f;
	if (openCount > 0 && openness == 0)
	{
		double xc = x + 0.5;
		double zc = z + 0.5;

		// 4J-PB - Seems the chest open volume is much louder than other sounds from user reports. We'll tone it down a bit		
		level->playSound(xc, y + 0.5, zc, eSoundType_RANDOM_CHEST_OPEN, 0.2f, level->random->nextFloat() * 0.1f + 0.9f);
	}
	if ((openCount == 0 && openness > 0) || (openCount > 0 && openness < 1))
	{
		float oldOpen = openness;
		if (openCount > 0) openness += speed;
		else openness -= speed;
		if (openness > 1)
		{
			openness = 1;
		}
		float lim = 0.5f;
		if (openness < lim && oldOpen >= lim)
		{
			double xc = x + 0.5;
			double zc = z + 0.5;

			// 4J-PB - Seems the chest open volume is much louder than other sounds from user reports. We'll tone it down a bit	
			level->playSound(xc, y + 0.5, zc, eSoundType_RANDOM_CHEST_CLOSE, 0.2f, level->random->nextFloat() * 0.1f + 0.9f);
		}
		if (openness < 0)
		{
			openness = 0;
		}
	}
}

bool EnderChestTileEntity::triggerEvent(int b0, int b1)
{
	if (b0 == ChestTile::EVENT_SET_OPEN_COUNT)
	{
		openCount = b1;
		return true;
	}
	return TileEntity::triggerEvent(b0, b1);
}

void EnderChestTileEntity::setRemoved()
{
	clearCache();
	TileEntity::setRemoved();
}

void EnderChestTileEntity::startOpen()
{
	openCount++;
	level->tileEvent(x, y, z, Tile::enderChest_Id, ChestTile::EVENT_SET_OPEN_COUNT, openCount);
}

void EnderChestTileEntity::stopOpen()
{
	openCount--;
	level->tileEvent(x, y, z, Tile::enderChest_Id, ChestTile::EVENT_SET_OPEN_COUNT, openCount);
}

bool EnderChestTileEntity::stillValid(shared_ptr<Player> player)
{
	if (level->getTileEntity(x, y, z) != shared_from_this()) return false;
	if (player->distanceToSqr(x + 0.5, y + 0.5, z + 0.5) > 8 * 8) return false;

	return true;
}

// 4J Added
shared_ptr<TileEntity> EnderChestTileEntity::clone()
{
	shared_ptr<EnderChestTileEntity> result = shared_ptr<EnderChestTileEntity>( new EnderChestTileEntity() );
	TileEntity::clone(result);

	return result;
}