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.phys.h"
4#include "net.minecraft.h"
5#include "net.minecraft.world.h"
6#include "FarmTile.h"
7
8
9FarmTile::FarmTile(int id) : Tile(id, Material::dirt,isSolidRender())
10{
11 iconWet = NULL;
12 iconDry = NULL;
13
14 setTicking(true);
15 updateDefaultShape();
16 setLightBlock(255);
17}
18
19// 4J Added override
20void FarmTile::updateDefaultShape()
21{
22 setShape(0, 0, 0, 1, 15 / 16.0f, 1);
23}
24
25AABB *FarmTile::getAABB(Level *level, int x, int y, int z)
26{
27 return AABB::newTemp(x + 0, y + 0, z + 0, x + 1, y + 1, z + 1);
28}
29
30bool FarmTile::isSolidRender(bool isServerLevel)
31{
32 return false;
33}
34
35bool FarmTile::isCubeShaped()
36{
37 return false;
38}
39
40Icon *FarmTile::getTexture(int face, int data)
41{
42 if (face == Facing::UP)
43 {
44 if(data > 0)
45 {
46 return iconWet;
47 }
48 else
49 {
50 return iconDry;
51 }
52 }
53 return Tile::dirt->getTexture(face);
54}
55
56void FarmTile::tick(Level *level, int x, int y, int z, Random *random)
57{
58 if (isNearWater(level, x, y, z) || level->isRainingAt(x, y + 1, z))
59 {
60 level->setData(x, y, z, 7, Tile::UPDATE_CLIENTS);
61 }
62 else
63 {
64 int moisture = level->getData(x, y, z);
65 if (moisture > 0)
66 {
67 level->setData(x, y, z, moisture - 1, Tile::UPDATE_CLIENTS);
68 }
69 else
70 {
71 if (!isUnderCrops(level, x, y, z))
72 {
73 level->setTileAndUpdate(x, y, z, Tile::dirt_Id);
74 }
75 }
76 }
77}
78
79void FarmTile::fallOn(Level *level, int x, int y, int z, shared_ptr<Entity> entity, float fallDistance)
80{
81 // 4J Stu - Fix for #86148 - Code: Gameplay: Jumping on Farmland does not always result in turning to Dirt Block
82 // We should not be setting tiles on the client based on random values!
83 if (!level->isClientSide && level->random->nextFloat() < (fallDistance - .5f))
84 {
85 if(entity->instanceof(eTYPE_PLAYER))
86 {
87 shared_ptr<Player> player = dynamic_pointer_cast<Player>(entity);
88 if(!player->isAllowedToMine())
89 {
90 return;
91 }
92 }
93 else if (!level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING))
94 {
95 return;
96 }
97 level->setTileAndUpdate(x, y, z, Tile::dirt_Id);
98 }
99}
100
101bool FarmTile::isUnderCrops(Level *level, int x, int y, int z)
102{
103 int r = 0;
104 for (int xx = x - r; xx <= x + r; xx++)
105 for (int zz = z - r; zz <= z + r; zz++)
106 {
107 int tile = level->getTile(xx, y + 1, zz);
108 if (tile == Tile::wheat_Id || tile == Tile::melonStem_Id || tile == Tile::pumpkinStem_Id || tile == Tile::potatoes_Id || tile == Tile::carrots_Id)
109 {
110 return true;
111 }
112 }
113 return false;
114}
115
116bool FarmTile::isNearWater(Level *level, int x, int y, int z)
117{
118 for (int xx = x - 4; xx <= x + 4; xx++)
119 for (int yy = y; yy <= y + 1; yy++)
120 for (int zz = z - 4; zz <= z + 4; zz++)
121 {
122 if (level->getMaterial(xx, yy, zz) == Material::water)
123 {
124 return true;
125 }
126 }
127 return false;
128}
129
130void FarmTile::neighborChanged(Level *level, int x, int y, int z, int type)
131{
132 Tile::neighborChanged(level, x, y, z, type);
133 Material *above = level->getMaterial(x, y + 1, z);
134 if (above->isSolid())
135 {
136 level->setTileAndUpdate(x, y, z, Tile::dirt_Id);
137 }
138}
139
140bool FarmTile::blocksLight()
141{
142 return true;
143}
144
145int FarmTile::getResource(int data, Random *random, int playerBonusLevel)
146{
147 return Tile::dirt->getResource(0, random, playerBonusLevel);
148}
149
150int FarmTile::cloneTileId(Level *level, int x, int y, int z)
151{
152 return Tile::dirt_Id;
153}
154
155void FarmTile::registerIcons(IconRegister *iconRegister)
156{
157 iconWet = iconRegister->registerIcon(L"farmland_wet");
158 iconDry = iconRegister->registerIcon(L"farmland_dry");
159}