aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/FenceTile.cpp
blob: 39f4aac1c77bad2509c42ab4d175a00faa75993f (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
#include "stdafx.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.h"
#include "FenceTile.h"

FenceTile::FenceTile(int id, const wstring &texture, Material *material) : Tile( id, material, isSolidRender())
{
	this->texture = texture;
}

void FenceTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
{
	bool n = connectsTo(level, x, y, z - 1);
	bool s = connectsTo(level, x, y, z + 1);
	bool w = connectsTo(level, x - 1, y, z);
	bool e = connectsTo(level, x + 1, y, z);

	float west = 6.0f / 16.0f;
	float east = 10.0f / 16.0f;
	float north = 6.0f / 16.0f;
	float south = 10.0f / 16.0f;

	if (n)
	{
		north = 0;
	}
	if (s)
	{
		south = 1;
	}
	if (n || s)
	{
		setShape(west, 0, north, east, 1.5f, south);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
	}
	north = 6.0f / 16.0f;
	south = 10.0f / 16.0f;
	if (w)
	{
		west = 0;
	}
	if (e)
	{
		east = 1;
	}
	if (w || e || (!n && !s))
	{
		setShape(west, 0, north, east, 1.5f, south);
		Tile::addAABBs(level, x, y, z, box, boxes, source);
	}

	if (n)
	{
		north = 0;
	}
	if (s)
	{
		south = 1;
	}

	setShape(west, 0, north, east, 1.0f, south);
}

void FenceTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
{
	bool n = connectsTo(level, x, y, z - 1);
	bool s = connectsTo(level, x, y, z + 1);
	bool w = connectsTo(level, x - 1, y, z);
	bool e = connectsTo(level, x + 1, y, z);

	float west = 6.0f / 16.0f;
	float east = 10.0f / 16.0f;
	float north = 6.0f / 16.0f;
	float south = 10.0f / 16.0f;

	if (n)
	{
		north = 0;
	}
	if (s)
	{
		south = 1;
	}
	if (w)
	{
		west = 0;
	}
	if (e)
	{
		east = 1;
	}

	setShape(west, 0, north, east, 1.0f, south);
}

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

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

bool FenceTile::isPathfindable(LevelSource *level, int x, int y, int z)
{
	return false;
}

int FenceTile::getRenderShape()
{
	return Tile::SHAPE_FENCE;
}

bool FenceTile::connectsTo(LevelSource *level, int x, int y, int z)
{
	int tile = level->getTile(x, y, z);
	if (tile == id || tile == Tile::fenceGate_Id)
	{
		return true;
	}
	Tile *tileInstance = Tile::tiles[tile];
	if (tileInstance != NULL)
	{
		if (tileInstance->material->isSolidBlocking() && tileInstance->isCubeShaped())
		{
			return tileInstance->material != Material::vegetable;
		}
	}
	return false;
}

bool FenceTile::isFence(int tile)
{
	return tile == Tile::fence_Id || tile == Tile::netherFence_Id;
}

void FenceTile::registerIcons(IconRegister *iconRegister)
{
	icon = iconRegister->registerIcon(texture);
}

bool FenceTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)
{
	return true;
}

bool FenceTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly)
{
	if (level->isClientSide) return true;
	if (LeashItem::bindPlayerMobs(player, level, x, y, z))
	{
		return true;
	}
	return false;
}