the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 127 lines 4.0 kB view raw
1#include "stdafx.h" 2#include "..\..\..\Minecraft.World\StringHelpers.h" 3#include "..\..\..\Minecraft.World\net.minecraft.world.item.h" 4#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h" 5#include "..\..\..\Minecraft.World\net.minecraft.world.entity.player.h" 6#include "AddItemRuleDefinition.h" 7#include "AddEnchantmentRuleDefinition.h" 8 9AddItemRuleDefinition::AddItemRuleDefinition() 10{ 11 m_itemId = m_quantity = m_auxValue = m_dataTag = 0; 12 m_slot = -1; 13} 14 15void AddItemRuleDefinition::writeAttributes(DataOutputStream *dos, UINT numAttrs) 16{ 17 GameRuleDefinition::writeAttributes(dos, numAttrs + 5); 18 19 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); 20 dos->writeUTF( _toString( m_itemId ) ); 21 22 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); 23 dos->writeUTF( _toString( m_quantity ) ); 24 25 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); 26 dos->writeUTF( _toString( m_auxValue ) ); 27 28 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag); 29 dos->writeUTF( _toString( m_dataTag ) ); 30 31 ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot); 32 dos->writeUTF( _toString( m_slot ) ); 33} 34 35void AddItemRuleDefinition::getChildren(vector<GameRuleDefinition *> *children) 36{ 37 GameRuleDefinition::getChildren( children ); 38 for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++) 39 children->push_back( *it ); 40} 41 42GameRuleDefinition *AddItemRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) 43{ 44 GameRuleDefinition *rule = NULL; 45 if(ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment) 46 { 47 rule = new AddEnchantmentRuleDefinition(); 48 m_enchantments.push_back((AddEnchantmentRuleDefinition *)rule); 49 } 50 else 51 { 52#ifndef _CONTENT_PACKAGE 53 //wprintf(L"AddItemRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); 54#endif 55 } 56 return rule; 57} 58 59void AddItemRuleDefinition::addAttribute(const wstring &attributeName, const wstring &attributeValue) 60{ 61 if(attributeName.compare(L"itemId") == 0) 62 { 63 int value = _fromString<int>(attributeValue); 64 m_itemId = value; 65 //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter itemId=%d\n",m_itemId); 66 } 67 else if(attributeName.compare(L"quantity") == 0) 68 { 69 int value = _fromString<int>(attributeValue); 70 m_quantity = value; 71 //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter quantity=%d\n",m_quantity); 72 } 73 else if(attributeName.compare(L"auxValue") == 0) 74 { 75 int value = _fromString<int>(attributeValue); 76 m_auxValue = value; 77 //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter auxValue=%d\n",m_auxValue); 78 } 79 else if(attributeName.compare(L"dataTag") == 0) 80 { 81 int value = _fromString<int>(attributeValue); 82 m_dataTag = value; 83 //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter dataTag=%d\n",m_dataTag); 84 } 85 else if(attributeName.compare(L"slot") == 0) 86 { 87 int value = _fromString<int>(attributeValue); 88 m_slot = value; 89 //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter slot=%d\n",m_slot); 90 } 91 else 92 { 93 GameRuleDefinition::addAttribute(attributeName, attributeValue); 94 } 95} 96 97bool AddItemRuleDefinition::addItemToContainer(shared_ptr<Container> container, int slotId) 98{ 99 bool added = false; 100 if(Item::items[m_itemId] != NULL) 101 { 102 int quantity = min(m_quantity, Item::items[m_itemId]->getMaxStackSize()); 103 shared_ptr<ItemInstance> newItem = shared_ptr<ItemInstance>(new ItemInstance(m_itemId,quantity,m_auxValue) ); 104 newItem->set4JData(m_dataTag); 105 106 for(AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); ++it) 107 { 108 (*it)->enchantItem(newItem); 109 } 110 111 if(m_slot >= 0 && m_slot < container->getContainerSize() ) 112 { 113 container->setItem( m_slot, newItem ); 114 added = true; 115 } 116 else if(slotId >= 0 && slotId < container->getContainerSize() ) 117 { 118 container->setItem( slotId, newItem ); 119 added = true; 120 } 121 else if(dynamic_pointer_cast<Inventory>(container) != NULL) 122 { 123 added = dynamic_pointer_cast<Inventory>(container)->add(newItem); 124 } 125 } 126 return added; 127}