summaryrefslogtreecommitdiffstats
path: root/source/BlockEntities
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-20 13:41:44 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-20 13:41:44 +0200
commit8dd5fe507083dd390742d782325ef3754f32fd59 (patch)
tree1918df5fedd7f3ec21a72dcc85d1e898fb18801e /source/BlockEntities
parentImplemented hopper output (diff)
downloadcuberite-8dd5fe507083dd390742d782325ef3754f32fd59.tar
cuberite-8dd5fe507083dd390742d782325ef3754f32fd59.tar.gz
cuberite-8dd5fe507083dd390742d782325ef3754f32fd59.tar.bz2
cuberite-8dd5fe507083dd390742d782325ef3754f32fd59.tar.lz
cuberite-8dd5fe507083dd390742d782325ef3754f32fd59.tar.xz
cuberite-8dd5fe507083dd390742d782325ef3754f32fd59.tar.zst
cuberite-8dd5fe507083dd390742d782325ef3754f32fd59.zip
Diffstat (limited to '')
-rw-r--r--source/BlockEntities/FurnaceEntity.cpp44
-rw-r--r--source/BlockEntities/FurnaceEntity.h13
-rw-r--r--source/BlockEntities/HopperEntity.cpp18
3 files changed, 54 insertions, 21 deletions
diff --git a/source/BlockEntities/FurnaceEntity.cpp b/source/BlockEntities/FurnaceEntity.cpp
index d4dddfd89..d90746c55 100644
--- a/source/BlockEntities/FurnaceEntity.cpp
+++ b/source/BlockEntities/FurnaceEntity.cpp
@@ -5,6 +5,7 @@
#include "../UI/Window.h"
#include "../Player.h"
#include "../Root.h"
+#include "../Chunk.h"
#include <json/json.h>
@@ -22,8 +23,10 @@ enum
-cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
+cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
super(E_BLOCK_FURNACE, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, NULL),
+ m_BlockType(a_BlockType),
+ m_BlockMeta(a_BlockMeta),
m_CurrentRecipe(NULL),
m_IsCooking(false),
m_NeedCookTime(0),
@@ -41,10 +44,12 @@ cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
-cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
+cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cWorld * a_World) :
super(E_BLOCK_FURNACE, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World),
+ m_BlockType(a_BlockType),
+ m_BlockMeta(a_BlockMeta),
m_CurrentRecipe(NULL),
- m_IsCooking(false),
+ m_IsCooking((a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_LIT_FURNACE)),
m_NeedCookTime(0),
m_TimeCooked(0),
m_FuelBurnTime(0),
@@ -252,7 +257,7 @@ void cFurnaceEntity::BurnNewFuel(void)
// The item in the fuel slot is not suitable
m_FuelBurnTime = 0;
m_TimeBurned = 0;
- m_IsCooking = false;
+ SetIsCooking(false);
return;
}
@@ -265,7 +270,7 @@ void cFurnaceEntity::BurnNewFuel(void)
// Burn one new fuel:
m_FuelBurnTime = NewTime;
m_TimeBurned = 0;
- m_IsCooking = true;
+ SetIsCooking(true);
if (m_Contents.GetSlot(fsFuel).m_ItemType == E_ITEM_LAVA_BUCKET)
{
m_Contents.SetSlot(fsFuel, cItem(E_ITEM_BUCKET));
@@ -334,12 +339,12 @@ void cFurnaceEntity::UpdateInput(void)
{
// This input cannot be cooked
m_NeedCookTime = 0;
- m_IsCooking = false;
+ SetIsCooking(false);
}
else
{
m_NeedCookTime = m_CurrentRecipe->CookTime;
- m_IsCooking = true;
+ SetIsCooking(true);
// Start burning new fuel if there's no flame now:
if (GetFuelBurnTimeLeft() <= 0)
@@ -378,7 +383,7 @@ void cFurnaceEntity::UpdateOutput(void)
// Cannot cook anymore:
m_TimeCooked = 0;
m_NeedCookTime = 0;
- m_IsCooking = false;
+ SetIsCooking(false);
return;
}
@@ -386,7 +391,7 @@ void cFurnaceEntity::UpdateOutput(void)
// Can cook, start cooking if not already underway:
m_NeedCookTime = m_CurrentRecipe->CookTime;
- m_IsCooking = true;
+ SetIsCooking(m_FuelBurnTime > 0);
}
@@ -403,13 +408,13 @@ void cFurnaceEntity::UpdateIsCooking(void)
)
{
// Reset everything
- m_IsCooking = false;
+ SetIsCooking(false);
m_TimeCooked = 0;
m_NeedCookTime = 0;
return;
}
- m_IsCooking = true;
+ SetIsCooking(true);
}
@@ -474,3 +479,20 @@ void cFurnaceEntity::UpdateProgressBars(void)
+
+void cFurnaceEntity::SetIsCooking(bool a_IsCooking)
+{
+ if (a_IsCooking == m_IsCooking)
+ {
+ return;
+ }
+
+ m_IsCooking = a_IsCooking;
+
+ // Light or extinguish the furnace:
+ m_World->FastSetBlock(m_PosX, m_PosY, m_PosZ, m_IsCooking ? E_BLOCK_LIT_FURNACE : E_BLOCK_FURNACE, m_BlockMeta);
+}
+
+
+
+
diff --git a/source/BlockEntities/FurnaceEntity.h b/source/BlockEntities/FurnaceEntity.h
index 037ed75db..ed6a7588f 100644
--- a/source/BlockEntities/FurnaceEntity.h
+++ b/source/BlockEntities/FurnaceEntity.h
@@ -40,12 +40,12 @@ public:
};
/// Constructor used while generating a chunk; sets m_World to NULL
- cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ);
+ cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
// tolua_end
/// Constructor used for normal operation
- cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
+ cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cWorld * a_World);
virtual ~cFurnaceEntity();
@@ -103,6 +103,12 @@ public:
protected:
+ /// Block type of the block currently represented by this entity (changes when furnace lights up)
+ BLOCKTYPE m_BlockType;
+
+ /// Block meta of the block currently represented by this entity
+ NIBBLETYPE m_BlockMeta;
+
/// The recipe for the current input slot
const cFurnaceRecipe::Recipe * m_CurrentRecipe;
@@ -146,6 +152,9 @@ protected:
/// Broadcasts progressbar updates, if needed
void UpdateProgressBars(void);
+ /// Sets the m_IsCooking variable, updates the furnace block type based on the value
+ void SetIsCooking(bool a_IsCooking);
+
// cItemGrid::cListener overrides:
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
diff --git a/source/BlockEntities/HopperEntity.cpp b/source/BlockEntities/HopperEntity.cpp
index 2a3813ed2..3fadf727c 100644
--- a/source/BlockEntities/HopperEntity.cpp
+++ b/source/BlockEntities/HopperEntity.cpp
@@ -162,11 +162,12 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
bool res = false;
switch (a_Chunk.GetBlock(m_RelX, m_PosY + 1, m_RelZ))
{
- case E_BLOCK_CHEST: res = MoveItemsFromChest(a_Chunk); break;
- case E_BLOCK_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break;
+ case E_BLOCK_CHEST: res = MoveItemsFromChest(a_Chunk); break;
+ case E_BLOCK_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break;
case E_BLOCK_DISPENSER:
- case E_BLOCK_DROPPER: res = MoveItemsFromGrid(((cDropSpenserEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break;
- case E_BLOCK_HOPPER: res = MoveItemsFromGrid(((cHopperEntity *) a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break;
+ case E_BLOCK_DROPPER: res = MoveItemsFromGrid(((cDropSpenserEntity *)a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break;
+ case E_BLOCK_HOPPER: res = MoveItemsFromGrid(((cHopperEntity *) a_Chunk.GetBlockEntity(m_PosX, m_PosY + 1, m_PosZ))->GetContents()); break;
+ case E_BLOCK_LIT_FURNACE: res = MoveItemsFromFurnace(a_Chunk); break;
}
// If the item has been moved, reset the last tick:
@@ -229,11 +230,12 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)
bool res = false;
switch (DestChunk->GetBlock(rx, by, rz))
{
- case E_BLOCK_CHEST: res = MoveItemsToChest(*DestChunk, bx, by, bz); break;
- case E_BLOCK_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break;
+ case E_BLOCK_CHEST: res = MoveItemsToChest(*DestChunk, bx, by, bz); break;
+ case E_BLOCK_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break;
case E_BLOCK_DISPENSER:
- case E_BLOCK_DROPPER: res = MoveItemsToGrid(((cDropSpenserEntity *)DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break;
- case E_BLOCK_HOPPER: res = MoveItemsToGrid(((cHopperEntity *) DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break;
+ case E_BLOCK_DROPPER: res = MoveItemsToGrid(((cDropSpenserEntity *)DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break;
+ case E_BLOCK_HOPPER: res = MoveItemsToGrid(((cHopperEntity *) DestChunk->GetBlockEntity(bx, by, bz))->GetContents()); break;
+ case E_BLOCK_LIT_FURNACE: res = MoveItemsToFurnace(*DestChunk, bx, by, bz, Meta); break;
}
// If the item has been moved, reset the last tick: