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.world.level.h"
3#include "net.minecraft.world.level.material.h"
4#include "net.minecraft.world.entity.h"
5#include "net.minecraft.world.phys.h"
6#include "net.minecraft.world.damagesource.h"
7#include "net.minecraft.h"
8#include "net.minecraft.world.h"
9#include "CactusTile.h"
10
11CactusTile::CactusTile(int id) : Tile(id, Material::cactus,isSolidRender())
12{
13 setTicking(true);
14 iconTop = NULL;
15 iconBottom = NULL;
16}
17
18void CactusTile::tick(Level *level, int x, int y, int z, Random *random)
19{
20 if (level->isEmptyTile(x, y + 1, z))
21 {
22 int height = 1;
23 while (level->getTile(x, y - height, z) == id)
24 {
25 height++;
26 }
27 if (height < 3)
28 {
29 int age = level->getData(x, y, z);
30 if (age == 15)
31 {
32 level->setTileAndUpdate(x, y + 1, z, id);
33 level->setData(x, y, z, 0, Tile::UPDATE_NONE);
34 neighborChanged(level, x, y + 1, z, id);
35 }
36 else
37 {
38 level->setData(x, y, z, age + 1, Tile::UPDATE_NONE);
39 }
40 }
41 }
42}
43
44AABB *CactusTile::getAABB(Level *level, int x, int y, int z)
45{
46 float r = 1 / 16.0f;
47 return AABB::newTemp(x + r, y, z + r, x + 1 - r, y + 1 - r, z + 1 - r);
48
49}
50
51AABB *CactusTile::getTileAABB(Level *level, int x, int y, int z)
52{
53 float r = 1 / 16.0f;
54 return AABB::newTemp(x + r, y, z + r, x + 1 - r, y + 1, z + 1 - r);
55}
56
57Icon *CactusTile::getTexture(int face, int data)
58{
59 if (face == Facing::UP) return iconTop;
60 if (face == Facing::DOWN) return iconBottom;
61 else return icon;
62}
63
64bool CactusTile::isCubeShaped()
65{
66 return false;
67}
68
69bool CactusTile::isSolidRender(bool isServerLevel)
70{
71 return false;
72}
73
74int CactusTile::getRenderShape()
75{
76 return Tile::SHAPE_CACTUS;
77}
78
79bool CactusTile::mayPlace(Level *level, int x, int y, int z)
80{
81 if (!Tile::mayPlace(level, x, y, z)) return false;
82
83 return canSurvive(level, x, y, z);
84}
85
86void CactusTile::neighborChanged(Level *level, int x, int y, int z, int type)
87{
88 if (!canSurvive(level, x, y, z))
89 {
90 level->destroyTile(x, y, z, true);
91 }
92}
93
94bool CactusTile::canSurvive(Level *level, int x, int y, int z)
95{
96 if (level->getMaterial(x - 1, y, z)->isSolid()) return false;
97 if (level->getMaterial(x + 1, y, z)->isSolid()) return false;
98 if (level->getMaterial(x, y, z - 1)->isSolid()) return false;
99 if (level->getMaterial(x, y, z + 1)->isSolid()) return false;
100 int below = level->getTile(x, y - 1, z);
101 return below == Tile::cactus_Id || below == Tile::sand_Id;
102}
103
104void CactusTile::entityInside(Level *level, int x, int y, int z, shared_ptr<Entity> entity)
105{
106 entity->hurt(DamageSource::cactus, 1);
107}
108
109void CactusTile::registerIcons(IconRegister *iconRegister)
110{
111 icon = iconRegister->registerIcon(L"cactus_side");
112 iconTop = iconRegister->registerIcon(L"cactus_top");
113 iconBottom = iconRegister->registerIcon(L"cactus_bottom");
114}
115
116bool CactusTile::shouldTileTick(Level *level, int x,int y,int z)
117{
118 return level->isEmptyTile(x, y + 1, z);
119}