From de44564825e239acf816ac820e786b3e0afe6cdb Mon Sep 17 00:00:00 2001 From: Windermed <80722937+Windermed@users.noreply.github.com> Date: Mon, 2 Mar 2026 15:58:25 -0800 Subject: [PATCH] pick block for mobs * adjusted the pick block addition to also count for mobs being looked at (which should give the player it's proper spawn egg) --- Minecraft.Client/Minecraft.cpp | 125 +++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 865f8a9..3494d2a 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -62,6 +62,7 @@ #include "..\Minecraft.World\StrongholdFeature.h" #include "..\Minecraft.World\IntCache.h" #include "..\Minecraft.World\Villager.h" +#include "..\Minecraft.World\EntityIO.h" // for mobs #include "..\Minecraft.World\SparseLightStorage.h" #include "..\Minecraft.World\SparseDataStorage.h" #include "TextureManager.h" @@ -3296,63 +3297,85 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) } #ifdef _WINDOWS64 // allows for the player to get the block they are looking at in creative by middle clicking. - if (iPad == 0 && player->abilities.instabuild && g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_MIDDLE) && hitResult != NULL && hitResult->type == HitResult::TILE) + if (iPad == 0 && player->abilities.instabuild && g_KBMInput.IsMouseButtonPressed(KeyboardMouseInput::MOUSE_MIDDLE) && hitResult != NULL && (hitResult->type == HitResult::TILE || hitResult->type == HitResult::ENTITY)) { - //printf("MIDDLE CLICK TEST!!"); - int tileId = level->getTile(hitResult->x, hitResult->y, hitResult->z); - Tile *tile = (tileId > 0 && tileId < Tile::TILE_NUM_COUNT) ? Tile::tiles[tileId] : NULL; + //printf("MIDDLE CLICK TEST!!"); // windermed was here. + int cloneId = -1; + int cloneData = 0; + bool checkData = false; - if (tile != NULL) + // if its a tile + if (hitResult->type == HitResult::TILE) { - int cloneId = tile->cloneTileId(level, hitResult->x, hitResult->y, hitResult->z); - - if (cloneId > 0 && cloneId < Item::ITEM_NUM_COUNT && Item::items[cloneId] != NULL) + int tileId = level->getTile(hitResult->x, hitResult->y, hitResult->z); + Tile* tile = (tileId > 0 && tileId < Tile::TILE_NUM_COUNT) ? Tile::tiles[tileId] : NULL; + if (tile != NULL) { - int cloneData = tile->cloneTileData(level, hitResult->x, hitResult->y, hitResult->z); - bool checkData = Item::items[cloneId]->isStackedByData(); - - int quickbarSlot = -1; - - for (int slot = 0; slot < Inventory::getSelectionSize(); ++slot) - { - shared_ptr quickbarItem = player->inventory->items[slot]; - if (quickbarItem == NULL || quickbarItem->id != cloneId) - { - continue; - } - - if (!checkData || quickbarItem->getAuxValue() == cloneData) - { - quickbarSlot = slot; - break; - } - } - - if (quickbarSlot >= 0) - { - player->inventory->selected = quickbarSlot; - } - else - { - player->inventory->grabTexture(cloneId, cloneData, checkData, true); - } - - // should prevent ghost items/blocks - shared_ptr selctedItem = player->inventory->getSelected(); - if (gameMode != NULL && selctedItem != NULL) - { - const int creativeHotbarSlotStart = 36; - gameMode->handleCreativeModeItemAdd(selctedItem, creativeHotbarSlotStart + player->inventory->selected); - } - - if (gameMode != NULL && gameMode->getTutorial() != NULL) - { - gameMode->getTutorial()->onSelectedItemChanged(player->inventory->getSelected()); - } - - player->updateRichPresence(); + cloneId = tile->cloneTileId(level, hitResult->x, hitResult->y, hitResult->z); + cloneData = tile->cloneTileData(level, hitResult->x, hitResult->y, hitResult->z); } } + + // if its an entity + else if (hitResult->type == HitResult::ENTITY && hitResult->entity != NULL) + { + int entityIoId = EntityIO::eTypeToIoid(hitResult->entity->GetType()); + if (entityIoId > 0 && EntityIO::idsSpawnableInCreative.find(entityIoId) != EntityIO::idsSpawnableInCreative.end()) + { + cloneId = Item::monsterPlacer_Id; + cloneData = entityIoId; + checkData = true; + } + } + + // if we have a valid cloneId, try to find it in the quickbar and select it, otherwise just grab it. + if (cloneId > 0 && cloneId < Item::ITEM_NUM_COUNT && Item::items[cloneId] != NULL) + { + if (hitResult->type == HitResult::TILE) + { + checkData = Item::items[cloneId]->isStackedByData(); + } + + int quickbarSlot = -1; + for (int slot = 0; slot < Inventory::getSelectionSize(); ++slot) + { + shared_ptr quickbarItem = player->inventory->items[slot]; + if (quickbarItem == NULL || quickbarItem->id != cloneId) + { + continue; + } + + if (!checkData || quickbarItem->getAuxValue() == cloneData) + { + quickbarSlot = slot; + break; + } + } + + if (quickbarSlot >= 0) + { + player->inventory->selected = quickbarSlot; + } + else + { + player->inventory->grabTexture(cloneId, cloneData, checkData, true); + } + + // should prevent ghost items/blocks + shared_ptr selectedItem = player->inventory->getSelected(); + if (gameMode != NULL && selectedItem != NULL) + { + const int creativeQuickbarSlotStart = 36; + gameMode->handleCreativeModeItemAdd(selectedItem, creativeQuickbarSlotStart + player->inventory->selected); + } + + if (gameMode != NULL && gameMode->getTutorial() != NULL) + { + gameMode->getTutorial()->onSelectedItemChanged(player->inventory->getSelected()); + } + + player->updateRichPresence(); + } } #endif