Files
cuberite-2a/src/Blocks/BlockCauldron.h
T

153 lines
2.8 KiB
C++
Raw Normal View History

2013-07-29 12:13:03 +01:00
#pragma once
#include "BlockHandler.h"
class cBlockCauldronHandler :
2020-03-23 22:07:08 +02:00
public cBlockHandler
2013-07-29 12:13:03 +01:00
{
2020-04-13 18:38:06 +02:00
using Super = cBlockHandler;
2013-07-29 12:13:03 +01:00
public:
cBlockCauldronHandler(BLOCKTYPE a_BlockType):
2020-04-13 18:38:06 +02:00
Super(a_BlockType)
2013-07-29 12:13:03 +01:00
{
}
2020-04-17 11:36:37 +02:00
2020-03-23 22:07:08 +02:00
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
{
return cItem(E_ITEM_CAULDRON, 1, 0);
}
2020-04-17 11:36:37 +02:00
2020-04-21 22:19:22 +02:00
virtual bool OnUse(
cChunkInterface & a_ChunkInterface,
cWorldInterface & a_WorldInterface,
cPlayer & a_Player,
const Vector3i a_BlockPos,
eBlockFace a_BlockFace,
const Vector3i a_CursorPos
) override
2013-07-29 12:13:03 +01:00
{
2020-04-21 22:19:22 +02:00
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockPos);
auto EquippedItem = a_Player.GetEquippedItem();
switch (EquippedItem.m_ItemType)
2013-07-29 12:13:03 +01:00
{
case E_ITEM_BUCKET:
{
if (Meta == 3)
{
2020-04-21 22:19:22 +02:00
a_ChunkInterface.SetBlockMeta(a_BlockPos, 0);
// Give new bucket, filled with fluid when the gamemode is not creative:
if (!a_Player.IsGameModeCreative())
{
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_WATER_BUCKET));
}
}
break;
}
2013-07-29 12:13:03 +01:00
case E_ITEM_WATER_BUCKET:
{
2014-02-20 17:45:18 +01:00
if (Meta < 3)
{
2020-04-21 22:19:22 +02:00
a_ChunkInterface.SetBlockMeta(a_BlockPos, 3);
// Give empty bucket back when the gamemode is not creative:
2017-07-31 21:17:52 +01:00
if (!a_Player.IsGameModeCreative())
2014-02-20 20:58:23 +01:00
{
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_BUCKET));
2014-02-20 20:58:23 +01:00
}
2014-02-20 17:45:18 +01:00
}
2013-07-29 12:13:03 +01:00
break;
}
case E_ITEM_GLASS_BOTTLE:
{
2014-02-20 17:45:18 +01:00
if (Meta > 0)
2013-07-29 12:13:03 +01:00
{
2020-04-21 22:19:22 +02:00
a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
// Give new potion when the gamemode is not creative:
if (!a_Player.IsGameModeCreative())
{
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_POTION));
}
2013-07-29 12:13:03 +01:00
}
break;
}
case E_ITEM_POTION:
{
// Refill cauldron with water bottles.
if ((Meta < 3) && (EquippedItem.m_ItemDamage == 0))
{
2020-04-21 22:19:22 +02:00
a_ChunkInterface.SetBlockMeta(Vector3i(a_BlockPos), ++Meta);
// Give back an empty bottle when the gamemode is not creative:
if (!a_Player.IsGameModeCreative())
{
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_GLASS_BOTTLE));
}
}
}
2013-07-29 12:13:03 +01:00
}
return true;
2013-07-29 12:13:03 +01:00
}
2020-04-17 11:36:37 +02:00
2013-07-29 12:13:03 +01:00
virtual bool IsUseable() override
{
return true;
}
2014-05-29 16:58:40 +01:00
2020-04-17 11:36:37 +02:00
virtual void OnUpdate(
cChunkInterface & a_ChunkInterface,
cWorldInterface & a_WorldInterface,
cBlockPluginInterface & a_PluginInterface,
cChunk & a_Chunk,
const Vector3i a_RelPos
) override
2014-05-29 16:58:40 +01:00
{
2020-04-17 11:36:37 +02:00
auto WorldPos = a_Chunk.RelativeToAbsolute(a_RelPos);
if (!a_WorldInterface.IsWeatherWetAtXYZ(WorldPos.addedY(1)))
2014-05-29 16:58:40 +01:00
{
2014-06-14 10:14:04 +01:00
// It's not raining at our current location or we do not have a direct view of the sky
2014-05-29 16:58:40 +01:00
return;
}
2020-04-17 11:36:37 +02:00
auto Meta = a_Chunk.GetMeta(a_RelPos);
2014-05-29 16:58:40 +01:00
if (Meta < 3)
{
2020-04-17 11:36:37 +02:00
a_Chunk.SetMeta(a_RelPos, Meta + 1);
2014-05-29 16:58:40 +01:00
}
}
2015-06-30 15:50:15 +01:00
2020-04-17 11:36:37 +02:00
2015-06-30 15:50:15 +01:00
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);
return 21;
}
2013-07-29 12:13:03 +01:00
} ;