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 "ConsoleGenerateStructure.h"
3#include "ConsoleGameRules.h"
4#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"
5#include "..\..\..\Minecraft.World\net.minecraft.world.level.dimension.h"
6#include "..\..\..\Minecraft.World\net.minecraft.world.level.levelgen.structure.h"
7#include "..\..\..\Minecraft.World\StringHelpers.h"
8#include "..\..\..\Minecraft.World\net.minecraft.h"
9
10ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0)
11{
12 m_x = m_y = m_z = 0;
13 boundingBox = NULL;
14 orientation = Direction::NORTH;
15 m_dimension = 0;
16}
17
18void ConsoleGenerateStructure::getChildren(vector<GameRuleDefinition *> *children)
19{
20 GameRuleDefinition::getChildren(children);
21
22 for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++)
23 children->push_back( *it );
24}
25
26GameRuleDefinition *ConsoleGenerateStructure::addChild(ConsoleGameRules::EGameRuleType ruleType)
27{
28 GameRuleDefinition *rule = NULL;
29 if(ruleType == ConsoleGameRules::eGameRuleType_GenerateBox)
30 {
31 rule = new XboxStructureActionGenerateBox();
32 m_actions.push_back((XboxStructureActionGenerateBox *)rule);
33 }
34 else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock)
35 {
36 rule = new XboxStructureActionPlaceBlock();
37 m_actions.push_back((XboxStructureActionPlaceBlock *)rule);
38 }
39 else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer)
40 {
41 rule = new XboxStructureActionPlaceContainer();
42 m_actions.push_back((XboxStructureActionPlaceContainer *)rule);
43 }
44 else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner)
45 {
46 rule = new XboxStructureActionPlaceSpawner();
47 m_actions.push_back((XboxStructureActionPlaceSpawner *)rule);
48 }
49 else
50 {
51#ifndef _CONTENT_PACKAGE
52 wprintf(L"ConsoleGenerateStructure: Attempted to add invalid child rule - %d\n", ruleType );
53#endif
54 }
55 return rule;
56}
57
58void ConsoleGenerateStructure::writeAttributes(DataOutputStream *dos, UINT numAttrs)
59{
60 GameRuleDefinition::writeAttributes(dos, numAttrs + 5);
61
62 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
63 dos->writeUTF(_toString(m_x));
64 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
65 dos->writeUTF(_toString(m_y));
66 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
67 dos->writeUTF(_toString(m_z));
68
69 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation);
70 dos->writeUTF(_toString(orientation));
71 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dimension);
72 dos->writeUTF(_toString(m_dimension));
73}
74
75void ConsoleGenerateStructure::addAttribute(const wstring &attributeName, const wstring &attributeValue)
76{
77 if(attributeName.compare(L"x") == 0)
78 {
79 int value = _fromString<int>(attributeValue);
80 m_x = value;
81 app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",m_x);
82 }
83 else if(attributeName.compare(L"y") == 0)
84 {
85 int value = _fromString<int>(attributeValue);
86 m_y = value;
87 app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",m_y);
88 }
89 else if(attributeName.compare(L"z") == 0)
90 {
91 int value = _fromString<int>(attributeValue);
92 m_z = value;
93 app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",m_z);
94 }
95 else if(attributeName.compare(L"orientation") == 0)
96 {
97 int value = _fromString<int>(attributeValue);
98 orientation = value;
99 app.DebugPrintf("ConsoleGenerateStructure: Adding parameter orientation=%d\n",orientation);
100 }
101 else if(attributeName.compare(L"dim") == 0)
102 {
103 m_dimension = _fromString<int>(attributeValue);
104 if(m_dimension > 1 || m_dimension < -1) m_dimension = 0;
105 app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension);
106 }
107 else
108 {
109 GameRuleDefinition::addAttribute(attributeName, attributeValue);
110 }
111}
112
113BoundingBox* ConsoleGenerateStructure::getBoundingBox()
114{
115 if(boundingBox == NULL)
116 {
117 // Find the max bounds
118 int maxX, maxY, maxZ;
119 maxX = maxY = maxZ = 1;
120 for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it)
121 {
122 ConsoleGenerateStructureAction *action = *it;
123 maxX = max(maxX,action->getEndX());
124 maxY = max(maxY,action->getEndY());
125 maxZ = max(maxZ,action->getEndZ());
126 }
127
128 boundingBox = new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ);
129 }
130 return boundingBox;
131}
132
133bool ConsoleGenerateStructure::postProcess(Level *level, Random *random, BoundingBox *chunkBB)
134{
135 if(level->dimension->id != m_dimension) return false;
136
137 for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it)
138 {
139 ConsoleGenerateStructureAction *action = *it;
140
141 switch(action->getActionType())
142 {
143 case ConsoleGameRules::eGameRuleType_GenerateBox:
144 {
145 XboxStructureActionGenerateBox *genBox = (XboxStructureActionGenerateBox *)action;
146 genBox->generateBoxInLevel(this,level,chunkBB);
147 }
148 break;
149 case ConsoleGameRules::eGameRuleType_PlaceBlock:
150 {
151 XboxStructureActionPlaceBlock *pPlaceBlock = (XboxStructureActionPlaceBlock *)action;
152 pPlaceBlock->placeBlockInLevel(this,level,chunkBB);
153 }
154 break;
155 case ConsoleGameRules::eGameRuleType_PlaceContainer:
156 {
157 XboxStructureActionPlaceContainer *pPlaceContainer = (XboxStructureActionPlaceContainer *)action;
158 pPlaceContainer->placeContainerInLevel(this,level,chunkBB);
159 }
160 break;
161 case ConsoleGameRules::eGameRuleType_PlaceSpawner:
162 {
163 XboxStructureActionPlaceSpawner *pPlaceSpawner = (XboxStructureActionPlaceSpawner *)action;
164 pPlaceSpawner->placeSpawnerInLevel(this,level,chunkBB);
165 }
166 break;
167 };
168 }
169
170 return false;
171}
172
173bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1)
174{
175 return getBoundingBox()->intersects(x0,y0,z0,x1,y1,z1);
176}
177
178int ConsoleGenerateStructure::getMinY()
179{
180 return getBoundingBox()->y0;
181}