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

ThinFenceTile::ThinFenceTile(int id, const wstring &tex, const wstring &edgeTex, Material *material, bool dropsResources) : Tile(id, material,isSolidRender())
{
	iconSide = nullptr;
	edgeTexture = edgeTex;
	this->dropsResources = dropsResources;
	this->texture = tex;
}

int ThinFenceTile::getResource(int data, Random *random, int playerBonusLevel)
{
    if (!dropsResources)
	{
        return 0;
    }
    return Tile::getResource(data, random, playerBonusLevel);
}

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

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

int ThinFenceTile::getRenderShape()
{
	return material == Material::glass ? Tile::SHAPE_THIN_PANE : Tile::SHAPE_IRON_FENCE;
}

bool ThinFenceTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)
{
    int id = level->getTile(x, y, z);
    if (id == this->id) return false;
    return Tile::shouldRenderFace(level, x, y, z, face);
}

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

    if ((w && e) || (!w && !e && !n && !s))
	{
        setShape(0, 0, 7.0f / 16.0f, 1, 1, 9.0f / 16.0f);
        Tile::addAABBs(level, x, y, z, box, boxes, source);
    }
	else if (w && !e)
	{
        setShape(0, 0, 7.0f / 16.0f, .5f, 1, 9.0f / 16.0f);
        Tile::addAABBs(level, x, y, z, box, boxes, source);
    }
	else if (!w && e)
	{
        setShape(.5f, 0, 7.0f / 16.0f, 1, 1, 9.0f / 16.0f);
        Tile::addAABBs(level, x, y, z, box, boxes, source);
    }
    if ((n && s) || (!w && !e && !n && !s))
	{
        setShape(7.0f / 16.0f, 0, 0, 9.0f / 16.0f, 1, 1);
        Tile::addAABBs(level, x, y, z, box, boxes, source);
    }
	else if (n && !s)
	{
        setShape(7.0f / 16.0f, 0, 0, 9.0f / 16.0f, 1, .5f);
        Tile::addAABBs(level, x, y, z, box, boxes, source);
    }
	else if (!n && s)
	{
        setShape(7.0f / 16.0f, 0, .5f, 9.0f / 16.0f, 1, 1);
        Tile::addAABBs(level, x, y, z, box, boxes, source);
    }
}

void ThinFenceTile::updateDefaultShape()
{
	setShape(0, 0, 0, 1, 1, 1);
}

void ThinFenceTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
{
    float minX = 7.0f / 16.0f;
    float maxX = 9.0f / 16.0f;
    float minZ = 7.0f / 16.0f;
    float maxZ = 9.0f / 16.0f;

    bool n = attachsTo(level->getTile(x, y, z - 1));
    bool s = attachsTo(level->getTile(x, y, z + 1));
    bool w = attachsTo(level->getTile(x - 1, y, z));
    bool e = attachsTo(level->getTile(x + 1, y, z));

    if ((w && e) || (!w && !e && !n && !s))
	{
        minX = 0;
        maxX = 1;
    }
	else if (w && !e)
	{
        minX = 0;
    }
	else if (!w && e)
	{
        maxX = 1;
    }
    if ((n && s) || (!w && !e && !n && !s))
	{
        minZ = 0;
        maxZ = 1;
    }
	else if (n && !s)
	{
        minZ = 0;
    }
	else if (!n && s)
	{
        maxZ = 1;
    }
	setShape(minX, 0, minZ, maxX, 1, maxZ);
}

Icon *ThinFenceTile::getEdgeTexture()
{
	return iconSide;
}

bool ThinFenceTile::attachsTo(int tile)
{
	return Tile::solid[tile] || tile == id || tile == Tile::glass_Id || tile == Tile::stained_glass_Id || tile == Tile::stained_glass_pane_Id;
}

bool ThinFenceTile::isSilkTouchable()
{
	return true;
}

shared_ptr<ItemInstance> ThinFenceTile::getSilkTouchItemInstance(int data)
{
	return std::make_shared<ItemInstance>(id, 1, data);
}

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