From 087b7e7abfe81dd7f0fdcdea36ac9f245950df1a Mon Sep 17 00:00:00 2001 From: Loki Rautio Date: Sat, 7 Mar 2026 21:12:22 -0600 Subject: Revert "Project modernization (#630)" This code was not tested and breaks in Release builds, reverting to restore functionality of the nightly. All in-game menus do not work and generating a world crashes. This reverts commit a9be52c41a02d207233199e98898fe7483d7e817. --- Minecraft.World/ItemInstance.cpp | 114 +++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'Minecraft.World/ItemInstance.cpp') diff --git a/Minecraft.World/ItemInstance.cpp b/Minecraft.World/ItemInstance.cpp index 4906c22e..4dcde7aa 100644 --- a/Minecraft.World/ItemInstance.cpp +++ b/Minecraft.World/ItemInstance.cpp @@ -25,7 +25,7 @@ void ItemInstance::_init(int id, int count, int auxValue) this->id = id; this->count = count; this->auxValue = auxValue; - this->tag = nullptr; + this->tag = NULL; this->frame = nullptr; // 4J-PB - for trading menu this->m_bForceNumberDisplay=false; @@ -81,18 +81,18 @@ shared_ptr ItemInstance::fromTag(CompoundTag *itemTag) { shared_ptr itemInstance = shared_ptr(new ItemInstance()); itemInstance->load(itemTag); - return itemInstance->getItem() != nullptr ? itemInstance : nullptr; + return itemInstance->getItem() != NULL ? itemInstance : nullptr; } ItemInstance::~ItemInstance() { - if(tag != nullptr) delete tag; + if(tag != NULL) delete tag; } shared_ptr ItemInstance::remove(int count) { - shared_ptr ii = std::make_shared(id, count, auxValue); - if (tag != nullptr) ii->tag = static_cast(tag->copy()); + shared_ptr ii = shared_ptr( new ItemInstance(id, count, auxValue) ); + if (tag != NULL) ii->tag = (CompoundTag *) tag->copy(); this->count -= count; // 4J Stu Fix for duplication glitch, make sure that item count is in range @@ -145,10 +145,10 @@ shared_ptr ItemInstance::useTimeDepleted(Level *level, shared_ptr< CompoundTag *ItemInstance::save(CompoundTag *compoundTag) { - compoundTag->putShort(L"id", static_cast(id)); - compoundTag->putByte(L"Count", static_cast(count)); - compoundTag->putShort(L"Damage", static_cast(auxValue)); - if (tag != nullptr) compoundTag->put(L"tag", tag->copy()); + compoundTag->putShort(L"id", (short) id); + compoundTag->putByte(L"Count", (byte) count); + compoundTag->putShort(L"Damage", (short) auxValue); + if (tag != NULL) compoundTag->put(L"tag", tag->copy()); return compoundTag; } @@ -165,7 +165,7 @@ void ItemInstance::load(CompoundTag *compoundTag) if (compoundTag->contains(L"tag")) { delete tag; - tag = static_cast(compoundTag->getCompound(L"tag")->copy()); + tag = (CompoundTag *)compoundTag->getCompound(L"tag")->copy(); } } @@ -257,7 +257,7 @@ bool ItemInstance::hurt(int dmg, Random *random) void ItemInstance::hurtAndBreak(int dmg, shared_ptr owner) { shared_ptr player = dynamic_pointer_cast(owner); - if (player != nullptr && player->abilities.instabuild) return; + if (player != NULL && player->abilities.instabuild) return; if (!isDamageableItem()) return; if (hurt(dmg, owner->getRandom())) @@ -265,10 +265,10 @@ void ItemInstance::hurtAndBreak(int dmg, shared_ptr owner) owner->breakItem(shared_from_this()); count--; - if (player != nullptr) + if (player != NULL) { //player->awardStat(Stats::itemBroke[id], 1); - if (count == 0 && dynamic_cast( getItem() ) != nullptr) + if (count == 0 && dynamic_cast( getItem() ) != NULL) { player->removeSelectedItem(); } @@ -302,10 +302,10 @@ bool ItemInstance::interactEnemy(shared_ptr player, shared_ptr ItemInstance::copy() const { - shared_ptr copy = std::make_shared(id, count, auxValue); - if (tag != nullptr) + shared_ptr copy = shared_ptr( new ItemInstance(id, count, auxValue) ); + if (tag != NULL) { - copy->tag = static_cast(tag->copy()); + copy->tag = (CompoundTag *) tag->copy(); } return copy; } @@ -314,9 +314,9 @@ shared_ptr ItemInstance::copy() const ItemInstance *ItemInstance::copy_not_shared() const { ItemInstance *copy = new ItemInstance(id, count, auxValue); - if (tag != nullptr) + if (tag != NULL) { - copy->tag = static_cast(tag->copy()); + copy->tag = (CompoundTag *) tag->copy(); if (!copy->tag->equals(tag)) { return copy; @@ -328,14 +328,14 @@ ItemInstance *ItemInstance::copy_not_shared() const // 4J Brought forward from 1.2 bool ItemInstance::tagMatches(shared_ptr a, shared_ptr b) { - if (a == nullptr && b == nullptr) return true; - if (a == nullptr || b == nullptr) return false; + if (a == NULL && b == NULL) return true; + if (a == NULL || b == NULL) return false; - if (a->tag == nullptr && b->tag != nullptr) + if (a->tag == NULL && b->tag != NULL) { return false; } - if (a->tag != nullptr && !a->tag->equals(b->tag)) + if (a->tag != NULL && !a->tag->equals(b->tag)) { return false; } @@ -344,8 +344,8 @@ bool ItemInstance::tagMatches(shared_ptr a, shared_ptr a, shared_ptr b) { - if (a == nullptr && b == nullptr) return true; - if (a == nullptr || b == nullptr) return false; + if (a == NULL && b == NULL) return true; + if (a == NULL || b == NULL) return false; return a->matches(b); } @@ -354,11 +354,11 @@ bool ItemInstance::matches(shared_ptr b) if (count != b->count) return false; if (id != b->id) return false; if (auxValue != b->auxValue) return false; - if (tag == nullptr && b->tag != nullptr) + if (tag == NULL && b->tag != NULL) { return false; } - if (tag != nullptr && !tag->equals(b->tag)) + if (tag != NULL && !tag->equals(b->tag)) { return false; } @@ -381,11 +381,11 @@ bool ItemInstance::sameItemWithTags(shared_ptr b) { if (id != b->id) return false; if (auxValue != b->auxValue) return false; - if (tag == nullptr && b->tag != nullptr) + if (tag == NULL && b->tag != NULL) { return false; } - if (tag != nullptr && !tag->equals(b->tag)) + if (tag != NULL && !tag->equals(b->tag)) { return false; } @@ -417,7 +417,7 @@ ItemInstance *ItemInstance::setDescriptionId(unsigned int id) shared_ptr ItemInstance::clone(shared_ptr item) { - return item == nullptr ? nullptr : item->copy(); + return item == NULL ? nullptr : item->copy(); } wstring ItemInstance::toString() @@ -426,9 +426,9 @@ wstring ItemInstance::toString() std::wostringstream oss; // 4J-PB - TODO - temp fix until ore recipe issue is fixed - if(Item::items[id]==nullptr) + if(Item::items[id]==NULL) { - oss << std::dec << count << L"x" << L" Item::items[id] is nullptr " << L"@" << auxValue; + oss << std::dec << count << L"x" << L" Item::items[id] is NULL " << L"@" << auxValue; } else { @@ -479,7 +479,7 @@ void ItemInstance::releaseUsing(Level *level, shared_ptr player, int dur // 4J Stu - Brought forward these functions for enchanting/game rules bool ItemInstance::hasTag() { - return tag != nullptr; + return tag != NULL; } CompoundTag *ItemInstance::getTag() @@ -489,11 +489,11 @@ CompoundTag *ItemInstance::getTag() ListTag *ItemInstance::getEnchantmentTags() { - if (tag == nullptr) + if (tag == NULL) { - return nullptr; + return NULL; } - return static_cast *>(tag->get(L"ench")); + return (ListTag *) tag->get(L"ench"); } void ItemInstance::setTag(CompoundTag *tag) @@ -506,7 +506,7 @@ wstring ItemInstance::getHoverName() { wstring title = getItem()->getHoverName(shared_from_this()); - if (tag != nullptr && tag->contains(L"display")) + if (tag != NULL && tag->contains(L"display")) { CompoundTag *display = tag->getCompound(L"display"); @@ -521,14 +521,14 @@ wstring ItemInstance::getHoverName() void ItemInstance::setHoverName(const wstring &name) { - if (tag == nullptr) tag = new CompoundTag(); + if (tag == NULL) tag = new CompoundTag(); if (!tag->contains(L"display")) tag->putCompound(L"display", new CompoundTag()); tag->getCompound(L"display")->putString(L"Name", name); } void ItemInstance::resetHoverName() { - if (tag == nullptr) return; + if (tag == NULL) return; if (!tag->contains(L"display")) return; CompoundTag *display = tag->getCompound(L"display"); display->remove(L"Name"); @@ -539,14 +539,14 @@ void ItemInstance::resetHoverName() if (tag->isEmpty()) { - setTag(nullptr); + setTag(NULL); } } } bool ItemInstance::hasCustomHoverName() { - if (tag == nullptr) return false; + if (tag == NULL) return false; if (!tag->contains(L"display")) return false; return tag->getCompound(L"display")->contains(L"Name"); } @@ -598,14 +598,14 @@ vector *ItemInstance::getHoverText(shared_ptr player, bool a if (hasTag()) { ListTag *list = getEnchantmentTags(); - if (list != nullptr) + if (list != NULL) { for (int i = 0; i < list->size(); i++) { int type = list->get(i)->getShort((wchar_t *)TAG_ENCH_ID); int level = list->get(i)->getShort((wchar_t *)TAG_ENCH_LEVEL); - if (Enchantment::enchantments[type] != nullptr) + if (Enchantment::enchantments[type] != NULL) { wstring unformatted = L""; lines->push_back(Enchantment::enchantments[type]->getFullname(level)); @@ -693,14 +693,14 @@ vector *ItemInstance::getHoverTextOnly(shared_ptr player, bo if (hasTag()) { ListTag *list = getEnchantmentTags(); - if (list != nullptr) + if (list != NULL) { for (int i = 0; i < list->size(); i++) { int type = list->get(i)->getShort((wchar_t *)TAG_ENCH_ID); int level = list->get(i)->getShort((wchar_t *)TAG_ENCH_LEVEL); - if (Enchantment::enchantments[type] != nullptr) + if (Enchantment::enchantments[type] != NULL) { wstring unformatted = L""; lines->push_back(Enchantment::enchantments[type]->getFullname(level)); @@ -730,25 +730,25 @@ bool ItemInstance::isEnchantable() void ItemInstance::enchant(const Enchantment *enchantment, int level) { - if (tag == nullptr) this->setTag(new CompoundTag()); + if (tag == NULL) this->setTag(new CompoundTag()); if (!tag->contains(L"ench")) tag->put(L"ench", new ListTag(L"ench")); - ListTag *list = static_cast *>(tag->get(L"ench")); + ListTag *list = (ListTag *) tag->get(L"ench"); CompoundTag *ench = new CompoundTag(); - ench->putShort((wchar_t *)TAG_ENCH_ID, static_cast(enchantment->id)); - ench->putShort((wchar_t *)TAG_ENCH_LEVEL, static_cast(level)); + ench->putShort((wchar_t *)TAG_ENCH_ID, (short) enchantment->id); + ench->putShort((wchar_t *)TAG_ENCH_LEVEL, (byte) level); list->add(ench); } bool ItemInstance::isEnchanted() { - if (tag != nullptr && tag->contains(L"ench")) return true; + if (tag != NULL && tag->contains(L"ench")) return true; return false; } void ItemInstance::addTagElement(wstring name, Tag *tag) { - if (this->tag == nullptr) + if (this->tag == NULL) { setTag(new CompoundTag()); } @@ -762,7 +762,7 @@ bool ItemInstance::mayBePlacedInAdventureMode() bool ItemInstance::isFramed() { - return frame != nullptr; + return frame != NULL; } void ItemInstance::setFramed(shared_ptr frame) @@ -795,7 +795,7 @@ void ItemInstance::setRepairCost(int cost) attrAttrModMap *ItemInstance::getAttributeModifiers() { - attrAttrModMap *result = nullptr; + attrAttrModMap *result = NULL; if (hasTag() && tag->contains(L"AttributeModifiers")) { @@ -824,12 +824,12 @@ attrAttrModMap *ItemInstance::getAttributeModifiers() void ItemInstance::set4JData(int data) { - if(tag == nullptr && data == 0) return; - if (tag == nullptr) this->setTag(new CompoundTag()); + if(tag == NULL && data == 0) return; + if (tag == NULL) this->setTag(new CompoundTag()); if (tag->contains(L"4jdata")) { - IntTag *dataTag = static_cast(tag->get(L"4jdata")); + IntTag *dataTag = (IntTag *)tag->get(L"4jdata"); dataTag->data = data; } else if(data != 0) @@ -840,10 +840,10 @@ void ItemInstance::set4JData(int data) int ItemInstance::get4JData() { - if(tag == nullptr || !tag->contains(L"4jdata")) return 0; + if(tag == NULL || !tag->contains(L"4jdata")) return 0; else { - IntTag *dataTag = static_cast(tag->get(L"4jdata")); + IntTag *dataTag = (IntTag *)tag->get(L"4jdata"); return dataTag->data; } } -- cgit v1.2.3