2012-12-19 16:19:36 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "DispenserEntity.h"
|
2013-05-28 15:12:47 -04:00
|
|
|
#include "../Player.h"
|
|
|
|
#include "../Simulator/FluidSimulator.h"
|
|
|
|
#include "../Chunk.h"
|
2012-12-26 12:16:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-25 07:59:13 -04:00
|
|
|
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
2013-05-26 10:39:04 -04:00
|
|
|
super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, NULL)
|
2012-12-19 16:19:36 -05:00
|
|
|
{
|
|
|
|
SetBlockEntity(this); // cBlockEntityWindowOwner
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-25 07:59:13 -04:00
|
|
|
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
|
2013-05-26 10:39:04 -04:00
|
|
|
super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, a_World)
|
2012-12-19 16:19:36 -05:00
|
|
|
{
|
2013-05-25 07:59:13 -04:00
|
|
|
SetBlockEntity(this); // cBlockEntityWindowOwner
|
2012-12-19 16:19:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 14:50:44 -04:00
|
|
|
void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
|
2012-12-19 16:19:36 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
int DispX = m_RelX;
|
2013-05-26 10:39:04 -04:00
|
|
|
int DispY = m_PosY;
|
2013-05-28 14:50:44 -04:00
|
|
|
int DispZ = m_RelZ;
|
|
|
|
NIBBLETYPE Meta = a_Chunk.GetMeta(m_RelX, m_PosY, m_RelZ);
|
2013-05-26 10:39:04 -04:00
|
|
|
AddDropSpenserDir(DispX, DispY, DispZ, Meta);
|
2013-05-28 14:50:44 -04:00
|
|
|
cChunk * DispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(DispX, DispZ);
|
|
|
|
if (DispChunk == NULL)
|
|
|
|
{
|
|
|
|
// Would dispense into / interact with a non-loaded chunk, ignore the tick
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BLOCKTYPE DispBlock = DispChunk->GetBlock(DispX, DispY, DispZ);
|
2013-05-26 10:39:04 -04:00
|
|
|
|
2013-04-10 17:40:30 -04:00
|
|
|
// Dispense the item:
|
2013-05-26 16:52:39 -04:00
|
|
|
switch (m_Contents.GetSlot(a_SlotNum).m_ItemType)
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-04-10 17:40:30 -04:00
|
|
|
case E_ITEM_BUCKET:
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
LOGD("Dispensing empty bucket in slot %d; DispBlock is \"%s\" (%d).", a_SlotNum, ItemTypeToString(DispBlock).c_str(), DispBlock);
|
2013-05-26 16:52:39 -04:00
|
|
|
switch (DispBlock)
|
2013-04-10 17:40:30 -04:00
|
|
|
{
|
2013-05-26 16:52:39 -04:00
|
|
|
case E_BLOCK_STATIONARY_WATER:
|
|
|
|
case E_BLOCK_WATER:
|
|
|
|
{
|
|
|
|
if (ScoopUpLiquid(a_SlotNum, E_ITEM_WATER_BUCKET))
|
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_AIR, 0);
|
2013-05-26 16:52:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_STATIONARY_LAVA:
|
|
|
|
case E_BLOCK_LAVA:
|
|
|
|
{
|
|
|
|
if (ScoopUpLiquid(a_SlotNum, E_ITEM_LAVA_BUCKET))
|
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_AIR, 0);
|
2013-05-26 16:52:39 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DropFromSlot(a_Chunk, a_SlotNum);
|
2013-05-26 16:52:39 -04:00
|
|
|
break;
|
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
}
|
|
|
|
break;
|
2013-05-26 16:52:39 -04:00
|
|
|
} // E_ITEM_BUCKET
|
2013-04-10 17:40:30 -04:00
|
|
|
|
|
|
|
case E_ITEM_WATER_BUCKET:
|
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
LOGD("Dispensing water bucket in slot %d; DispBlock is \"%s\" (%d).", a_SlotNum, ItemTypeToString(DispBlock).c_str(), DispBlock);
|
|
|
|
if (EmptyLiquidBucket(DispBlock, a_SlotNum))
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_WATER, 0);
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
else
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DropFromSlot(a_Chunk, a_SlotNum);
|
2012-12-26 13:15:11 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case E_ITEM_LAVA_BUCKET:
|
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
LOGD("Dispensing lava bucket in slot %d; DispBlock is \"%s\" (%d).", a_SlotNum, ItemTypeToString(DispBlock).c_str(), DispBlock);
|
|
|
|
if (EmptyLiquidBucket(DispBlock, a_SlotNum))
|
2012-12-26 13:15:11 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_LAVA, 0);
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
else
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DropFromSlot(a_Chunk, a_SlotNum);
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
break;
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
|
|
|
|
case E_ITEM_SPAWN_EGG:
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
|
|
|
|
double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
|
|
|
|
if (m_World->SpawnMob(MobX, DispY, MobZ, m_Contents.GetSlot(a_SlotNum).m_ItemDamage) >= 0)
|
2013-04-10 17:40:30 -04:00
|
|
|
{
|
2013-05-26 16:52:39 -04:00
|
|
|
m_Contents.ChangeSlotCount(a_SlotNum, -1);
|
2013-04-10 17:40:30 -04:00
|
|
|
}
|
|
|
|
break;
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
|
2013-06-21 17:19:47 -04:00
|
|
|
case E_BLOCK_TNT:
|
|
|
|
{
|
|
|
|
// Spawn a primed TNT entity, if space allows:
|
|
|
|
if (DispChunk->GetBlock(DispX, DispY, DispZ) == E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
double TNTX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
|
|
|
|
double TNTZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
|
|
|
|
m_World->SpawnPrimedTNT(TNTX, DispY + 0.5, TNTZ, 4, 0); // 4 seconds fuse, no initial velocity
|
|
|
|
m_Contents.ChangeSlotCount(a_SlotNum, -1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-06-22 06:03:41 -04:00
|
|
|
|
|
|
|
case E_ITEM_FLINT_AND_STEEL:
|
|
|
|
{
|
|
|
|
// Spawn fire if the block in front is air.
|
|
|
|
if (DispChunk->GetBlock(DispX, DispY, DispZ) == E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_FIRE, 0);
|
|
|
|
m_Contents.SetSlot(a_SlotNum, m_Contents.GetSlot(a_SlotNum).m_ItemType, m_Contents.GetSlot(a_SlotNum).m_ItemCount, m_Contents.GetSlot(a_SlotNum).m_ItemDamage + 1);
|
|
|
|
// If the durability has run out destroy the item.
|
|
|
|
if (m_Contents.GetSlot(a_SlotNum).m_ItemDamage > 64)
|
|
|
|
{
|
|
|
|
m_Contents.ChangeSlotCount(a_SlotNum, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-06-21 17:19:47 -04:00
|
|
|
|
2013-04-10 17:40:30 -04:00
|
|
|
default:
|
2012-12-26 12:16:33 -05:00
|
|
|
{
|
2013-05-28 14:50:44 -04:00
|
|
|
DropFromSlot(a_Chunk, a_SlotNum);
|
2013-04-10 17:40:30 -04:00
|
|
|
break;
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
2013-04-10 17:40:30 -04:00
|
|
|
} // switch (ItemType)
|
2012-12-26 12:16:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-26 16:52:39 -04:00
|
|
|
|
|
|
|
bool cDispenserEntity::ScoopUpLiquid(int a_SlotNum, short a_BucketItemType)
|
|
|
|
{
|
|
|
|
cItem LiquidBucket(a_BucketItemType, 1);
|
|
|
|
if (m_Contents.GetSlot(a_SlotNum).m_ItemCount == 1)
|
|
|
|
{
|
|
|
|
// Special case: replacing one empty bucket with one full bucket
|
|
|
|
m_Contents.SetSlot(a_SlotNum, LiquidBucket);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are stacked buckets at the selected slot, see if a full bucket will fit somewhere else
|
|
|
|
if (m_Contents.HowManyCanFit(LiquidBucket) < 1)
|
|
|
|
{
|
|
|
|
// Cannot fit into m_Contents
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Contents.ChangeSlotCount(a_SlotNum, -1);
|
|
|
|
m_Contents.AddItem(LiquidBucket);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 14:50:44 -04:00
|
|
|
bool cDispenserEntity::EmptyLiquidBucket(BLOCKTYPE a_BlockInFront, int a_SlotNum)
|
2013-05-26 16:52:39 -04:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
(a_BlockInFront != E_BLOCK_AIR) &&
|
|
|
|
!IsBlockLiquid(a_BlockInFront) &&
|
|
|
|
!cFluidSimulator::CanWashAway(a_BlockInFront)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Not a suitable block in front
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cItem EmptyBucket(E_ITEM_BUCKET, 1);
|
|
|
|
if (m_Contents.GetSlot(a_SlotNum).m_ItemCount == 1)
|
|
|
|
{
|
|
|
|
// Change the single full bucket present into a single empty bucket
|
|
|
|
m_Contents.SetSlot(a_SlotNum, EmptyBucket);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are full buckets stacked at this slot, check if we can fit in the empty bucket
|
|
|
|
if (m_Contents.HowManyCanFit(EmptyBucket) < 1)
|
|
|
|
{
|
|
|
|
// The empty bucket wouldn't fit into m_Contents
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The empty bucket fits in, remove one full bucket and add the empty one
|
|
|
|
m_Contents.ChangeSlotCount(a_SlotNum, -1);
|
|
|
|
m_Contents.AddItem(EmptyBucket);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|