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())
|
|
|
|
{
|
2021-06-23 11:00:28 -04:00
|
|
|
if (m_ItemType == E_ITEM_FLINT_AND_STEEL)
|
2014-03-14 18:52:51 -04:00
|
|
|
{
|
2021-06-23 11:00:28 -04:00
|
|
|
a_Player->UseEquippedItem();
|
|
|
|
}
|
|
|
|
else // Fire charge.
|
|
|
|
{
|
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
2014-03-14 18:52:51 -04:00
|
|
|
}
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2021-06-23 11:00:28 -04:00
|
|
|
// Activate TNT if we clicked on it while not crouched:
|
|
|
|
if ((a_World->GetBlock(a_ClickedBlockPos) == E_BLOCK_TNT) && !a_Player->IsCrouched())
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2021-06-23 11:00:28 -04:00
|
|
|
a_World->DigBlock(a_ClickedBlockPos, a_Player);
|
|
|
|
a_World->SpawnPrimedTNT(Vector3d(a_ClickedBlockPos) + Vector3d(0.5, 0.5, 0.5)); // 80 ticks to boom
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto FirePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace);
|
|
|
|
if (!cChunkDef::IsValidHeight(FirePos.y))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Light a fire next to / on top of the block if air:
|
|
|
|
if (a_World->GetBlock(FirePos) == E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
a_World->PlaceBlock(FirePos, E_BLOCK_FIRE, 0);
|
|
|
|
|
|
|
|
// The client plays flint and steel sounds, only need to handle fire charges:
|
|
|
|
if (m_ItemType == E_ITEM_FIRE_CHARGE)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2021-06-23 11:00:28 -04:00
|
|
|
a_World->BroadcastSoundEffect("item.firecharge.use", FirePos, 1.0f, 1.04f);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} ;
|