2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
|
|
|
#include "../World.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
class cItemLighterHandler:
|
2013-07-29 07:13:03 -04:00
|
|
|
public cItemHandler
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
using Super = cItemHandler;
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
cItemLighterHandler(int a_ItemType):
|
|
|
|
Super(a_ItemType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
virtual bool OnItemUse(
|
2020-04-21 16:19:22 -04:00
|
|
|
cWorld * a_World,
|
|
|
|
cPlayer * a_Player,
|
|
|
|
cBlockPluginInterface & a_PluginInterface,
|
|
|
|
const cItem & a_HeldItem,
|
|
|
|
const Vector3i a_ClickedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace
|
2015-04-14 04:49:01 -04:00
|
|
|
) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
if (a_ClickedBlockFace < 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-03-14 18:52:51 -04:00
|
|
|
if (!a_Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
switch (m_ItemType)
|
|
|
|
{
|
|
|
|
case E_ITEM_FLINT_AND_STEEL:
|
|
|
|
{
|
|
|
|
a_Player->UseEquippedItem();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_ITEM_FIRE_CHARGE:
|
|
|
|
{
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unknown Lighter Item!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
switch (a_World->GetBlock(a_ClickedBlockPos))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
case E_BLOCK_TNT:
|
|
|
|
{
|
|
|
|
// Activate the TNT:
|
2020-04-21 16:19:22 -04:00
|
|
|
a_World->SetBlock(a_ClickedBlockPos, E_BLOCK_AIR, 0);
|
|
|
|
a_World->SpawnPrimedTNT(Vector3d(a_ClickedBlockPos) + Vector3d(0.5, 0.5, 0.5)); // 80 ticks to boom
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2015-05-09 03:25:09 -04:00
|
|
|
// Light a fire next to / on top of the block if air:
|
2020-04-21 16:19:22 -04:00
|
|
|
auto FirePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace);
|
|
|
|
if (!cChunkDef::IsValidHeight(FirePos.y))
|
2014-01-23 16:24:20 -05:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2020-04-21 16:19:22 -04:00
|
|
|
if (a_World->GetBlock(FirePos) == E_BLOCK_AIR)
|
2013-08-23 13:13:54 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
a_World->SetBlock(FirePos, E_BLOCK_FIRE, 0);
|
|
|
|
a_World->BroadcastSoundEffect("item.flintandsteel.use", FirePos, 1.0f, 1.04f);
|
2013-08-23 13:13:54 -04:00
|
|
|
break;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} ;
|