aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PS3/SPU_Tasks/ChunkUpdate/TripWireTile_SPU.h
blob: fbb84fb59dd5fb570e84f3dadcc6d7516b927da7 (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
#pragma once

#include "Tile_SPU.h"
#include "TripWireSourceTile_SPU.h"
#include "Direction_SPU.h"

class TripWireTile_SPU : public Tile_SPU
{
public:
	static const int MASK_POWERED = 0x1;
	static const int MASK_SUSPENDED = 0x2;
	static const int MASK_ATTACHED = 0x4;
	static const int MASK_DISARMED = 0x8;

	TripWireTile_SPU(int id) : Tile_SPU(id) {}

	bool blocksLight() { return false; }
 	bool isSolidRender(bool isServerLevel = false) { return false; }
	bool isCubeShaped() { return false;}
	int getRenderLayer() { return 1; }
	int getRenderShape() { return Tile_SPU::SHAPE_TRIPWIRE; }

	void updateShape(ChunkRebuildData *level, int x, int y, int z)
	{
		int data = level->getData(x, y, z);
		bool attached = (data & MASK_ATTACHED) == MASK_ATTACHED;
		bool suspended = (data & MASK_SUSPENDED) == MASK_SUSPENDED;

		if (!suspended)
		{
			setShape(0, 0, 0, 1, 1.5f / 16.0f, 1);
		}
		else if (!attached)
		{
			setShape(0, 0, 0, 1, 8.0f / 16.0f, 1);
		}
		else
		{
			setShape(0, 1.0f / 16.0f, 0, 1, 2.5f / 16.0f, 1);
		}

	}
	static bool shouldConnectTo(ChunkRebuildData *level, int x, int y, int z, int data, int dir)
	{
		{
			int tx = x + Direction::STEP_X[dir];
			int ty = y;
			int tz = z + Direction::STEP_Z[dir];
			int t = level->getTile(tx, ty, tz);
			bool suspended = (data & MASK_SUSPENDED) == MASK_SUSPENDED;

			if (t == Tile_SPU::tripWireSource_Id)
			{
				int otherData = level->getData(tx, ty, tz);
				int facing = otherData & TripWireSourceTile_SPU::MASK_DIR;

				return facing == Direction::DIRECTION_OPPOSITE[dir];
			}

			if (t == Tile_SPU::tripWire_Id)
			{
				int otherData = level->getData(tx, ty, tz);
				bool otherSuspended = (otherData & MASK_SUSPENDED) == MASK_SUSPENDED;
				return suspended == otherSuspended;
			}

			return false;
		}
	}
};