the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 117 lines 3.8 kB view raw
1#include "stdafx.h" 2#include "..\..\WstringLookup.h" 3#include "..\..\..\Minecraft.World\StringHelpers.h" 4#include "CollectItemRuleDefinition.h" 5#include "..\..\..\Minecraft.World\net.minecraft.world.item.h" 6#include "..\..\..\Minecraft.World\Connection.h" 7#include "..\..\..\Minecraft.World\net.minecraft.network.packet.h" 8 9CollectItemRuleDefinition::CollectItemRuleDefinition() 10{ 11 m_itemId = 0; 12 m_auxValue = 0; 13 m_quantity = 0; 14} 15 16CollectItemRuleDefinition::~CollectItemRuleDefinition() 17{ 18} 19 20void CollectItemRuleDefinition::writeAttributes(DataOutputStream *dos, UINT numAttributes) 21{ 22 GameRuleDefinition::writeAttributes(dos, numAttributes + 3); 23 24 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); 25 dos->writeUTF( _toString( m_itemId ) ); 26 27 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); 28 dos->writeUTF( _toString( m_auxValue ) ); 29 30 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); 31 dos->writeUTF( _toString( m_quantity ) ); 32} 33 34void CollectItemRuleDefinition::addAttribute(const wstring &attributeName, const wstring &attributeValue) 35{ 36 if(attributeName.compare(L"itemId") == 0) 37 { 38 m_itemId = _fromString<int>(attributeValue); 39 app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n",m_itemId); 40 } 41 else if(attributeName.compare(L"auxValue") == 0) 42 { 43 m_auxValue = _fromString<int>(attributeValue); 44 app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n",m_auxValue); 45 } 46 else if(attributeName.compare(L"quantity") == 0) 47 { 48 m_quantity = _fromString<int>(attributeValue); 49 app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n",m_quantity); 50 } 51 else 52 { 53 GameRuleDefinition::addAttribute(attributeName, attributeValue); 54 } 55} 56 57int CollectItemRuleDefinition::getGoal() 58{ 59 return m_quantity; 60} 61 62int CollectItemRuleDefinition::getProgress(GameRule *rule) 63{ 64 GameRule::ValueType value = rule->getParameter(L"iQuantity"); 65 return value.i; 66} 67 68void CollectItemRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) 69{ 70 GameRule::ValueType value; 71 value.i = 0; 72 rule->setParameter(L"iQuantity",value); 73 74 GameRuleDefinition::populateGameRule(type, rule); 75} 76 77bool CollectItemRuleDefinition::onCollectItem(GameRule *rule, shared_ptr<ItemInstance> item) 78{ 79 bool statusChanged = false; 80 if(item != NULL && item->id == m_itemId && item->getAuxValue() == m_auxValue && item->get4JData() == m_4JDataValue) 81 { 82 if(!getComplete(rule)) 83 { 84 GameRule::ValueType value = rule->getParameter(L"iQuantity"); 85 int quantityCollected = (value.i += item->count); 86 rule->setParameter(L"iQuantity",value); 87 88 statusChanged = true; 89 90 if(quantityCollected >= m_quantity) 91 { 92 setComplete(rule, true); 93 app.DebugPrintf("Completed CollectItemRule with info - itemId:%d, auxValue:%d, quantity:%d, dataTag:%d\n", m_itemId,m_auxValue,m_quantity,m_4JDataValue); 94 95 if(rule->getConnection() != NULL) 96 { 97 rule->getConnection()->send( shared_ptr<UpdateGameRuleProgressPacket>( new UpdateGameRuleProgressPacket(getActionType(), this->m_descriptionId, m_itemId, m_auxValue, this->m_4JDataValue,NULL,0))); 98 } 99 } 100 } 101 } 102 return statusChanged; 103} 104 105wstring CollectItemRuleDefinition::generateXml(shared_ptr<ItemInstance> item) 106{ 107 // 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd 108 wstring xml = L""; 109 if(item != NULL) 110 { 111 xml = L"<CollectItemRule itemId=\"" + _toString<int>(item->id) + L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" promptName=\"OPTIONAL\""; 112 if(item->getAuxValue() != 0) xml += L" auxValue=\"" + _toString<int>(item->getAuxValue()) + L"\""; 113 if(item->get4JData() != 0) xml += L" dataTag=\"" + _toString<int>(item->get4JData()) + L"\""; 114 xml += L"/>\n"; 115 } 116 return xml; 117}