the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 150 lines 3.9 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.player.h" 3#include "net.minecraft.world.level.h" 4#include "net.minecraft.world.level.tile.h" 5#include "net.minecraft.world.item.h" 6#include "net.minecraft.world.item.crafting.h" 7#include "CraftingContainer.h" 8#include "ResultContainer.h" 9#include "ResultSlot.h" 10#include "FireworksMenu.h" 11 12FireworksMenu::FireworksMenu(shared_ptr<Inventory> inventory, Level *level, int xt, int yt, int zt) : AbstractContainerMenu() 13{ 14 m_canMakeFireworks = false; 15 m_canMakeCharge = false; 16 m_canMakeFade = false; 17 18 craftSlots = shared_ptr<CraftingContainer>( new CraftingContainer(this, 3, 3) ); 19 resultSlots = shared_ptr<ResultContainer>( new ResultContainer() ); 20 21 this->level = level; 22 x = xt; 23 y = yt; 24 z = zt; 25 addSlot(new ResultSlot( inventory->player, craftSlots, resultSlots, 0, 120 + 4, 31 + 4)); 26 27 for (int y = 0; y < 3; y++) 28 { 29 for (int x = 0; x < 3; x++) 30 { 31 addSlot(new Slot(craftSlots, x + y * 3, 30 + x * 18, 17 + y * 18)); 32 } 33 } 34 35 for (int y = 0; y < 3; y++) 36 { 37 for (int x = 0; x < 9; x++) 38 { 39 addSlot(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); 40 } 41 } 42 for (int x = 0; x < 9; x++) 43 { 44 addSlot(new Slot(inventory, x, 8 + x * 18, 142)); 45 } 46 47 slotsChanged(); // 4J - removed craftSlots parameter, see comment below 48} 49 50void FireworksMenu::slotsChanged() // 4J used to take a shared_ptr<Container> but wasn't using it, so removed to simplify things 51{ 52 FireworksRecipe::updatePossibleRecipes(craftSlots, &m_canMakeFireworks, &m_canMakeCharge, &m_canMakeFade); 53 resultSlots->setItem(0, Recipes::getInstance()->getItemFor(craftSlots, level, Recipes::pFireworksRecipes)); 54} 55 56void FireworksMenu::removed(shared_ptr<Player> player) 57{ 58 AbstractContainerMenu::removed(player); 59 if (level->isClientSide) return; 60 61 for (int i = 0; i < 9; i++) 62 { 63 shared_ptr<ItemInstance> item = craftSlots->removeItemNoUpdate(i); 64 if (item != NULL) 65 { 66 player->drop(item); 67 } 68 } 69} 70 71bool FireworksMenu::stillValid(shared_ptr<Player> player) 72{ 73 return true; 74} 75 76shared_ptr<ItemInstance> FireworksMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex) 77{ 78 shared_ptr<ItemInstance> clicked = nullptr; 79 Slot *slot = slots.at(slotIndex); 80 if (slot != NULL && slot->hasItem()) 81 { 82 shared_ptr<ItemInstance> stack = slot->getItem(); 83 clicked = stack->copy(); 84 85 if (slotIndex == RESULT_SLOT) 86 { 87 if(!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, true)) 88 { 89 return nullptr; 90 } 91 slot->onQuickCraft(stack, clicked); 92 } 93 else if (slotIndex >= INV_SLOT_START && slotIndex < INV_SLOT_END) 94 { 95 if(isValidIngredient(stack, -1) && moveItemStackTo(stack, CRAFT_SLOT_START, CRAFT_SLOT_END, false)) 96 { 97 } 98 else if(!moveItemStackTo(stack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false)) 99 { 100 return nullptr; 101 } 102 } 103 else if (slotIndex >= USE_ROW_SLOT_START && slotIndex < USE_ROW_SLOT_END) 104 { 105 if(isValidIngredient(stack, -1) && moveItemStackTo(stack, CRAFT_SLOT_START, CRAFT_SLOT_END, false)) 106 { 107 } 108 else if(!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END, false)) 109 { 110 return nullptr; 111 } 112 } 113 else 114 { 115 if(!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, false)) 116 { 117 return nullptr; 118 } 119 } 120 if (stack->count == 0) 121 { 122 slot->set(nullptr); 123 } 124 else 125 { 126 slot->setChanged(); 127 } 128 if (stack->count == clicked->count) 129 { 130 // nothing moved 131 return nullptr; 132 } 133 else 134 { 135 slot->onTake(player, stack); 136 } 137 } 138 return clicked; 139} 140 141bool FireworksMenu::canTakeItemForPickAll(shared_ptr<ItemInstance> carried, Slot *target) 142{ 143 return target->container != resultSlots && AbstractContainerMenu::canTakeItemForPickAll(carried, target); 144} 145 146bool FireworksMenu::isValidIngredient(shared_ptr<ItemInstance> item, int slotId) 147{ 148 if(item == NULL || slotId == RESULT_SLOT) return true; 149 return FireworksRecipe::isValidIngredient(item, m_canMakeFireworks, m_canMakeCharge, m_canMakeFade); 150}