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

Commit

Permalink
fixed getBlockOrItem
Browse files Browse the repository at this point in the history
  • Loading branch information
engsr6982 committed Apr 23, 2024
1 parent 5b328bc commit 2f27380
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/Form/function/GetBlockOrItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ std::vector<JsonItem> loadJson() {

void give(Player& player, string itemType, int count = 1, int lightLevel = 0) {
try {
// clang-format off
#ifdef DEBUG
tls::entry::getInstance().getSelf().getLogger().info("give | itemType: {}, count: {}, lightLevel: {}", itemType, count, lightLevel);
#endif
// clang-format on

// check start with minecraft:
if (itemType.find("minecraft:") == std::string::npos) itemType = "minecraft:" + itemType;

Expand Down Expand Up @@ -99,13 +105,19 @@ void give(Player& player, string itemType, int count = 1, int lightLevel = 0) {

void inputCount(Player& player, string itemType) {
try {
// clang-format off
#ifdef DEBUG
tls::entry::getInstance().getSelf().getLogger().info("inputCount | itemType: {}", itemType);
#endif
// clang-format on
CustomForm fm;
fm.setTitle("LeviOPTools - Input Count"_tr());

fm.appendLabel("Select Input Count"_tr());

// 数量
fm.appendInput("count", "Enter the required quantity", "integer", "1");
// fm.appendInput("count", "Enter the required quantity", "integer", "1");
fm.appendSlider("count", "Slide to select the amount to be given that has been selected: ", 1, 64);

// 光照等级
if (itemType == "light_block" || itemType == "minecraft:light_block") {
Expand All @@ -127,10 +139,18 @@ void inputCount(Player& player, string itemType) {
});
fm.appendDropdown("target", "Selection of targets to be given"_tr(), options, currentPlayer);

fm.sendTo(player, [&](Player& pl, CustomFormResult const& dt, FormCancelReason) {
fm.sendTo(player, [itemType](Player& pl, CustomFormResult const& dt, FormCancelReason) {
if (!dt) return sendMsg(pl, "Canceled"_tr());
DebugFormCallBack(dt);

// clang-format off
#ifdef DEBUG
tls::entry::getInstance().getSelf().getLogger().info("inputCount.lambda | itemType: {}", itemType);
#endif
// clang-format on

int count = string2Int(std::get<string>(dt->at("count")));
// int count = string2Int(std::get<string>(dt->at("count")));
int count = std::get<double>(dt->at("count"));

string targetStr = std::get<string>(dt->at("target"));

Expand Down Expand Up @@ -171,13 +191,13 @@ void getBlockOrItem(Player& player) {
#ifdef DEBUG
tls::entry::getInstance().getSelf().getLogger().info("Name: {}, Type: {}, ImageType: {}, ImageUrl: {}", it.name, it.type, it.imageType, it.imageUrl);
#endif
string imageType = it.imageType; // copy to local variable to avoid error
string itemType = it.type; // copy to local variable to avoid error
if (it.imageType == "url" || it.imageType == "path") {
fm.appendButton(it.name, it.imageUrl, it.imageType, [&imageType](Player& pl) {
inputCount(pl, imageType);
fm.appendButton(it.name, it.imageUrl, it.imageType, [itemType](Player& pl) {
inputCount(pl, itemType);
});
} else {
fm.appendButton(it.name, [&imageType](Player& pl) { inputCount(pl, imageType); });
fm.appendButton(it.name, [itemType](Player& pl) { inputCount(pl, itemType); });
}
} catch (...) {
tls::entry::getInstance().getSelf().getLogger().error("Failed to build button for item: {}", it.name);
Expand Down

0 comments on commit 2f27380

Please sign in to comment.