From b691c43c44ff180d10e7d4a9afc83b98551ff586 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Sun, 1 Mar 2026 12:16:08 +0800 Subject: Initial commit --- Minecraft.World/TrapMenu.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Minecraft.World/TrapMenu.cpp (limited to 'Minecraft.World/TrapMenu.cpp') diff --git a/Minecraft.World/TrapMenu.cpp b/Minecraft.World/TrapMenu.cpp new file mode 100644 index 00000000..5e59c6fe --- /dev/null +++ b/Minecraft.World/TrapMenu.cpp @@ -0,0 +1,81 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.player.h" +#include "net.minecraft.world.level.tile.entity.h" +#include "Container.h" +#include "Slot.h" +#include "TrapMenu.h" + +TrapMenu::TrapMenu(shared_ptr inventory, shared_ptr trap) +{ + this->trap = trap; + + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 3; x++) + { + addSlot(new Slot(trap, x + y * 3, 62 + x * 18, 17 + y * 18)); + } + } + + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 9; x++) + { + addSlot(new Slot(inventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); + } + } + for (int x = 0; x < 9; x++) + { + addSlot(new Slot(inventory, x, 8 + x * 18, 70 + 4 * 18)); + } +} + +bool TrapMenu::stillValid(shared_ptr player) +{ + return trap->stillValid(player); +} + +// 4J Stu - Brought forward from 1.2 +shared_ptr TrapMenu::quickMoveStack(shared_ptr player, int slotIndex) +{ + shared_ptr clicked = nullptr; + Slot *slot = slots->at(slotIndex); + if (slot != NULL && slot->hasItem()) + { + shared_ptr stack = slot->getItem(); + clicked = stack->copy(); + + if (slotIndex < INV_SLOT_START) + { + if (!moveItemStackTo(stack, INV_SLOT_START, USE_ROW_SLOT_END, true)) + { + return nullptr; + } + } + else + { + if (!moveItemStackTo(stack, 0, INV_SLOT_START, false)) + { + return nullptr; + } + } + if (stack->count == 0) + { + slot->set(nullptr); + } + else + { + slot->setChanged(); + } + if (stack->count == clicked->count) + { + // nothing moved + return nullptr; + } + else + { + slot->onTake(player, stack); + } + } + return clicked; +} \ No newline at end of file -- cgit v1.2.3