diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/ItemFrame.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/ItemFrame.cpp')
| -rw-r--r-- | Minecraft.World/ItemFrame.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/Minecraft.World/ItemFrame.cpp b/Minecraft.World/ItemFrame.cpp index 141f0630..0d52b421 100644 --- a/Minecraft.World/ItemFrame.cpp +++ b/Minecraft.World/ItemFrame.cpp @@ -20,6 +20,8 @@ void ItemFrame::_init() // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that // the derived version of the function is called this->defineSynchedData(); + + dropChance = 1; } ItemFrame::ItemFrame(Level *level) : HangingEntity( level ) @@ -39,19 +41,45 @@ void ItemFrame::defineSynchedData() getEntityData()->define(DATA_ROTATION, (byte) 0); } -void ItemFrame::dropItem() +bool ItemFrame::shouldRenderAtSqrDistance(double distance) +{ + double size = 16; + size *= 64.0f * viewScale; + return distance < size * size; +} + +void ItemFrame::dropItem(shared_ptr<Entity> causedBy) { - spawnAtLocation(shared_ptr<ItemInstance>(new ItemInstance(Item::frame)), 0.0f); shared_ptr<ItemInstance> item = getItem(); - if (item != NULL) + + if (causedBy != NULL && causedBy->instanceof(eTYPE_PLAYER)) { - shared_ptr<MapItemSavedData> data = Item::map->getSavedData(item, level); - data->removeItemFrameDecoration(item); + if (dynamic_pointer_cast<Player>(causedBy)->abilities.instabuild) + { + removeFramedMap(item); + return; + } + } - shared_ptr<ItemInstance> itemToDrop = item->copy(); - itemToDrop->setFramed(nullptr); - spawnAtLocation(itemToDrop, 0.0f); + spawnAtLocation( shared_ptr<ItemInstance>(new ItemInstance(Item::frame) ), 0); + if ( (item != NULL) && (random->nextFloat() < dropChance) ) + { + item = item->copy(); + removeFramedMap(item); + spawnAtLocation(item, 0); + } +} + +void ItemFrame::removeFramedMap(shared_ptr<ItemInstance> item) +{ + if (item == NULL) return; + if (item->id == Item::map_Id) + { + shared_ptr<MapItemSavedData> mapItemSavedData = Item::map->getSavedData(item, level); + mapItemSavedData->removeItemFrameDecoration(item); + //mapItemSavedData.decorations.remove("frame-" + entityId); } + item->setFramed(nullptr); } shared_ptr<ItemInstance> ItemFrame::getItem() @@ -88,7 +116,7 @@ void ItemFrame::addAdditonalSaveData(CompoundTag *tag) { tag->putCompound(L"Item", getItem()->save(new CompoundTag())); tag->putByte(L"ItemRotation", (byte) getRotation()); - //tag->putFloat(L"ItemDropChance", dropChance); + tag->putFloat(L"ItemDropChance", dropChance); } HangingEntity::addAdditonalSaveData(tag); } @@ -101,7 +129,7 @@ void ItemFrame::readAdditionalSaveData(CompoundTag *tag) setItem(ItemInstance::fromTag(itemTag)); setRotation(tag->getByte(L"ItemRotation")); - //if (tag->contains(L"ItemDropChance")) dropChance = tag->getFloat(L"ItemDropChance"); + if (tag->contains(L"ItemDropChance")) dropChance = tag->getFloat(L"ItemDropChance"); } HangingEntity::readAdditionalSaveData(tag); } @@ -125,10 +153,10 @@ bool ItemFrame::interact(shared_ptr<Player> player) if (!player->abilities.instabuild) { - if (--item->count <= 0) - { - player->inventory->setItem(player->inventory->selected, nullptr); - } + if (--item->count <= 0) + { + player->inventory->setItem(player->inventory->selected, nullptr); + } } } } |
