2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2020-09-19 21:24:58 -04:00
|
|
|
#include "../Entities/Player.h"
|
|
|
|
#include "../ClientHandle.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockCauldronHandler final :
|
2020-03-23 16:07:08 -04:00
|
|
|
public cBlockHandler
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2020-04-17 05:36:37 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2020-04-17 05:36:37 -04:00
|
|
|
|
2020-09-23 11:06:27 -04:00
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override
|
2020-03-23 16:07:08 -04:00
|
|
|
{
|
|
|
|
return cItem(E_ITEM_CAULDRON, 1, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
virtual bool OnUse(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cPlayer & a_Player,
|
|
|
|
const Vector3i a_BlockPos,
|
|
|
|
eBlockFace a_BlockFace,
|
|
|
|
const Vector3i a_CursorPos
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockPos);
|
2020-04-02 08:42:15 -04:00
|
|
|
auto EquippedItem = a_Player.GetEquippedItem();
|
2020-09-20 10:39:17 -04:00
|
|
|
|
2020-04-02 08:42:15 -04:00
|
|
|
switch (EquippedItem.m_ItemType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-02 08:42:15 -04:00
|
|
|
case E_ITEM_BUCKET:
|
|
|
|
{
|
|
|
|
if (Meta == 3)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, 0);
|
2020-04-02 08:42:15 -04:00
|
|
|
// 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 07:13:03 -04:00
|
|
|
case E_ITEM_WATER_BUCKET:
|
|
|
|
{
|
2014-02-20 11:45:18 -05:00
|
|
|
if (Meta < 3)
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, 3);
|
2020-04-02 08:42:15 -04:00
|
|
|
// Give empty bucket back when the gamemode is not creative:
|
2017-07-31 16:17:52 -04:00
|
|
|
if (!a_Player.IsGameModeCreative())
|
2014-02-20 14:58:23 -05:00
|
|
|
{
|
2020-04-02 08:42:15 -04:00
|
|
|
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_BUCKET));
|
2014-02-20 14:58:23 -05:00
|
|
|
}
|
2020-09-05 11:13:44 -04:00
|
|
|
a_Player.GetStatManager().AddValue(Statistic::FillCauldron);
|
2014-02-20 11:45:18 -05:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_ITEM_GLASS_BOTTLE:
|
|
|
|
{
|
2014-02-20 11:45:18 -05:00
|
|
|
if (Meta > 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
|
2020-04-02 08:42:15 -04:00
|
|
|
// Give new potion when the gamemode is not creative:
|
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_POTION));
|
|
|
|
}
|
2020-09-19 21:24:58 -04:00
|
|
|
a_Player.GetStatManager().AddValue(Statistic::UseCauldron);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-04-02 08:42:15 -04:00
|
|
|
case E_ITEM_POTION:
|
|
|
|
{
|
|
|
|
// Refill cauldron with water bottles.
|
|
|
|
if ((Meta < 3) && (EquippedItem.m_ItemDamage == 0))
|
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
a_ChunkInterface.SetBlockMeta(Vector3i(a_BlockPos), ++Meta);
|
|
|
|
// Give back an empty bottle when the gamemode is not creative:
|
2020-04-02 08:42:15 -04:00
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.ReplaceOneEquippedItemTossRest(cItem(E_ITEM_GLASS_BOTTLE));
|
|
|
|
}
|
|
|
|
}
|
2020-09-19 21:24:58 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_ITEM_LEATHER_BOOTS:
|
|
|
|
case E_ITEM_LEATHER_CAP:
|
|
|
|
case E_ITEM_LEATHER_PANTS:
|
|
|
|
case E_ITEM_LEATHER_TUNIC:
|
|
|
|
{
|
2020-09-20 10:39:17 -04:00
|
|
|
// Resets any color to default:
|
2020-09-19 21:24:58 -04:00
|
|
|
if ((Meta > 0) && ((EquippedItem.m_ItemColor.GetRed() != 255) || (EquippedItem.m_ItemColor.GetBlue() != 255) || (EquippedItem.m_ItemColor.GetGreen() != 255)))
|
|
|
|
{
|
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
|
|
|
|
auto NewItem = cItem(EquippedItem);
|
|
|
|
NewItem.m_ItemColor.Clear();
|
|
|
|
a_Player.ReplaceOneEquippedItemTossRest(NewItem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_BLACK_SHULKER_BOX:
|
|
|
|
case E_BLOCK_BLUE_SHULKER_BOX:
|
|
|
|
case E_BLOCK_BROWN_SHULKER_BOX:
|
|
|
|
case E_BLOCK_CYAN_SHULKER_BOX:
|
|
|
|
case E_BLOCK_GRAY_SHULKER_BOX:
|
|
|
|
case E_BLOCK_GREEN_SHULKER_BOX:
|
|
|
|
case E_BLOCK_LIGHT_BLUE_SHULKER_BOX:
|
|
|
|
case E_BLOCK_LIGHT_GRAY_SHULKER_BOX:
|
|
|
|
case E_BLOCK_LIME_SHULKER_BOX:
|
|
|
|
case E_BLOCK_MAGENTA_SHULKER_BOX:
|
|
|
|
case E_BLOCK_ORANGE_SHULKER_BOX:
|
|
|
|
case E_BLOCK_PINK_SHULKER_BOX:
|
|
|
|
case E_BLOCK_RED_SHULKER_BOX:
|
|
|
|
case E_BLOCK_YELLOW_SHULKER_BOX:
|
|
|
|
{
|
2020-09-20 10:39:17 -04:00
|
|
|
// Resets shulker box color.
|
|
|
|
|
2020-09-19 21:24:58 -04:00
|
|
|
// TODO: When there is an actual default shulker box add the appropriate changes here! - 19.09.2020 - 12xx12
|
|
|
|
if (Meta == 0)
|
|
|
|
{
|
|
|
|
// The cauldron is empty:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed with normal cleaning:
|
|
|
|
a_ChunkInterface.SetBlockMeta(a_BlockPos, --Meta);
|
|
|
|
auto NewShulker = cItem(EquippedItem);
|
|
|
|
NewShulker.m_ItemType = E_BLOCK_PURPLE_SHULKER_BOX;
|
|
|
|
a_Player.ReplaceOneEquippedItemTossRest(NewShulker);
|
2020-09-20 10:39:17 -04:00
|
|
|
|
2020-09-19 21:24:58 -04:00
|
|
|
break;
|
2020-04-02 08:42:15 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2020-09-20 10:39:17 -04:00
|
|
|
|
|
|
|
if (!ItemHandler(EquippedItem.m_ItemType)->IsPlaceable())
|
|
|
|
{
|
|
|
|
// Item not placeable in the first place, our work is done:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a workaround for versions < 1.13, where rclking a cauldron with a block, places a block.
|
|
|
|
// Using cauldrons with blocks was added in 1.13 as part of shulker cleaning.
|
|
|
|
const auto ResendPosition = AddFaceDirection(a_BlockPos, a_BlockFace);
|
|
|
|
a_Player.GetClientHandle()->SendBlockChange(
|
|
|
|
ResendPosition.x, ResendPosition.y, ResendPosition.z,
|
|
|
|
a_ChunkInterface.GetBlock(ResendPosition), a_ChunkInterface.GetBlockMeta(ResendPosition)
|
|
|
|
);
|
|
|
|
|
2015-12-01 17:12:44 -05:00
|
|
|
return true;
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual bool IsUseable() const override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-29 11:58:40 -04:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void OnUpdate(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cBlockPluginInterface & a_PluginInterface,
|
|
|
|
cChunk & a_Chunk,
|
|
|
|
const Vector3i a_RelPos
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2014-05-29 11:58:40 -04:00
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
auto WorldPos = a_Chunk.RelativeToAbsolute(a_RelPos);
|
|
|
|
if (!a_WorldInterface.IsWeatherWetAtXYZ(WorldPos.addedY(1)))
|
2014-05-29 11:58:40 -04:00
|
|
|
{
|
2014-06-14 05:14:04 -04:00
|
|
|
// It's not raining at our current location or we do not have a direct view of the sky
|
2014-05-29 11:58:40 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
auto Meta = a_Chunk.GetMeta(a_RelPos);
|
2014-05-29 11:58:40 -04:00
|
|
|
if (Meta < 3)
|
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
a_Chunk.SetMeta(a_RelPos, Meta + 1);
|
2014-05-29 11:58:40 -04:00
|
|
|
}
|
|
|
|
}
|
2015-06-30 10:50:15 -04:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 21;
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|