the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 86 lines 2.6 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.tile.entity.h" 3#include "net.minecraft.world.item.h" 4#include "WeighedRandom.h" 5#include "WeighedTreasure.h" 6 7WeighedTreasure::WeighedTreasure(int itemId, int auxValue, int minCount, int maxCount, int weight) : WeighedRandomItem(weight) 8{ 9 this->item = shared_ptr<ItemInstance>( new ItemInstance(itemId, 1, auxValue) ); 10 this->minCount = minCount; 11 this->maxCount = maxCount; 12} 13 14WeighedTreasure::WeighedTreasure(shared_ptr<ItemInstance> item, int minCount, int maxCount, int weight) : WeighedRandomItem(weight) 15{ 16 this->item = item; 17 this->minCount = minCount; 18 this->maxCount = maxCount; 19} 20 21void WeighedTreasure::addChestItems(Random *random, WeighedTreasureArray items, shared_ptr<Container> dest, int numRolls) 22{ 23 for (int r = 0; r < numRolls; r++) 24 { 25 WeighedTreasure *treasure = (WeighedTreasure *) WeighedRandom::getRandomItem(random, *((WeighedRandomItemArray *)&items)); 26 27 int count = treasure->minCount + random->nextInt(treasure->maxCount - treasure->minCount + 1); 28 if (treasure->item->getMaxStackSize() >= count) 29 { 30 shared_ptr<ItemInstance> copy = treasure->item->copy(); 31 copy->count = count; 32 dest->setItem(random->nextInt(dest->getContainerSize()), copy); 33 } 34 else 35 { 36 // use multiple slots 37 for (int c = 0; c < count; c++) 38 { 39 shared_ptr<ItemInstance> copy = treasure->item->copy(); 40 copy->count = 1; 41 dest->setItem(random->nextInt(dest->getContainerSize()), copy); 42 } 43 } 44 } 45} 46 47void WeighedTreasure::addDispenserItems(Random *random, WeighedTreasureArray items, shared_ptr<DispenserTileEntity> dest, int numRolls) 48{ 49 for (int r = 0; r < numRolls; r++) 50 { 51 WeighedTreasure *treasure = (WeighedTreasure *) WeighedRandom::getRandomItem(random, *((WeighedRandomItemArray *)&items)); 52 53 int count = treasure->minCount + random->nextInt(treasure->maxCount - treasure->minCount + 1); 54 if (treasure->item->getMaxStackSize() >= count) 55 { 56 shared_ptr<ItemInstance> copy = treasure->item->copy(); 57 copy->count = count; 58 dest->setItem(random->nextInt(dest->getContainerSize()), copy); 59 } 60 else 61 { 62 // use multiple slots 63 for (int c = 0; c < count; c++) 64 { 65 shared_ptr<ItemInstance> copy = treasure->item->copy(); 66 copy->count = 1; 67 dest->setItem(random->nextInt(dest->getContainerSize()), copy); 68 } 69 } 70 } 71} 72 73WeighedTreasureArray WeighedTreasure::addToTreasure(WeighedTreasureArray items, WeighedTreasure *extra) 74{ 75 WeighedTreasureArray result(items.length + 1); 76 int i = 0; 77 78 for (int j = 0; j < items.length; j++) 79 { 80 result[i++] = items[j]; 81 } 82 83 result[i++] = extra; 84 85 return result; 86}