the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 132 lines 3.5 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.item.h" 3#include "net.minecraft.world.entity.animal.h" 4#include "HorseInventoryMenu.h" 5 6HorseSaddleSlot::HorseSaddleSlot( shared_ptr<Container> horseInventory ) : Slot(horseInventory, EntityHorse::INV_SLOT_SADDLE, 8, 18) 7{ 8} 9 10bool HorseSaddleSlot::mayPlace(shared_ptr<ItemInstance> item) 11{ 12 return Slot::mayPlace(item) && item->id == Item::saddle_Id && !hasItem(); 13} 14 15 16HorseArmorSlot::HorseArmorSlot( HorseInventoryMenu *parent, shared_ptr<Container> horseInventory ) : Slot(horseInventory, EntityHorse::INV_SLOT_ARMOR, 8, 18 * 2) 17{ 18 m_parent = parent; 19} 20 21bool HorseArmorSlot::mayPlace(shared_ptr<ItemInstance> item) 22{ 23 return Slot::mayPlace(item) && m_parent->horse->canWearArmor() && EntityHorse::isHorseArmor(item->id); 24} 25 26bool HorseArmorSlot::isActive() 27{ 28 return m_parent->horse->canWearArmor(); 29} 30 31 32HorseInventoryMenu::HorseInventoryMenu(shared_ptr<Container> playerInventory, shared_ptr<Container> horseInventory, shared_ptr<EntityHorse> horse) 33{ 34 horseContainer = horseInventory; 35 this->horse = horse; 36 int containerRows = 3; 37 horseInventory->startOpen(); 38 39 int yo = (containerRows - 4) * 18; 40 41 // equipment slots 42 addSlot(new HorseSaddleSlot(horseInventory) ); 43 addSlot(new HorseArmorSlot(this, horseInventory) ); 44 45 if (horse->isChestedHorse()) 46 { 47 for (int y = 0; y < containerRows; y++) 48 { 49 for (int x = 0; x < 5; x++) 50 { 51 addSlot(new Slot(horseInventory, EntityHorse::INV_BASE_COUNT + x + y * 5, 80 + x * 18, 18 + y * 18)); 52 } 53 } 54 } 55 56 for (int y = 0; y < 3; y++) 57 { 58 for (int x = 0; x < 9; x++) 59 { 60 addSlot(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, 102 + y * 18 + yo)); 61 } 62 } 63 for (int x = 0; x < 9; x++) 64 { 65 addSlot(new Slot(playerInventory, x, 8 + x * 18, 160 + yo)); 66 } 67} 68 69bool HorseInventoryMenu::stillValid(shared_ptr<Player> player) 70{ 71 return horseContainer->stillValid(player) && horse->isAlive() && horse->distanceTo(player) < 8; 72} 73 74shared_ptr<ItemInstance> HorseInventoryMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex) 75{ 76 shared_ptr<ItemInstance> clicked = nullptr; 77 Slot *slot = slots.at(slotIndex); 78 if (slot != NULL && slot->hasItem()) 79 { 80 shared_ptr<ItemInstance> stack = slot->getItem(); 81 clicked = stack->copy(); 82 83 if (slotIndex < horseContainer->getContainerSize()) 84 { 85 if (!moveItemStackTo(stack, horseContainer->getContainerSize(), slots.size(), true)) 86 { 87 return nullptr; 88 } 89 } 90 else 91 { 92 if (getSlot(EntityHorse::INV_SLOT_ARMOR)->mayPlace(stack) && !getSlot(EntityHorse::INV_SLOT_ARMOR)->hasItem()) 93 { 94 if (!moveItemStackTo(stack, EntityHorse::INV_SLOT_ARMOR, EntityHorse::INV_SLOT_ARMOR + 1, false)) 95 { 96 return nullptr; 97 } 98 } 99 else if (getSlot(EntityHorse::INV_SLOT_SADDLE)->mayPlace(stack)) 100 { 101 if (!moveItemStackTo(stack, EntityHorse::INV_SLOT_SADDLE, EntityHorse::INV_SLOT_SADDLE + 1, false)) 102 { 103 return nullptr; 104 } 105 } 106 else if (horseContainer->getContainerSize() <= EntityHorse::INV_BASE_COUNT || !moveItemStackTo(stack, EntityHorse::INV_BASE_COUNT, horseContainer->getContainerSize(), false)) 107 { 108 return nullptr; 109 } 110 } 111 if (stack->count == 0) 112 { 113 slot->set(nullptr); 114 } 115 else 116 { 117 slot->setChanged(); 118 } 119 } 120 return clicked; 121} 122 123void HorseInventoryMenu::removed(shared_ptr<Player> player) 124{ 125 AbstractContainerMenu::removed(player); 126 horseContainer->stopOpen(); 127} 128 129shared_ptr<Container> HorseInventoryMenu::getContainer() 130{ 131 return horseContainer; 132}