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 "..\..\..\Minecraft.World\StringHelpers.h"
3#include "UseTileRuleDefinition.h"
4
5UseTileRuleDefinition::UseTileRuleDefinition()
6{
7 m_tileId = -1;
8 m_useCoords = false;
9}
10
11void UseTileRuleDefinition::writeAttributes(DataOutputStream *dos, UINT numAttributes)
12{
13 GameRuleDefinition::writeAttributes(dos, numAttributes + 5);
14
15 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId);
16 dos->writeUTF(_toString(m_tileId));
17
18 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_useCoords);
19 dos->writeUTF(_toString(m_useCoords));
20
21 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x);
22 dos->writeUTF(_toString(m_coordinates.x));
23
24 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y);
25 dos->writeUTF(_toString(m_coordinates.y));
26
27 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z);
28 dos->writeUTF(_toString(m_coordinates.z));
29}
30
31void UseTileRuleDefinition::addAttribute(const wstring &attributeName, const wstring &attributeValue)
32{
33 if(attributeName.compare(L"tileId") == 0)
34 {
35 m_tileId = _fromString<int>(attributeValue);
36 app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n",m_tileId);
37 }
38 else if(attributeName.compare(L"useCoords") == 0)
39 {
40 m_useCoords = _fromString<bool>(attributeValue);
41 app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n",m_useCoords?"TRUE":"FALSE");
42 }
43 else if(attributeName.compare(L"x") == 0)
44 {
45 m_coordinates.x = _fromString<int>(attributeValue);
46 app.DebugPrintf("UseTileRule: Adding parameter x=%d\n",m_coordinates.x);
47 }
48 else if(attributeName.compare(L"y") == 0)
49 {
50 m_coordinates.y = _fromString<int>(attributeValue);
51 app.DebugPrintf("UseTileRule: Adding parameter y=%d\n",m_coordinates.y);
52 }
53 else if(attributeName.compare(L"z") == 0)
54 {
55 m_coordinates.z = _fromString<int>(attributeValue);
56 app.DebugPrintf("UseTileRule: Adding parameter z=%d\n",m_coordinates.z);
57 }
58 else
59 {
60 GameRuleDefinition::addAttribute(attributeName, attributeValue);
61 }
62}
63
64bool UseTileRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z)
65{
66 bool statusChanged = false;
67 if( m_tileId == tileId )
68 {
69 if( !m_useCoords || (m_coordinates.x == x && m_coordinates.y == y && m_coordinates.z == z) )
70 {
71 if(!getComplete(rule))
72 {
73 statusChanged = true;
74 setComplete(rule,true);
75 app.DebugPrintf("Completed UseTileRule with info - t:%d, coords:%s, x:%d, y:%d, z:%d\n", m_tileId,m_useCoords?"TRUE":"FALSE",m_coordinates.x,m_coordinates.y,m_coordinates.z);
76
77 // Send a packet or some other announcement here
78 }
79 }
80 }
81 return statusChanged;
82}