the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.stats.h"
3#include "net.minecraft.world.entity.player.h"
4#include "net.minecraft.world.entity.item.h"
5#include "net.minecraft.world.item.h"
6#include "net.minecraft.world.level.h"
7#include "net.minecraft.world.phys.h"
8#include "net.minecraft.world.h"
9#include "TopSnowTile.h"
10
11const int TopSnowTile::MAX_HEIGHT = 6;
12const int TopSnowTile::HEIGHT_MASK = 7; // max 8 steps
13
14TopSnowTile::TopSnowTile(int id) : Tile(id, Material::topSnow,isSolidRender())
15{
16 setShape(0, 0, 0, 1, 2 / 16.0f, 1);
17 setTicking(true);
18 updateShape(0);
19}
20
21void TopSnowTile::registerIcons(IconRegister *iconRegister)
22{
23 icon = iconRegister->registerIcon(L"snow");
24}
25
26AABB *TopSnowTile::getAABB(Level *level, int x, int y, int z)
27{
28 int height = level->getData(x, y, z) & HEIGHT_MASK;
29 float offset = 2.0f / SharedConstants::WORLD_RESOLUTION;
30 ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape);
31 return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + (height * offset), z + tls->zz1);
32}
33
34float TopSnowTile::getHeight(Level *level, int x, int y, int z)
35{
36 int height = level->getData(x, y, z) & HEIGHT_MASK;
37 return 2 * (1 + height) / 16.0f;
38}
39
40bool TopSnowTile::blocksLight()
41{
42 return false;
43}
44
45bool TopSnowTile::isSolidRender(bool isServerLevel)
46{
47 return false;
48}
49
50bool TopSnowTile::isCubeShaped()
51{
52 return false;
53}
54
55void TopSnowTile::updateDefaultShape()
56{
57 updateShape(0);
58}
59
60void TopSnowTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
61{
62 updateShape(level->getData(x, y, z));
63}
64
65void TopSnowTile::updateShape(int data)
66{
67 int height = data & HEIGHT_MASK;
68 float o = 2 * (1 + height) / 16.0f;
69 setShape(0, 0, 0, 1, o, 1);
70}
71
72bool TopSnowTile::mayPlace(Level *level, int x, int y, int z)
73{
74 int t = level->getTile(x, y - 1, z);
75 if (t == 0) return false;
76 if (t == id && (level->getData(x, y - 1, z) & HEIGHT_MASK) == MAX_HEIGHT + 1) return true;
77 // 4J Stu - Assume when placing that this is the server level and we don't care how it's going to be rendered
78 // Fix for #9407 - Gameplay: Destroying a block of snow on top of trees, removes any adjacent snow.
79 if (t != Tile::leaves_Id && !Tile::tiles[t]->isSolidRender(true)) return false;
80 return level->getMaterial(x, y - 1, z)->blocksMotion();
81}
82
83void TopSnowTile::neighborChanged(Level *level, int x, int y, int z, int type)
84{
85 checkCanSurvive(level, x, y, z);
86}
87
88bool TopSnowTile::checkCanSurvive(Level *level, int x, int y, int z)
89{
90 if (!mayPlace(level, x, y, z))
91 {
92 spawnResources(level, x, y, z, level->getData(x, y, z), 0);
93 level->removeTile(x, y, z);
94 return false;
95 }
96 return true;
97}
98
99void TopSnowTile::playerDestroy(Level *level, shared_ptr<Player> player, int x, int y, int z, int data)
100{
101 int type = Item::snowBall->id;
102 int height = data & HEIGHT_MASK;
103 popResource(level, x, y, z, shared_ptr<ItemInstance>( new ItemInstance(type, height + 1, 0)));
104 level->removeTile(x, y, z);
105}
106
107int TopSnowTile::getResource(int data, Random *random, int playerBonusLevel)
108{
109 return Item::snowBall->id;
110}
111
112int TopSnowTile::getResourceCount(Random *random)
113{
114 return 0;
115}
116
117void TopSnowTile::tick(Level *level, int x, int y, int z, Random *random)
118{
119 if (level->getBrightness(LightLayer::Block, x, y, z) > 11)
120 {
121 spawnResources(level, x, y, z, level->getData(x, y, z), 0);
122 level->removeTile(x, y, z);
123 }
124}
125
126bool TopSnowTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)
127{
128 if (face == 1) return true;
129 // 4J - don't render faces if neighbouring tiles are also TopSnowTile with at least the same height as this one
130 // Otherwise we get horrible artifacts from the non-manifold geometry created. Fixes bug #8506
131 if ( ( level->getTile(x,y,z) == Tile::topSnow_Id ) && ( face >= 2 ) )
132 {
133 int h0 = level->getData(x,y,z) & HEIGHT_MASK;
134 int xx = x;
135 int yy = y;
136 int zz = z;
137 // Work out coords of tile who's face we're considering (rather than it's neighbour which is passed in here as x,y,z already
138 // offsetting by the face direction)
139 switch(face)
140 {
141 case 2:
142 zz += 1;
143 break;
144 case 3:
145 zz -= 1;
146 break;
147 case 4:
148 xx += 1;
149 break;
150 case 5:
151 xx -= 1;
152 break;
153 default:
154 break;
155 }
156 int h1 = level->getData(xx,yy,zz) & HEIGHT_MASK;
157 if( h0 >= h1 ) return false;
158 }
159 return Tile::shouldRenderFace(level, x, y, z, face);
160}
161
162bool TopSnowTile::shouldTileTick(Level *level, int x,int y,int z)
163{
164 return level->getBrightness(LightLayer::Block, x, y, z) > 11;
165}