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
|
|
|
|
2013-08-19 05:39:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
class cItemHoeHandler:
|
2013-08-19 05:39:13 -04:00
|
|
|
public cItemHandler
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
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
|
|
|
|
|
|
|
cItemHoeHandler(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 == BLOCK_FACE_NONE) || (a_ClickedBlockPos.y >= cChunkDef::Height))
|
2014-09-12 07:19:33 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
// Need air above the hoe-d block to transform it:
|
|
|
|
BLOCKTYPE UpperBlockType = a_World->GetBlock(a_ClickedBlockPos.addedY(1));
|
|
|
|
if (UpperBlockType != E_BLOCK_AIR)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-30 14:31:27 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
// Can only transform dirt or grass blocks:
|
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
|
|
|
a_World->GetBlockTypeMeta(a_ClickedBlockPos, BlockType, BlockMeta);
|
|
|
|
if ((BlockType != E_BLOCK_DIRT) && (BlockType != E_BLOCK_GRASS))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((BlockType == E_BLOCK_DIRT) && (BlockMeta == E_META_DIRT_PODZOL))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
return false;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2014-07-23 10:32:09 -04:00
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
// Transform:
|
|
|
|
auto NewBlockType = ((BlockType == E_BLOCK_DIRT) && (BlockMeta == E_META_DIRT_COARSE)) ? E_BLOCK_DIRT : E_BLOCK_FARMLAND;
|
|
|
|
a_World->SetBlock(a_ClickedBlockPos, NewBlockType, 0);
|
|
|
|
a_World->BroadcastSoundEffect("item.hoe.till", a_ClickedBlockPos + Vector3d(0.5, 0.5, 0.5), 1.0f, 0.8f);
|
|
|
|
a_Player->UseEquippedItem();
|
|
|
|
return true;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2014-07-23 10:32:09 -04:00
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-26 11:09:59 -04:00
|
|
|
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
2014-07-23 10:32:09 -04:00
|
|
|
{
|
2018-01-05 06:28:06 -05:00
|
|
|
switch (a_Action)
|
|
|
|
{
|
|
|
|
case dlaAttackEntity: return 1;
|
|
|
|
case dlaBreakBlock: return 0;
|
|
|
|
case dlaBreakBlockInstant: return 0;
|
|
|
|
}
|
2018-02-04 18:07:12 -05:00
|
|
|
UNREACHABLE("Unsupported durability loss action");
|
2014-07-23 10:32:09 -04:00
|
|
|
}
|
2013-08-19 05:39:13 -04:00
|
|
|
} ;
|