summaryrefslogtreecommitdiffstats
path: root/source/DispenserEntity.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-26 16:39:04 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-26 16:39:04 +0200
commit5c3235ecdc3f718ce20e006f1ecfa2159df82c87 (patch)
treeaea2e4a722715498c59b0a828486b30b74506bb5 /source/DispenserEntity.cpp
parentItemGrid: Added the RemoveOneItem() function (diff)
downloadcuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.tar
cuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.tar.gz
cuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.tar.bz2
cuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.tar.lz
cuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.tar.xz
cuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.tar.zst
cuberite-5c3235ecdc3f718ce20e006f1ecfa2159df82c87.zip
Diffstat (limited to '')
-rw-r--r--source/DispenserEntity.cpp210
1 files changed, 21 insertions, 189 deletions
diff --git a/source/DispenserEntity.cpp b/source/DispenserEntity.cpp
index ccf4e0f95..73aed05a6 100644
--- a/source/DispenserEntity.cpp
+++ b/source/DispenserEntity.cpp
@@ -2,38 +2,15 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "DispenserEntity.h"
-#include "BlockID.h"
-#include "Item.h"
-#include "UI/Window.h"
#include "Player.h"
-#include "World.h"
-#include "ClientHandle.h"
-#include "Server.h"
-#include "Pickup.h"
-#include "Root.h"
#include "Simulator/FluidSimulator.h"
-#include <json/json.h>
-
-
-
-
-
-#define AddDispenserDir(x, y, z, dir) \
- switch (dir) \
- { \
- case 2: (z) --; break; \
- case 3: (z) ++; break; \
- case 4: (x) --; break; \
- case 5: (x) ++; break; \
- }
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
- super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, NULL),
- m_ShouldDispense(false)
+ super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, NULL)
{
SetBlockEntity(this); // cBlockEntityWindowOwner
}
@@ -43,8 +20,7 @@ cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ) :
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
- super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World),
- m_ShouldDispense(false)
+ super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, a_World)
{
SetBlockEntity(this); // cBlockEntityWindowOwner
}
@@ -53,71 +29,37 @@ cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWo
-cDispenserEntity::~cDispenserEntity()
+void cDispenserEntity::DropSpenseFromSlot(int a_SlotNum)
{
- // Tell window its owner is destroyed
- cWindow * Window = GetWindow();
- if (Window != NULL)
- {
- Window->OwnerDestroyed();
- }
-}
-
-
-
-
-
-void cDispenserEntity::Dispense(void)
-{
- int Disp_X = m_PosX;
- int Disp_Y = m_PosY;
- int Disp_Z = m_PosZ;
+ int DispX = m_PosX;
+ int DispY = m_PosY;
+ int DispZ = m_PosZ;
NIBBLETYPE Meta = m_World->GetBlockMeta(m_PosX, m_PosY, m_PosZ);
- AddDispenserDir(Disp_X, Disp_Y, Disp_Z, Meta);
- int OccupiedSlots[9];
- int SlotsCnt = 0;
- for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--)
- {
- if (!m_Contents.GetSlot(i).IsEmpty())
- {
- OccupiedSlots[SlotsCnt] = i;
- SlotsCnt++;
- }
- } // for i - m_Contents[]
-
- if (SlotsCnt == 0)
- {
- // Nothing in the dispenser, play the click sound
- m_World->BroadcastSoundEffect("random.click", m_PosX * 8, m_PosY * 8, m_PosZ * 8, 1.0f, 1.2f);
- return;
- }
-
- // Pick an item to dispense:
- MTRand r1;
- int RandomSlot = r1.randInt(SlotsCnt - 1);
- cItem & Drop = m_Contents.GetSlot(OccupiedSlots[RandomSlot]);
+ AddDropSpenserDir(DispX, DispY, DispZ, Meta);
+
+ cItem & Drop = m_Contents.GetSlot(a_SlotNum);
// Dispense the item:
switch (Drop.m_ItemType)
{
case E_ITEM_BUCKET:
{
- BLOCKTYPE DispBlock = m_World->GetBlock(Disp_X, Disp_Y, Disp_Z);
+ BLOCKTYPE DispBlock = m_World->GetBlock(DispX, DispY, DispZ);
if (DispBlock == E_BLOCK_STATIONARY_WATER)
{
- m_World->SetBlock(Disp_X, Disp_Y, Disp_Z, E_BLOCK_AIR, 0);
+ m_World->SetBlock(DispX, DispY, DispZ, E_BLOCK_AIR, 0);
Drop.m_ItemType = E_ITEM_WATER_BUCKET; // TODO: Duplication glitch - bucket stacking allows you to duplicate water
}
else if (DispBlock == E_BLOCK_STATIONARY_LAVA)
{
- m_World->SetBlock(Disp_X, Disp_Y, Disp_Z, E_BLOCK_AIR, 0);
+ m_World->SetBlock(DispX, DispY, DispZ, E_BLOCK_AIR, 0);
Drop.m_ItemType = E_ITEM_LAVA_BUCKET; // TODO: Duplication glitch - bucket stacking allows you to duplicate lava
}
else
{
cItems Pickups;
Pickups.push_back(Drop.CopyOne());
- m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z);
+ m_World->SpawnItemPickups(Pickups, DispX, DispY, DispZ);
Drop.m_ItemCount--;
}
break;
@@ -125,17 +67,17 @@ void cDispenserEntity::Dispense(void)
case E_ITEM_WATER_BUCKET:
{
- BLOCKTYPE DispBlock = m_World->GetBlock(Disp_X, Disp_Y, Disp_Z);
+ BLOCKTYPE DispBlock = m_World->GetBlock(DispX, DispY, DispZ);
if ((DispBlock == E_BLOCK_AIR) || IsBlockLiquid(DispBlock) || cFluidSimulator::CanWashAway(DispBlock))
{
- m_World->SetBlock(Disp_X, Disp_Y, Disp_Z, E_BLOCK_STATIONARY_WATER, 0);
+ m_World->SetBlock(DispX, DispY, DispZ, E_BLOCK_STATIONARY_WATER, 0);
Drop.m_ItemType = E_ITEM_BUCKET;
}
else
{
cItems Pickups;
Pickups.push_back(Drop.CopyOne());
- m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z);
+ m_World->SpawnItemPickups(Pickups, DispX, DispY, DispZ);
Drop.m_ItemCount--;
}
break;
@@ -143,17 +85,17 @@ void cDispenserEntity::Dispense(void)
case E_ITEM_LAVA_BUCKET:
{
- BLOCKTYPE DispBlock = m_World->GetBlock( Disp_X, Disp_Y, Disp_Z );
+ BLOCKTYPE DispBlock = m_World->GetBlock( DispX, DispY, DispZ );
if ((DispBlock == E_BLOCK_AIR) || IsBlockLiquid(DispBlock) || cFluidSimulator::CanWashAway(DispBlock))
{
- m_World->SetBlock(Disp_X, Disp_Y, Disp_Z, E_BLOCK_STATIONARY_LAVA, 0);
+ m_World->SetBlock(DispX, DispY, DispZ, E_BLOCK_STATIONARY_LAVA, 0);
Drop.m_ItemType = E_ITEM_BUCKET;
}
else
{
cItems Pickups;
Pickups.push_back(Drop.CopyOne());
- m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z);
+ m_World->SpawnItemPickups(Pickups, DispX, DispY, DispZ);
Drop.m_ItemCount--;
}
break;
@@ -161,7 +103,7 @@ void cDispenserEntity::Dispense(void)
case E_ITEM_SPAWN_EGG:
{
- if (m_World->SpawnMob(Disp_X + 0.5, Disp_Y, Disp_Z + 0.5, Drop.m_ItemDamage) >= 0)
+ if (m_World->SpawnMob(DispX + 0.5, DispY, DispZ + 0.5, Drop.m_ItemDamage) >= 0)
{
Drop.m_ItemCount--;
}
@@ -172,124 +114,14 @@ void cDispenserEntity::Dispense(void)
{
cItems Pickups;
Pickups.push_back(Drop.CopyOne());
- m_World->SpawnItemPickups(Pickups, Disp_X, Disp_Y, Disp_Z);
+ m_World->SpawnItemPickups(Pickups, DispX, DispY, DispZ);
Drop.m_ItemCount--;
break;
}
} // switch (ItemType)
-
- char SmokeDir = 0;
- switch (Meta)
- {
- case 2: SmokeDir = 1; break;
- case 3: SmokeDir = 7; break;
- case 4: SmokeDir = 3; break;
- case 5: SmokeDir = 5; break;
- }
- m_World->BroadcastSoundParticleEffect(2000, m_PosX * 8, m_PosY * 8, m_PosZ * 8, SmokeDir);
- m_World->BroadcastSoundEffect("random.click", m_PosX * 8, m_PosY * 8, m_PosZ * 8, 1.0f, 1.0f);
- cWindow * Window = GetWindow();
- if (Window != NULL)
- {
- Window->BroadcastWholeWindow();
- }
-}
-
-
-
-
-
-void cDispenserEntity::UsedBy(cPlayer * a_Player)
-{
- if (GetWindow() == NULL)
- {
- OpenWindow(new cDispenserWindow(m_PosX, m_PosY, m_PosZ, this));
- }
- if (GetWindow() != NULL)
- {
- if (a_Player->GetWindow() != GetWindow())
- {
- a_Player->OpenWindow(GetWindow());
- GetWindow()->SendWholeWindow(*a_Player->GetClientHandle());
- }
- }
-}
-
-
-
-
-
-void cDispenserEntity::Activate(void)
-{
- m_ShouldDispense = true;
}
-bool cDispenserEntity::Tick(float a_Dt)
-{
- if (m_ShouldDispense)
- {
- m_ShouldDispense = false;
- Dispense();
- }
- return false;
-}
-
-
-
-
-
-bool cDispenserEntity::LoadFromJson(const Json::Value & a_Value)
-{
- m_PosX = a_Value.get("x", 0).asInt();
- m_PosY = a_Value.get("y", 0).asInt();
- m_PosZ = a_Value.get("z", 0).asInt();
-
- Json::Value AllSlots = a_Value.get("Slots", 0);
- int SlotIdx = 0;
- for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr)
- {
- m_Contents.GetSlot(SlotIdx).FromJson(*itr);
- SlotIdx++;
- }
-
- return true;
-}
-
-
-
-
-
-void cDispenserEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- Json::Value AllSlots;
- int NumSlots = m_Contents.GetNumSlots();
- for (int i = 0; i < NumSlots; i++)
- {
- Json::Value Slot;
- m_Contents.GetSlot(i).GetJson(Slot);
- AllSlots.append(Slot);
- }
- a_Value["Slots"] = AllSlots;
-}
-
-
-
-
-
-void cDispenserEntity::SendTo(cClientHandle & a_Client)
-{
- // Nothing needs to be sent
- UNUSED(a_Client);
-}
-
-
-
-