Files
neoLegacy/Minecraft.World/BannerPatternRecipe.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

381 lines
14 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.level.tile.h"
#include "BannerItem.h"
#include "BannerPatternRecipe.h"
#include "Rose.h"
#include "com.mojang.nbt.h"
#include "ItemInstance.h"
#include "Recipes.h"
const BannerPatternRecipe::PatternInfo BannerPatternRecipe::PATTERNS[] =
{
{ L"bl", {" ", " ", "# "}, 0, -1 }, // 0
{ L"br", {" ", " ", " #"}, 0, -1 }, // 1
{ L"tl", {"# ", " ", " "}, 0, -1 }, // 2
{ L"tr", {" #", " ", " "}, 0, -1 }, // 3
{ L"bs", {" ", " ", "###"}, 0, -1 }, // 4
{ L"ts", {"###", " ", " "}, 0, -1 }, // 5
{ L"ls", {"# ", "# ", "# "}, 0, -1 }, // 6
{ L"rs", {" #", " #", " #"}, 0, -1 }, // 7
{ L"cs", {" # ", " # ", " # "}, 0, -1 }, // 8
{ L"ms", {" ", "###", " "}, 0, -1 }, // 9
{ L"drs", {"# ", " # ", " #"}, 0, -1 }, // 10
{ L"dls", {" #", " # ", "# "}, 0, -1 }, // 11
{ L"ss", {"# #", "# #", " "}, 0, -1 }, // 12
{ L"cr", {"# #", " # ", "# #"}, 0, -1 }, // 13
{ L"sc", {" # ", "###", " # "}, 0, -1 }, // 14
{ L"bt", {" ", " # ", "# #"}, 0, -1 }, // 15
{ L"tt", {"# #", " # ", " "}, 0, -1 }, // 16
{ L"bts", {" ", "# #", " # "}, 0, -1 }, // 17
{ L"tts", {" # ", "# #", " "}, 0, -1 }, // 18
{ L"ld", {"## ", "# ", " "}, 0, -1 }, // 19
{ L"rd", {" ", " #", " ##"}, 0, -1 }, // 20
{ L"lud", {" ", "# ", "## "}, 0, -1 }, // 21
{ L"rud", {" ##", " #", " "}, 0, -1 }, // 22
{ L"mc", {" ", " # ", " "}, 0, -1 }, // 23
{ L"mr", {" # ", "# #", " # "}, 0, -1 }, // 24
{ L"vh", {"## ", "## ", "## "}, 0, -1 }, // 25
{ L"hh", {"###", "###", " "}, 0, -1 }, // 26
{ L"vhr", {" ##", " ##", " ##"}, 0, -1 }, // 27
{ L"hhb", {" ", "###", "###"}, 0, -1 }, // 28
{ L"bo", {"###", "# #", "###"}, 0, -1 }, // 29
{ L"gra", {"# #", " # ", " # "}, 0, -1 }, // 30
{ L"gru", {" # ", " # ", "# #"}, 0, -1 }, // 31
{ L"cbo", {nullptr, nullptr, nullptr}, Tile::vine_Id, -1 }, // 32
{ L"bri", {nullptr, nullptr, nullptr}, Tile::brick_block_Id, -1 }, // 33
{ L"cre", {nullptr, nullptr, nullptr}, Item::skull_Id, 4 }, // 34
{ L"sku", {nullptr, nullptr, nullptr}, Item::skull_Id, 1 }, // 35
{ L"flo", {nullptr, nullptr, nullptr}, Tile::red_flower_Id, Rose::OXEYE_DAISY }, // 36
{ L"moj", {nullptr, nullptr, nullptr}, Item::golden_apple_Id, 1 }, // 37
};
const int BannerPatternRecipe::PATTERN_COUNT = static_cast<int>(sizeof(PATTERNS) / sizeof(PATTERNS[0]));
const wchar_t* BannerPatternRecipe::matchPattern(shared_ptr<CraftingContainer> craftSlots, int& outDyeColor)
{
int slots = craftSlots->getContainerSize();
for (int p = 0; p < PATTERN_COUNT; p++)
{
const PatternInfo& pat = PATTERNS[p];
bool gridBased = (pat.rows[0] != nullptr);
if (gridBased)
{
if (slots != 9) continue;
int dyeColor = -1;
bool ok = true;
for (int k = 0; k < 9 && ok; k++)
{
int row = k / 3;
int col = k % 3;
shared_ptr<ItemInstance> item = craftSlots->getItem(k);
char cell = pat.rows[row][col];
if (item != nullptr && dynamic_cast<BannerItem*>(item->getItem()) == nullptr)
{
if (item->id != Item::dye_Id) { ok = false; break; }
if (cell == ' ') { ok = false; break; }
if (dyeColor != -1 && dyeColor != item->getAuxValue()) { ok = false; break; }
dyeColor = item->getAuxValue();
}
else
{
if (cell != ' ') { ok = false; break; }
}
}
if (ok && dyeColor != -1)
{
outDyeColor = dyeColor;
return pat.id;
}
}
else
{
// item-based pattern: needs a banner and one special item, classic crafting only
if (slots != 9) continue;
bool hasSpecial = false;
int dyeColor = -1;
bool ok = true;
for (int k = 0; k < slots && ok; k++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(k);
if (item == nullptr) continue;
if (dynamic_cast<BannerItem*>(item->getItem()) != nullptr) continue;
if (item->id == Item::dye_Id)
{
if (dyeColor != -1) { ok = false; break; }
dyeColor = item->getAuxValue();
}
else if (item->id == pat.specialItemId &&
(pat.specialItemAux == -1 || item->getAuxValue() == pat.specialItemAux))
{
if (hasSpecial) { ok = false; break; }
hasSpecial = true;
}
else
{
ok = false; break;
}
}
if (ok && hasSpecial)
{
outDyeColor = dyeColor;
return pat.id;
}
}
}
return nullptr;
}
bool BannerPatternRecipe::matches(shared_ptr<CraftingContainer> craftSlots, Level* level)
{
if (craftSlots->getContainerSize() != 9) return false;
shared_ptr<ItemInstance> banner = nullptr;
for (int i = 0; i < craftSlots->getContainerSize(); i++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(i);
if (item == nullptr) continue;
if (dynamic_cast<BannerItem*>(item->getItem()) != nullptr)
{
if (banner != nullptr) return false;
if (getBannerPatternCount(item) >= 6) return false;
banner = item;
}
}
if (banner == nullptr) return false;
int dyeColor = -1;
return matchPattern(craftSlots, dyeColor) != nullptr;
}
shared_ptr<ItemInstance> BannerPatternRecipe::assemble(shared_ptr<CraftingContainer> craftSlots)
{
if (craftSlots == nullptr)
return std::make_shared<ItemInstance>(Tile::standing_banner_Id, 1, 0);
shared_ptr<ItemInstance> banner = nullptr;
for (int i = 0; i < craftSlots->getContainerSize(); i++)
{
shared_ptr<ItemInstance> item = craftSlots->getItem(i);
if (item != nullptr && dynamic_cast<BannerItem*>(item->getItem()) != nullptr)
{
banner = item;
break;
}
}
if (banner == nullptr) return nullptr;
int dyeColor = -1;
const wchar_t* patternId = matchPattern(craftSlots, dyeColor);
if (patternId == nullptr) return nullptr;
shared_ptr<ItemInstance> result = banner->copy();
result->count = 1;
addBannerPattern(result, patternId, dyeColor);
return result;
}
int BannerPatternRecipe::size()
{
return 10;
}
const ItemInstance* BannerPatternRecipe::getResultItem()
{
return nullptr;
}
const int BannerPatternRecipe::getGroup()
{
return eGroupType_Max;
}
bool BannerPatternRecipe::reqs(int iRecipe)
{
return false;
}
void BannerPatternRecipe::reqs(INGREDIENTS_REQUIRED* pIngReq)
{
pIngReq->iIngC = 0;
pIngReq->iType = RECIPE_TYPE_3x3;
pIngReq->iIngIDA = new int[1]();
pIngReq->iIngValA = new int[1]();
pIngReq->iIngAuxValA = new int[1]();
pIngReq->uiGridA = new unsigned int[9]();
pIngReq->pRecipy = this;
for (unsigned int i = 0; i < XUSER_MAX_COUNT; ++i)
pIngReq->bCanMake[i] = false;
}
void BannerPatternRecipe::writeToStream(DataOutputStream* dos)
{
dos->writeByte(99);
}
void BannerPatternRecipe::addBannerPattern(shared_ptr<ItemInstance>& banner, const wchar_t* patternId, char dyeColor) {
if (banner == nullptr || patternId == nullptr) return;
if (getBannerPatternCount(banner) >= 6) return;
if (!banner->hasTag()) banner->setTag(new CompoundTag());
CompoundTag* tag = banner->getTag();
if (!tag->contains(L"BlockEntityTag", Tag::TAG_Compound))
tag->putCompound(L"BlockEntityTag", new CompoundTag());
CompoundTag* bet = tag->getCompound(L"BlockEntityTag");
ListTag<CompoundTag>* list;
if (bet->contains(L"Patterns"))
{
list = static_cast<ListTag<CompoundTag>*>(static_cast<void*>(bet->getList(L"Patterns")));
}
else
{
list = new ListTag<CompoundTag>();
bet->put(L"Patterns", list);
}
CompoundTag* entry = new CompoundTag();
entry->putString(L"Pattern", patternId);
entry->putInt(L"Color", dyeColor == -1 ? DyePowderItem::BLACK : dyeColor);
list->add(entry);
}
shared_ptr<ItemInstance> BannerPatternRecipe::createBannerWithPattern(const wchar_t* patternId, char dyeColor, char bannerColor) {
auto item = make_shared<ItemInstance>(Tile::standing_banner_Id, 1, bannerColor);
addBannerPattern(item, patternId, dyeColor);
return item;
}
int BannerPatternRecipe::getBannerPatternCount(shared_ptr<ItemInstance> banner)
{
if (!banner->hasTag()) return 0;
CompoundTag* tag = banner->getTag();
if (!tag->contains(L"BlockEntityTag", Tag::TAG_Compound)) return 0;
CompoundTag* bet = tag->getCompound(L"BlockEntityTag");
if (!bet->contains(L"Patterns")) return 0;
ListTag<Tag>* list = bet->getList(L"Patterns");
return list ? list->size() : 0;
}
vector<const wchar_t*> BannerPatternRecipe::getBannerPatternIds(shared_ptr<ItemInstance> banner) {
vector<const wchar_t*> returnVector;
CompoundTag* tag = banner != nullptr ? banner->getTag() : nullptr;
if (tag != nullptr && tag->contains(L"BlockEntityTag", Tag::TAG_Compound)) {
CompoundTag* bet = tag->getCompound(L"BlockEntityTag");
if (bet->contains(L"Patterns")) {
ListTag<CompoundTag>* list = static_cast<ListTag<CompoundTag>*>(static_cast<void*>(bet->getList(L"Patterns")));
for (int i = 0; list != nullptr && i < list->size(); i++) {
CompoundTag* entry = list->get(i);
if (entry == nullptr || !entry->contains(L"Pattern")) continue;
wstring id = entry->getString(L"Pattern");
for (int p = 0; p < PATTERN_COUNT; p++) {
if (id == PATTERNS[p].id) {
returnVector.push_back(PATTERNS[p].id);
break;
}
}
}
}
}
return returnVector;
}
vector<char> BannerPatternRecipe::getBannerPatternIndexs(shared_ptr<ItemInstance> banner) {
const auto& bannerPatternIds = getBannerPatternIds(banner);
vector<char> bannerPatternIndexs;
for (const wchar_t* id : bannerPatternIds) {
for (int i = 0; i < BannerPatternRecipe::PATTERN_COUNT; i++) {
if (wcscmp(BannerPatternRecipe::PATTERNS[i].id, id) == 0) {
bannerPatternIndexs.push_back(i);
}
}
}
return bannerPatternIndexs;
}
vector<char> BannerPatternRecipe::getBannerColorIndexs(shared_ptr<ItemInstance> banner) {
vector<char> returnVector;
CompoundTag* tag = banner != nullptr ? banner->getTag() : nullptr;
if (tag != nullptr && tag->contains(L"BlockEntityTag", Tag::TAG_Compound)) {
CompoundTag* bet = tag->getCompound(L"BlockEntityTag");
if (bet->contains(L"Patterns")) {
ListTag<CompoundTag>* list = static_cast<ListTag<CompoundTag>*>(static_cast<void*>(bet->getList(L"Patterns")));
for (int i = 0; list != nullptr && i < list->size(); i++) {
CompoundTag* entry = list->get(i);
if (entry == nullptr || !entry->contains(L"Pattern")) continue;
returnVector.push_back(static_cast<char>(entry->getInt(L"Color")));
}
}
}
return returnVector;
}
namespace
{
struct CraftRows { const wchar_t* id; const char* rows[3]; };
const CraftRows s_craftRows[] =
{
{ L"cr", { "# #", " # ", "#*#" } }, { L"ss", { "# #", "#*#", " " } }, { L"sc", { " # ", "###", "*# " } },
{ L"bs", { " ", " * ", "###" } }, { L"cs", { " # ", " #*", " # " } }, { L"dls", { " #", " #*", "# " } },
{ L"drs", { "# ", " #*", " #" } }, { L"ls", { "# ", "#* ", "# " } }, { L"ms", { " ", "###", " * " } },
{ L"rs", { " #", " *#", " #" } }, { L"ts", { "###", " * ", " " } }, { L"ld", { "## ", "#* ", " " } },
{ L"rud", { " ##", " *#", " " } }, { L"lud", { " ", "#* ", "## " } }, { L"rd", { " ", " *#", " ##" } },
{ L"hh", { "###", "###", " * " } }, { L"hhb", { " * ", "###", "###" } }, { L"vh", { "## ", "##*", "## " } },
{ L"vhr", { " ##", "*##", " ##" } }, { L"mc", { " ", " # ", " * " } }, { L"mr", { " # ", "#*#", " # " } },
{ L"bl", { " ", " * ", "# " } }, { L"br", { " ", " * ", " #" } }, { L"tl", { "# ", " * ", " " } },
{ L"tr", { " #", " * ", " " } }, { L"bt", { " * ", " # ", "# #" } }, { L"tt", { "# #", " # ", " * " } },
{ L"bts", { " ", "#*#", " # " } }, { L"tts", { " # ", "#*#", " " } }, { L"bo", { "###", "#*#", "###" } },
{ L"gra", { "#*#", " # ", " # " } }, { L"gru", { " # ", " # ", "#*#" } },
};
}
const char* BannerPatternRecipe::getCraftRow(int patternIndex, int row)
{
if (patternIndex < 0 || patternIndex >= PATTERN_COUNT || row < 0 || row > 2) return nullptr;
for (const CraftRows& entry : s_craftRows)
{
if (wcscmp(entry.id, PATTERNS[patternIndex].id) == 0) return entry.rows[row];
}
return nullptr;
}
int BannerPatternRecipe::getCraftDyeCount(int patternIndex)
{
if (patternIndex < 0 || patternIndex >= PATTERN_COUNT) return 0;
if (PATTERNS[patternIndex].specialItemId != 0) return 1;
int count = 0;
for (int row = 0; row < 3; row++)
{
const char* line = getCraftRow(patternIndex, row);
if (line == nullptr) return 0;
for (int col = 0; col < 3; col++) if (line[col] == '#') count++;
}
return count;
}