the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 140 lines 3.2 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.item.h" 3#include "net.minecraft.world.level.tile.entity.h" 4#include "BeaconMenu.h" 5 6BeaconMenu::BeaconMenu(shared_ptr<Container> inventory, shared_ptr<BeaconTileEntity> beacon) 7{ 8 this->beacon = beacon; 9 10 addSlot(paymentSlot = new BeaconMenu::PaymentSlot(beacon, PAYMENT_SLOT, 136, 110)); 11 12 int xo = 36; 13 int yo = 137; 14 15 for (int y = 0; y < 3; y++) 16 { 17 for (int x = 0; x < 9; x++) 18 { 19 addSlot(new Slot(inventory, x + y * 9 + 9, xo + x * 18, yo + y * 18)); 20 } 21 } 22 for (int x = 0; x < 9; x++) 23 { 24 addSlot(new Slot(inventory, x, xo + x * 18, 58 + yo)); 25 } 26 27 levels = beacon->getLevels(); 28 primaryPower = beacon->getPrimaryPower(); 29 secondaryPower = beacon->getSecondaryPower(); 30} 31 32 33void BeaconMenu::addSlotListener(ContainerListener *listener) 34{ 35 AbstractContainerMenu::addSlotListener(listener); 36 37 listener->setContainerData(this, 0, levels); 38 listener->setContainerData(this, 1, primaryPower); 39 listener->setContainerData(this, 2, secondaryPower); 40} 41 42void BeaconMenu::setData(int id, int value) 43{ 44 if (id == 0) beacon->setLevels(value); 45 if (id == 1) beacon->setPrimaryPower(value); 46 if (id == 2) beacon->setSecondaryPower(value); 47} 48 49shared_ptr<BeaconTileEntity> BeaconMenu::getBeacon() 50{ 51 return beacon; 52} 53 54bool BeaconMenu::stillValid(shared_ptr<Player> player) 55{ 56 return beacon->stillValid(player); 57} 58 59shared_ptr<ItemInstance> BeaconMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex) 60{ 61 shared_ptr<ItemInstance> clicked = nullptr; 62 Slot *slot = slots.at(slotIndex); 63 if (slot != NULL && slot->hasItem()) 64 { 65 shared_ptr<ItemInstance> stack = slot->getItem(); 66 clicked = stack->copy(); 67 68 if (slotIndex == PAYMENT_SLOT) 69 { 70 if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, true)) 71 { 72 return nullptr; 73 } 74 slot->onQuickCraft(stack, clicked); 75 } 76 else if (!paymentSlot->hasItem() && paymentSlot->mayPlace(stack) && stack->count == 1) 77 { 78 if (!moveItemStackTo(stack, PAYMENT_SLOT, PAYMENT_SLOT + 1, false)) 79 { 80 return nullptr; 81 } 82 } 83 else if (slotIndex >= INV_SLOT_START && slotIndex < INV_SLOT_END) 84 { 85 if (!moveItemStackTo(stack, USE_ROW_SLOT_START, USE_ROW_SLOT_END, false)) 86 { 87 return nullptr; 88 } 89 } 90 else if (slotIndex >= USE_ROW_SLOT_START && slotIndex < USE_ROW_SLOT_END) 91 { 92 if (!moveItemStackTo(stack, INV_SLOT_START, INV_SLOT_END, false)) 93 { 94 return nullptr; 95 } 96 } 97 else 98 { 99 if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, false)) 100 { 101 return nullptr; 102 } 103 } 104 if (stack->count == 0) 105 { 106 slot->set(nullptr); 107 } 108 else 109 { 110 slot->setChanged(); 111 } 112 if (stack->count == clicked->count) 113 { 114 return nullptr; 115 } 116 else 117 { 118 slot->onTake(player, stack); 119 } 120 } 121 return clicked; 122} 123 124BeaconMenu::PaymentSlot::PaymentSlot(shared_ptr<Container> container, int slot, int x, int y) : Slot(container, slot, x, y) 125{ 126} 127 128bool BeaconMenu::PaymentSlot::mayPlace(shared_ptr<ItemInstance> item) 129{ 130 if (item != NULL) 131 { 132 return (item->id == Item::emerald_Id || item->id == Item::diamond_Id || item->id == Item::goldIngot_Id || item->id == Item::ironIngot_Id); 133 } 134 return false; 135} 136 137int BeaconMenu::PaymentSlot::getMaxStackSize() const 138{ 139 return 1; 140}