[FurnaceWidget] Visual indicator added.
This commit is contained in:
parent
a258fde36a
commit
dd49aff276
@ -42,6 +42,9 @@ class FurnaceWidget : public Widget {
|
||||
|
||||
BlockData &m_blockData;
|
||||
|
||||
Image m_burnImage{"texture-furnace"};
|
||||
Image m_progressImage{"texture-furnace"};
|
||||
|
||||
MouseItemWidget m_mouseItemWidget{this};
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,12 @@ FurnaceWidget::FurnaceWidget(Inventory &playerInventory, Inventory &hotbarInvent
|
||||
m_inputInventoryWidget.setPosition(55, 16, 0);
|
||||
m_outputInventoryWidget.setPosition(115, 34, 0);
|
||||
m_fuelInventoryWidget.setPosition(55, 52, 0);
|
||||
|
||||
m_burnImage.setClipRect(176, 0, 14, 14);
|
||||
m_burnImage.setPosition(57, 37, 0);
|
||||
|
||||
m_progressImage.setClipRect(176, 14, 24, 17);
|
||||
m_progressImage.setPosition(80, 35, 0);
|
||||
}
|
||||
|
||||
void FurnaceWidget::onEvent(const SDL_Event &event) {
|
||||
@ -42,6 +48,20 @@ void FurnaceWidget::onEvent(const SDL_Event &event) {
|
||||
}
|
||||
|
||||
void FurnaceWidget::update() {
|
||||
u16 ticksRemaining = m_blockData.data & 0xffff;
|
||||
u16 currentBurnTime = (m_blockData.data >> 16) & 0xffff;
|
||||
u16 itemProgress = (m_blockData.data >> 32) & 0xffff;
|
||||
|
||||
if (currentBurnTime) {
|
||||
m_burnImage.setPosition(57, 37 + 14 - ticksRemaining * 14 / currentBurnTime, 0);
|
||||
m_burnImage.setClipRect(176, 14 - ticksRemaining * 14 / currentBurnTime, 14, ticksRemaining * 14 / currentBurnTime);
|
||||
}
|
||||
else {
|
||||
m_burnImage.setClipRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
m_progressImage.setClipRect(176, 14, itemProgress * 24 / 200, 17);
|
||||
|
||||
m_inputInventoryWidget.init(m_blockData.inventory, 0, 1);
|
||||
m_outputInventoryWidget.init(m_blockData.inventory, 1, 1);
|
||||
m_fuelInventoryWidget.init(m_blockData.inventory, 2, 1);
|
||||
@ -69,6 +89,9 @@ void FurnaceWidget::draw(RenderTarget &target, RenderStates states) const {
|
||||
target.draw(m_outputInventoryWidget, states);
|
||||
target.draw(m_fuelInventoryWidget, states);
|
||||
|
||||
target.draw(m_burnImage, states);
|
||||
target.draw(m_progressImage, states);
|
||||
|
||||
target.draw(m_mouseItemWidget, states);
|
||||
}
|
||||
|
||||
|
@ -43,27 +43,30 @@ void BlockFurnace::onTick(const glm::ivec3 &blockPosition, Player &, Chunk &, Wo
|
||||
const ItemStack &fuelStack = data->inventory.getStack(2, 0);
|
||||
|
||||
u16 ticksRemaining = data->data & 0xffff;
|
||||
u16 itemProgress = (data->data >> 16) & 0xffff;
|
||||
|
||||
DEBUG((int)ticksRemaining, (int)itemProgress, fuelStack.amount());
|
||||
u16 currentBurnTime = (data->data >> 16) & 0xffff;
|
||||
u16 itemProgress = (data->data >> 32) & 0xffff;
|
||||
|
||||
if (ticksRemaining == 0 && fuelStack.amount() && inputStack.amount() && inputStack.item().id() == ItemType::IronOre) {
|
||||
data->inventory.setStack(2, 0, fuelStack.item().id(), fuelStack.amount() - 1);
|
||||
ticksRemaining = fuelStack.item().burnTime();
|
||||
currentBurnTime = fuelStack.item().burnTime();
|
||||
}
|
||||
else if (ticksRemaining > 0 && (!outputStack.amount() || !outputStack.item().id() || outputStack.item().id() == ItemType::IronIngot)) { // FIXME
|
||||
--ticksRemaining;
|
||||
++itemProgress;
|
||||
}
|
||||
else if (ticksRemaining == 0) {
|
||||
currentBurnTime = 0;
|
||||
}
|
||||
|
||||
if (itemProgress > 200) {
|
||||
if (itemProgress >= 200) {
|
||||
itemProgress = 0;
|
||||
if (inputStack.item().id() == ItemType::IronOre && inputStack.amount()) {
|
||||
data->inventory.setStack(0, 0, inputStack.item().id(), inputStack.amount() - 1);
|
||||
data->inventory.setStack(1, 0, ItemType::IronIngot);
|
||||
data->inventory.setStack(1, 0, ItemType::IronIngot, outputStack.amount() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
data->data = ticksRemaining | (itemProgress << 16);
|
||||
data->data = ticksRemaining | (currentBurnTime << 16) | ((u32)itemProgress << 32);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user