Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions game/assets/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@
!/patches/p_info_updategame1.png
!/patches/p_info_updategame2.png
!/patches/p_slot_more.png
/resource_packs/
10 changes: 10 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,16 @@ add_library(nbcraft-core STATIC
renderer/hal/interface/ShaderConstantWithData.cpp
renderer/hal/interface/ShaderProgram.cpp
renderer/hal/interface/Texture.cpp
world/tile/FurnaceTile.cpp
world/tile/FurnaceTile.hpp
client/gui/screens/inventory/FurnaceScreen.cpp
client/gui/screens/inventory/FurnaceScreen.hpp
world/inventory/FurnaceMenu.cpp
world/inventory/FurnaceMenu.h
world/inventory/FurnaceTileEntity.cpp
world/inventory/FurnaceTileEntity.h
world/level/tileentity/TileEntity.cpp
world/level/tileentity/TileEntity.h
)
target_include_directories(nbcraft-core PUBLIC . ..)

Expand Down
73 changes: 73 additions & 0 deletions source/client/gui/screens/inventory/FurnaceScreen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "FurnaceScreen.hpp"
#include "world/inventory/FurnaceMenu.h"
#include "client/app/Minecraft.hpp"

FurnaceScreen::FurnaceScreen(Inventory* inventory, FurnaceTileEntity* furnace)
: ContainerScreen(new FurnaceMenu(inventory, furnace)), m_pFurnace(furnace)
{
}

void FurnaceScreen::_renderLabels() {
// Draw text using the built-in font renderer (Text, X, Y, Hex Color)
m_pFont->draw("Furnace", 64 , 6, 0x404040);
}

void FurnaceScreen::_renderBg(float partialTick) {
// 1. Bind the texture file (using the exact pointer your compiler suggested)
m_pMinecraft->m_pTextures->loadAndBindTexture("gui/furnace.png");

// 2. Define the exact pixel size of the texture locally
int xSize = 176;
int ySize = 166;

// 3. Center the UI on the screen
int x = (m_width - xSize) / 2;
int y = (m_height - ySize) / 2;

// 4. Draw the main background
// Notice how we pass xSize and ySize twice (Destination Width/Height, then Source Width/Height)
blit(x, y, 0, 0, xSize, ySize, xSize, ySize);

// 5. Draw the animated Fire (Fuel)
if (m_pFurnace->isBurning()) {
int fireHeight = 12; // Maximum height of the fire icon
if (m_pFurnace->currentItemBurnTime > 0) {
// Scale the fire down as the fuel burns away
fireHeight = (m_pFurnace->furnaceBurnTime * 12) / m_pFurnace->currentItemBurnTime;
}

// Draw the fire! (Again, we duplicate the width '14' and height 'fireHeight + 2')
blit(x + 56, y + 36 + 12 - fireHeight, 176, 12 - fireHeight, 14, fireHeight + 2, 14, fireHeight + 2);
}

// 6. Draw the animated Progress Arrow (Cook Time)
// The arrow is 24 pixels wide, and a full smelt takes 200 ticks
int arrowWidth = (m_pFurnace->furnaceCookTime * 24) / 200;

// Draw the arrow! (Duplicating the width 'arrowWidth' and height '16')
blit(x + 79, y + 34, 176, 14, arrowWidth, 16, arrowWidth, 16);
}

SlotDisplay FurnaceScreen::_createSlotDisplay(const Slot& slot) {

if (slot.m_pContainer == m_pFurnace) {
const int id = slot.m_slot; // Slot 0, 1, or 2
if (id == 0) return SlotDisplay(56, 17); // Top Input Slot
if (id == 1) return SlotDisplay(56, 53); // Bottom Fuel Slot
if (id == 2) return SlotDisplay(116, 35); // Right Output Slot
}
// Otherwise, it belongs to the Player's Inventory
else {
const int id = slot.m_slot;
if (id < 9) {
// The Hotbar (Bottom row)
return SlotDisplay(8 + id * 18, 142);
} else {
// The Main Backpack (3 rows of 9)
int gridX = (id - 9) % 9;
int gridY = (id - 9) / 9;
return SlotDisplay(8 + gridX * 18, 84 + gridY * 18);
}
}
return SlotDisplay(0, 0); // Safety fallback
}
24 changes: 24 additions & 0 deletions source/client/gui/screens/inventory/FurnaceScreen.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef NBCRAFT_FURNACESCREEN_H
#define NBCRAFT_FURNACESCREEN_H

#include "ContainerScreen.hpp"
#include "world/inventory/FurnaceTileEntity.h"

class FurnaceScreen : public ContainerScreen {
private:
FurnaceTileEntity* m_pFurnace;

public:
FurnaceScreen(Inventory* inventory, FurnaceTileEntity* furnace);

// Fixed the C++11 warning here!
~FurnaceScreen() override {}

protected:
// These are the exact 3 pure virtual methods NBCraft demands!
void _renderLabels() override;
void _renderBg(float partialTick) override;
SlotDisplay _createSlotDisplay(const Slot& slot) override;
};

#endif // NBCRAFT_FURNACESCREEN_H
6 changes: 4 additions & 2 deletions source/client/player/LocalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "network/packets/PlayerEquipmentPacket.hpp"
#include "client/gui/screens/inventory/CraftingScreen.hpp"
#include "client/gui/screens/inventory/ChestScreen.hpp"
#include "client/gui/screens/inventory/FurnaceScreen.hpp"
#include "world/inventory/FurnaceTileEntity.h"

int dword_250ADC, dword_250AE0;

Expand Down Expand Up @@ -134,11 +136,11 @@ void LocalPlayer::startCrafting(const TilePos& pos)
m_pMinecraft->getScreenChooser()->pushCraftingScreen(this, pos);
}

/*void LocalPlayer::openFurnace(FurnaceTileEntity* furnace)
void LocalPlayer::openFurnace(FurnaceTileEntity* furnace)
{
// PE 0.3.2 doesn't let you cook in creative mode
m_pMinecraft->setScreen(new FurnaceScreen(m_pInventory, furnace));
}*/
}

void LocalPlayer::openContainer(Container* container)
{
Expand Down
3 changes: 3 additions & 0 deletions source/client/player/LocalPlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "world/entity/Player.hpp"
#include "client/player/input/IMoveInput.hpp"
#include "client/player/input/User.hpp"
#include "world/inventory/FurnaceTileEntity.h"

class Minecraft;

Expand Down Expand Up @@ -39,6 +40,8 @@ class LocalPlayer : public Player
void setPlayerGameType(GameType gameType) override;
void swing() override;
void startCrafting(const TilePos&) override;
void openFurnace(FurnaceTileEntity *furnace);

//void openFurnace(FurnaceTileEntity* furnace) override;
void openContainer(Container* container) override;
void closeContainer() override;
Expand Down
11 changes: 9 additions & 2 deletions source/world/entity/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,16 @@ void Player::drop(const ItemStack& item, bool randomly)
reallyDrop(pItemEntity);
}

void Player::startCrafting(const TilePos& pos)
{
void Player::startCrafting(const TilePos& pos) {
}

void Player::openFurnace(const TilePos& pos)
{
TileEntity* te = m_pLevel->getTileEntity(pos.x, pos.y, pos.z);
if (te != nullptr)
{
this->openFurnace(static_cast<FurnaceTileEntity*>(te));
}
}

void Player::startStonecutting(const TilePos& pos)
Expand Down
7 changes: 7 additions & 0 deletions source/world/entity/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "world/entity/Mob.hpp"
#include "world/entity/ItemEntity.hpp"
#include "world/gamemode/GameType.hpp"
#include "world/inventory/FurnaceTileEntity.h"
#include "world/inventory/InventoryMenu.hpp"

#define C_PLAYER_FLAG_USING_ITEM (4)
Expand Down Expand Up @@ -69,6 +70,12 @@ class Player : public Mob
//virtual void drop(); // see definition
virtual void drop(const ItemStack& item, bool randomly = false);
virtual void startCrafting(const TilePos& pos);

void openFurnace(const TilePos &pos);
virtual void openFurnace(FurnaceTileEntity* furnace) {}

void startSmelting(const TilePos &pos);

virtual void startStonecutting(const TilePos& pos);
virtual void startDestroying();
virtual void stopDestroying();
Expand Down
40 changes: 40 additions & 0 deletions source/world/inventory/FurnaceMenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "FurnaceMenu.h"

#include "FurnaceTileEntity.h"
#include "world/inventory/ResultSlot.hpp"
#include "world/inventory/Slot.hpp"


FurnaceMenu::FurnaceMenu(Inventory* inventory, FurnaceTileEntity* furnace)
: ContainerMenu(Container::FURNACE)
, m_pFurnace(furnace)
{
// Slot 0: Input (Top slot of the furnace)
// Slot 1: Fuel (Bottom slot of the furnace)
// Slot 2: Output/Result (Right slot of the furnace)

// Note: The actual coordinates (x, y) for drawing the slots will be handled by FurnaceScreen later.
// For now, we just register them in order.

addSlot(new Slot(m_pFurnace, 0, Slot::INPUT)); // Input
addSlot(new Slot(m_pFurnace, 1, Slot::INPUT)); // Fuel
addSlot(new ResultSlot(inventory->m_pPlayer, nullptr, m_pFurnace, 2)); // Result

// Add the 27 slots for the player's main inventory
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 9; ++x) {
addSlot(new Slot(inventory, x + y * 9 + 9, Slot::INVENTORY));
}
}

// Add the 9 slots for the player's hotbar
for (int i = 0; i < 9; ++i) {
addSlot(new Slot(inventory, i, Slot::HOTBAR));
}
}

bool FurnaceMenu::stillValid(Player* player) const
{
// The FurnaceTileEntity will tell us if it's still valid (e.g., if the block was destroyed)
return m_pFurnace->stillValid(player);
}
25 changes: 25 additions & 0 deletions source/world/inventory/FurnaceMenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef NBCRAFT_FURNACEMENU_H
#define NBCRAFT_FURNACEMENU_H

#include "world/inventory/ContainerMenu.hpp"
#include "world/item/Inventory.hpp"

// Forward declaration so the compiler knows this class exists
class FurnaceTileEntity;

class FurnaceMenu : public ContainerMenu {
public:
FurnaceMenu(Inventory* inventory, FurnaceTileEntity* furnace);
~FurnaceMenu() override = default;

bool stillValid(Player* player) const override;
// slotsChanged is NOT needed for a furnace! The TileEntity handles smelting.

// quickMoveStack is complex, we can leave it empty for now to prevent crashes
ItemStack quickMoveStack(int index) override { return ItemStack::EMPTY; }

private:
FurnaceTileEntity *m_pFurnace;
};

#endif //NBCRAFT_FURNACEMENU_H
Loading