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/DispenserTileEntity.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/DispenserTileEntity.cpp')
| -rw-r--r-- | Minecraft.World/DispenserTileEntity.cpp | 105 |
1 files changed, 63 insertions, 42 deletions
diff --git a/Minecraft.World/DispenserTileEntity.cpp b/Minecraft.World/DispenserTileEntity.cpp index 2c4705ea..b087e535 100644 --- a/Minecraft.World/DispenserTileEntity.cpp +++ b/Minecraft.World/DispenserTileEntity.cpp @@ -1,5 +1,3 @@ -using namespace std; - #include "stdafx.h" #include "com.mojang.nbt.h" #include "TileEntity.h" @@ -13,14 +11,14 @@ using namespace std; DispenserTileEntity::DispenserTileEntity() : TileEntity() { - items = new ItemInstanceArray(9); + items = ItemInstanceArray(9); random = new Random(); + name = L""; } DispenserTileEntity::~DispenserTileEntity() { - delete[] items->data; - delete items; + delete[] items.data; delete random; } @@ -32,27 +30,27 @@ unsigned int DispenserTileEntity::getContainerSize() shared_ptr<ItemInstance> DispenserTileEntity::getItem(unsigned int slot) { - return items->data[slot]; + return items[slot]; } shared_ptr<ItemInstance> DispenserTileEntity::removeItem(unsigned int slot, int count) { - if (items->data[slot] != NULL) + if (items[slot] != NULL) { - if (items->data[slot]->count <= count) + if (items[slot]->count <= count) { - shared_ptr<ItemInstance> item = items->data[slot]; - items->data[slot] = nullptr; - this->setChanged(); + shared_ptr<ItemInstance> item = items[slot]; + items[slot] = nullptr; + setChanged(); // 4J Stu - Fix for duplication glitch if(item->count <= 0) return nullptr; return item; } else { - shared_ptr<ItemInstance> i = items->data[slot]->remove(count); - if (items->data[slot]->count == 0) items->data[slot] = nullptr; - this->setChanged(); + shared_ptr<ItemInstance> i = items[slot]->remove(count); + if (items[slot]->count == 0) items[slot] = nullptr; + setChanged(); // 4J Stu - Fix for duplication glitch if(i->count <= 0) return nullptr; return i; @@ -63,10 +61,10 @@ shared_ptr<ItemInstance> DispenserTileEntity::removeItem(unsigned int slot, int shared_ptr<ItemInstance> DispenserTileEntity::removeItemNoUpdate(int slot) { - if (items->data[slot] != NULL) + if (items[slot] != NULL) { - shared_ptr<ItemInstance> item = items->data[slot]; - items->data[slot] = nullptr; + shared_ptr<ItemInstance> item = items[slot]; + items[slot] = nullptr; return item; } return nullptr; @@ -75,20 +73,20 @@ shared_ptr<ItemInstance> DispenserTileEntity::removeItemNoUpdate(int slot) // 4J-PB added for spawn eggs not being useable due to limits, so add them in again void DispenserTileEntity::AddItemBack(shared_ptr<ItemInstance>item, unsigned int slot) { - if (items->data[slot] != NULL) + if (items[slot] != NULL) { // just increment the count of the items - if(item->id==items->data[slot]->id) + if(item->id==items[slot]->id) { - items->data[slot]->count++; - this->setChanged(); + items[slot]->count++; + setChanged(); } } else { - items->data[slot] = item; + items[slot] = item; if (item != NULL && item->count > getMaxStackSize()) item->count = getMaxStackSize(); - this->setChanged(); + setChanged(); } } /** @@ -99,9 +97,9 @@ void DispenserTileEntity::AddItemBack(shared_ptr<ItemInstance>item, unsigned int */ bool DispenserTileEntity::removeProjectile(int itemId) { - for (unsigned int i = 0; i < items->length; i++) + for (unsigned int i = 0; i < items.length; i++) { - if (items->data[i] != NULL && items->data[i]->id == itemId) + if (items[i] != NULL && items[i]->id == itemId) { shared_ptr<ItemInstance> removedItem = removeItem(i, 1); return removedItem != NULL; @@ -114,9 +112,9 @@ int DispenserTileEntity::getRandomSlot() { int replaceSlot = -1; int replaceOdds = 1; - for (unsigned int i = 0; i < items->length; i++) + for (unsigned int i = 0; i < items.length; i++) { - if (items->data[i] != NULL && random->nextInt(replaceOdds++) == 0) + if (items[i] != NULL && random->nextInt(replaceOdds++) == 0) { replaceSlot = i; } @@ -127,18 +125,18 @@ int DispenserTileEntity::getRandomSlot() void DispenserTileEntity::setItem(unsigned int slot, shared_ptr<ItemInstance> item) { - items->data[slot] = item; + items[slot] = item; if (item != NULL && item->count > getMaxStackSize()) item->count = getMaxStackSize(); - this->setChanged(); + setChanged(); } int DispenserTileEntity::addItem(shared_ptr<ItemInstance> item) { - for (int i = 0; i < items->length; i++) + for (int i = 0; i < items.length; i++) { - if ((*items)[i] == NULL || (*items)[i]->id == 0) + if (items[i] == NULL || items[i]->id == 0) { - (*items)[i] = item; + setItem(i, item); return i; } } @@ -146,22 +144,39 @@ int DispenserTileEntity::addItem(shared_ptr<ItemInstance> item) return -1; } -int DispenserTileEntity::getName() +wstring DispenserTileEntity::getName() +{ + return hasCustomName() ? name : app.GetString(IDS_TILE_DISPENSER); +} + +wstring DispenserTileEntity::getCustomName() +{ + return hasCustomName() ? name : L""; +} + +void DispenserTileEntity::setCustomName(const wstring &name) { - return IDS_TILE_DISPENSER; + this->name = name; +} + +bool DispenserTileEntity::hasCustomName() +{ + return !name.empty(); } void DispenserTileEntity::load(CompoundTag *base) { TileEntity::load(base); ListTag<CompoundTag> *inventoryList = (ListTag<CompoundTag> *) base->getList(L"Items"); - items = new ItemInstanceArray(getContainerSize()); + delete [] items.data; + items = ItemInstanceArray(getContainerSize()); for (int i = 0; i < inventoryList->size(); i++) { CompoundTag *tag = inventoryList->get(i); unsigned int slot = tag->getByte(L"Slot") & 0xff; - if (slot >= 0 && slot < items->length) (*items)[slot] = ItemInstance::fromTag(tag); + if (slot >= 0 && slot < items.length) items[slot] = ItemInstance::fromTag(tag); } + if (base->contains(L"CustomName")) name = base->getString(L"CustomName"); } void DispenserTileEntity::save(CompoundTag *base) @@ -169,17 +184,18 @@ void DispenserTileEntity::save(CompoundTag *base) TileEntity::save(base); ListTag<CompoundTag> *listTag = new ListTag<CompoundTag>; - for (unsigned int i = 0; i < items->length; i++) + for (unsigned int i = 0; i < items.length; i++) { - if (items->data[i] != NULL) + if (items[i] != NULL) { CompoundTag *tag = new CompoundTag(); tag->putByte(L"Slot", (byte) i); - items->data[i]->save(tag); + items[i]->save(tag); listTag->add(tag); } } base->put(L"Items", listTag); + if (hasCustomName()) base->putString(L"CustomName", name); } int DispenserTileEntity::getMaxStackSize() @@ -207,17 +223,22 @@ void DispenserTileEntity::stopOpen() { } +bool DispenserTileEntity::canPlaceItem(int slot, shared_ptr<ItemInstance> item) +{ + return true; +} + // 4J Added shared_ptr<TileEntity> DispenserTileEntity::clone() { shared_ptr<DispenserTileEntity> result = shared_ptr<DispenserTileEntity>( new DispenserTileEntity() ); TileEntity::clone(result); - for (unsigned int i = 0; i < items->length; i++) + for (unsigned int i = 0; i < items.length; i++) { - if (items->data[i] != NULL) + if (items[i] != NULL) { - result->items->data[i] = ItemInstance::clone(items->data[i]); + result->items[i] = ItemInstance::clone(items[i]); } } return result; |
