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.level.tile.h"
5#include "net.minecraft.world.level.tile.entity.h"
6#include "net.minecraft.world.item.h"
7#include "WeighedTreasure.h"
8#include "MonsterRoomFeature.h"
9
10WeighedTreasure *MonsterRoomFeature::monsterRoomTreasure[MonsterRoomFeature::TREASURE_ITEMS_COUNT] =
11{
12 new WeighedTreasure(Item::saddle_Id, 0, 1, 1, 10),
13 new WeighedTreasure(Item::ironIngot_Id, 0, 1, 4, 10),
14 new WeighedTreasure(Item::bread_Id, 0, 1, 1, 10),
15 new WeighedTreasure(Item::wheat_Id, 0, 1, 4, 10),
16 new WeighedTreasure(Item::gunpowder_Id, 0, 1, 4, 10),
17 new WeighedTreasure(Item::string_Id, 0, 1, 4, 10),
18 new WeighedTreasure(Item::bucket_empty_Id, 0, 1, 1, 10),
19 new WeighedTreasure(Item::apple_gold_Id, 0, 1, 1, 1),
20 new WeighedTreasure(Item::redStone_Id, 0, 1, 4, 10),
21 new WeighedTreasure(Item::record_01_Id, 0, 1, 1, 10),
22 new WeighedTreasure(Item::record_02_Id, 0, 1, 1, 10),
23 new WeighedTreasure(Item::nameTag_Id, 0, 1, 1, 10),
24 new WeighedTreasure(Item::horseArmorGold_Id, 0, 1, 1, 2),
25 new WeighedTreasure(Item::horseArmorMetal_Id, 0, 1, 1, 5),
26 new WeighedTreasure(Item::horseArmorDiamond_Id, 0, 1, 1, 1),
27};
28
29bool MonsterRoomFeature::place(Level *level, Random *random, int x, int y, int z)
30{
31 int hr = 3;
32 int xr = random->nextInt(2) + 2;
33 int zr = random->nextInt(2) + 2;
34
35 int holeCount = 0;
36 for (int xx = x - xr - 1; xx <= x + xr + 1; xx++)
37 {
38 for (int yy = y - 1; yy <= y + hr + 1; yy++)
39 {
40 for (int zz = z - zr - 1; zz <= z + zr + 1; zz++)
41 {
42 Material *m = level->getMaterial(xx, yy, zz);
43 if (yy == y - 1 && !m->isSolid()) return false;
44 if (yy == y + hr + 1 && !m->isSolid()) return false;
45
46 if (xx == x - xr - 1 || xx == x + xr + 1 || zz == z - zr - 1 || zz == z + zr + 1)
47 {
48 if (yy == y && level->isEmptyTile(xx, yy, zz) && level->isEmptyTile(xx, yy + 1, zz))
49 {
50 holeCount++;
51 }
52 }
53
54 }
55 }
56 }
57
58 if (holeCount < 1 || holeCount > 5) return false;
59
60 for (int xx = x - xr - 1; xx <= x + xr + 1; xx++)
61 {
62 for (int yy = y + hr; yy >= y - 1; yy--)
63 {
64 for (int zz = z - zr - 1; zz <= z + zr + 1; zz++)
65 {
66
67 if (xx == x - xr - 1 || yy == y - 1 || zz == z - zr - 1 || xx == x + xr + 1 || yy == y + hr + 1 || zz == z + zr + 1)
68 {
69 if (yy >= 0 && !level->getMaterial(xx, yy - 1, zz)->isSolid())
70 {
71 level->removeTile(xx, yy, zz);
72 }
73 else if (level->getMaterial(xx, yy, zz)->isSolid())
74 {
75 if (yy == y - 1 && random->nextInt(4) != 0)
76 {
77 level->setTileAndData(xx, yy, zz, Tile::mossyCobblestone_Id, 0, Tile::UPDATE_CLIENTS);
78 }
79 else
80 {
81 level->setTileAndData(xx, yy, zz, Tile::cobblestone_Id, 0, Tile::UPDATE_CLIENTS);
82 }
83 }
84 } else
85 {
86 level->removeTile(xx, yy, zz);
87 }
88 }
89 }
90 }
91
92 for (int cc = 0; cc < 2; cc++)
93 {
94 for (int i = 0; i < 3; i++)
95 {
96 int xc = x + random->nextInt(xr * 2 + 1) - xr;
97 int yc = y;
98 int zc = z + random->nextInt(zr * 2 + 1) - zr;
99 if (!level->isEmptyTile(xc, yc, zc)) continue;
100
101 int count = 0;
102 if (level->getMaterial(xc - 1, yc, zc)->isSolid()) count++;
103 if (level->getMaterial(xc + 1, yc, zc)->isSolid()) count++;
104 if (level->getMaterial(xc, yc, zc - 1)->isSolid()) count++;
105 if (level->getMaterial(xc, yc, zc + 1)->isSolid()) count++;
106
107 if (count != 1) continue;
108
109 level->setTileAndData(xc, yc, zc, Tile::chest_Id, 0, Tile::UPDATE_CLIENTS);
110 WeighedTreasureArray wrapperArray(monsterRoomTreasure, TREASURE_ITEMS_COUNT);
111 WeighedTreasureArray treasure = WeighedTreasure::addToTreasure(wrapperArray, Item::enchantedBook->createForRandomTreasure(random));
112 shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity >( level->getTileEntity(xc, yc, zc) );
113 if (chest != NULL )
114 {
115 WeighedTreasure::addChestItems(random, treasure, chest, 8);
116 }
117
118 break;
119 }
120 }
121
122
123 level->setTileAndData(x, y, z, Tile::mobSpawner_Id, 0, Tile::UPDATE_CLIENTS);
124 shared_ptr<MobSpawnerTileEntity> entity = dynamic_pointer_cast<MobSpawnerTileEntity>( level->getTileEntity(x, y, z) );
125 if( entity != NULL )
126 {
127 entity->getSpawner()->setEntityId(randomEntityId(random));
128 }
129
130 return true;
131
132}
133
134wstring MonsterRoomFeature::randomEntityId(Random *random)
135{
136 int id = random->nextInt(4);
137 if (id == 0) return wstring(L"Skeleton");
138 if (id == 1) return wstring(L"Zombie");
139 if (id == 2) return wstring(L"Zombie");
140 if (id == 3) return wstring(L"Spider");
141 return wstring(L"");
142}