the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 130 lines 3.0 kB view raw
1#include "stdafx.h" 2 3#include "net.minecraft.world.ContainerListener.h" 4#include "net.minecraft.world.item.h" 5 6#include "SimpleContainer.h" 7 8SimpleContainer::SimpleContainer(int name, wstring stringName, bool customName, int size) 9{ 10 this->name = name; 11 this->stringName = stringName; 12 this->customName = customName; 13 this->size = size; 14 items = new ItemInstanceArray( size ); 15 16 listeners = NULL; 17} 18 19void SimpleContainer::addListener(net_minecraft_world::ContainerListener *listener) 20{ 21 if (listeners == NULL) listeners = new vector<net_minecraft_world::ContainerListener *>(); 22 listeners->push_back(listener); 23} 24 25void SimpleContainer::removeListener(net_minecraft_world::ContainerListener *listener) 26{ 27 // 4J Java has a remove function on lists that will find the first occurence of 28 // an object and remove it. We need to replicate that ourselves 29 30 vector<net_minecraft_world::ContainerListener *>::iterator it = listeners->begin(); 31 vector<net_minecraft_world::ContainerListener *>::iterator itEnd = listeners->end(); 32 while( it != itEnd && *it != listener ) 33 it++; 34 35 if( it != itEnd ) 36 listeners->erase( it ); 37} 38 39shared_ptr<ItemInstance> SimpleContainer::getItem(unsigned int slot) 40{ 41 return (*items)[slot]; 42} 43 44shared_ptr<ItemInstance> SimpleContainer::removeItem(unsigned int slot, int count) 45{ 46 if ((*items)[slot] != NULL) { 47 if ((*items)[slot]->count <= count) 48 { 49 shared_ptr<ItemInstance> item = (*items)[slot]; 50 (*items)[slot] = nullptr; 51 setChanged(); 52 return item; 53 } 54 else 55 { 56 shared_ptr<ItemInstance> i = (*items)[slot]->remove(count); 57 if ((*items)[slot]->count == 0) (*items)[slot] = nullptr; 58 setChanged(); 59 return i; 60 } 61 } 62 return nullptr; 63} 64 65shared_ptr<ItemInstance> SimpleContainer::removeItemNoUpdate(int slot) 66{ 67 if ((*items)[slot] != NULL) 68 { 69 shared_ptr<ItemInstance> item = (*items)[slot]; 70 (*items)[slot] = nullptr; 71 return item; 72 } 73 return nullptr; 74} 75 76void SimpleContainer::setItem(unsigned int slot, shared_ptr<ItemInstance> item) 77{ 78 (*items)[slot] = item; 79 if (item != NULL && item->count > getMaxStackSize()) item->count = getMaxStackSize(); 80 setChanged(); 81} 82 83unsigned int SimpleContainer::getContainerSize() 84{ 85 return size; 86} 87 88wstring SimpleContainer::getName() 89{ 90 return stringName.empty() ? app.GetString(name) : stringName; 91} 92 93wstring SimpleContainer::getCustomName() 94{ 95 return hasCustomName() ? stringName : L""; 96} 97 98bool SimpleContainer::hasCustomName() 99{ 100 return customName; 101} 102 103void SimpleContainer::setCustomName(const wstring &name) 104{ 105 customName = true; 106 this->stringName = name; 107} 108 109int SimpleContainer::getMaxStackSize() const 110{ 111 return Container::LARGE_MAX_STACK_SIZE; 112} 113 114void SimpleContainer::setChanged() 115{ 116 if (listeners != NULL) for (unsigned int i = 0; i < listeners->size(); i++) 117 { 118 listeners->at(i)->containerChanged();//shared_from_this()); 119 } 120} 121 122bool SimpleContainer::stillValid(shared_ptr<Player> player) 123{ 124 return true; 125} 126 127bool SimpleContainer::canPlaceItem(int slot, shared_ptr<ItemInstance> item) 128{ 129 return true; 130}