the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 178 lines 4.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.player.h" 3#include "net.minecraft.world.item.h" 4#include "net.minecraft.world.level.tile.entity.h" 5#include "FurnaceResultSlot.h" 6#include "Slot.h" 7#include "GenericStats.h" 8#include "FurnaceMenu.h" 9#include "FurnaceRecipes.h" 10 11FurnaceMenu::FurnaceMenu(shared_ptr<Inventory> inventory, shared_ptr<FurnaceTileEntity> furnace) : AbstractContainerMenu() 12{ 13 tc = 0; 14 lt = 0; 15 ld = 0; 16 17 this->furnace = furnace; 18 19 addSlot(new Slot(furnace, 0, 52 + 4, 13 + 4)); 20 addSlot(new Slot(furnace, 1, 52 + 4, 49 + 4)); 21 addSlot(new FurnaceResultSlot( dynamic_pointer_cast<Player>( inventory->player->shared_from_this() ), furnace, 2, 112 + 4, 31 + 4)); 22 23 for (int y = 0; y < 3; y++) 24 { 25 for (int x = 0; x < 9; x++) 26 { 27 addSlot(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); 28 } 29 } 30 for (int x = 0; x < 9; x++) 31 { 32 addSlot(new Slot(inventory, x, 8 + x * 18, 142)); 33 } 34} 35 36void FurnaceMenu::addSlotListener(ContainerListener *listener) 37{ 38 AbstractContainerMenu::addSlotListener(listener); 39 listener->setContainerData(this, 0, furnace->tickCount); 40 listener->setContainerData(this, 1, furnace->litTime); 41 listener->setContainerData(this, 2, furnace->litDuration); 42} 43 44void FurnaceMenu::broadcastChanges() 45{ 46 AbstractContainerMenu::broadcastChanges(); 47 48 AUTO_VAR(itEnd, containerListeners.end()); 49 for (AUTO_VAR(it, containerListeners.begin()); it != itEnd; it++) 50 { 51 ContainerListener *listener = *it; //containerListeners->at(i); 52 if (tc != furnace->tickCount) 53 { 54 listener->setContainerData(this, 0, furnace->tickCount); 55 } 56 if (lt != furnace->litTime) 57 { 58 listener->setContainerData(this, 1, furnace->litTime); 59 } 60 if (ld != furnace->litDuration) 61 { 62 listener->setContainerData(this, 2, furnace->litDuration); 63 } 64 } 65 66 tc = furnace->tickCount; 67 lt = furnace->litTime; 68 ld = furnace->litDuration; 69} 70 71void FurnaceMenu::setData(int id, int value) 72{ 73 if (id == 0) furnace->tickCount = value; 74 if (id == 1) furnace->litTime = value; 75 if (id == 2) furnace->litDuration = value; 76} 77 78bool FurnaceMenu::stillValid(shared_ptr<Player> player) 79{ 80 return furnace->stillValid(player); 81} 82 83shared_ptr<ItemInstance> FurnaceMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex) 84{ 85 shared_ptr<ItemInstance> clicked = nullptr; 86 Slot *slot = slots.at(slotIndex); 87 //Slot *IngredientSlot = slots->at(INGREDIENT_SLOT); 88 89 bool charcoalUsed = furnace->wasCharcoalUsed(); 90 91 if (slot != NULL && slot->hasItem()) 92 { 93 shared_ptr<ItemInstance> stack = slot->getItem(); 94 clicked = stack->copy(); 95 96 if (slotIndex == RESULT_SLOT) 97 { 98 if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, true)) 99 { 100 return nullptr; 101 } 102 slot->onQuickCraft(stack, clicked); 103 104 // 4J-JEV, hook for Durango achievement 'Renewable Energy'. 105#ifdef _EXTENDED_ACHIEVEMENTS 106 if ( charcoalUsed && stack->getItem()->id == Item::coal_Id && stack->getAuxValue() == CoalItem::CHAR_COAL) 107 player->awardStat(GenericStats::renewableEnergy(),GenericStats::param_renewableEnergy()); 108#endif 109 } 110 else if (slotIndex == FUEL_SLOT || slotIndex == INGREDIENT_SLOT) 111 { 112 if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, false)) 113 { 114 return nullptr; 115 } 116 } 117 else if (FurnaceRecipes::getInstance()->getResult(stack->getItem()->id) != NULL) 118 { 119 if (!moveItemStackTo(stack, INGREDIENT_SLOT, INGREDIENT_SLOT + 1, false)) 120 { 121 return nullptr; 122 } 123 } 124 else if (FurnaceTileEntity::isFuel(stack)) 125 { 126 if (!moveItemStackTo(stack, FUEL_SLOT, FUEL_SLOT + 1, false)) 127 { 128 return nullptr; 129 } 130 } else if (slotIndex >= INV_SLOT_START && slotIndex < INV_SLOT_END) 131 { 132 if (!moveItemStackTo(stack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false)) 133 { 134 return nullptr; 135 } 136 } else if (slotIndex >= USE_ROW_SLOT_START && slotIndex < USE_ROW_SLOT_END) 137 { 138 if (!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END, false)) 139 { 140 return nullptr; 141 } 142 } 143 if (stack->count == 0) 144 { 145 slot->set(nullptr); 146 } 147 else 148 { 149 slot->setChanged(); 150 } 151 if (stack->count == clicked->count) 152 { 153 return nullptr; 154 } 155 else 156 { 157 slot->onTake(player, stack); 158 } 159 } 160 return clicked; 161} 162 163shared_ptr<ItemInstance> FurnaceMenu::clicked(int slotIndex, int buttonNum, int clickType, shared_ptr<Player> player, bool looped) // 4J Added looped param 164{ 165 bool charcoalUsed = furnace->wasCharcoalUsed(); 166 167 shared_ptr<ItemInstance> out = AbstractContainerMenu::clicked(slotIndex, buttonNum, clickType, player, looped); 168 169#ifdef _EXTENDED_ACHIEVEMENTS 170 if ( charcoalUsed && (out!=nullptr) && (buttonNum==0 || buttonNum==1) && clickType==CLICK_PICKUP 171 && out->getItem()->id == Item::coal_Id && out->getAuxValue() == CoalItem::CHAR_COAL ) 172 { 173 player->awardStat(GenericStats::renewableEnergy(),GenericStats::param_renewableEnergy()); 174 } 175#endif 176 177 return out; 178}