the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1using namespace std;
2
3#include "stdafx.h"
4#include "com.mojang.nbt.h"
5#include "net.minecraft.world.level.tile.h"
6#include "net.minecraft.world.phys.h"
7#include "net.minecraft.world.level.h"
8#include "net.minecraft.world.item.h"
9#include "net.minecraft.world.entity.item.h"
10#include "net.minecraft.world.entity.player.h"
11#include "net.minecraft.world.entity.global.h"
12#include "net.minecraft.world.entity.animal.h"
13#include "net.minecraft.world.h"
14#include "Material.h"
15#include "DyePowderItem.h"
16
17DyePowderItem::DyePowderItem(int id) : Item( id )
18{
19 setStackedByData(true);
20 setMaxDamage(0);
21 icons = NULL;
22}
23
24const unsigned int DyePowderItem::COLOR_DESCS[] =
25{
26 IDS_ITEM_DYE_POWDER_BLACK,
27 IDS_ITEM_DYE_POWDER_RED,
28 IDS_ITEM_DYE_POWDER_GREEN,
29 IDS_ITEM_DYE_POWDER_BROWN,
30 IDS_ITEM_DYE_POWDER_BLUE,
31 IDS_ITEM_DYE_POWDER_PURPLE,
32 IDS_ITEM_DYE_POWDER_CYAN,
33 IDS_ITEM_DYE_POWDER_SILVER,
34 IDS_ITEM_DYE_POWDER_GRAY,
35 IDS_ITEM_DYE_POWDER_PINK,
36 IDS_ITEM_DYE_POWDER_LIME,
37 IDS_ITEM_DYE_POWDER_YELLOW,
38 IDS_ITEM_DYE_POWDER_LIGHT_BLUE,
39 IDS_ITEM_DYE_POWDER_MAGENTA,
40 IDS_ITEM_DYE_POWDER_ORANGE,
41 IDS_ITEM_DYE_POWDER_WHITE
42};
43
44const unsigned int DyePowderItem::COLOR_USE_DESCS[] =
45{
46 IDS_DESC_DYE_BLACK,
47 IDS_DESC_DYE_RED,
48 IDS_DESC_DYE_GREEN,
49 IDS_DESC_DYE_BROWN,
50 IDS_DESC_DYE_BLUE,
51 IDS_DESC_DYE_PURPLE,
52 IDS_DESC_DYE_CYAN,
53 IDS_DESC_DYE_LIGHTGRAY,
54 IDS_DESC_DYE_GRAY,
55 IDS_DESC_DYE_PINK,
56 IDS_DESC_DYE_LIME,
57 IDS_DESC_DYE_YELLOW,
58 IDS_DESC_DYE_LIGHTBLUE,
59 IDS_DESC_DYE_MAGENTA,
60 IDS_DESC_DYE_ORANGE,
61 IDS_DESC_DYE_WHITE
62};
63
64const wstring DyePowderItem::COLOR_TEXTURES[] =
65{ L"black", L"red", L"green", L"brown", L"blue", L"purple", L"cyan", L"silver", L"gray", L"pink",
66L"lime", L"yellow", L"light_blue", L"magenta", L"orange", L"white"};
67
68const int DyePowderItem::COLOR_RGB[] =
69{
70 0x1e1b1b,
71 0xb3312c,
72 0x3b511a,
73 0x51301a,
74 0x253192,
75 0x7b2fbe,
76 0x287697,
77 0xababab,
78 0x434343,
79 0xd88198,
80 0x41cd34,
81 0xdecf2a,
82 0x6689d3,
83 0xc354cd,
84 0xeb8844,
85 0xf0f0f0
86};
87
88const int DyePowderItem::BLACK = 0;
89const int DyePowderItem::RED = 1;
90const int DyePowderItem::GREEN = 2;
91const int DyePowderItem::BROWN = 3;
92const int DyePowderItem::BLUE = 4;
93const int DyePowderItem::PURPLE = 5;
94const int DyePowderItem::CYAN = 6;
95const int DyePowderItem::SILVER = 7;
96const int DyePowderItem::GRAY = 8;
97const int DyePowderItem::PINK = 9;
98const int DyePowderItem::LIME = 10;
99const int DyePowderItem::YELLOW = 11;
100const int DyePowderItem::LIGHT_BLUE = 12;
101const int DyePowderItem::MAGENTA = 13;
102const int DyePowderItem::ORANGE = 14;
103const int DyePowderItem::WHITE = 15;
104
105Icon *DyePowderItem::getIcon(int itemAuxValue)
106{
107 int colorValue = Mth::clamp(itemAuxValue, 0, 15);
108 return icons[colorValue];
109}
110
111unsigned int DyePowderItem::getDescriptionId(shared_ptr<ItemInstance> itemInstance)
112{
113 int colorValue = Mth::clamp(itemInstance->getAuxValue(), 0, 15);
114 return COLOR_DESCS[colorValue];
115}
116
117unsigned int DyePowderItem::getUseDescriptionId(shared_ptr<ItemInstance> itemInstance)
118{
119 return COLOR_USE_DESCS[itemInstance->getAuxValue()];
120}
121
122bool DyePowderItem::useOn(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, bool bTestUseOnOnly)
123{
124 if (!player->mayUseItemAt(x, y, z, face, itemInstance)) return false;
125
126 // 4J-PB - Adding a test only version to allow tooltips to be displayed
127 if (itemInstance->getAuxValue() == WHITE)
128 {
129 // bone meal is a fertilizer, so instantly grow trees and stuff
130
131 if (growCrop(itemInstance, level, x, y, z, bTestUseOnOnly))
132 {
133 if (!level->isClientSide) level->levelEvent(LevelEvent::PARTICLES_PLANT_GROWTH, x, y, z, 0);
134 return true;
135 }
136 }
137 else if (itemInstance->getAuxValue() == BROWN)
138 {
139 // plant cocoa
140
141 int tile = level->getTile(x, y, z);
142 int data = level->getData(x, y, z);
143
144 if (tile == Tile::treeTrunk_Id && TreeTile::getWoodType(data) == TreeTile::JUNGLE_TRUNK)
145 {
146 if (face == 0) return false;
147 if (face == 1) return false;
148 if (face == 2) z--;
149 if (face == 3) z++;
150 if (face == 4) x--;
151 if (face == 5) x++;
152
153 if(!bTestUseOnOnly)
154 {
155 if (level->isEmptyTile(x, y, z))
156 {
157 int cocoaData = Tile::tiles[Tile::cocoa_Id]->getPlacedOnFaceDataValue(level, x, y, z, face, clickX, clickY, clickZ, 0);
158 level->setTileAndData(x, y, z, Tile::cocoa_Id, cocoaData, Tile::UPDATE_CLIENTS);
159 if (!player->abilities.instabuild)
160 {
161 itemInstance->count--;
162 }
163 }
164 }
165 return true;
166 }
167 }
168 return false;
169}
170
171bool DyePowderItem::growCrop(shared_ptr<ItemInstance> itemInstance, Level *level, int x, int y, int z, bool bTestUseOnOnly)
172{
173 int tile = level->getTile(x, y, z);
174 if (tile == Tile::sapling_Id)
175 {
176 if(!bTestUseOnOnly)
177 {
178 if (!level->isClientSide)
179 {
180 if (level->random->nextFloat() < 0.45) ((Sapling *) Tile::sapling)->advanceTree(level, x, y, z, level->random);
181 itemInstance->count--;
182 }
183 }
184 return true;
185 }
186 else if (tile == Tile::mushroom_brown_Id || tile == Tile::mushroom_red_Id)
187 {
188 if(!bTestUseOnOnly)
189 {
190 if (!level->isClientSide)
191 {
192 if (level->random->nextFloat() < 0.4) ((Mushroom *) Tile::tiles[tile])->growTree(level, x, y, z, level->random);
193 itemInstance->count--;
194 }
195 }
196 return true;
197 }
198 else if (tile == Tile::melonStem_Id || tile == Tile::pumpkinStem_Id)
199 {
200 if (level->getData(x, y, z) == 7) return false;
201 if(!bTestUseOnOnly)
202 {
203 if (!level->isClientSide)
204 {
205 ((StemTile *) Tile::tiles[tile])->growCrops(level, x, y, z);
206 itemInstance->count--;
207 }
208 }
209 return true;
210 }
211 else if (tile == Tile::carrots_Id || tile == Tile::potatoes_Id)
212 {
213 if (level->getData(x, y, z) == 7) return false;
214 if(!bTestUseOnOnly)
215 {
216 if (!level->isClientSide)
217 {
218 ((CropTile *) Tile::tiles[tile])->growCrops(level, x, y, z);
219 itemInstance->count--;
220 }
221 }
222 return true;
223 }
224 else if (tile == Tile::wheat_Id)
225 {
226 if (level->getData(x, y, z) == 7) return false;
227 if(!bTestUseOnOnly)
228 {
229 if (!level->isClientSide)
230 {
231 ((CropTile *) Tile::tiles[tile])->growCrops(level, x, y, z);
232 itemInstance->count--;
233 }
234 }
235 return true;
236 }
237 else if (tile == Tile::cocoa_Id)
238 {
239 if(!bTestUseOnOnly)
240 {
241 int data = level->getData(x, y, z);
242 int direction = DirectionalTile::getDirection(data);
243 int age = CocoaTile::getAge(data);
244 if (age >= 2) return false;
245 if (!level->isClientSide)
246 {
247 age++;
248 level->setData(x, y, z, (age << 2) | direction, Tile::UPDATE_CLIENTS);
249 itemInstance->count--;
250 }
251 }
252 return true;
253 }
254 else if (tile == Tile::grass_Id)
255 {
256 if(!bTestUseOnOnly)
257 {
258 if (!level->isClientSide)
259 {
260 itemInstance->count--;
261
262 for (int j = 0; j < 128; j++)
263 {
264 int xx = x;
265 int yy = y + 1;
266 int zz = z;
267 for (int i = 0; i < j / 16; i++)
268 {
269 xx += random->nextInt(3) - 1;
270 yy += (random->nextInt(3) - 1) * random->nextInt(3) / 2;
271 zz += random->nextInt(3) - 1;
272 if (level->getTile(xx, yy - 1, zz) != Tile::grass_Id || level->isSolidBlockingTile(xx, yy, zz))
273 {
274 goto mainloop;
275 }
276 }
277
278 if (level->getTile(xx, yy, zz) == 0)
279 {
280 if (random->nextInt(10) != 0)
281 {
282 if (Tile::tallgrass->canSurvive(level, xx, yy, zz)) level->setTileAndData(xx, yy, zz, Tile::tallgrass_Id, TallGrass::TALL_GRASS, Tile::UPDATE_ALL);
283 }
284 else if (random->nextInt(3) != 0)
285 {
286 if (Tile::flower->canSurvive(level, xx, yy, zz)) level->setTileAndUpdate(xx, yy, zz, Tile::flower_Id);
287 }
288 else
289 {
290 if (Tile::rose->canSurvive(level, xx, yy, zz)) level->setTileAndUpdate(xx, yy, zz, Tile::rose_Id);
291 }
292 }
293
294 // 4J - Stops infinite loops.
295mainloop: continue;
296 }
297 }
298 }
299
300 return true;
301 }
302 return false;
303}
304
305void DyePowderItem::addGrowthParticles(Level *level, int x, int y, int z, int count)
306{
307 int id = level->getTile(x, y, z);
308 if (count == 0) count = 15;
309 Tile *tile = id > 0 && id < Tile::TILE_NUM_COUNT ? Tile::tiles[id] : NULL;
310
311 if (tile == NULL) return;
312 tile->updateShape(level, x, y, z);
313
314 for (int i = 0; i < count; i++)
315 {
316 double xa = level->random->nextGaussian() * 0.02;
317 double ya = level->random->nextGaussian() * 0.02;
318 double za = level->random->nextGaussian() * 0.02;
319 level->addParticle(eParticleType_happyVillager, x + level->random->nextFloat(), y + level->random->nextFloat() * tile->getShapeY1(), z + level->random->nextFloat(), xa, ya, za);
320 }
321}
322
323bool DyePowderItem::interactEnemy(shared_ptr<ItemInstance> itemInstance, shared_ptr<Player> player, shared_ptr<LivingEntity> mob)
324{
325 if (dynamic_pointer_cast<Sheep>( mob ) != NULL)
326 {
327 shared_ptr<Sheep> sheep = dynamic_pointer_cast<Sheep>(mob);
328 // convert to tile-based color value (0 is white instead of black)
329 int newColor = ColoredTile::getTileDataForItemAuxValue(itemInstance->getAuxValue());
330 if (!sheep->isSheared() && sheep->getColor() != newColor)
331 {
332 sheep->setColor(newColor);
333 itemInstance->count--;
334 }
335 return true;
336 }
337 return false;
338}
339
340void DyePowderItem::registerIcons(IconRegister *iconRegister)
341{
342 icons = new Icon *[DYE_POWDER_ITEM_TEXTURE_COUNT];
343
344 for (int i = 0; i < DYE_POWDER_ITEM_TEXTURE_COUNT; i++)
345 {
346 icons[i] = iconRegister->registerIcon(getIconName() + L"_" + COLOR_TEXTURES[i]);
347 }
348}