aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/TallGrass.cpp
blob: 1a89d3edf6df1a0efbc3055dbf58d4fa58e20e92 (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
115
116
117
118
119
#include "stdafx.h"
#include "..\Minecraft.Client\Minecraft.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.biome.h"
#include "net.minecraft.stats.h"
#include "net.minecraft.world.h"
#include "TallGrass.h"

const unsigned int TallGrass::TALL_GRASS_TILE_NAMES[TALL_GRASS_TILE_NAMES_LENGTH] = {	IDS_TILE_SHRUB,
													IDS_TILE_TALL_GRASS,
													IDS_TILE_FERN,
												};

const wstring TallGrass::TEXTURE_NAMES[] = {L"deadbush", L"tallgrass", L"fern"};

TallGrass::TallGrass(int id) : Bush(id, Material::replaceable_plant)
{
	this->updateDefaultShape();
}

// 4J Added override
void TallGrass::updateDefaultShape()
{
	float ss = 0.4f;
	this->setShape(0.5f - ss, 0, 0.5f - ss, 0.5f + ss, 0.8f, 0.5f + ss);
}


Icon *TallGrass::getTexture(int face, int data)
{
	if (data >= TALL_GRASS_TILE_NAMES_LENGTH) data = 0;
	return icons[data];
}

int TallGrass::getColor(int auxData)
{
    if (auxData == DEAD_SHRUB) return 0xffffff;

    return FoliageColor::getDefaultColor();
}

int TallGrass::getColor() const
{
	// 4J Stu - Not using this any more
	//double temp = 0.5;
	//double rain = 1.0;

	//return GrassColor::get(temp, rain);

	return Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Grass_Common );
}

int TallGrass::getColor(LevelSource *level, int x, int y, int z )
{
	return getColor( level, x, y, z, level->getData(x, y, z) );
}

// 4J - changed interface to have data passed in, and put existing interface as wrapper above
int TallGrass::getColor(LevelSource *level, int x, int y, int z, int data)
{
	int d = data;
	if (d == DEAD_SHRUB) return 0xffffff;

	return level->getBiome(x, z)->getGrassColor();
}

int TallGrass::getResource(int data, Random *random, int playerBonusLevel)
{
	if (random->nextInt(8) == 0) {
		return Item::seeds_wheat->id;
	}

	return -1;
}

int TallGrass::getResourceCountForLootBonus(int bonusLevel, Random *random)
{
	return 1 + random->nextInt(bonusLevel * 2 + 1);
}

void TallGrass::playerDestroy(Level *level, shared_ptr<Player> player, int x, int y, int z, int data)
{
    if (!level->isClientSide && player->getSelectedItem() != NULL && player->getSelectedItem()->id == Item::shears->id)
	{
        player->awardStat(
			GenericStats::blocksMined(id), 
			GenericStats::param_blocksMined(id,data,1)
			);

        // drop leaf block instead of sapling
        popResource(level, x, y, z, shared_ptr<ItemInstance>(new ItemInstance(Tile::tallgrass, 1, data)));
    }
	else
	{
        Bush::playerDestroy(level, player, x, y, z, data);
    }
}

int TallGrass::cloneTileData(Level *level, int x, int y, int z)
{
	return level->getData(x, y, z);
}

unsigned int TallGrass::getDescriptionId(int iData /*= -1*/)
{
	if(iData < 0 ) iData = 0;
	return TallGrass::TALL_GRASS_TILE_NAMES[iData];
}

void TallGrass::registerIcons(IconRegister *iconRegister)
{
	icons = new Icon*[TALL_GRASS_TILE_NAMES_LENGTH];

	for (int i = 0; i < TALL_GRASS_TILE_NAMES_LENGTH; i++)
	{
		icons[i] = iconRegister->registerIcon(TEXTURE_NAMES[i]);
	}
}