Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
feat: complete issue#2
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolLoong committed Dec 19, 2023
1 parent 3a11d30 commit 5d85b98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/DataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void dumpBlockAttributesData() {

std::unique_ptr<class CompoundTag> generateNBTFromItem(const Item& item) {
Logger logger;
auto nbt = createCompound();
std::unique_ptr<class CompoundTag> nbt = createCompound();
logger.info("Extracting item - " + item.getFullItemName());
nbt->putShort("id", item.getId());
try {
Expand All @@ -374,7 +374,6 @@ std::unique_ptr<class CompoundTag> generateNBTFromItem(const Item& item) {
catch (exception& e) {
logger.warn("Exception occur when trying to get block for item " + item.getFullItemName());
}
nbt->putString("descriptionId", item.getDescriptionId());
nbt->putBoolean("isComponentBased", item.isComponentBased());
nbt->putString("name", item.getFullItemName());
nbt->putShort("maxDamage", item.getMaxDamage());//最大耐久
Expand All @@ -401,8 +400,22 @@ std::unique_ptr<class CompoundTag> generateNBTFromItem(const Item& item) {
nbt->putFloat("viewDamping", item.getViewDamping());
nbt->putInt("cooldownTime", item.getCooldownTime());
nbt->putString("cooldownType", item.getCooldownType().getString());
//必须在最后,因为构建itemstack持有了item
nbt->putInt("maxStackSize", (int)ItemStack(item, 1, 0, 0).getMaxStackSize());
CompoundTag descriptionId;
std::set<string> uniqueStr;
for (int i = 0; i <= 256; ++i) {
try {
if (item.isValidAuxValue(i)) {
const auto itemstack = ItemStack(item, 1, i);//ignore some invaild aux exception
if (!uniqueStr.contains(itemstack.getDescriptionId())) {
uniqueStr.insert(itemstack.getDescriptionId());
descriptionId.putString(to_string(i), itemstack.getDescriptionId());
}
}
}
catch (...) {}
}
nbt->putCompound("descriptionId", descriptionId);
return nbt;
}

Expand All @@ -418,9 +431,11 @@ void dumpItemData() {
}
std::unique_ptr<class CompoundTag> obj2 = generateNBTFromItem(*item);
list->add(obj2->copy());
obj2.release();
counter++;
}
tag->put("item", list->copyList());
list.release();
logger.info("Successfully extract " + to_string(counter) + " items' data!");
writeNBT("data/item_data.nbt", tag.get());
tag.release();
Expand Down
11 changes: 11 additions & 0 deletions src/mc/item/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,23 @@ class Item {
// vIndex: 65, symbol: ?getToughnessValue@Item@@UEBAHXZ
int getToughnessValue() const;

// vIndex: 67, symbol: ?isValidAuxValue@Item@@UEBA_NH@Z
bool isValidAuxValue(int) const;

// vIndex: 69, symbol: ?getViewDamping@Item@@UEBAMXZ
float getViewDamping() const;

// vIndex: 83, symbol: ?canUseOnSimTick@Item@@UEBA_NXZ
bool canUseOnSimTick() const;

// vIndex: 94, symbol:
// ?buildDescriptionName@Item@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVItemStackBase@@@Z
std::string buildDescriptionName(class ItemStackBase const&) const;

// vIndex: 95, symbol:
// ?buildDescriptionId@Item@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVItemDescriptor@@PEBVCompoundTag@@@Z
std::string buildDescriptionId(class ItemDescriptor const&, class CompoundTag const*) const;

// vIndex: 103, symbol: ?getCooldownType@Item@@UEBAAEBVHashedString@@XZ
class HashedString const& getCooldownType() const;

Expand Down

0 comments on commit 5d85b98

Please sign in to comment.