ItemHandler initialisation is a constant expression (#5344)
* Transition to non-pointer item handler * That is my destructor - I decide when I leave this world * I declare your destruction private and you final
This commit is contained in:
parent
1be14ebf7f
commit
3ff57559e3
@ -146,7 +146,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
if (!ItemHandler(EquippedItem.m_ItemType)->IsPlaceable())
|
||||
if (!EquippedItem.GetHandler().IsPlaceable())
|
||||
{
|
||||
// Item not placeable in the first place, our work is done:
|
||||
return true;
|
||||
|
@ -71,8 +71,8 @@ private:
|
||||
}
|
||||
|
||||
const auto Player = static_cast<const cPlayer *>(a_Digger);
|
||||
auto Handler = Player->GetEquippedItem().GetHandler();
|
||||
if (!Player->IsGameModeSurvival() || !Handler->CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
|
||||
auto & Handler = Player->GetEquippedItem().GetHandler();
|
||||
if (!Player->IsGameModeSurvival() || !Handler.CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ItemHandler(Player->GetEquippedItem().m_ItemType)->CanHarvestBlock(m_BlockType))
|
||||
if (!Player->GetEquippedItem().GetHandler().CanHarvestBlock(m_BlockType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -985,7 +985,7 @@ cItems cChunk::PickupsFromBlock(Vector3i a_RelPos, const cEntity * a_Digger, con
|
||||
cItems Pickups;
|
||||
const auto BlockEntity = GetBlockEntityRel(a_RelPos);
|
||||
|
||||
if ((a_Tool == nullptr) || a_Tool->GetHandler()->CanHarvestBlock(BlockType))
|
||||
if ((a_Tool == nullptr) || a_Tool->GetHandler().CanHarvestBlock(BlockType))
|
||||
{
|
||||
Pickups = cBlockHandler::For(BlockType).ConvertToPickups(BlockMeta, a_Tool);
|
||||
|
||||
|
@ -1164,8 +1164,8 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
|
||||
|
||||
case DIG_STATUS_SHOOT_EAT:
|
||||
{
|
||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
||||
if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage))
|
||||
auto & ItemHandler = m_Player->GetEquippedItem().GetHandler();
|
||||
if (ItemHandler.IsFood() || ItemHandler.IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage))
|
||||
{
|
||||
m_Player->AbortEating();
|
||||
return;
|
||||
@ -1180,9 +1180,12 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
|
||||
// When bow is in off-hand / shield slot
|
||||
if (m_Player->GetInventory().GetShieldSlot().m_ItemType == E_ITEM_BOW)
|
||||
{
|
||||
ItemHandler = cItemHandler::GetItemHandler(m_Player->GetInventory().GetShieldSlot());
|
||||
m_Player->GetInventory().GetShieldSlot().GetHandler().OnItemShoot(m_Player, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemHandler.OnItemShoot(m_Player, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
}
|
||||
ItemHandler->OnItemShoot(m_Player, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -1319,8 +1322,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
|
||||
cChunkInterface ChunkInterface(World->GetChunkMap());
|
||||
cBlockHandler::For(DiggingBlock).OnDigging(ChunkInterface, *World, *m_Player, {a_BlockX, a_BlockY, a_BlockZ});
|
||||
|
||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
||||
ItemHandler->OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
m_Player->GetEquippedItem().GetHandler().OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
}
|
||||
|
||||
|
||||
@ -1452,7 +1454,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
|
||||
// TODO: We are still consuming the items in main hand. Remove this override when the off-hand consumption is handled correctly.
|
||||
a_UsedMainHand = true;
|
||||
const cItem & HeldItem = a_UsedMainHand ? m_Player->GetEquippedItem() : m_Player->GetInventory().GetShieldSlot();
|
||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(HeldItem.m_ItemType);
|
||||
auto & ItemHandler = HeldItem.GetHandler();
|
||||
|
||||
// TODO: This distance should be calculated from the point that the cursor pointing at, instead of the center of the block
|
||||
// Distance from the block's center to the player's eye height
|
||||
@ -1480,7 +1482,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
|
||||
World->GetBlockTypeMeta(ClickedBlockPos, BlockType, BlockMeta);
|
||||
const auto & BlockHandler = cBlockHandler::For(BlockType);
|
||||
|
||||
bool Placeable = ItemHandler->IsPlaceable() && !m_Player->IsGameModeAdventure() && !m_Player->IsGameModeSpectator();
|
||||
bool Placeable = ItemHandler.IsPlaceable() && !m_Player->IsGameModeAdventure() && !m_Player->IsGameModeSpectator();
|
||||
bool BlockUsable = BlockHandler.IsUseable() && (!m_Player->IsGameModeSpectator() || cBlockInfo::IsUseableBySpectator(BlockType));
|
||||
|
||||
if (BlockUsable && !(m_Player->IsCrouched() && !HeldItem.IsEmpty()))
|
||||
@ -1499,7 +1501,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
|
||||
if (Placeable)
|
||||
{
|
||||
// Place a block:
|
||||
ItemHandler->OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ});
|
||||
ItemHandler.OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ});
|
||||
}
|
||||
|
||||
return;
|
||||
@ -1516,7 +1518,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
|
||||
}
|
||||
|
||||
// Place a block:
|
||||
ItemHandler->OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ});
|
||||
ItemHandler.OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ});
|
||||
return;
|
||||
}
|
||||
else if (!PlgMgr->CallHookPlayerUsingItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
|
||||
@ -1525,7 +1527,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
|
||||
// Use an item in hand with a target block.
|
||||
|
||||
cBlockInServerPluginInterface PluginInterface(*World);
|
||||
ItemHandler->OnItemUse(World, m_Player, PluginInterface, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
ItemHandler.OnItemUse(World, m_Player, PluginInterface, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||
PlgMgr->CallHookPlayerUsedItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
|
||||
return;
|
||||
}
|
||||
@ -1854,7 +1856,7 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand)
|
||||
// TODO: We are still consuming the items in main hand. Remove this override when the off-hand consumption is handled correctly.
|
||||
a_UsedMainHand = true;
|
||||
const cItem & HeldItem = a_UsedMainHand ? m_Player->GetEquippedItem() : m_Player->GetInventory().GetShieldSlot();
|
||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(HeldItem.m_ItemType);
|
||||
auto & ItemHandler = HeldItem.GetHandler();
|
||||
cWorld * World = m_Player->GetWorld();
|
||||
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
|
||||
|
||||
@ -1872,10 +1874,10 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand)
|
||||
return;
|
||||
}
|
||||
|
||||
if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(HeldItem.m_ItemDamage))
|
||||
if (ItemHandler.IsFood() || ItemHandler.IsDrinkable(HeldItem.m_ItemDamage))
|
||||
{
|
||||
if (
|
||||
ItemHandler->IsFood() &&
|
||||
ItemHandler.IsFood() &&
|
||||
(m_Player->IsSatiated() || m_Player->IsGameModeCreative()) && // Only non-creative or hungry players can eat
|
||||
(HeldItem.m_ItemType != E_ITEM_GOLDEN_APPLE) && // Golden apple is a special case, it is used instead of eaten
|
||||
(HeldItem.m_ItemType != E_ITEM_CHORUS_FRUIT) // Chorus fruit is a special case, it is used instead of eaten
|
||||
@ -1896,7 +1898,7 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand)
|
||||
{
|
||||
// All plugins agree with using the item
|
||||
cBlockInServerPluginInterface PluginInterface(*World);
|
||||
ItemHandler->OnItemUse(World, m_Player, PluginInterface, HeldItem, {-1, 255, -1}, BLOCK_FACE_NONE);
|
||||
ItemHandler.OnItemUse(World, m_Player, PluginInterface, HeldItem, {-1, 255, -1}, BLOCK_FACE_NONE);
|
||||
PlgMgr->CallHookPlayerUsedItem(*m_Player, -1, 255, -1, BLOCK_FACE_NONE, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
|
||||
{
|
||||
cPlayer * Player = static_cast<cPlayer *>(a_TDI.Attacker);
|
||||
|
||||
Player->GetEquippedItem().GetHandler()->OnEntityAttack(Player, this);
|
||||
Player->GetEquippedItem().GetHandler().OnEntityAttack(Player, this);
|
||||
|
||||
// Whether an enchantment boosted this attack's damage.
|
||||
bool MagicalCriticalHit = false;
|
||||
|
@ -525,12 +525,12 @@ void cPlayer::FinishEating(void)
|
||||
// consume the item:
|
||||
cItem Item(GetEquippedItem());
|
||||
Item.m_ItemCount = 1;
|
||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Item.m_ItemType);
|
||||
if (!ItemHandler->EatItem(this, &Item))
|
||||
auto & ItemHandler = Item.GetHandler();
|
||||
if (!ItemHandler.EatItem(this, &Item))
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemHandler->OnFoodEaten(m_World, this, &Item);
|
||||
ItemHandler.OnFoodEaten(m_World, this, &Item);
|
||||
}
|
||||
|
||||
|
||||
@ -2035,7 +2035,7 @@ void cPlayer::UseEquippedItem(cItemHandler::eDurabilityLostAction a_Action)
|
||||
cItem Item = GetEquippedItem();
|
||||
|
||||
// Get base damage for action type:
|
||||
short Dmg = cItemHandler::GetItemHandler(Item)->GetDurabilityLossByAction(a_Action);
|
||||
short Dmg = Item.GetHandler().GetDurabilityLossByAction(a_Action);
|
||||
|
||||
UseEquippedItem(Dmg);
|
||||
}
|
||||
@ -2613,10 +2613,10 @@ float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
|
||||
// Based on: https://minecraft.gamepedia.com/Breaking#Speed
|
||||
|
||||
// Get the base speed multiplier of the equipped tool for the mined block
|
||||
float MiningSpeed = GetEquippedItem().GetHandler()->GetBlockBreakingStrength(a_Block);
|
||||
float MiningSpeed = GetEquippedItem().GetHandler().GetBlockBreakingStrength(a_Block);
|
||||
|
||||
// If we can harvest the block then we can apply material and enchantment bonuses
|
||||
if (GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block))
|
||||
if (GetEquippedItem().GetHandler().CanHarvestBlock(a_Block))
|
||||
{
|
||||
if (MiningSpeed > 1.0f) // If the base multiplier for this block is greater than 1, now we can check enchantments
|
||||
{
|
||||
@ -2683,7 +2683,7 @@ float cPlayer::GetMiningProgressPerTick(BLOCKTYPE a_Block)
|
||||
return 1;
|
||||
}
|
||||
|
||||
const bool CanHarvest = GetEquippedItem().GetHandler()->CanHarvestBlock(a_Block);
|
||||
const bool CanHarvest = GetEquippedItem().GetHandler().CanHarvestBlock(a_Block);
|
||||
const float BlockHardness = cBlockInfo::GetHardness(a_Block) * (CanHarvest ? 1.5f : 5.0f);
|
||||
ASSERT(BlockHardness > 0); // Can't divide by 0 or less, IsOneHitDig should have returned true
|
||||
|
||||
|
@ -78,7 +78,7 @@ int cInventory::HowManyCanFit(const cItem & a_ItemStack, int a_BeginSlotNum, int
|
||||
}
|
||||
|
||||
char NumLeft = a_ItemStack.m_ItemCount;
|
||||
int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize();
|
||||
int MaxStack = a_ItemStack.GetMaxStackSize();
|
||||
for (int i = a_BeginSlotNum; i <= a_EndSlotNum; i++)
|
||||
{
|
||||
const cItem & Slot = GetSlot(i);
|
||||
@ -260,8 +260,7 @@ int cInventory::ReplaceOneEquippedItem(const cItem & a_Item, bool a_TryOtherSlot
|
||||
cItem ItemsToAdd = a_Item;
|
||||
if (EquippedItem.IsEqual(ItemsToAdd))
|
||||
{
|
||||
cItemHandler Handler(ItemsToAdd.m_ItemType);
|
||||
auto AmountToAdd = std::min(static_cast<char>(Handler.GetMaxStackSize() - EquippedItem.m_ItemCount), ItemsToAdd.m_ItemCount);
|
||||
auto AmountToAdd = std::min(static_cast<char>(ItemsToAdd.GetMaxStackSize() - EquippedItem.m_ItemCount), ItemsToAdd.m_ItemCount);
|
||||
|
||||
EquippedItem.m_ItemCount += AmountToAdd;
|
||||
SetEquippedItem(EquippedItem);
|
||||
@ -689,7 +688,7 @@ void cInventory::UpdateItems(void)
|
||||
const cItem & Slot = GetEquippedItem();
|
||||
if (!Slot.IsEmpty())
|
||||
{
|
||||
ItemHandler(Slot.m_ItemType)->OnUpdate(m_Owner.GetWorld(), &m_Owner, Slot);
|
||||
Slot.GetHandler().OnUpdate(m_Owner.GetWorld(), &m_Owner, Slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ bool cItem::DamageItem(short a_Amount)
|
||||
|
||||
bool cItem::IsFullStack(void) const
|
||||
{
|
||||
return (m_ItemCount >= ItemHandler(m_ItemType)->GetMaxStackSize());
|
||||
return (m_ItemCount >= GetMaxStackSize());
|
||||
}
|
||||
|
||||
|
||||
@ -206,16 +206,16 @@ bool cItem::IsFullStack(void) const
|
||||
|
||||
char cItem::GetMaxStackSize(void) const
|
||||
{
|
||||
return ItemHandler(m_ItemType)->GetMaxStackSize();
|
||||
return cItemHandler::For(m_ItemType).GetMaxStackSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cItemHandler * cItem::GetHandler(void) const
|
||||
const cItemHandler & cItem::GetHandler(void) const
|
||||
{
|
||||
return ItemHandler(m_ItemType);
|
||||
return cItemHandler::For(m_ItemType);
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,7 +124,7 @@ public:
|
||||
// tolua_end
|
||||
|
||||
/** Returns the cItemHandler responsible for this item type */
|
||||
cItemHandler * GetHandler(void) const;
|
||||
const cItemHandler & GetHandler(void) const;
|
||||
|
||||
/** Saves the item data into JSON representation */
|
||||
void GetJson(Json::Value & a_OutValue) const;
|
||||
|
@ -246,7 +246,7 @@ void cItemGrid::Clear(void)
|
||||
int cItemGrid::HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks)
|
||||
{
|
||||
int NumLeft = a_ItemStack.m_ItemCount;
|
||||
int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize();
|
||||
int MaxStack = a_ItemStack.GetMaxStackSize();
|
||||
|
||||
if (!m_Slots.IsStorageAllocated())
|
||||
{
|
||||
@ -491,10 +491,9 @@ int cItemGrid::ChangeSlotCount(int a_SlotNum, int a_AddToCount)
|
||||
|
||||
m_Slots[a_SlotNum].m_ItemCount += a_AddToCount;
|
||||
|
||||
cItemHandler * Handler = cItemHandler::GetItemHandler(m_Slots[a_SlotNum].m_ItemType);
|
||||
if (m_Slots[a_SlotNum].m_ItemCount > Handler->GetMaxStackSize())
|
||||
if (m_Slots[a_SlotNum].m_ItemCount > m_Slots[a_SlotNum].GetMaxStackSize())
|
||||
{
|
||||
m_Slots[a_SlotNum].m_ItemCount = Handler->GetMaxStackSize();
|
||||
m_Slots[a_SlotNum].m_ItemCount = m_Slots[a_SlotNum].GetMaxStackSize();
|
||||
}
|
||||
|
||||
TriggerListeners(a_SlotNum);
|
||||
|
@ -19,6 +19,7 @@ target_sources(
|
||||
ItemCloth.h
|
||||
ItemComparator.h
|
||||
ItemCookedFish.h
|
||||
ItemDefaultItem.h
|
||||
ItemDoor.h
|
||||
ItemDropSpenser.h
|
||||
ItemDye.h
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemAnvilHandler :
|
||||
class cItemAnvilHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(
|
||||
a_PlacePosition,
|
||||
|
@ -8,17 +8,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemArmorHandler:
|
||||
class cItemArmorHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemArmorHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
int SlotNum;
|
||||
if (ItemCategory::IsHelmet(a_HeldItem.m_ItemType))
|
||||
@ -71,7 +68,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
|
@ -8,21 +8,18 @@
|
||||
|
||||
|
||||
|
||||
class cItemAxeHandler:
|
||||
class cItemAxeHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemAxeHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||
{
|
||||
switch (a_Action)
|
||||
{
|
||||
@ -35,7 +32,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
|
||||
{
|
||||
if (!IsBlockMaterialWood(a_Block) && !IsBlockMaterialPlants(a_Block) && !IsBlockMaterialVine(a_Block))
|
||||
{
|
||||
|
@ -12,21 +12,18 @@
|
||||
|
||||
|
||||
|
||||
class cItemBannerHandler:
|
||||
class cItemBannerHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBannerHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Cannot place a banner at "no face" and from the bottom:
|
||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_BOTTOM))
|
||||
@ -54,7 +51,7 @@ private:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -9,20 +9,17 @@
|
||||
|
||||
|
||||
|
||||
class cItemBedHandler:
|
||||
class cItemBedHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBedHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
const auto BlockMeta = cBlockBedHandler::YawToMetaData(a_Player.GetYaw());
|
||||
const auto HeadPosition = a_PlacePosition + cBlockBedHandler::MetaDataToDirection(BlockMeta);
|
||||
@ -65,7 +62,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -8,23 +8,16 @@
|
||||
|
||||
|
||||
|
||||
class cItemBigFlowerHandler:
|
||||
class cItemBigFlowerHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBigFlowerHandler():
|
||||
Super(E_BLOCK_BIG_FLOWER)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Needs at least two free blocks to build in:
|
||||
if (a_PlacePosition.y >= (cChunkDef::Height - 1))
|
||||
|
@ -8,17 +8,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemBoatHandler:
|
||||
class cItemBoatHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBoatHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -31,7 +28,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// Only allow placing blocks on top of blocks, or when not in range of dest block:
|
||||
if ((a_ClickedBlockFace != BLOCK_FACE_YM) && (a_ClickedBlockFace != BLOCK_FACE_NONE))
|
||||
|
@ -9,17 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemBottleHandler:
|
||||
class cItemBottleHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBottleHandler():
|
||||
Super(E_ITEM_GLASS_BOTTLE)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -28,7 +25,7 @@ public:
|
||||
/** Searches for a water source block in the line of sight.
|
||||
Returns true and sets a_BlockPos if a water source block is found within line-of-sight.
|
||||
Returns false if not. */
|
||||
bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos)
|
||||
bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos) const
|
||||
{
|
||||
class cCallbacks:
|
||||
public cBlockTracer::cCallbacks
|
||||
@ -81,7 +78,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
||||
{
|
||||
|
@ -8,17 +8,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemBowHandler:
|
||||
class cItemBowHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBowHandler(void):
|
||||
Super(E_ITEM_BOW)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -31,7 +28,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
ASSERT(a_Player != nullptr);
|
||||
|
||||
@ -47,7 +44,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual void OnItemShoot(cPlayer * a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) override
|
||||
virtual void OnItemShoot(cPlayer * a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const override
|
||||
{
|
||||
// Actual shot - produce the arrow with speed based on the number of ticks that the bow was charged
|
||||
UNUSED(a_BlockPos);
|
||||
|
@ -13,14 +13,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemBucketHandler :
|
||||
class cItemBucketHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBucketHandler(int a_ItemType):
|
||||
constexpr cItemBucketHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
|
||||
@ -37,7 +37,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
@ -56,7 +56,7 @@ public:
|
||||
|
||||
|
||||
|
||||
bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace)
|
||||
bool ScoopUpFluid(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, const Vector3i a_ClickedBlockPos, eBlockFace a_ClickedBlockFace) const
|
||||
{
|
||||
// Players can't pick up fluid while in adventure mode.
|
||||
if (a_Player->IsGameModeAdventure())
|
||||
@ -127,7 +127,7 @@ public:
|
||||
bool PlaceFluid(
|
||||
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
||||
const Vector3i a_BlockPos, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock
|
||||
)
|
||||
) const
|
||||
{
|
||||
// Players can't place fluid while in adventure mode.
|
||||
if (a_Player->IsGameModeAdventure())
|
||||
@ -182,7 +182,7 @@ public:
|
||||
|
||||
|
||||
|
||||
bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos)
|
||||
bool GetBlockFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos) const
|
||||
{
|
||||
class cCallbacks :
|
||||
public cBlockTracer::cCallbacks
|
||||
@ -233,7 +233,7 @@ public:
|
||||
|
||||
|
||||
|
||||
bool GetPlacementCoordsFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta, eBlockFace & a_BlockFace)
|
||||
bool GetPlacementCoordsFromTrace(cWorld * a_World, cPlayer * a_Player, Vector3i & a_BlockPos, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta, eBlockFace & a_BlockFace) const
|
||||
{
|
||||
class cCallbacks :
|
||||
public cBlockTracer::cCallbacks
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemButtonHandler :
|
||||
class cItemButtonHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -38,7 +38,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), BlockFaceToMetaData(a_ClickedBlockFace));
|
||||
}
|
||||
|
@ -8,23 +8,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemChestHandler:
|
||||
class cItemChestHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemChestHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
cItemChestHandler(const cItemChestHandler &) = delete;
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Check that there is at most one single neighbor of the same chest type:
|
||||
static const Vector3i CrossCoords[] =
|
||||
|
@ -8,19 +8,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemChorusFruitHandler:
|
||||
class cItemChorusFruitHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemChorusFruitHandler():
|
||||
Super(E_ITEM_CHORUS_FRUIT, FoodInfo(4, 2.4))
|
||||
constexpr cItemChorusFruitHandler(int a_ItemType) :
|
||||
Super(a_ItemType, FoodInfo(4, 2.4))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
cItemHandler::EatItem(a_Player, a_Item);
|
||||
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
|
||||
|
||||
class cItemClothHandler :
|
||||
class cItemClothHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
public:
|
||||
cItemClothHandler(int a_ItemType)
|
||||
constexpr cItemClothHandler(int a_ItemType)
|
||||
: cItemHandler(a_ItemType)
|
||||
{
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemComparatorHandler:
|
||||
class cItemComparatorHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -24,7 +24,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_INACTIVE_COMPARATOR, cBlockComparatorHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
@ -33,7 +33,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemCookedFishHandler:
|
||||
class cItemCookedFishHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemCookedFishHandler():
|
||||
Super(E_ITEM_COOKED_FISH, FoodInfo(0, 0))
|
||||
constexpr cItemCookedFishHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(0, 0))
|
||||
{
|
||||
}
|
||||
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
|
||||
{
|
||||
static const FoodInfo CookedFishInfos[] =
|
||||
{
|
||||
|
9
src/Items/ItemDefaultItem.h
Normal file
9
src/Items/ItemDefaultItem.h
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#include "ItemHandler.h"
|
||||
|
||||
class cDefaultItemHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
public:
|
||||
using cItemHandler::cItemHandler;
|
||||
};
|
@ -9,14 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemDoorHandler:
|
||||
class cItemDoorHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemDoorHandler(int a_ItemType):
|
||||
constexpr cItemDoorHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
|
||||
@ -25,7 +25,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Vanilla only allows door placement while clicking on the top face of the block below the door:
|
||||
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
||||
@ -109,7 +109,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemDropSpenserHandler :
|
||||
class cItemDropSpenserHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockDropSpenserHandler::DisplacementYawToMetaData(a_PlacePosition, a_Player.GetEyePosition(), a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -10,16 +10,13 @@
|
||||
|
||||
|
||||
|
||||
class cItemDyeHandler :
|
||||
class cItemDyeHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
cItemDyeHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
if ((a_HeldItem.m_ItemDamage == E_META_DYE_WHITE) && (a_ClickedBlockFace != BLOCK_FACE_NONE))
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemEmptyMapHandler:
|
||||
class cItemEmptyMapHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -16,10 +16,7 @@ class cItemEmptyMapHandler:
|
||||
|
||||
public:
|
||||
|
||||
cItemEmptyMapHandler():
|
||||
Super(E_ITEM_EMPTY_MAP)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
UNUSED(a_HeldItem);
|
||||
UNUSED(a_ClickedBlockFace);
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemEnchantingTableHandler:
|
||||
class cItemEnchantingTableHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -20,7 +20,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
if (!Super::CommitPlacement(a_Player, a_HeldItem, a_PlacePosition, a_ClickedBlockFace, a_CursorPosition))
|
||||
{
|
||||
@ -44,7 +44,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -9,14 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemEndCrystalHandler :
|
||||
class cItemEndCrystalHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemEndCrystalHandler(int a_ItemType) :
|
||||
constexpr cItemEndCrystalHandler(int a_ItemType) :
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
@ -26,7 +26,7 @@ public:
|
||||
cWorld * a_World, cPlayer * a_Player,
|
||||
cBlockPluginInterface & a_PluginInterface, const cItem & a_HeldItem,
|
||||
const Vector3i a_BlockPos,
|
||||
eBlockFace a_ClickedBlockFace) override
|
||||
eBlockFace a_ClickedBlockFace) const override
|
||||
{
|
||||
// Must click a valid block:
|
||||
if (a_ClickedBlockFace < 0)
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemEndPortalFrameHandler :
|
||||
class cItemEndPortalFrameHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_END_PORTAL_FRAME, cBlockEndPortalFrameHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemEnderchestHandler :
|
||||
class cItemEnderchestHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_ENDER_CHEST, cBlockEnderchestHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -8,15 +8,15 @@
|
||||
|
||||
|
||||
|
||||
class cItemEyeOfEnderHandler:
|
||||
class cItemEyeOfEnderHandler final:
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
using Super = cItemThrowableHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemEyeOfEnderHandler():
|
||||
Super(E_ITEM_EYE_OF_ENDER, cProjectileEntity::pkSnowball, 30)
|
||||
constexpr cItemEyeOfEnderHandler(int a_ItemType):
|
||||
Super(a_ItemType, cProjectileEntity::pkSnowball, 30)
|
||||
{
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ public:
|
||||
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// Try to fill an End Portal Frame block:
|
||||
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemFenceGateHandler :
|
||||
class cItemFenceGateHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockFenceGateHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -49,17 +49,14 @@ protected:
|
||||
|
||||
|
||||
|
||||
class cItemFishingRodHandler:
|
||||
class cItemFishingRodHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemFishingRodHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -72,7 +69,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
||||
{
|
||||
@ -108,7 +105,7 @@ public:
|
||||
|
||||
|
||||
/** Reels back the fishing line, reeling any attached mob, or creating fished loot, or just breaking the fishing rod. */
|
||||
void ReelIn(cWorld & a_World, cPlayer & a_Player)
|
||||
void ReelIn(cWorld & a_World, cPlayer & a_Player) const
|
||||
{
|
||||
cFloaterCallback FloaterInfo;
|
||||
a_World.DoWithEntityByID(a_Player.GetFloaterID(), FloaterInfo);
|
||||
@ -140,7 +137,7 @@ public:
|
||||
|
||||
|
||||
/** Reels back the entity, specified by the ID, and damages the fishing rod accordingly. */
|
||||
void ReelInEntity(cWorld & a_World, cPlayer & a_Player, UInt32 a_EntityID)
|
||||
void ReelInEntity(cWorld & a_World, cPlayer & a_Player, UInt32 a_EntityID) const
|
||||
{
|
||||
auto PlayerPos = a_Player.GetPosition();
|
||||
a_World.DoWithEntityByID(a_EntityID, [=](cEntity & a_Entity)
|
||||
@ -157,7 +154,7 @@ public:
|
||||
|
||||
|
||||
|
||||
void ReelInLoot(cWorld & a_World, cPlayer & a_Player, const Vector3d a_FloaterBitePos)
|
||||
void ReelInLoot(cWorld & a_World, cPlayer & a_Player, const Vector3d a_FloaterBitePos) const
|
||||
{
|
||||
auto LotSLevel = std::min(a_Player.GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchLuckOfTheSea), 3u);
|
||||
|
||||
|
@ -14,25 +14,25 @@ class cItemFoodHandler:
|
||||
|
||||
public:
|
||||
|
||||
cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||
constexpr cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||
Super(a_ItemType),
|
||||
m_FoodInfo(a_FoodInfo)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsFood(void) override
|
||||
virtual bool IsFood(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
|
||||
{
|
||||
UNUSED(a_Item);
|
||||
return m_FoodInfo;
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
@ -50,8 +50,11 @@ public:
|
||||
protected:
|
||||
FoodInfo m_FoodInfo;
|
||||
|
||||
~cItemFoodHandler() = default;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemSimpleFoodHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using cItemFoodHandler::cItemFoodHandler;
|
||||
};
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemFoodSeedsHandler:
|
||||
class cItemFoodSeedsHandler final:
|
||||
public cItemSeedsHandler
|
||||
{
|
||||
using Super = cItemSeedsHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemFoodSeedsHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||
constexpr cItemFoodSeedsHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||
Super(a_ItemType),
|
||||
m_FoodInfo(a_FoodInfo)
|
||||
{
|
||||
@ -23,18 +23,18 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsFood(void) override
|
||||
virtual bool IsFood(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
|
||||
{
|
||||
UNUSED(a_Item);
|
||||
return m_FoodInfo;
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemFurnaceHandler :
|
||||
class cItemFurnaceHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_FURNACE, cBlockFurnaceHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemGlazedTerracottaHandler :
|
||||
class cItemGlazedTerracottaHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockGlazedTerracottaHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemGoldenAppleHandler:
|
||||
class cItemGoldenAppleHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemGoldenAppleHandler():
|
||||
Super(E_ITEM_GOLDEN_APPLE, FoodInfo(4, 9.6))
|
||||
constexpr cItemGoldenAppleHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(4, 9.6))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
cItemHandler::EatItem(a_Player, a_Item);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,8 @@ class cItemHandler
|
||||
{
|
||||
public:
|
||||
|
||||
friend class cItem;
|
||||
|
||||
/** Actions that may cause durability of an item may be lost, where the
|
||||
magnitude of the loss depends on the specific item used to perform the
|
||||
action */
|
||||
@ -32,10 +34,10 @@ public:
|
||||
dlaBreakBlockInstant,
|
||||
};
|
||||
|
||||
cItemHandler(int a_ItemType);
|
||||
constexpr cItemHandler(int a_ItemType) : m_ItemType(a_ItemType)
|
||||
{
|
||||
}
|
||||
|
||||
/** Force virtual destructor */
|
||||
virtual ~cItemHandler() {}
|
||||
|
||||
/** Called when the player tries to place the item (right mouse button, IsPlaceable() == true).
|
||||
a_ClickedBlockPos is the (neighbor) block that has been clicked to place this item.
|
||||
@ -44,7 +46,7 @@ public:
|
||||
The default handler uses GetBlocksToPlace() and places the returned blocks.
|
||||
Override if the item needs advanced processing, such as spawning a mob based on the blocks being placed.
|
||||
If the block placement is refused inside this call, it will automatically revert the client-side changes. */
|
||||
void OnPlayerPlace(cPlayer & a_Player, const cItem & a_HeldItem, Vector3i a_ClickedBlockPosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition);
|
||||
void OnPlayerPlace(cPlayer & a_Player, const cItem & a_HeldItem, Vector3i a_ClickedBlockPosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition) const;
|
||||
|
||||
/** Called when the player tries to use the item (right mouse button).
|
||||
Descendants can return false to abort the usage (default behavior). */
|
||||
@ -55,17 +57,17 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
);
|
||||
) const;
|
||||
|
||||
/** Called when the client sends the SHOOT status in the lclk packet (releasing the bow). */
|
||||
virtual void OnItemShoot(cPlayer *, const Vector3i a_BlockPos, eBlockFace a_BlockFace)
|
||||
virtual void OnItemShoot(cPlayer *, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const
|
||||
{
|
||||
UNUSED(a_BlockPos);
|
||||
UNUSED(a_BlockFace);
|
||||
}
|
||||
|
||||
/** Called every tick while the item is on the player's inventory (used by maps, for example) - For now, called only for equipped items */
|
||||
virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item)
|
||||
virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) const
|
||||
{
|
||||
UNUSED(a_World);
|
||||
UNUSED(a_Player);
|
||||
@ -77,28 +79,28 @@ public:
|
||||
cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
);
|
||||
) const;
|
||||
|
||||
/** Called when a player attacks an entity with this item in hand. */
|
||||
virtual void OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity);
|
||||
virtual void OnEntityAttack(cPlayer * a_Attacker, cEntity * a_AttackedEntity) const;
|
||||
|
||||
/** Called after the player has eaten this item. */
|
||||
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item);
|
||||
virtual void OnFoodEaten(cWorld *a_World, cPlayer *a_Player, cItem *a_Item) const;
|
||||
|
||||
/** Get the durability lost which the item will get, when a specified action
|
||||
was performed. This is only relevant for uses where the damage taken may
|
||||
depend on the item used. */
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action);
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const;
|
||||
|
||||
/** Returns the maximum stack size for a given item */
|
||||
virtual char GetMaxStackSize(void);
|
||||
virtual char GetMaxStackSize(void) const;
|
||||
|
||||
struct FoodInfo
|
||||
{
|
||||
int FoodLevel;
|
||||
double Saturation;
|
||||
|
||||
FoodInfo(int a_FoodLevel, double a_Saturation) :
|
||||
constexpr FoodInfo(int a_FoodLevel, double a_Saturation) :
|
||||
FoodLevel(a_FoodLevel),
|
||||
Saturation(a_Saturation)
|
||||
{
|
||||
@ -106,53 +108,44 @@ public:
|
||||
} ;
|
||||
|
||||
/** Returns the FoodInfo for this item. (FoodRecovery and Saturation) */
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item);
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const;
|
||||
|
||||
/** Lets the player eat a selected item. Returns true if the player ate the item */
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item);
|
||||
|
||||
/** Indicates if this item is a tool */
|
||||
virtual bool IsTool(void);
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const;
|
||||
|
||||
/** Indicates if this item is food */
|
||||
virtual bool IsFood(void);
|
||||
virtual bool IsFood(void) const;
|
||||
|
||||
/** Indicates if this item is drinkable */
|
||||
virtual bool IsDrinkable(short a_ItemDamage);
|
||||
virtual bool IsDrinkable(short a_ItemDamage) const;
|
||||
|
||||
/** Blocks simply get placed */
|
||||
virtual bool IsPlaceable(void);
|
||||
virtual bool IsPlaceable(void) const;
|
||||
|
||||
/** Can the anvil repair this item, when a_Item is the second input? */
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType);
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) const;
|
||||
|
||||
/** Returns whether this tool / item can harvest a specific block (e.g. iron pickaxe can harvest diamond ore, but wooden one can't).
|
||||
Defaults to false unless overridden. */
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType);
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const;
|
||||
|
||||
/** Returns the strength to break a specific block.
|
||||
Defaults to 1 unless overriden. */
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block);
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const;
|
||||
|
||||
static cItemHandler * GetItemHandler(int a_ItemType);
|
||||
static cItemHandler * GetItemHandler(const cItem & a_Item) { return GetItemHandler(a_Item.m_ItemType); }
|
||||
|
||||
static void Deinit();
|
||||
|
||||
protected:
|
||||
|
||||
int m_ItemType;
|
||||
static cItemHandler * CreateItemHandler(int m_ItemType);
|
||||
static const cItemHandler & For(int a_ItemType);
|
||||
|
||||
~cItemHandler() = default;
|
||||
|
||||
const int m_ItemType;
|
||||
|
||||
/** Performs the actual placement of this placeable item.
|
||||
The descendant handler should call a_Player.PlaceBlock(s) supplying correct values for the newly placed block.
|
||||
The default handler uses the stored block type and meta copied from the lowest 4 bits of the player's equipped item's damage value.
|
||||
Handlers return what a_Player.PlaceBlock(s) returns, indicating whether the placement was successful. */
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition);
|
||||
|
||||
static cItemHandler * m_ItemHandler[E_ITEM_LAST + 1];
|
||||
static bool m_HandlerInitialized; // used to detect if the itemhandlers are initialized
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition) const;
|
||||
};
|
||||
|
||||
// Short function
|
||||
inline cItemHandler *ItemHandler(int a_ItemType) { return cItemHandler::GetItemHandler(a_ItemType); }
|
||||
|
@ -9,17 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemHoeHandler:
|
||||
class cItemHoeHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemHoeHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockPos.y >= cChunkDef::Height))
|
||||
{
|
||||
@ -71,7 +68,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||
{
|
||||
switch (a_Action)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemHopperHandler :
|
||||
class cItemHopperHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -33,7 +33,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_HOPPER, BlockFaceToMetaData(a_ClickedBlockFace));
|
||||
}
|
||||
|
@ -9,17 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemItemFrameHandler:
|
||||
class cItemItemFrameHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemItemFrameHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// Can only place on a side face:
|
||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_YP) || (a_ClickedBlockFace == BLOCK_FACE_YM))
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemJackOLanternHandler :
|
||||
class cItemJackOLanternHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Re-use the pumpkin converter for lanterns:
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_JACK_O_LANTERN, cBlockPumpkinHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemLadderHandler :
|
||||
class cItemLadderHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -35,7 +35,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
const auto & World = *a_Player.GetWorld();
|
||||
const auto ClickedBlockType = World.GetBlock(AddFaceDirection(a_PlacePosition, a_ClickedBlockFace, true));
|
||||
|
@ -7,23 +7,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemLeavesHandler:
|
||||
class cItemLeavesHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemLeavesHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(
|
||||
a_PlacePosition,
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemLeverHandler :
|
||||
class cItemLeverHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -36,7 +36,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), BlockFaceToMetaData(a_ClickedBlockFace));
|
||||
}
|
||||
|
@ -9,17 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemLighterHandler:
|
||||
class cItemLighterHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemLighterHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
if (a_ClickedBlockFace < 0)
|
||||
{
|
||||
|
@ -9,14 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemLilypadHandler:
|
||||
class cItemLilypadHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemLilypadHandler(int a_ItemType):
|
||||
constexpr cItemLilypadHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return false; // Set as not placeable so OnItemUse is called
|
||||
}
|
||||
@ -42,7 +42,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// The client sends BLOCK_FACE_NONE when it determines it should do a tracing-based placement.
|
||||
// Otherwise, a normal block face is sent.
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemMapHandler:
|
||||
class cItemMapHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -16,12 +16,9 @@ class cItemMapHandler:
|
||||
|
||||
public:
|
||||
|
||||
cItemMapHandler():
|
||||
Super(E_ITEM_MAP)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) override
|
||||
virtual void OnUpdate(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item) const override
|
||||
{
|
||||
cMap * Map = a_World->GetMapManager().GetMapData(static_cast<unsigned>(a_Item.m_ItemDamage));
|
||||
|
||||
|
@ -5,25 +5,22 @@
|
||||
|
||||
|
||||
|
||||
class cItemMilkHandler:
|
||||
class cItemMilkHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemMilkHandler():
|
||||
Super(E_ITEM_MILK)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
virtual bool IsDrinkable(short a_ItemDamage) override
|
||||
virtual bool IsDrinkable(short a_ItemDamage) const override
|
||||
{
|
||||
UNUSED(a_ItemDamage);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
UNUSED(a_Item);
|
||||
a_Player->ClearEntityEffects();
|
||||
|
@ -5,17 +5,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemMinecartHandler:
|
||||
class cItemMinecartHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemMinecartHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -28,7 +25,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// Must be used on a block
|
||||
if (a_ClickedBlockFace < 0)
|
||||
|
@ -9,23 +9,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemMobHeadHandler:
|
||||
class cItemMobHeadHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemMobHeadHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Cannot place a head at "no face" and from the bottom:
|
||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_BOTTOM))
|
||||
@ -58,7 +55,7 @@ public:
|
||||
|
||||
/** Called after placing a regular head block with no mob spawning.
|
||||
Adjusts the mob head entity based on the equipped item's data. */
|
||||
void RegularHeadPlaced(const cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace)
|
||||
void RegularHeadPlaced(const cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace) const
|
||||
{
|
||||
const auto HeadType = static_cast<eMobHeadType>(a_HeldItem.m_ItemDamage);
|
||||
const auto BlockMeta = static_cast<NIBBLETYPE>(a_ClickedBlockFace);
|
||||
@ -88,7 +85,7 @@ public:
|
||||
|
||||
/** Spawns a wither if the wither skull placed at the specified coords completes wither's spawning formula.
|
||||
Returns true if the wither was created. */
|
||||
bool TrySpawnWitherAround(cPlayer & a_Player, const Vector3i a_BlockPos)
|
||||
bool TrySpawnWitherAround(cPlayer & a_Player, const Vector3i a_BlockPos) const
|
||||
{
|
||||
// No wither can be created at Y < 2 - not enough space for the formula:
|
||||
if (a_BlockPos.y < 2)
|
||||
@ -131,7 +128,7 @@ public:
|
||||
cWorld & a_World, cPlayer & a_Player,
|
||||
Vector3i a_PlacedHeadPos,
|
||||
int a_OffsetX, int a_OffsetZ
|
||||
)
|
||||
) const
|
||||
{
|
||||
// Image for the wither at the X axis:
|
||||
static const sSetBlock ImageWitherX[] =
|
||||
@ -189,7 +186,7 @@ public:
|
||||
cWorld & a_World, cPlayer & a_Player, const sSetBlock (& a_Image)[9],
|
||||
Vector3i a_PlacedHeadPos,
|
||||
int a_OffsetX, int a_OffsetZ
|
||||
)
|
||||
) const
|
||||
{
|
||||
std::array<Vector3i, 9> PositionsToClear;
|
||||
|
||||
@ -280,7 +277,7 @@ public:
|
||||
|
||||
|
||||
/** Awards the achievement to all players close to the specified point. */
|
||||
void AwardSpawnWitherAchievement(cWorld & a_World, Vector3i a_BlockPos)
|
||||
void AwardSpawnWitherAchievement(cWorld & a_World, Vector3i a_BlockPos) const
|
||||
{
|
||||
Vector3f Pos(a_BlockPos);
|
||||
a_World.ForEachPlayer([=](cPlayer & a_Player)
|
||||
@ -323,7 +320,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -8,23 +8,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemNetherWartHandler:
|
||||
class cItemNetherWartHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemNetherWartHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Only allow planting nether wart onto the top side of the block:
|
||||
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
||||
@ -39,7 +36,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemObserverHandler :
|
||||
class cItemObserverHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_OBSERVER, cBlockObserverHandler::DisplacementYawToMetaData(a_PlacePosition, a_Player.GetEyePosition(), a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -10,17 +10,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemPaintingHandler:
|
||||
class cItemPaintingHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemPaintingHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -33,7 +30,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// Paintings can't be flatly placed:
|
||||
if (
|
||||
|
@ -5,14 +5,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemPickaxeHandler:
|
||||
class cItemPickaxeHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemPickaxeHandler(int a_ItemType):
|
||||
constexpr cItemPickaxeHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
|
||||
@ -20,7 +20,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||
{
|
||||
switch (a_Action)
|
||||
{
|
||||
@ -33,7 +33,7 @@ public:
|
||||
|
||||
|
||||
|
||||
char PickaxeLevel()
|
||||
char PickaxeLevel() const
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
@ -47,7 +47,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
|
||||
{
|
||||
// NOTICE: Make sure to update cItemHandler::CanHarvestBlock() if adding new blocks here!
|
||||
switch (a_BlockType)
|
||||
@ -155,7 +155,7 @@ public:
|
||||
return Super::CanHarvestBlock(a_BlockType);
|
||||
}
|
||||
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
@ -169,7 +169,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
|
||||
{
|
||||
if (!IsBlockMaterialIron(a_Block) && (a_Block != E_BLOCK_ANVIL) && !IsBlockMaterialRock(a_Block))
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemPistonHandler :
|
||||
class cItemPistonHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockPistonHandler::DisplacementYawToMetaData(a_PlacePosition, a_Player.GetEyePosition(), a_Player.GetYaw()));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemPlanksHandler :
|
||||
class cItemPlanksHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -18,7 +18,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), static_cast<NIBBLETYPE>(a_HeldItem.m_ItemDamage));
|
||||
}
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemPoisonousPotatoHandler:
|
||||
class cItemPoisonousPotatoHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemPoisonousPotatoHandler():
|
||||
Super(E_ITEM_POISONOUS_POTATO, FoodInfo(2, 1.2))
|
||||
constexpr cItemPoisonousPotatoHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(2, 1.2))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
|
@ -4,24 +4,21 @@
|
||||
#include "../Entities/EntityEffect.h"
|
||||
|
||||
|
||||
class cItemPotionHandler:
|
||||
class cItemPotionHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemPotionHandler():
|
||||
Super(E_ITEM_POTION)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// cItemHandler overrides:
|
||||
virtual bool IsDrinkable(short a_ItemDamage) override
|
||||
virtual bool IsDrinkable(short a_ItemDamage) const override
|
||||
{
|
||||
// Drinkable potion if 13th lowest bit is set
|
||||
// Ref.: https://minecraft.gamepedia.com/Potions#Data_value_table
|
||||
@ -39,7 +36,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
short PotionDamage = a_HeldItem.m_ItemDamage;
|
||||
|
||||
@ -72,7 +69,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
short PotionDamage = a_Item->m_ItemDamage;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemPumpkinHandler:
|
||||
class cItemPumpkinHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// First try spawning a snow golem or an iron golem:
|
||||
if (TrySpawnGolem(a_Player, a_PlacePosition))
|
||||
@ -39,7 +39,7 @@ private:
|
||||
|
||||
/** Spawns a snow / iron golem if the shape matches the recipe, supposing that the block placed at the specified coords is a pumpkin.
|
||||
Returns true if the golem blocks are removed (for spawning), false if the recipe is not matched. */
|
||||
bool TrySpawnGolem(cPlayer & a_Player, const Vector3i a_PumpkinPos)
|
||||
bool TrySpawnGolem(cPlayer & a_Player, const Vector3i a_PumpkinPos) const
|
||||
{
|
||||
// A golem can't form with a pumpkin below level 2 or above level 255:
|
||||
if ((a_PumpkinPos.y < 2) || (a_PumpkinPos.y >= cChunkDef::Height))
|
||||
@ -69,7 +69,7 @@ private:
|
||||
/** Spawns a snow golem if the shape matches the recipe, supposing that the block placed at the specified coords is a pumpkin.
|
||||
Returns true if the golem blocks are removed (for spawning), false if the recipe is not matched.
|
||||
Assumes that the block below the specified block has already been checked and is a snow block. */
|
||||
bool TrySpawnSnowGolem(cWorld & a_World, cPlayer & a_Player, const Vector3i a_PumpkinPos)
|
||||
bool TrySpawnSnowGolem(cWorld & a_World, cPlayer & a_Player, const Vector3i a_PumpkinPos) const
|
||||
{
|
||||
ASSERT(a_PumpkinPos.y > 1);
|
||||
ASSERT(a_World.GetBlock(a_PumpkinPos.addedY(-1)) == E_BLOCK_SNOW_BLOCK);
|
||||
@ -106,7 +106,7 @@ private:
|
||||
/** Spawns an iron golem if the shape matches the recipe, supposing that the block placed at the specified coords is a pumpkin.
|
||||
Returns true if the golem blocks are removed (for spawning), false if the recipe is not matched.
|
||||
Assumes that the block below the specified block has already been checked and is an iron block. */
|
||||
bool TrySpawnIronGolem(cWorld & a_World, cPlayer & a_Player, const Vector3i a_PumpkinPos)
|
||||
bool TrySpawnIronGolem(cWorld & a_World, cPlayer & a_Player, const Vector3i a_PumpkinPos) const
|
||||
{
|
||||
ASSERT(a_PumpkinPos.y > 1);
|
||||
ASSERT(a_World.GetBlock(a_PumpkinPos.addedY(-1)) == E_BLOCK_IRON_BLOCK);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemQuartzHandler :
|
||||
class cItemQuartzHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -45,7 +45,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
const auto Meta = static_cast<NIBBLETYPE>(a_Player.GetEquippedItem().m_ItemDamage);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemRailHandler :
|
||||
class cItemRailHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
cChunkInterface ChunkInterface(a_Player.GetWorld()->GetChunkMap());
|
||||
const auto RailType = static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType);
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemRawChickenHandler:
|
||||
class cItemRawChickenHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemRawChickenHandler():
|
||||
Super(E_ITEM_RAW_CHICKEN, FoodInfo(2, 1.2))
|
||||
constexpr cItemRawChickenHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(2, 1.2))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemRawFishHandler:
|
||||
class cItemRawFishHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemRawFishHandler():
|
||||
Super(E_ITEM_RAW_FISH, FoodInfo(0, 0))
|
||||
constexpr cItemRawFishHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(0, 0))
|
||||
{
|
||||
}
|
||||
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
|
||||
{
|
||||
static const FoodInfo RawFishInfos[] =
|
||||
{
|
||||
@ -37,7 +37,7 @@ public:
|
||||
return RawFishInfos[a_Item->m_ItemDamage];
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
|
@ -7,23 +7,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemRedstoneDustHandler:
|
||||
class cItemRedstoneDustHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemRedstoneDustHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_REDSTONE_WIRE, 0);
|
||||
}
|
||||
@ -32,7 +29,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -8,23 +8,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemRedstoneRepeaterHandler:
|
||||
class cItemRedstoneRepeaterHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemRedstoneRepeaterHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_REDSTONE_REPEATER_OFF, cBlockRedstoneRepeaterHandler::YawToMetaData(a_Player.GetYaw()));
|
||||
}
|
||||
@ -33,7 +30,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable() override
|
||||
virtual bool IsPlaceable() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemRottenFleshHandler:
|
||||
class cItemRottenFleshHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemRottenFleshHandler():
|
||||
Super(E_ITEM_ROTTEN_FLESH, FoodInfo(4, 0.8))
|
||||
constexpr cItemRottenFleshHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(4, 0.8))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
|
@ -7,20 +7,17 @@
|
||||
|
||||
|
||||
|
||||
class cItemSaplingHandler:
|
||||
class cItemSaplingHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemSaplingHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(
|
||||
a_PlacePosition,
|
||||
|
@ -15,7 +15,7 @@ class cItemSeedsHandler:
|
||||
|
||||
public:
|
||||
|
||||
cItemSeedsHandler(int a_ItemType):
|
||||
constexpr cItemSeedsHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
|
||||
@ -25,7 +25,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Only allow planting seeds from the top side of the block:
|
||||
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
||||
@ -54,12 +54,20 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
~cItemSeedsHandler() = default;
|
||||
} ;
|
||||
|
||||
class cItemSimpleSeedsHandler final:
|
||||
public cItemSeedsHandler
|
||||
{
|
||||
using cItemSeedsHandler::cItemSeedsHandler;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@ -9,26 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemShearsHandler:
|
||||
class cItemShearsHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemShearsHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
virtual bool IsTool(void) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
@ -40,7 +28,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
BLOCKTYPE Block;
|
||||
NIBBLETYPE BlockMeta;
|
||||
@ -59,7 +47,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
|
||||
{
|
||||
switch (a_BlockType)
|
||||
{
|
||||
@ -77,7 +65,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||
{
|
||||
switch (a_Action)
|
||||
{
|
||||
@ -92,7 +80,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
|
||||
{
|
||||
if ((a_Block == E_BLOCK_COBWEB) || IsBlockMaterialLeaves(a_Block))
|
||||
{
|
||||
|
@ -12,21 +12,18 @@
|
||||
|
||||
|
||||
|
||||
class cItemShovelHandler:
|
||||
class cItemShovelHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemShovelHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||
{
|
||||
switch (a_Action)
|
||||
{
|
||||
@ -41,7 +38,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
|
||||
{
|
||||
if (a_BlockType == E_BLOCK_SNOW)
|
||||
{
|
||||
@ -54,7 +51,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
@ -71,7 +68,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
|
||||
{
|
||||
switch (a_Block)
|
||||
{
|
||||
|
@ -11,7 +11,7 @@
|
||||
/** Handler for blocks that have 3 orientations (hay bale, log), specified by the upper 2 bits in meta.
|
||||
Handles setting the correct orientation on placement.
|
||||
Additionally supports the metadata specifying block sub-type in its lower 2 bits. */
|
||||
class cItemSidewaysHandler :
|
||||
class cItemSidewaysHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -46,7 +46,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), BlockFaceToMetaData(a_ClickedBlockFace, static_cast<NIBBLETYPE>(a_HeldItem.m_ItemDamage)));
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemSignHandler:
|
||||
class cItemSignHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -40,7 +40,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
if (a_ClickedBlockFace == BLOCK_FACE_TOP)
|
||||
{
|
||||
@ -60,7 +60,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemSlabHandler:
|
||||
class cItemSlabHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -18,7 +18,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
// Confer BlockSlab.h, which we're in cahoots with to make the below logic work.
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemSnowHandler :
|
||||
class cItemSnowHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -18,7 +18,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
BLOCKTYPE Block;
|
||||
NIBBLETYPE Meta;
|
||||
|
@ -8,20 +8,20 @@
|
||||
|
||||
|
||||
|
||||
class cItemSoupHandler:
|
||||
class cItemSoupHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemSoupHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||
constexpr cItemSoupHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||
Super(a_ItemType, a_FoodInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
// Skip over food handler, which does removal for us.
|
||||
if (!cItemHandler::EatItem(a_Player, a_Item))
|
||||
|
@ -9,21 +9,14 @@
|
||||
|
||||
|
||||
|
||||
class cItemSpawnEggHandler:
|
||||
class cItemSpawnEggHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemSpawnEggHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
using Super::Super;
|
||||
|
||||
virtual bool OnItemUse(
|
||||
cWorld * a_World,
|
||||
@ -32,7 +25,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
// Must click a valid block:
|
||||
if (a_ClickedBlockFace < 0)
|
||||
|
@ -7,19 +7,19 @@
|
||||
|
||||
|
||||
|
||||
class cItemSpiderEyeHandler:
|
||||
class cItemSpiderEyeHandler final:
|
||||
public cItemFoodHandler
|
||||
{
|
||||
using Super = cItemFoodHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemSpiderEyeHandler():
|
||||
Super(E_ITEM_SPIDER_EYE, FoodInfo(2, 3.2))
|
||||
constexpr cItemSpiderEyeHandler(int a_ItemType):
|
||||
Super(a_ItemType, FoodInfo(2, 3.2))
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) override
|
||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const override
|
||||
{
|
||||
if (!Super::EatItem(a_Player, a_Item))
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemStairsHandler :
|
||||
class cItemStairsHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
NIBBLETYPE Meta = cBlockStairsHandler::YawToMetaData(a_Player.GetYaw());
|
||||
|
||||
|
@ -8,20 +8,16 @@
|
||||
|
||||
|
||||
|
||||
class cItemSwordHandler:
|
||||
class cItemSwordHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemSwordHandler(int a_ItemType):
|
||||
Super(a_ItemType)
|
||||
{
|
||||
}
|
||||
using Super::Super;
|
||||
|
||||
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
|
||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
|
||||
{
|
||||
if (a_BlockType == E_BLOCK_COBWEB)
|
||||
{
|
||||
@ -31,7 +27,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
|
||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
|
||||
{
|
||||
switch (m_ItemType)
|
||||
{
|
||||
@ -45,7 +41,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||
{
|
||||
switch (a_Action)
|
||||
{
|
||||
@ -58,7 +54,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) override
|
||||
virtual float GetBlockBreakingStrength(BLOCKTYPE a_Block) const override
|
||||
{
|
||||
if (a_Block == E_BLOCK_COBWEB)
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ class cItemThrowableHandler:
|
||||
|
||||
public:
|
||||
|
||||
cItemThrowableHandler(int a_ItemType, cProjectileEntity::eKind a_ProjectileKind, double a_SpeedCoeff):
|
||||
constexpr cItemThrowableHandler(int a_ItemType, cProjectileEntity::eKind a_ProjectileKind, double a_SpeedCoeff):
|
||||
Super(a_ItemType),
|
||||
m_ProjectileKind(a_ProjectileKind),
|
||||
m_SpeedCoeff(a_SpeedCoeff)
|
||||
@ -32,7 +32,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
auto Pos = a_Player->GetThrowStartPos();
|
||||
auto Speed = a_Player->GetLookVector() * m_SpeedCoeff;
|
||||
@ -62,21 +62,23 @@ protected:
|
||||
|
||||
/** The speed multiplier (to the player's normalized look vector) to set for the new projectile. */
|
||||
double m_SpeedCoeff;
|
||||
|
||||
~cItemThrowableHandler() = default;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cItemEggHandler:
|
||||
class cItemEggHandler final:
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
using Super = cItemThrowableHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemEggHandler():
|
||||
Super(E_ITEM_EGG, cProjectileEntity::pkEgg, 30)
|
||||
constexpr cItemEggHandler(int a_ItemType):
|
||||
Super(a_ItemType, cProjectileEntity::pkEgg, 30)
|
||||
{
|
||||
}
|
||||
} ;
|
||||
@ -84,15 +86,15 @@ public:
|
||||
|
||||
|
||||
|
||||
class cItemSnowballHandler:
|
||||
class cItemSnowballHandler final:
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
using Super = cItemThrowableHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemSnowballHandler():
|
||||
Super(E_ITEM_SNOWBALL, cProjectileEntity::pkSnowball, 30)
|
||||
constexpr cItemSnowballHandler(int a_ItemType):
|
||||
Super(a_ItemType, cProjectileEntity::pkSnowball, 30)
|
||||
{
|
||||
}
|
||||
} ;
|
||||
@ -101,15 +103,15 @@ public:
|
||||
|
||||
|
||||
|
||||
class cItemEnderPearlHandler:
|
||||
class cItemEnderPearlHandler final:
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
using Super = cItemThrowableHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemEnderPearlHandler():
|
||||
Super(E_ITEM_ENDER_PEARL, cProjectileEntity::pkEnderPearl, 30)
|
||||
constexpr cItemEnderPearlHandler(int a_ItemType):
|
||||
Super(a_ItemType, cProjectileEntity::pkEnderPearl, 30)
|
||||
{
|
||||
}
|
||||
} ;
|
||||
@ -118,15 +120,15 @@ public:
|
||||
|
||||
|
||||
|
||||
class cItemBottleOEnchantingHandler:
|
||||
class cItemBottleOEnchantingHandler final :
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
using Super = cItemThrowableHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemBottleOEnchantingHandler():
|
||||
Super(E_ITEM_BOTTLE_O_ENCHANTING, cProjectileEntity::pkExpBottle, 14)
|
||||
constexpr cItemBottleOEnchantingHandler(int a_ItemType):
|
||||
Super(a_ItemType, cProjectileEntity::pkExpBottle, 14)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -135,15 +137,15 @@ public:
|
||||
|
||||
|
||||
|
||||
class cItemFireworkHandler:
|
||||
class cItemFireworkHandler final:
|
||||
public cItemThrowableHandler
|
||||
{
|
||||
using Super = cItemThrowableHandler;
|
||||
|
||||
public:
|
||||
|
||||
cItemFireworkHandler():
|
||||
Super(E_ITEM_FIREWORK_ROCKET, cProjectileEntity::pkFirework, 0)
|
||||
constexpr cItemFireworkHandler(int a_ItemType):
|
||||
Super(a_ItemType, cProjectileEntity::pkFirework, 0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -158,7 +160,7 @@ public:
|
||||
const cItem & a_HeldItem,
|
||||
const Vector3i a_ClickedBlockPos,
|
||||
eBlockFace a_ClickedBlockFace
|
||||
) override
|
||||
) const override
|
||||
{
|
||||
if (a_World->GetBlock(a_ClickedBlockPos) == E_BLOCK_AIR)
|
||||
{
|
||||
@ -177,5 +179,4 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemTorchHandler :
|
||||
class cItemTorchHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -34,7 +34,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
const auto & World = *a_Player.GetWorld();
|
||||
BLOCKTYPE ClickedBlockType;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemTrapdoorHandler :
|
||||
class cItemTrapdoorHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -32,7 +32,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
NIBBLETYPE Meta;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemTripwireHookHandler :
|
||||
class cItemTripwireHookHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -31,7 +31,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
if ((a_ClickedBlockFace == BLOCK_FACE_YP) || (a_ClickedBlockFace == BLOCK_FACE_YM))
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
class cItemVineHandler :
|
||||
class cItemVineHandler final :
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
@ -18,7 +18,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
BLOCKTYPE Block;
|
||||
NIBBLETYPE Meta;
|
||||
|
@ -6,27 +6,27 @@
|
||||
|
||||
|
||||
|
||||
class cSimplePlaceableItemHandler :
|
||||
class cSimplePlaceableItemHandler final:
|
||||
public cItemHandler
|
||||
{
|
||||
using Super = cItemHandler;
|
||||
|
||||
public:
|
||||
|
||||
cSimplePlaceableItemHandler(int a_ItemType, BLOCKTYPE a_BlockType) :
|
||||
constexpr cSimplePlaceableItemHandler(int a_ItemType, BLOCKTYPE a_BlockType) :
|
||||
Super(a_ItemType),
|
||||
m_BlockType(a_BlockType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsPlaceable(void) override
|
||||
virtual bool IsPlaceable(void) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||
{
|
||||
return a_Player.PlaceBlock(a_PlacePosition, m_BlockType, 0);
|
||||
}
|
||||
|
@ -1511,7 +1511,7 @@ void cMonster::RightClickFeed(cPlayer & a_Player)
|
||||
void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth)
|
||||
{
|
||||
auto Count = GetRandomProvider().RandInt<unsigned int>(a_Min, a_Max);
|
||||
auto MaxStackSize = static_cast<unsigned char>(ItemHandler(a_Item)->GetMaxStackSize());
|
||||
auto MaxStackSize = static_cast<unsigned char>(cItem(a_Item).GetMaxStackSize());
|
||||
while (Count > MaxStackSize)
|
||||
{
|
||||
a_Drops.emplace_back(a_Item, MaxStackSize, a_ItemHealth);
|
||||
|
@ -218,7 +218,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
||||
{
|
||||
if (m_Health < m_MaxHealth)
|
||||
{
|
||||
Heal(ItemHandler(EquippedItemType)->GetFoodInfo(&EquippedItem).FoodLevel);
|
||||
Heal(EquippedItem.GetHandler().GetFoodInfo(&EquippedItem).FoodLevel);
|
||||
if (!a_Player.IsGameModeCreative())
|
||||
{
|
||||
a_Player.GetInventory().RemoveOneEquippedItem();
|
||||
|
@ -243,8 +243,6 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo)
|
||||
LOGD("Stopping plugin manager...");
|
||||
delete m_PluginManager; m_PluginManager = nullptr;
|
||||
|
||||
cItemHandler::Deinit();
|
||||
|
||||
LOG("Cleaning up...");
|
||||
delete m_Server; m_Server = nullptr;
|
||||
|
||||
|
@ -138,8 +138,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA
|
||||
else if ((Slot.m_ItemType <= 0) || DraggingItem.IsEqual(Slot))
|
||||
{
|
||||
// Drop one item in slot
|
||||
cItemHandler * Handler = ItemHandler(Slot.m_ItemType);
|
||||
if ((DraggingItem.m_ItemCount > 0) && (Slot.m_ItemCount < Handler->GetMaxStackSize()))
|
||||
if ((DraggingItem.m_ItemCount > 0) && (Slot.m_ItemCount < Slot.GetMaxStackSize()))
|
||||
{
|
||||
char OldSlotCount = Slot.m_ItemCount;
|
||||
|
||||
@ -177,8 +176,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA
|
||||
else
|
||||
{
|
||||
// Same type, add items:
|
||||
cItemHandler * Handler = ItemHandler(DraggingItem.m_ItemType);
|
||||
int FreeSlots = Handler->GetMaxStackSize() - Slot.m_ItemCount;
|
||||
int FreeSlots = DraggingItem.GetMaxStackSize() - Slot.m_ItemCount;
|
||||
if (FreeSlots < 0)
|
||||
{
|
||||
ASSERT(!"Bad item stack size - where did we get more items in a slot than allowed?");
|
||||
@ -365,7 +363,7 @@ void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_
|
||||
// Different items
|
||||
continue;
|
||||
}
|
||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
if (NumFit <= 0)
|
||||
{
|
||||
// Full stack already
|
||||
@ -636,8 +634,7 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player)
|
||||
}
|
||||
else if (DraggingItem.IsEqual(Result))
|
||||
{
|
||||
cItemHandler * Handler = ItemHandler(Result.m_ItemType);
|
||||
if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Handler->GetMaxStackSize())
|
||||
if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Result.GetMaxStackSize())
|
||||
{
|
||||
DraggingItem.m_ItemCount += Result.m_ItemCount;
|
||||
Recipe.ConsumeIngredients(Grid);
|
||||
@ -928,7 +925,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
|
||||
}
|
||||
if (!DraggingItem.IsEmpty())
|
||||
{
|
||||
if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= cItemHandler::GetItemHandler(Slot)->GetMaxStackSize())))
|
||||
if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= Slot.GetMaxStackSize())))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1004,7 +1001,7 @@ void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo
|
||||
// Different items
|
||||
continue;
|
||||
}
|
||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
if (NumFit <= 0)
|
||||
{
|
||||
// Full stack already
|
||||
@ -1151,7 +1148,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
||||
RepairCost += Sacrifice.m_RepairCost;
|
||||
|
||||
// Can we repair with sacrifce material?
|
||||
if (Target.IsDamageable() && cItemHandler::GetItemHandler(Target)->CanRepairWithRawMaterial(Sacrifice.m_ItemType))
|
||||
if (Target.IsDamageable() && Target.GetHandler().CanRepairWithRawMaterial(Sacrifice.m_ItemType))
|
||||
{
|
||||
// Tool and armor repair with special item (iron / gold / diamond / ...)
|
||||
int DamageDiff = std::min(static_cast<int>(Target.m_ItemDamage), static_cast<int>(Target.GetMaxDamage()) / 4);
|
||||
@ -1620,7 +1617,7 @@ void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Playe
|
||||
{
|
||||
// It's lapis, put it in the lapis spot.
|
||||
const cItem * Slot = GetSlot(1, a_Player);
|
||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
if (NumFit <= 0)
|
||||
{
|
||||
// Full stack already
|
||||
@ -2036,7 +2033,7 @@ void cSlotAreaFurnace::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player,
|
||||
return;
|
||||
}
|
||||
|
||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
if (NumFit <= 0)
|
||||
{
|
||||
// Full stack already
|
||||
@ -2300,7 +2297,7 @@ void cSlotAreaBrewingstand::DistributeStack(cItem & a_ItemStack, cPlayer & a_Pla
|
||||
return;
|
||||
}
|
||||
|
||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||
if (NumFit <= 0)
|
||||
{
|
||||
// Full stack already
|
||||
|
@ -696,7 +696,7 @@ void cWindow::OnMiddlePaintEnd(cPlayer & a_Player)
|
||||
|
||||
// Fill available slots with full stacks of the dragging item
|
||||
const auto & DraggingItem = a_Player.GetDraggingItem();
|
||||
auto StackSize = ItemHandler(DraggingItem.m_ItemType)->GetMaxStackSize();
|
||||
auto StackSize = DraggingItem.GetMaxStackSize();
|
||||
if (0 < DistributeItemToSlots(a_Player, DraggingItem, StackSize, a_Player.GetInventoryPaintSlots(), false))
|
||||
{
|
||||
// If any items were distibuted, set dragging item empty
|
||||
|
Loading…
Reference in New Issue
Block a user