summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorLukas Pioch <lukas@zgow.de>2017-05-05 11:58:21 +0200
committerLukas Pioch <lukas@zgow.de>2017-05-08 06:30:54 +0200
commit41bfb22834f0cd13166914b35d4616f21f3c99df (patch)
treeedb3ed8e3ef8b0258d4522a2f3202cc9aa09521d /src/BlockEntities
parentAdjusted RipeMeta for off by one error (#3691) (diff)
downloadcuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.tar
cuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.tar.gz
cuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.tar.bz2
cuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.tar.lz
cuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.tar.xz
cuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.tar.zst
cuberite-41bfb22834f0cd13166914b35d4616f21f3c99df.zip
Diffstat (limited to 'src/BlockEntities')
-rw-r--r--src/BlockEntities/BrewingstandEntity.cpp63
-rw-r--r--src/BlockEntities/BrewingstandEntity.h22
2 files changed, 66 insertions, 19 deletions
diff --git a/src/BlockEntities/BrewingstandEntity.cpp b/src/BlockEntities/BrewingstandEntity.cpp
index f202ab419..e357dbf98 100644
--- a/src/BlockEntities/BrewingstandEntity.cpp
+++ b/src/BlockEntities/BrewingstandEntity.cpp
@@ -24,7 +24,8 @@ cBrewingstandEntity::cBrewingstandEntity(int a_BlockX, int a_BlockY, int a_Block
m_BlockMeta(a_BlockMeta),
m_IsDestroyed(false),
m_IsBrewing(false),
- m_TimeBrewed(0)
+ m_TimeBrewed(0),
+ m_RemainingFuel(0)
{
m_Contents.AddListener(*this);
for (int i = 0; i < 3; i++)
@@ -76,6 +77,7 @@ bool cBrewingstandEntity::UsedBy(cPlayer * a_Player)
{
BroadcastProgress(0, 0);
}
+ BroadcastProgress(1, m_RemainingFuel);
return true;
}
@@ -95,12 +97,11 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// The necessary brewing time, has been reached
if (m_TimeBrewed >= m_NeedBrewingTime)
{
- const cBrewingRecipes::cRecipe * Recipe = nullptr;
BroadcastProgress(0, 0);
m_IsBrewing = false;
m_TimeBrewed = 0;
- // Return if the hook has been canceled
+ // Return if the hook has been cancelled
if (cPluginManager::Get()->CallHookBrewingCompleting(*m_World, *this))
{
return false;
@@ -111,7 +112,27 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
Ingredient.m_ItemCount -= 1;
m_Contents.SetSlot(bsIngredient, Ingredient);
+ // Fuel slot
+ m_RemainingFuel--;
+ if (m_RemainingFuel <= 0)
+ {
+ if (!m_Contents.GetSlot(bsFuel).IsEmpty())
+ {
+ cItem Fuel = m_Contents.GetSlot(bsFuel);
+ Fuel.m_ItemCount -= 1;
+ m_Contents.SetSlot(bsFuel, Fuel);
+ m_RemainingFuel = 20;
+ BroadcastProgress(1, m_RemainingFuel);
+ }
+ }
+ else
+ {
+ BroadcastProgress(1, m_RemainingFuel);
+ }
+
+
// Loop over all bottle slots and update available bottles
+ const cBrewingRecipes::cRecipe * Recipe = nullptr;
for (int i = 0; i < 3; i++)
{
if (m_Contents.GetSlot(i).IsEmpty() || (m_CurrentBrewingRecipes[i] == nullptr))
@@ -125,7 +146,6 @@ bool cBrewingstandEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Brewing process completed
cPluginManager::Get()->CallHookBrewingCompleted(*m_World, *this);
-
return true;
}
@@ -174,6 +194,26 @@ void cBrewingstandEntity::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
ASSERT(a_ItemGrid == &m_Contents);
+ // Check for fuel
+ if (m_RemainingFuel <= 0)
+ {
+ if (GetSlot(bsFuel).IsEmpty())
+ {
+ // No remaining fuel stop brewing and bail out
+ m_IsBrewing = false;
+ return;
+ }
+ else
+ {
+ // Fuel is available, refill
+ m_RemainingFuel = 20;
+ BroadcastProgress(1, m_RemainingFuel);
+ cItem Fuel = m_Contents.GetSlot(bsFuel);
+ Fuel.m_ItemCount -= 1;
+ m_Contents.SetSlot(bsFuel, Fuel);
+ }
+ }
+
// Check if still a item is in the ingredient slot
if (GetSlot(bsIngredient).IsEmpty())
{
@@ -258,19 +298,10 @@ void cBrewingstandEntity::UpdateProgressBars(bool a_ForceUpdate)
-void cBrewingstandEntity::setTimeBrewed(short a_TimeBrewed)
-{
- m_TimeBrewed = a_TimeBrewed;
-}
-
-
-
-
-
void cBrewingstandEntity::ContinueBrewing(void)
{
// Continue brewing if number is greater than 0
- if (m_TimeBrewed > 0)
+ if ((m_TimeBrewed > 0) && (m_RemainingFuel > 0))
{
m_IsBrewing = true;
}
@@ -280,9 +311,9 @@ void cBrewingstandEntity::ContinueBrewing(void)
-void cBrewingstandEntity::GetRecipes(void)
+void cBrewingstandEntity::LoadRecipes(void)
{
- if (GetSlot(3).IsEmpty())
+ if (GetSlot(bsIngredient).IsEmpty())
{
return;
}
diff --git a/src/BlockEntities/BrewingstandEntity.h b/src/BlockEntities/BrewingstandEntity.h
index 89f836e71..efdf72daf 100644
--- a/src/BlockEntities/BrewingstandEntity.h
+++ b/src/BlockEntities/BrewingstandEntity.h
@@ -27,8 +27,9 @@ public:
bsMiddleBottle = 1, // Middle bottle slot number
bsRightBottle = 2, // Right bottle slot number
bsIngredient = 3, // Top ingredient slot number
+ bsFuel = 4, // Top left fuel slot number
- ContentsWidth = 4,
+ ContentsWidth = 5,
ContentsHeight = 1,
};
@@ -59,6 +60,9 @@ public:
/** Returns the time that the current items has been brewing, in ticks */
short GetTimeBrewed(void) { return m_TimeBrewed; }
+ /** Returns the remaining fuel that is left. */
+ short GetRemainingFuel(void) { return m_RemainingFuel; }
+
/** Returns the item in the left bottle slot */
const cItem & GetLeftBottleSlot(void) const { return GetSlot(bsLeftBottle); }
@@ -71,6 +75,9 @@ public:
/** Returns the item in the ingredient slot */
const cItem & GetIndgredientSlot(void) const { return GetSlot(bsIngredient); }
+ /** Returns the item in the fuel slot. */
+ const cItem & GetFuelSlot(void) const { return GetSlot(bsFuel); }
+
/** Get the expected result item for the given slot number */
const cItem & GetResultItem(int a_SlotNumber) { return m_Results[a_SlotNumber]; }
@@ -86,16 +93,22 @@ public:
/** Sets the item in the ingredient slot */
void SetIngredientSlot(const cItem & a_Item) { SetSlot(bsIngredient, a_Item); }
+ /** Sets the item in the fuel slot */
+ void SetFuelSlot(const cItem & a_Item) { SetSlot(bsFuel, a_Item); }
+
// tolua_end
/** Sets the current brewing time. Will be called if the brewing stand gets loaded from the world. */
- void setTimeBrewed(short a_TimeBrewed);
+ void SetTimeBrewed(short a_TimeBrewed) { m_TimeBrewed = a_TimeBrewed; }
+
+ /** Sets the remaining fuel. Will be called if the brewing stand gets loaded from the world. */
+ void SetRemainingFuel(short a_RemainingFuel) { m_RemainingFuel = a_RemainingFuel; }
/** Starts the brewing proccess. Will be called if the brewing stand gets loaded from the world. */
void ContinueBrewing(void);
/** Gets the recipes. Will be called if the brewing stand gets loaded from the world. */
- void GetRecipes(void);
+ void LoadRecipes(void);
protected:
/** Block meta of the block currently represented by this entity */
@@ -119,6 +132,9 @@ protected:
/** Amount of ticks that the current item has been brewed */
short m_TimeBrewed;
+ /** The remaining fuel for the brewing stand. It's the amount of brewing operations that can be done. */
+ short m_RemainingFuel;
+
/** Sends the specified progressbar value to all clients of the window */
void BroadcastProgress(short a_ProgressbarID, short a_Value);