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 "BonusChestFeature.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.level.tile.entity.h"
6#include "WeighedTreasure.h"
7#include "StructurePiece.h"
8
9BonusChestFeature::BonusChestFeature(WeighedTreasureArray treasureList, int numRolls) : treasureList(treasureList), numRolls(numRolls)
10{
11}
12
13// 4J - original virtual method
14bool BonusChestFeature::place(Level *level, Random *random, int x, int y, int z)
15{
16 return place(level, random, x, y, z, false );
17}
18
19// 4J - added force parameter - trying to keep this as similar as possible to the original algorithm, but would also like it to definitely place a
20// chest as it doesn't necessarily find somewhere in the original java. This method is called multple times for different x,y,z round the
21// spawn point and force signifies that this is the last time this will be called. In this case, just place the chest exactly where the input
22// parameters requested we place it (we know this will be one tile above the top solid block of a randomn column), and then do our best to place
23// any surrounding torches where appropriate.
24
25bool BonusChestFeature::place(Level *level, Random *random, int x, int y, int z, bool force)
26{
27 if( !force )
28 {
29 int t = 0;
30 while (((t = level->getTile(x, y, z)) == 0 || t == Tile::leaves_Id) && y > 1)
31 y--;
32
33 if (y < 1)
34 {
35 return false;
36 }
37 y++;
38 }
39
40 for (int i = 0; i < 4; i++)
41 {
42 int x2, y2, z2;
43
44 if( force )
45 {
46 x2 = x;
47 y2 = y - 1; // 4J - the position passed in is actually two above the top solid block, as the calling function adds 1 to getTopSolidBlock, and that actually returns the block above anyway.
48 // this would explain why there is a while loop above here (not used in force mode) to move the y back down again, shouldn't really be needed if 1 wasn't added to the getTopSolidBlock return value.
49 z2 = z;
50 }
51 else
52 {
53 x2 = x + random->nextInt(4) - random->nextInt(4);
54 y2 = y + random->nextInt(3) - random->nextInt(3);
55 z2 = z + random->nextInt(4) - random->nextInt(4);
56 }
57
58 if (force || ( level->isEmptyTile(x2, y2, z2) && level->isTopSolidBlocking(x2, y2 - 1, z2)))
59 {
60 level->setTileAndData(x2, y2, z2, Tile::chest_Id, 0, Tile::UPDATE_CLIENTS);
61 shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity>(level->getTileEntity(x2, y2, z2));
62 if (chest != NULL)
63 {
64 WeighedTreasure::addChestItems(random, treasureList, chest, numRolls);
65 chest->isBonusChest = true; // 4J added
66 }
67 if (level->isEmptyTile(x2 - 1, y2, z2) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
68 {
69 level->setTileAndData(x2 - 1, y2, z2, Tile::torch_Id, 0, Tile::UPDATE_CLIENTS);
70 }
71 if (level->isEmptyTile(x2 + 1, y2, z2) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
72 {
73 level->setTileAndData(x2 + 1, y2, z2, Tile::torch_Id, 0, Tile::UPDATE_CLIENTS);
74 }
75 if (level->isEmptyTile(x2, y2, z2 - 1) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
76 {
77 level->setTileAndData(x2, y2, z2 - 1, Tile::torch_Id, 0, Tile::UPDATE_CLIENTS);
78 }
79 if (level->isEmptyTile(x2, y2, z2 + 1) && level->isTopSolidBlocking(x2 - 1, y2 - 1, z2))
80 {
81 level->setTileAndData(x2, y2, z2 + 1, Tile::torch_Id, 0, Tile::UPDATE_CLIENTS);
82 }
83 return true;
84 }
85 }
86
87 return false;
88}