* Improve the inventory. Prepare for survival mode inventory.

This commit is contained in:
iProgramInCpp
2023-08-04 09:54:39 +03:00
parent 7c83a4d6aa
commit aa027ec549
12 changed files with 290 additions and 309 deletions

View File

@@ -15,6 +15,9 @@ Player::Player(Level* pLevel) : Mob(pLevel)
m_pInventory = new Inventory(this);
// @TODO: GameMode::prepareInventory
m_pInventory->prepareCreativeInventory();
field_84 = 1.62f;
Pos pos = m_pLevel->getSharedSpawnPos();

View File

@@ -14,10 +14,16 @@ void ItemInstance::init(int itemID, int amount, int auxValue)
{
m_itemID = itemID;
m_amount = amount;
m_auxValue = auxValue;
//@BUG? Not using the auxValue. This is problematic in the case of wool and dyes.
}
ItemInstance::ItemInstance()
{
init(0, 0, 0);
}
ItemInstance::ItemInstance(Item* pItem)
{
init(pItem->m_itemID, 1, 0);

View File

@@ -20,6 +20,7 @@ class Player;
class ItemInstance
{
public:
ItemInstance();
ItemInstance(Item*);
ItemInstance(Item*, int amount);
ItemInstance(Item*, int amount, int auxValue);

View File

@@ -70,8 +70,9 @@ void PlayerData::loadPlayer(Player* player)
// @NOTE: Why are we updating m_pos, field_3C and field_98 above if we do this?
player->setPos(m_pos.x, m_pos.y, m_pos.z);
// TODO: survival mode stuff
for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
player->m_pInventory->setSelectionSlotItemId(i, m_hotbar[i]);
player->m_pInventory->setQuickSlotIndexByItemId(i, m_hotbar[i]);
}
void PlayerData::savePlayer(Player* player)
@@ -85,6 +86,7 @@ void PlayerData::savePlayer(Player* player)
field_26 = player->field_BC;
field_28 = player->field_7C;
// TODO: survival mode stuff
for (int i = 0; i < C_MAX_HOTBAR_ITEMS; i++)
m_hotbar[i] = player->m_pInventory->getSelectionSlotItemId(i);
m_hotbar[i] = player->m_pInventory->getQuickSlotItemId(i);
}

View File

@@ -165,87 +165,86 @@ void ItemRenderer::renderGuiItem(Font* font, Textures* textures, ItemInstance* i
return;
int itemID = instance->m_itemID;
if (b)
{
// @BUG: This is one of the reasons you can't actually hold items in early Minecraft.
// There's an attempt to index `Tile::tiles` out of bounds, which of course fails, and likely crashes the game. :(
// If only they'd placed the g_ItemFrames[itemID] check before the TileRenderer::canRender check...
if (!b)
return;
// @BUG: This is one of the reasons you can't actually hold items in early Minecraft.
// There's an attempt to index `Tile::tiles` out of bounds, which of course fails, and likely crashes the game. :(
// If only they'd placed the g_ItemFrames[itemID] check before the TileRenderer::canRender check...
#ifdef ORIGINAL_CODE
#define COND_PRE
#else
#define COND_PRE (0 <= itemID && itemID < C_MAX_TILES) &&
#endif
bool bCanRenderAsIs = false;
bool bCanRenderAsIs = false;
#ifdef ENH_3D_INVENTORY_TILES
// We don't need to care about g_ItemFrames at all since blocks will get 3D rendered and 2D props will use the terrain.png as the texture.
if (COND_PRE(TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape())))
{
bCanRenderAsIs = true;
}
// We don't need to care about g_ItemFrames at all since blocks will get 3D rendered and 2D props will use the terrain.png as the texture.
if (COND_PRE(TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape())))
{
bCanRenderAsIs = true;
}
#else
if (COND_PRE(TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape()) || g_ItemFrames[itemID] != 0))
{
bCanRenderAsIs = true;
}
if (COND_PRE(TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape()) || g_ItemFrames[itemID] != 0))
{
bCanRenderAsIs = true;
}
#endif
if (itemID < C_MAX_TILES && bCanRenderAsIs)
{
if (itemID < C_MAX_TILES && bCanRenderAsIs)
{
#ifndef ENH_3D_INVENTORY_TILES
textures->loadAndBindTexture(C_BLOCKS_NAME);
textures->loadAndBindTexture(C_BLOCKS_NAME);
float texU = float(g_ItemFrames[instance->m_itemID] % 10) * 48.0f;
float texV = float(g_ItemFrames[instance->m_itemID] / 10) * 48.0f;
float texU = float(g_ItemFrames[instance->m_itemID] % 10) * 48.0f;
float texV = float(g_ItemFrames[instance->m_itemID] / 10) * 48.0f;
Tesselator& t = Tesselator::instance;
// @NOTE: These do nothing, due to a previous t.voidBeginAndEndCalls call.
t.begin();
t.vertexUV(float(x + 0), float(y + 16), 0.0f, texU / 512.0f, (texV + 48.0f) / 512.0f);
t.vertexUV(float(x + 16), float(y + 16), 0.0f, (texU + 48.0f) / 512.0f, (texV + 48.0f) / 512.0f);
t.vertexUV(float(x + 16), float(y + 0), 0.0f, (texU + 48.0f) / 512.0f, texV / 512.0f);
t.vertexUV(float(x + 0), float(y + 0), 0.0f, texU / 512.0f, texV / 512.0f);
t.draw();
Tesselator& t = Tesselator::instance;
// @NOTE: These do nothing, due to a previous t.voidBeginAndEndCalls call.
t.begin();
t.vertexUV(float(x + 0), float(y + 16), 0.0f, texU / 512.0f, (texV + 48.0f) / 512.0f);
t.vertexUV(float(x + 16), float(y + 16), 0.0f, (texU + 48.0f) / 512.0f, (texV + 48.0f) / 512.0f);
t.vertexUV(float(x + 16), float(y + 0), 0.0f, (texU + 48.0f) / 512.0f, texV / 512.0f);
t.vertexUV(float(x + 0), float(y + 0), 0.0f, texU / 512.0f, texV / 512.0f);
t.draw();
#else
textures->loadAndBindTexture(C_TERRAIN_NAME);
textures->loadAndBindTexture(C_TERRAIN_NAME);
//glDisable(GL_BLEND);
//glEnable(GL_DEPTH_TEST);
//glDisable(GL_BLEND);
//glEnable(GL_DEPTH_TEST);
glPushMatrix();
glPushMatrix();
// scale, rotate, and translate the tile onto the correct screen coordinate
glTranslatef((GLfloat)x + 8, (GLfloat)y + 8, -8);
glScalef(10, 10, 10);
glRotatef(210.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
// scale, rotate, and translate the tile onto the correct screen coordinate
glTranslatef((GLfloat)x + 8, (GLfloat)y + 8, -8);
glScalef(10, 10, 10);
glRotatef(210.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
#ifdef ENH_SHADE_HELD_TILES
# define PARM_HACK , 1
#else
# define PARM_HACK
#endif
tileRenderer->renderTile(Tile::tiles[itemID], instance->m_auxValue PARM_HACK);
#undef PARM_HACK
#ifdef ENH_SHADE_HELD_TILES
# define PARM_HACK , 1
#else
# define PARM_HACK
#endif
tileRenderer->renderTile(Tile::tiles[itemID], instance->m_auxValue PARM_HACK);
#undef PARM_HACK
glPopMatrix();
glPopMatrix();
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
#endif
}
else if (instance->getIcon() >= 0)
{
// @BUG: The last bound texture will be the texture that ALL items will take. This is because begin and end calls
// have been void'ed by a t.voidBeginAndEndCalls call in Gui::render.
if (instance->m_itemID <= 255)
textures->loadAndBindTexture(C_TERRAIN_NAME);
else
textures->loadAndBindTexture(C_ITEMS_NAME);
}
else if (instance->getIcon() >= 0)
{
// @BUG: The last bound texture will be the texture that ALL items will take. This is because begin and end calls
// have been void'ed by a t.voidBeginAndEndCalls call in Gui::render.
if (instance->m_itemID <= 255)
textures->loadAndBindTexture(C_TERRAIN_NAME);
else
textures->loadAndBindTexture(C_ITEMS_NAME);
blit(x, y, 16 * (instance->getIcon() % 16), 16 * (instance->getIcon() / 16), 16, 16);
}
blit(x, y, 16 * (instance->getIcon() % 16), 16 * (instance->getIcon() / 16), 16, 16);
}
}