the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 85 lines 2.4 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.network.packet.h" 3#include "net.minecraft.world.item.h" 4#include "net.minecraft.world.item.enchantment.h" 5#include "..\Minecraft.Client\ServerPlayer.h" 6#include "EnchantItemCommand.h" 7 8EGameCommand EnchantItemCommand::getId() 9{ 10 return eGameCommand_EnchantItem; 11} 12 13int EnchantItemCommand::getPermissionLevel() 14{ 15 return LEVEL_GAMEMASTERS; 16} 17 18void EnchantItemCommand::execute(shared_ptr<CommandSender> source, byteArray commandData) 19{ 20 ByteArrayInputStream bais(commandData); 21 DataInputStream dis(&bais); 22 23 PlayerUID uid = dis.readPlayerUID(); 24 int enchantmentId = dis.readInt(); 25 int enchantmentLevel = dis.readInt(); 26 27 bais.reset(); 28 29 shared_ptr<ServerPlayer> player = getPlayer(uid); 30 31 if(player == NULL) return; 32 33 shared_ptr<ItemInstance> selectedItem = player->getSelectedItem(); 34 35 if(selectedItem == NULL) return; 36 37 Enchantment *e = Enchantment::enchantments[enchantmentId]; 38 39 if(e == NULL) return; 40 if(!e->canEnchant(selectedItem)) return; 41 42 if(enchantmentLevel < e->getMinLevel()) enchantmentLevel = e->getMinLevel(); 43 if(enchantmentLevel > e->getMaxLevel()) enchantmentLevel = e->getMaxLevel(); 44 45 if (selectedItem->hasTag()) 46 { 47 ListTag<CompoundTag> *enchantmentTags = selectedItem->getEnchantmentTags(); 48 if (enchantmentTags != NULL) 49 { 50 for (int i = 0; i < enchantmentTags->size(); i++) 51 { 52 int type = enchantmentTags->get(i)->getShort((wchar_t *)ItemInstance::TAG_ENCH_ID); 53 54 if (Enchantment::enchantments[type] != NULL) 55 { 56 Enchantment *other = Enchantment::enchantments[type]; 57 if (!other->isCompatibleWith(e)) 58 { 59 return; 60 //throw new CommandException("commands.enchant.cantCombine", e.getFullname(level), other.getFullname(enchantmentTags.get(i).getShort(ItemInstance.TAG_ENCH_LEVEL))); 61 } 62 } 63 } 64 } 65 } 66 67 selectedItem->enchant(e, enchantmentLevel); 68 69 //logAdminAction(source, "commands.enchant.success"); 70 logAdminAction(source, ChatPacket::e_ChatCustom, L"commands.enchant.success"); 71} 72 73shared_ptr<GameCommandPacket> EnchantItemCommand::preparePacket(shared_ptr<Player> player, int enchantmentId, int enchantmentLevel) 74{ 75 if(player == NULL) return nullptr; 76 77 ByteArrayOutputStream baos; 78 DataOutputStream dos(&baos); 79 80 dos.writePlayerUID(player->getXuid()); 81 dos.writeInt(enchantmentId); 82 dos.writeInt(enchantmentLevel); 83 84 return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_EnchantItem, baos.toByteArray() )); 85}