aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/PistonExtensionTile.cpp
blob: 25c5adb951a58fbbb5fce3ec6211b7d7815a2732 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "stdafx.h"
#include "PistonExtensionTile.h"
#include "PistonBaseTile.h"
#include "Facing.h"
#include "net.minecraft.world.level.h"

PistonExtensionTile::PistonExtensionTile(int id) : Tile(id, Material::piston,isSolidRender() )
{
	// 4J added initialiser
	overrideTopTexture = NULL;

	setSoundType(SOUND_STONE);
	setDestroyTime(0.5f);
}

void PistonExtensionTile::setOverrideTopTexture(Icon *overrideTopTexture)
{
	this->overrideTopTexture = overrideTopTexture;
}

void PistonExtensionTile::clearOverrideTopTexture()
{
	this->overrideTopTexture = NULL;
}

void PistonExtensionTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player)
{
	if (player->abilities.instabuild)
	{
		int facing = getFacing(data);
		int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
		if (tile == Tile::pistonBase_Id || tile == Tile::pistonStickyBase_Id)
		{
			level->removeTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
		}
	}
	Tile::playerWillDestroy(level, x, y, z, data, player);
}

void PistonExtensionTile::onRemove(Level *level, int x, int y, int z, int id, int data)
{
	Tile::onRemove(level, x, y, z, id, data);
	int facing = Facing::OPPOSITE_FACING[getFacing(data)];
	x += Facing::STEP_X[facing];
	y += Facing::STEP_Y[facing];
	z += Facing::STEP_Z[facing];

	int t = level->getTile(x, y, z);

	if (t == Tile::pistonBase_Id || t == Tile::pistonStickyBase_Id)
	{
		data = level->getData(x, y, z);
		if (PistonBaseTile::isExtended(data))
		{
			Tile::tiles[t]->spawnResources(level, x, y, z, data, 0);
			level->removeTile(x, y, z);

		}
	}
}

Icon *PistonExtensionTile::getTexture(int face, int data)
{
	int facing = getFacing(data);

	if (face == facing)
	{
		if (overrideTopTexture != NULL)
		{
			return overrideTopTexture;
		}
		if ((data & STICKY_BIT) != 0)
		{
			return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_STICKY_TEX);
		}
		return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX);
	}
	if (facing < 6 && face == Facing::OPPOSITE_FACING[facing])
	{
		return PistonBaseTile::getTexture(PistonBaseTile::PLATFORM_TEX);
	}
	return PistonBaseTile::getTexture(PistonBaseTile::EDGE_TEX); // edge and arms
}

void PistonExtensionTile::registerIcons(IconRegister *iconRegister)
{
	// None
}

int PistonExtensionTile::getRenderShape()
{
	return SHAPE_PISTON_EXTENSION;
}

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

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

bool PistonExtensionTile::mayPlace(Level *level, int x, int y, int z)
{
	return false;
}

bool PistonExtensionTile::mayPlace(Level *level, int x, int y, int z, int face)
{
	return false;
}

int PistonExtensionTile::getResourceCount(Random *random)
{
	return 0;
}

void PistonExtensionTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
{
	int data = level->getData(x, y, z);

	const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;
	const float smallEdge1 = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f;
	const float smallEdge2 = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f;
	const float largeEdge1 = (8.0f - PistonBaseTile::PLATFORM_THICKNESS) / 16.0f;
	const float largeEdge2 = (8.0f + PistonBaseTile::PLATFORM_THICKNESS) / 16.0f;

	switch (getFacing(data))
	{
	case Facing::DOWN:
		setShape(0, 0, 0, 1, thickness, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		setShape(smallEdge1, thickness, smallEdge1, smallEdge2, 1, smallEdge2);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		break;
	case Facing::UP:
		setShape(0, 1 - thickness, 0, 1, 1, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		setShape(smallEdge1, 0, smallEdge1, smallEdge2, 1 - thickness, smallEdge2);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		break;
	case Facing::NORTH:
		setShape(0, 0, 0, 1, 1, thickness);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		setShape(largeEdge1, smallEdge1, thickness, largeEdge2, smallEdge2, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		break;
	case Facing::SOUTH:
		setShape(0, 0, 1 - thickness, 1, 1, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		setShape(largeEdge1, smallEdge1, 0, largeEdge2, smallEdge2, 1 - thickness);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		break;
	case Facing::WEST:
		setShape(0, 0, 0, thickness, 1, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		setShape(smallEdge1, largeEdge1, thickness, smallEdge2, largeEdge2, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		break;
	case Facing::EAST:
		setShape(1 - thickness, 0, 0, 1, 1, 1);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		setShape(0, smallEdge1, largeEdge1, 1 - thickness, smallEdge2, largeEdge2);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
		break;
	}
	setShape(0, 0, 0, 1, 1, 1);

}

void PistonExtensionTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
{
	int data = (forceData == -1 ) ? level->getData(x, y, z) : forceData;

	const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f;

	switch (getFacing(data))
	{
	case Facing::DOWN:
		setShape(0, 0, 0, 1, thickness, 1);
		break;
	case Facing::UP:
		setShape(0, 1 - thickness, 0, 1, 1, 1);
		break;
	case Facing::NORTH:
		setShape(0, 0, 0, 1, 1, thickness);
		break;
	case Facing::SOUTH:
		setShape(0, 0, 1 - thickness, 1, 1, 1);
		break;
	case Facing::WEST:
		setShape(0, 0, 0, thickness, 1, 1);
		break;
	case Facing::EAST:
		setShape(1 - thickness, 0, 0, 1, 1, 1);
		break;
	}
}

void PistonExtensionTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
	int facing = getFacing(level->getData(x, y, z));
	int tile = level->getTile(x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing]);
	if (tile != Tile::pistonBase_Id && tile != Tile::pistonStickyBase_Id)
	{
		level->removeTile(x, y, z);
	}
	else
	{
		Tile::tiles[tile]->neighborChanged(level, x - Facing::STEP_X[facing], y - Facing::STEP_Y[facing], z - Facing::STEP_Z[facing], type);
	}
}

int PistonExtensionTile::getFacing(int data)
{
	return data & 0x7;
}

int PistonExtensionTile::cloneTileId(Level *level, int x, int y, int z)
{
	int data = level->getData(x, y, z);
	if ((data & STICKY_BIT) != 0)
	{
		return Tile::pistonStickyBase_Id;
	}
	return Tile::pistonBase_Id;
	return 0;
}