* Allow overwriting of frame data from the patch data file.

This commit is contained in:
iProgramInCpp
2023-08-10 12:32:40 +03:00
parent 0412fd1bc5
commit b1c2bf946c
6 changed files with 113 additions and 4 deletions

1
.gitignore vendored
View File

@@ -403,6 +403,7 @@ FodyWeavers.xsd
# Avoid including Minecraft Classic assets from Mojang, for now.
/game/assets/patches/*.png
/game/assets/patches/classic/*.png
# Ignore keep directory - where you can keep files for later use
/keep

View File

@@ -2,6 +2,7 @@
# Commands you can use:
# - terrain|x|y|filename -- Patches terrain.png
# - items|x|y|filename -- Patches gui/items.png
# - frame|itemid|x|y -- Sets the base texture frame of the tile or itemID.
# - vegetation_tint|bool -- Enables default vegetation tint. (grass and leaves)
# - metal_block_sides|int -- Makes metal blocks have separate side textures, and allows specification of their Y offset. -1 to disable.
@@ -26,3 +27,5 @@
#items|7|3|c_i_emerald.png
#vegetation_tint|false
#metal_block_sides|10
#frame|blockGold|5|5

View File

@@ -695,6 +695,8 @@ void Minecraft::init()
GetPatchManager()->PatchTextures(platform(), TYPE_TERRAIN);
m_pTextures->loadAndBindTexture(C_ITEMS_NAME);
GetPatchManager()->PatchTextures(platform(), TYPE_ITEMS);
GetPatchManager()->PatchTiles();
}
Minecraft::~Minecraft()

View File

@@ -1,6 +1,8 @@
#include "PatchManager.hpp"
#include "AppPlatform.hpp"
#include "client/common/Utils.hpp"
#include "world/tile/Tile.hpp"
#include "world/item/Item.hpp"
#include "compat/GL.hpp"
#define PM_SEPARATOR ('|')
@@ -55,6 +57,67 @@ void PatchManager::LoadPatchData(const std::string& patchData)
continue;
}
if (command == "frame")
{
std::string xStr, yStr, itemName;
if (!std::getline(lineStream, itemName, PM_SEPARATOR)) continue;
if (!std::getline(lineStream, xStr, PM_SEPARATOR)) continue;
if (!std::getline(lineStream, yStr, PM_SEPARATOR)) continue;
int itemID = -1, x = 0, y = 0;
if (!sscanf(xStr.c_str(), "%d", &x)) continue;
if (!sscanf(yStr.c_str(), "%d", &y)) continue;
// try to parse the item name as an int first
if (sscanf(itemName.c_str(), "%d", &itemID))
{
if (itemID < 0 || itemID >= C_MAX_ITEMS)
goto namefailure;
if (itemID < C_MAX_TILES && !Tile::tiles[itemID])
goto namefailure;
if (itemID >= C_MAX_TILES && !Item::items[itemID])
goto namefailure;
}
else
{
std::string tileDesc = "tile." + itemName;
std::string itemDesc = "item." + itemName;
// look through the entirety of the Tiles and Items array
for (int i = 0; i < C_MAX_TILES && itemID == -1; i++)
{
if (!Tile::tiles[i])
continue;
if (Tile::tiles[i]->m_descriptionID != tileDesc)
continue;
itemID = i;
}
for (int i = 0; i < C_MAX_ITEMS && itemID == -1; i++)
{
if (!Item::items[i])
continue;
if (Item::items[i]->m_DescriptionID != itemDesc)
continue;
itemID = i;
}
}
if (itemID == -1)
{
namefailure:
LogMsg("Unknown item/tile with the name %s", itemName.c_str());
continue;
}
m_patchData.push_back(PatchData(TYPE_FRAME, itemID, 16 * y + x));
continue;
}
// features -- TODO un-hardcode this
if (command == "vegetation_tint")
{
@@ -105,6 +168,30 @@ void PatchManager::PatchTextures(AppPlatform* pAppPlatform, ePatchType patchType
}
}
void PatchManager::PatchTiles()
{
for (int i = 0; i < int(m_patchData.size()); i++)
{
PatchData& pd = m_patchData[i];
if (pd.m_type != TYPE_FRAME)
continue;
if (pd.m_destID < C_MAX_TILES && Tile::tiles[pd.m_destID])
{
Tile::tiles[pd.m_destID]->m_TextureFrame = pd.m_frameNo;
continue;
}
if (Item::items[pd.m_destID])
{
Item::items[pd.m_destID]->m_icon = pd.m_frameNo;
continue;
}
LogMsg("PatchTiles: unknown item ID %d", pd.m_destID);
}
}
bool PatchManager::IsGrassTinted()
{
return m_bGrassTinted;

View File

@@ -11,6 +11,7 @@ enum ePatchType
TYPE_NONE,
TYPE_TERRAIN,
TYPE_ITEMS,
TYPE_FRAME,
TYPE_FEATURE,
};
@@ -25,9 +26,18 @@ struct PatchData
ePatchType m_type;
ePatchOption m_option;
int m_destX, m_destY;
int m_destID, m_frameNo;
std::string m_filename;
bool m_bEnable;
PatchData(ePatchType type, int id, int frameNo)
{
_init();
m_type = type;
m_destID = id;
m_frameNo = frameNo;
}
PatchData(ePatchType type, int x, int y, const std::string& fn)
{
_init();
@@ -50,6 +60,8 @@ struct PatchData
m_type = TYPE_NONE;
m_option = PO_NONE;
m_destX = m_destY = 0;
m_destID = 0;
m_frameNo = -1;
m_bEnable = false;
}
};
@@ -62,6 +74,7 @@ public:
void LoadPatchData(const std::string& patchData);
void PatchTextures(AppPlatform*, ePatchType);
void PatchTiles();
// Features
bool IsGrassTinted();

View File

@@ -8,6 +8,7 @@
#include "TileRenderer.hpp"
#include "Minecraft.hpp"
#include "client/renderer/PatchManager.hpp"
void TileRenderer::_init()
{
@@ -2335,10 +2336,12 @@ LABEL_102:
#define SHADE_PREPARE do { \
red = bright, grn = bright, blu = bright; \
if (tile->m_ID == Tile::leaves->m_ID) \
red *= 0.35f, grn *= 0.65f, blu *= 0.25f; \
if (!SHADE_IS_DECOLOR_GRASS_DEFINED && tile->m_ID == Tile::grass->m_ID) \
red *= 0.25f, grn *= 0.60f, blu *= 0.25f; \
if (GetPatchManager()->IsGrassTinted()) { \
if (tile->m_ID == Tile::leaves->m_ID) \
red *= 0.35f, grn *= 0.65f, blu *= 0.25f; \
if (tile->m_ID == Tile::grass->m_ID) \
red *= 0.25f, grn *= 0.60f, blu *= 0.25f; \
} \
} while (0)
#define SHADE_IF_NEEDED(col) t.color(col*red,col*grn,col*blu,1.0f)