Furnaces light up visually when they're cooking

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1612 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2013-06-20 11:41:44 +00:00
parent 512c342782
commit 8dd5fe5070
9 changed files with 102 additions and 39 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 06/18/13 21:08:59.
** Generated automatically by tolua++-1.0.92 on 06/20/13 13:33:05.
*/
#ifndef __cplusplus
@ -17118,7 +17118,9 @@ static int tolua_AllToLua_cFurnaceEntity_new00(lua_State* tolua_S)
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
!tolua_isnumber(tolua_S,5,0,&tolua_err) ||
!tolua_isnumber(tolua_S,6,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,7,&tolua_err)
)
goto tolua_lerror;
else
@ -17127,8 +17129,10 @@ static int tolua_AllToLua_cFurnaceEntity_new00(lua_State* tolua_S)
int a_BlockX = ((int) tolua_tonumber(tolua_S,2,0));
int a_BlockY = ((int) tolua_tonumber(tolua_S,3,0));
int a_BlockZ = ((int) tolua_tonumber(tolua_S,4,0));
unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,5,0));
unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,6,0));
{
cFurnaceEntity* tolua_ret = (cFurnaceEntity*) Mtolua_new((cFurnaceEntity)(a_BlockX,a_BlockY,a_BlockZ));
cFurnaceEntity* tolua_ret = (cFurnaceEntity*) Mtolua_new((cFurnaceEntity)(a_BlockX,a_BlockY,a_BlockZ,a_BlockType,a_BlockMeta));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cFurnaceEntity");
}
}
@ -17152,7 +17156,9 @@ static int tolua_AllToLua_cFurnaceEntity_new00_local(lua_State* tolua_S)
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
!tolua_isnumber(tolua_S,5,0,&tolua_err) ||
!tolua_isnumber(tolua_S,6,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,7,&tolua_err)
)
goto tolua_lerror;
else
@ -17161,8 +17167,10 @@ static int tolua_AllToLua_cFurnaceEntity_new00_local(lua_State* tolua_S)
int a_BlockX = ((int) tolua_tonumber(tolua_S,2,0));
int a_BlockY = ((int) tolua_tonumber(tolua_S,3,0));
int a_BlockZ = ((int) tolua_tonumber(tolua_S,4,0));
unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,5,0));
unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,6,0));
{
cFurnaceEntity* tolua_ret = (cFurnaceEntity*) Mtolua_new((cFurnaceEntity)(a_BlockX,a_BlockY,a_BlockZ));
cFurnaceEntity* tolua_ret = (cFurnaceEntity*) Mtolua_new((cFurnaceEntity)(a_BlockX,a_BlockY,a_BlockZ,a_BlockType,a_BlockMeta));
tolua_pushusertype(tolua_S,(void*)tolua_ret,"cFurnaceEntity");
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
}

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 06/18/13 21:09:00.
** Generated automatically by tolua++-1.0.92 on 06/20/13 13:33:06.
*/
/* Exported function */

View File

@ -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);
}

View File

@ -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;

View File

@ -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:

View File

@ -1246,11 +1246,13 @@ void cChunk::CreateBlockEntities(void)
break;
}
case E_BLOCK_LIT_FURNACE:
case E_BLOCK_FURNACE:
{
if (!HasBlockEntityAt(x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width))
{
m_BlockEntities.push_back(new cFurnaceEntity(x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width, m_World));
NIBBLETYPE BlockMeta = cChunkDef::GetNibble(m_BlockMeta, x, y, z);
m_BlockEntities.push_back(new cFurnaceEntity(x + m_PosX * Width, y + m_PosY * Height, z + m_PosZ * Width, BlockType, BlockMeta, m_World));
}
break;
}
@ -1456,9 +1458,10 @@ void cChunk::SetBlock( int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType
AddBlockEntity(new cDropperEntity( WorldPos.x, WorldPos.y, WorldPos.z, m_World));
break;
}
case E_BLOCK_LIT_FURNACE:
case E_BLOCK_FURNACE:
{
AddBlockEntity(new cFurnaceEntity( WorldPos.x, WorldPos.y, WorldPos.z, m_World));
AddBlockEntity(new cFurnaceEntity( WorldPos.x, WorldPos.y, WorldPos.z, a_BlockType, a_BlockMeta, m_World));
break;
}
case E_BLOCK_HOPPER:

View File

@ -331,7 +331,7 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT
cEntityList Entities;
cBlockEntityList BlockEntities;
LoadEntitiesFromNBT (Entities, a_NBT, a_NBT.FindChildByName(Level, "Entities"));
LoadBlockEntitiesFromNBT(BlockEntities, a_NBT, a_NBT.FindChildByName(Level, "TileEntities"));
LoadBlockEntitiesFromNBT(BlockEntities, a_NBT, a_NBT.FindChildByName(Level, "TileEntities"), BlockTypes, MetaData);
bool IsLightValid = (a_NBT.FindChildByName(Level, "MCSIsLightValid") > 0);
@ -539,7 +539,7 @@ void cWSSAnvil::LoadEntitiesFromNBT(cEntityList & a_Entities, const cParsedNBT &
void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx)
void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas)
{
if ((a_TagIdx < 0) || (a_NBT.GetType(a_TagIdx) != TAG_List))
{
@ -567,7 +567,7 @@ void cWSSAnvil::LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntities, con
}
else if (strncmp(a_NBT.GetData(sID), "Furnace", a_NBT.GetDataLength(sID)) == 0)
{
LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child);
LoadFurnaceFromNBT(a_BlockEntities, a_NBT, Child, a_BlockTypes, a_BlockMetas);
}
else if (strncmp(a_NBT.GetData(sID), "Hopper", a_NBT.GetDataLength(sID)) == 0)
{
@ -737,7 +737,7 @@ void cWSSAnvil::LoadDropperFromNBT(cBlockEntityList & a_BlockEntities, const cPa
void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx)
void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas)
{
ASSERT(a_NBT.GetType(a_TagIdx) == TAG_Compound);
int x, y, z;
@ -750,7 +750,19 @@ void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cPa
{
return; // Make it an empty furnace - the chunk loader will provide an empty cFurnaceEntity for this
}
std::auto_ptr<cFurnaceEntity> Furnace(new cFurnaceEntity(x, y, z, m_World));
// Convert coords to relative:
int RelX = x;
int RelZ = z;
int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(RelX, y, RelZ, ChunkX, ChunkZ);
// Create the furnace entity, with proper BlockType and BlockMeta info:
BLOCKTYPE BlockType = cChunkDef::GetBlock(a_BlockTypes, RelX, y, RelZ);
NIBBLETYPE BlockMeta = cChunkDef::GetNibble(a_BlockMetas, RelX, y, RelZ);
std::auto_ptr<cFurnaceEntity> Furnace(new cFurnaceEntity(x, y, z, BlockType, BlockMeta, m_World));
// Load slots:
for (int Child = a_NBT.GetFirstChild(Items); Child != -1; Child = a_NBT.GetNextSibling(Child))
{
int Slot = a_NBT.FindChildByName(Child, "Slot");
@ -764,6 +776,8 @@ void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cPa
Furnace->SetSlot(a_NBT.GetByte(Slot), Item);
}
} // for itr - ItemDefs[]
// Load burn time:
int BurnTime = a_NBT.FindChildByName(a_TagIdx, "BurnTime");
if (BurnTime >= 0)
{
@ -771,6 +785,8 @@ void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cPa
// Anvil doesn't store the time that the fuel can burn. We simply "reset" the current value to be the 100%
Furnace->SetBurnTimes(bt, 0);
}
// Load cook time:
int CookTime = a_NBT.FindChildByName(a_TagIdx, "CookTime");
if (CookTime >= 0)
{
@ -778,6 +794,8 @@ void cWSSAnvil::LoadFurnaceFromNBT(cBlockEntityList & a_BlockEntities, const cPa
// Anvil doesn't store the time that an item takes to cook. We simply use the default - 10 seconds (200 ticks)
Furnace->SetCookTimes(200, ct);
}
// Restart cooking:
Furnace->ContinueCooking();
a_BlockEntities.push_back(Furnace.release());
}

View File

@ -116,7 +116,7 @@ protected:
void LoadEntitiesFromNBT(cEntityList & a_Entitites, const cParsedNBT & a_NBT, int a_Tag);
/// Loads the chunk's BlockEntities from NBT data (a_Tag is the Level\\TileEntities list tag; may be -1)
void LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntitites, const cParsedNBT & a_NBT, int a_Tag);
void LoadBlockEntitiesFromNBT(cBlockEntityList & a_BlockEntitites, const cParsedNBT & a_NBT, int a_Tag, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas);
/// Loads a cItem contents from the specified NBT tag; returns true if successful. Doesn't load the Slot tag
bool LoadItemFromNBT(cItem & a_Item, const cParsedNBT & a_NBT, int a_TagIdx);
@ -130,7 +130,7 @@ protected:
void LoadChestFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDispenserFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadDropperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadFurnaceFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadFurnaceFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx, BLOCKTYPE * a_BlockTypes, NIBBLETYPE * a_BlockMetas);
void LoadHopperFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadJukeboxFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);
void LoadNoteFromNBT (cBlockEntityList & a_BlockEntities, const cParsedNBT & a_NBT, int a_TagIdx);

View File

@ -310,15 +310,16 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
for( Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr )
{
Json::Value & Furnace = *itr;
cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0,0,0, a_World);
if( !FurnaceEntity->LoadFromJson( Furnace ) )
// TODO: The block type and meta aren't correct, there's no way to get them here
cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World);
if (!FurnaceEntity->LoadFromJson(Furnace))
{
LOGERROR("ERROR READING FURNACE FROM JSON!" );
delete FurnaceEntity;
}
else
{
a_BlockEntities.push_back( FurnaceEntity );
a_BlockEntities.push_back(FurnaceEntity);
}
} // for itr - AllFurnaces[]
}