2018-01-05 06:28:06 -05:00
|
|
|
|
2014-03-28 18:51:30 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ItemHandler.h"
|
|
|
|
#include "../Entities/Player.h"
|
|
|
|
#include "../LineBlockTracer.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cItemLilypadHandler:
|
2014-03-28 18:51:30 -04:00
|
|
|
public cItemHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cItemHandler;
|
2014-03-28 18:51:30 -04:00
|
|
|
|
|
|
|
public:
|
2020-04-13 12:38:06 -04:00
|
|
|
|
2014-04-04 03:56:57 -04:00
|
|
|
cItemLilypadHandler(int a_ItemType):
|
2020-04-13 12:38:06 -04:00
|
|
|
Super(a_ItemType)
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-04 03:56:57 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-28 18:51:30 -04:00
|
|
|
virtual bool IsPlaceable(void) override
|
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
return false; // Set as not placeable so OnItemUse is called
|
2014-03-28 18:51:30 -04:00
|
|
|
}
|
|
|
|
|
2014-04-04 03:56:57 -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
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
if (a_ClickedBlockFace > BLOCK_FACE_NONE)
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
// Clicked on a face of a submerged block; vanilla allows placement, so should we
|
|
|
|
auto PlacePos = AddFaceDirection(a_ClickedBlockPos, a_ClickedBlockFace);
|
|
|
|
a_World->SetBlock(PlacePos, E_BLOCK_LILY_PAD, 0);
|
2014-03-28 18:51:30 -04:00
|
|
|
if (!a_Player->IsGameModeCreative())
|
2014-03-28 19:51:52 -04:00
|
|
|
{
|
2014-03-28 18:51:30 -04:00
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
2014-03-28 19:51:52 -04:00
|
|
|
}
|
2014-03-28 18:51:30 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
class cCallbacks:
|
2014-03-28 18:51:30 -04:00
|
|
|
public cBlockTracer::cCallbacks
|
|
|
|
{
|
|
|
|
public:
|
2014-04-23 16:06:07 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
cCallbacks():
|
2014-04-23 16:06:07 -04:00
|
|
|
m_HasHitFluid(false)
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-08 05:04:07 -04:00
|
|
|
virtual bool OnNextBlock(Vector3i a_CBBlockPos, BLOCKTYPE a_CBBlockType, NIBBLETYPE a_CBBlockMeta, eBlockFace a_CBEntryFace) override
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
2014-04-04 03:56:57 -04:00
|
|
|
if (IsBlockWater(a_CBBlockType))
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
if ((a_CBBlockMeta != 0) || (a_CBEntryFace == BLOCK_FACE_NONE)) // The hit block should be a source. The FACE_NONE check is clicking whilst submerged
|
2014-03-28 18:51:30 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-08 05:04:07 -04:00
|
|
|
a_CBBlockPos = AddFaceDirection(a_CBBlockPos, BLOCK_FACE_YP); // Always place pad at top of water block
|
2014-03-28 18:51:30 -04:00
|
|
|
if (
|
2014-04-23 16:06:07 -04:00
|
|
|
!IsBlockWater(a_CBBlockType) &&
|
|
|
|
cBlockInfo::FullyOccupiesVoxel(a_CBBlockType)
|
2014-03-28 18:51:30 -04:00
|
|
|
)
|
|
|
|
{
|
2015-05-09 03:25:09 -04:00
|
|
|
// Can't place lilypad on air / in another block!
|
2014-03-28 18:51:30 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_HasHitFluid = true;
|
2020-05-08 05:04:07 -04:00
|
|
|
m_Pos = a_CBBlockPos;
|
2014-03-28 18:51:30 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3i m_Pos;
|
|
|
|
bool m_HasHitFluid;
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
} Callbacks;
|
|
|
|
auto Start = a_Player->GetEyePosition() + a_Player->GetLookVector();
|
|
|
|
auto End = a_Player->GetEyePosition() + a_Player->GetLookVector() * 5;
|
2020-05-08 05:04:07 -04:00
|
|
|
cLineBlockTracer::Trace(*a_Player->GetWorld(), Callbacks, Start, End);
|
2014-03-28 18:51:30 -04:00
|
|
|
|
|
|
|
if (Callbacks.m_HasHitFluid)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
a_World->SetBlock(Callbacks.m_Pos, E_BLOCK_LILY_PAD, 0);
|
2014-03-28 18:51:30 -04:00
|
|
|
if (!a_Player->IsGameModeCreative())
|
2014-03-28 19:51:52 -04:00
|
|
|
{
|
2014-03-28 18:51:30 -04:00
|
|
|
a_Player->GetInventory().RemoveOneEquippedItem();
|
2014-03-28 19:51:52 -04:00
|
|
|
}
|
2014-03-28 18:51:30 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|