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:
|
// Item not placeable in the first place, our work is done:
|
||||||
return true;
|
return true;
|
||||||
|
@ -71,8 +71,8 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto Player = static_cast<const cPlayer *>(a_Digger);
|
const auto Player = static_cast<const cPlayer *>(a_Digger);
|
||||||
auto Handler = Player->GetEquippedItem().GetHandler();
|
auto & Handler = Player->GetEquippedItem().GetHandler();
|
||||||
if (!Player->IsGameModeSurvival() || !Handler->CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
|
if (!Player->IsGameModeSurvival() || !Handler.CanHarvestBlock(E_BLOCK_MOB_SPAWNER))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ItemHandler(Player->GetEquippedItem().m_ItemType)->CanHarvestBlock(m_BlockType))
|
if (!Player->GetEquippedItem().GetHandler().CanHarvestBlock(m_BlockType))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -985,7 +985,7 @@ cItems cChunk::PickupsFromBlock(Vector3i a_RelPos, const cEntity * a_Digger, con
|
|||||||
cItems Pickups;
|
cItems Pickups;
|
||||||
const auto BlockEntity = GetBlockEntityRel(a_RelPos);
|
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);
|
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:
|
case DIG_STATUS_SHOOT_EAT:
|
||||||
{
|
{
|
||||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
auto & ItemHandler = m_Player->GetEquippedItem().GetHandler();
|
||||||
if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage))
|
if (ItemHandler.IsFood() || ItemHandler.IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage))
|
||||||
{
|
{
|
||||||
m_Player->AbortEating();
|
m_Player->AbortEating();
|
||||||
return;
|
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
|
// When bow is in off-hand / shield slot
|
||||||
if (m_Player->GetInventory().GetShieldSlot().m_ItemType == E_ITEM_BOW)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -1319,8 +1322,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
|
|||||||
cChunkInterface ChunkInterface(World->GetChunkMap());
|
cChunkInterface ChunkInterface(World->GetChunkMap());
|
||||||
cBlockHandler::For(DiggingBlock).OnDigging(ChunkInterface, *World, *m_Player, {a_BlockX, a_BlockY, a_BlockZ});
|
cBlockHandler::For(DiggingBlock).OnDigging(ChunkInterface, *World, *m_Player, {a_BlockX, a_BlockY, a_BlockZ});
|
||||||
|
|
||||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem());
|
m_Player->GetEquippedItem().GetHandler().OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace);
|
||||||
ItemHandler->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.
|
// TODO: We are still consuming the items in main hand. Remove this override when the off-hand consumption is handled correctly.
|
||||||
a_UsedMainHand = true;
|
a_UsedMainHand = true;
|
||||||
const cItem & HeldItem = a_UsedMainHand ? m_Player->GetEquippedItem() : m_Player->GetInventory().GetShieldSlot();
|
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
|
// 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
|
// 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);
|
World->GetBlockTypeMeta(ClickedBlockPos, BlockType, BlockMeta);
|
||||||
const auto & BlockHandler = cBlockHandler::For(BlockType);
|
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));
|
bool BlockUsable = BlockHandler.IsUseable() && (!m_Player->IsGameModeSpectator() || cBlockInfo::IsUseableBySpectator(BlockType));
|
||||||
|
|
||||||
if (BlockUsable && !(m_Player->IsCrouched() && !HeldItem.IsEmpty()))
|
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)
|
if (Placeable)
|
||||||
{
|
{
|
||||||
// Place a block:
|
// 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;
|
return;
|
||||||
@ -1516,7 +1518,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Place a block:
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
else if (!PlgMgr->CallHookPlayerUsingItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
|
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.
|
// Use an item in hand with a target block.
|
||||||
|
|
||||||
cBlockInServerPluginInterface PluginInterface(*World);
|
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);
|
PlgMgr->CallHookPlayerUsedItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
|
||||||
return;
|
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.
|
// TODO: We are still consuming the items in main hand. Remove this override when the off-hand consumption is handled correctly.
|
||||||
a_UsedMainHand = true;
|
a_UsedMainHand = true;
|
||||||
const cItem & HeldItem = a_UsedMainHand ? m_Player->GetEquippedItem() : m_Player->GetInventory().GetShieldSlot();
|
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();
|
cWorld * World = m_Player->GetWorld();
|
||||||
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
|
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
|
||||||
|
|
||||||
@ -1872,10 +1874,10 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(HeldItem.m_ItemDamage))
|
if (ItemHandler.IsFood() || ItemHandler.IsDrinkable(HeldItem.m_ItemDamage))
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
ItemHandler->IsFood() &&
|
ItemHandler.IsFood() &&
|
||||||
(m_Player->IsSatiated() || m_Player->IsGameModeCreative()) && // Only non-creative or hungry players can eat
|
(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_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
|
(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
|
// All plugins agree with using the item
|
||||||
cBlockInServerPluginInterface PluginInterface(*World);
|
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);
|
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);
|
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.
|
// Whether an enchantment boosted this attack's damage.
|
||||||
bool MagicalCriticalHit = false;
|
bool MagicalCriticalHit = false;
|
||||||
|
@ -525,12 +525,12 @@ void cPlayer::FinishEating(void)
|
|||||||
// consume the item:
|
// consume the item:
|
||||||
cItem Item(GetEquippedItem());
|
cItem Item(GetEquippedItem());
|
||||||
Item.m_ItemCount = 1;
|
Item.m_ItemCount = 1;
|
||||||
cItemHandler * ItemHandler = cItemHandler::GetItemHandler(Item.m_ItemType);
|
auto & ItemHandler = Item.GetHandler();
|
||||||
if (!ItemHandler->EatItem(this, &Item))
|
if (!ItemHandler.EatItem(this, &Item))
|
||||||
{
|
{
|
||||||
return;
|
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();
|
cItem Item = GetEquippedItem();
|
||||||
|
|
||||||
// Get base damage for action type:
|
// Get base damage for action type:
|
||||||
short Dmg = cItemHandler::GetItemHandler(Item)->GetDurabilityLossByAction(a_Action);
|
short Dmg = Item.GetHandler().GetDurabilityLossByAction(a_Action);
|
||||||
|
|
||||||
UseEquippedItem(Dmg);
|
UseEquippedItem(Dmg);
|
||||||
}
|
}
|
||||||
@ -2613,10 +2613,10 @@ float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
|
|||||||
// Based on: https://minecraft.gamepedia.com/Breaking#Speed
|
// Based on: https://minecraft.gamepedia.com/Breaking#Speed
|
||||||
|
|
||||||
// Get the base speed multiplier of the equipped tool for the mined block
|
// 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 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
|
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;
|
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);
|
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
|
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;
|
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++)
|
for (int i = a_BeginSlotNum; i <= a_EndSlotNum; i++)
|
||||||
{
|
{
|
||||||
const cItem & Slot = GetSlot(i);
|
const cItem & Slot = GetSlot(i);
|
||||||
@ -260,8 +260,7 @@ int cInventory::ReplaceOneEquippedItem(const cItem & a_Item, bool a_TryOtherSlot
|
|||||||
cItem ItemsToAdd = a_Item;
|
cItem ItemsToAdd = a_Item;
|
||||||
if (EquippedItem.IsEqual(ItemsToAdd))
|
if (EquippedItem.IsEqual(ItemsToAdd))
|
||||||
{
|
{
|
||||||
cItemHandler Handler(ItemsToAdd.m_ItemType);
|
auto AmountToAdd = std::min(static_cast<char>(ItemsToAdd.GetMaxStackSize() - EquippedItem.m_ItemCount), ItemsToAdd.m_ItemCount);
|
||||||
auto AmountToAdd = std::min(static_cast<char>(Handler.GetMaxStackSize() - EquippedItem.m_ItemCount), ItemsToAdd.m_ItemCount);
|
|
||||||
|
|
||||||
EquippedItem.m_ItemCount += AmountToAdd;
|
EquippedItem.m_ItemCount += AmountToAdd;
|
||||||
SetEquippedItem(EquippedItem);
|
SetEquippedItem(EquippedItem);
|
||||||
@ -689,7 +688,7 @@ void cInventory::UpdateItems(void)
|
|||||||
const cItem & Slot = GetEquippedItem();
|
const cItem & Slot = GetEquippedItem();
|
||||||
if (!Slot.IsEmpty())
|
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
|
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
|
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
|
// tolua_end
|
||||||
|
|
||||||
/** Returns the cItemHandler responsible for this item type */
|
/** Returns the cItemHandler responsible for this item type */
|
||||||
cItemHandler * GetHandler(void) const;
|
const cItemHandler & GetHandler(void) const;
|
||||||
|
|
||||||
/** Saves the item data into JSON representation */
|
/** Saves the item data into JSON representation */
|
||||||
void GetJson(Json::Value & a_OutValue) const;
|
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 cItemGrid::HowManyCanFit(const cItem & a_ItemStack, bool a_AllowNewStacks)
|
||||||
{
|
{
|
||||||
int NumLeft = a_ItemStack.m_ItemCount;
|
int NumLeft = a_ItemStack.m_ItemCount;
|
||||||
int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize();
|
int MaxStack = a_ItemStack.GetMaxStackSize();
|
||||||
|
|
||||||
if (!m_Slots.IsStorageAllocated())
|
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;
|
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 > m_Slots[a_SlotNum].GetMaxStackSize())
|
||||||
if (m_Slots[a_SlotNum].m_ItemCount > Handler->GetMaxStackSize())
|
|
||||||
{
|
{
|
||||||
m_Slots[a_SlotNum].m_ItemCount = Handler->GetMaxStackSize();
|
m_Slots[a_SlotNum].m_ItemCount = m_Slots[a_SlotNum].GetMaxStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerListeners(a_SlotNum);
|
TriggerListeners(a_SlotNum);
|
||||||
|
@ -19,6 +19,7 @@ target_sources(
|
|||||||
ItemCloth.h
|
ItemCloth.h
|
||||||
ItemComparator.h
|
ItemComparator.h
|
||||||
ItemCookedFish.h
|
ItemCookedFish.h
|
||||||
|
ItemDefaultItem.h
|
||||||
ItemDoor.h
|
ItemDoor.h
|
||||||
ItemDropSpenser.h
|
ItemDropSpenser.h
|
||||||
ItemDye.h
|
ItemDye.h
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemAnvilHandler :
|
class cItemAnvilHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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(
|
return a_Player.PlaceBlock(
|
||||||
a_PlacePosition,
|
a_PlacePosition,
|
||||||
|
@ -8,17 +8,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemArmorHandler:
|
class cItemArmorHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemArmorHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
int SlotNum;
|
int SlotNum;
|
||||||
if (ItemCategory::IsHelmet(a_HeldItem.m_ItemType))
|
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)
|
switch (m_ItemType)
|
||||||
{
|
{
|
||||||
|
@ -8,21 +8,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemAxeHandler:
|
class cItemAxeHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemAxeHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||||
{
|
{
|
||||||
switch (a_Action)
|
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))
|
if (!IsBlockMaterialWood(a_Block) && !IsBlockMaterialPlants(a_Block) && !IsBlockMaterialVine(a_Block))
|
||||||
{
|
{
|
||||||
|
@ -12,21 +12,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBannerHandler:
|
class cItemBannerHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBannerHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
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:
|
// Cannot place a banner at "no face" and from the bottom:
|
||||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -9,20 +9,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBedHandler:
|
class cItemBedHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBedHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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 BlockMeta = cBlockBedHandler::YawToMetaData(a_Player.GetYaw());
|
||||||
const auto HeadPosition = a_PlacePosition + cBlockBedHandler::MetaDataToDirection(BlockMeta);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBigFlowerHandler:
|
class cItemBigFlowerHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBigFlowerHandler():
|
using Super::Super;
|
||||||
Super(E_BLOCK_BIG_FLOWER)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
|
|
||||||
{
|
{
|
||||||
// Needs at least two free blocks to build in:
|
// Needs at least two free blocks to build in:
|
||||||
if (a_PlacePosition.y >= (cChunkDef::Height - 1))
|
if (a_PlacePosition.y >= (cChunkDef::Height - 1))
|
||||||
|
@ -8,17 +8,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBoatHandler:
|
class cItemBoatHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBoatHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// Only allow placing blocks on top of blocks, or when not in range of dest block:
|
// 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))
|
if ((a_ClickedBlockFace != BLOCK_FACE_YM) && (a_ClickedBlockFace != BLOCK_FACE_NONE))
|
||||||
|
@ -9,17 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBottleHandler:
|
class cItemBottleHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBottleHandler():
|
using Super::Super;
|
||||||
Super(E_ITEM_GLASS_BOTTLE)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -28,7 +25,7 @@ public:
|
|||||||
/** Searches for a water source block in the line of sight.
|
/** 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 true and sets a_BlockPos if a water source block is found within line-of-sight.
|
||||||
Returns false if not. */
|
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:
|
class cCallbacks:
|
||||||
public cBlockTracer::cCallbacks
|
public cBlockTracer::cCallbacks
|
||||||
@ -81,7 +78,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
||||||
{
|
{
|
||||||
|
@ -8,17 +8,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBowHandler:
|
class cItemBowHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBowHandler(void):
|
using Super::Super;
|
||||||
Super(E_ITEM_BOW)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
ASSERT(a_Player != nullptr);
|
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
|
// Actual shot - produce the arrow with speed based on the number of ticks that the bow was charged
|
||||||
UNUSED(a_BlockPos);
|
UNUSED(a_BlockPos);
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBucketHandler :
|
class cItemBucketHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBucketHandler(int a_ItemType):
|
constexpr cItemBucketHandler(int a_ItemType):
|
||||||
Super(a_ItemType)
|
Super(a_ItemType)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
switch (m_ItemType)
|
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.
|
// Players can't pick up fluid while in adventure mode.
|
||||||
if (a_Player->IsGameModeAdventure())
|
if (a_Player->IsGameModeAdventure())
|
||||||
@ -127,7 +127,7 @@ public:
|
|||||||
bool PlaceFluid(
|
bool PlaceFluid(
|
||||||
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
||||||
const Vector3i a_BlockPos, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock
|
const Vector3i a_BlockPos, eBlockFace a_BlockFace, BLOCKTYPE a_FluidBlock
|
||||||
)
|
) const
|
||||||
{
|
{
|
||||||
// Players can't place fluid while in adventure mode.
|
// Players can't place fluid while in adventure mode.
|
||||||
if (a_Player->IsGameModeAdventure())
|
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 :
|
class cCallbacks :
|
||||||
public cBlockTracer::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 :
|
class cCallbacks :
|
||||||
public cBlockTracer::cCallbacks
|
public cBlockTracer::cCallbacks
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemButtonHandler :
|
class cItemButtonHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemChestHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
cItemChestHandler(const cItemChestHandler &) = delete;
|
cItemChestHandler(const cItemChestHandler &) = delete;
|
||||||
|
|
||||||
private:
|
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:
|
// Check that there is at most one single neighbor of the same chest type:
|
||||||
static const Vector3i CrossCoords[] =
|
static const Vector3i CrossCoords[] =
|
||||||
|
@ -8,19 +8,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemChorusFruitHandler:
|
class cItemChorusFruitHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemChorusFruitHandler():
|
constexpr cItemChorusFruitHandler(int a_ItemType) :
|
||||||
Super(E_ITEM_CHORUS_FRUIT, FoodInfo(4, 2.4))
|
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);
|
cItemHandler::EatItem(a_Player, a_Item);
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemClothHandler :
|
class cItemClothHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cItemClothHandler(int a_ItemType)
|
constexpr cItemClothHandler(int a_ItemType)
|
||||||
: cItemHandler(a_ItemType)
|
: cItemHandler(a_ItemType)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemComparatorHandler:
|
class cItemComparatorHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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()));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemCookedFishHandler:
|
class cItemCookedFishHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemCookedFishHandler():
|
constexpr cItemCookedFishHandler(int a_ItemType):
|
||||||
Super(E_ITEM_COOKED_FISH, FoodInfo(0, 0))
|
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[] =
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemDoorHandler(int a_ItemType):
|
constexpr cItemDoorHandler(int a_ItemType):
|
||||||
Super(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:
|
// Vanilla only allows door placement while clicking on the top face of the block below the door:
|
||||||
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsPlaceable(void) override
|
virtual bool IsPlaceable(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemDropSpenserHandler :
|
class cItemDropSpenserHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cItemDyeHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
if ((a_HeldItem.m_ItemDamage == E_META_DYE_WHITE) && (a_ClickedBlockFace != BLOCK_FACE_NONE))
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -16,10 +16,7 @@ class cItemEmptyMapHandler:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemEmptyMapHandler():
|
using Super::Super;
|
||||||
Super(E_ITEM_EMPTY_MAP)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
UNUSED(a_HeldItem);
|
UNUSED(a_HeldItem);
|
||||||
UNUSED(a_ClickedBlockFace);
|
UNUSED(a_ClickedBlockFace);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemEnchantingTableHandler:
|
class cItemEnchantingTableHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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))
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemEndCrystalHandler :
|
class cItemEndCrystalHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemEndCrystalHandler(int a_ItemType) :
|
constexpr cItemEndCrystalHandler(int a_ItemType) :
|
||||||
Super(a_ItemType)
|
Super(a_ItemType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ public:
|
|||||||
cWorld * a_World, cPlayer * a_Player,
|
cWorld * a_World, cPlayer * a_Player,
|
||||||
cBlockPluginInterface & a_PluginInterface, const cItem & a_HeldItem,
|
cBlockPluginInterface & a_PluginInterface, const cItem & a_HeldItem,
|
||||||
const Vector3i a_BlockPos,
|
const Vector3i a_BlockPos,
|
||||||
eBlockFace a_ClickedBlockFace) override
|
eBlockFace a_ClickedBlockFace) const override
|
||||||
{
|
{
|
||||||
// Must click a valid block:
|
// Must click a valid block:
|
||||||
if (a_ClickedBlockFace < 0)
|
if (a_ClickedBlockFace < 0)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemEndPortalFrameHandler :
|
class cItemEndPortalFrameHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemThrowableHandler
|
||||||
{
|
{
|
||||||
using Super = cItemThrowableHandler;
|
using Super = cItemThrowableHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemEyeOfEnderHandler():
|
constexpr cItemEyeOfEnderHandler(int a_ItemType):
|
||||||
Super(E_ITEM_EYE_OF_ENDER, cProjectileEntity::pkSnowball, 30)
|
Super(a_ItemType, cProjectileEntity::pkSnowball, 30)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ public:
|
|||||||
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// Try to fill an End Portal Frame block:
|
// Try to fill an End Portal Frame block:
|
||||||
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemFenceGateHandler :
|
class cItemFenceGateHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemFishingRodHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +69,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
if (a_ClickedBlockFace != BLOCK_FACE_NONE)
|
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. */
|
/** 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;
|
cFloaterCallback FloaterInfo;
|
||||||
a_World.DoWithEntityByID(a_Player.GetFloaterID(), 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. */
|
/** 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();
|
auto PlayerPos = a_Player.GetPosition();
|
||||||
a_World.DoWithEntityByID(a_EntityID, [=](cEntity & a_Entity)
|
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);
|
auto LotSLevel = std::min(a_Player.GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::enchLuckOfTheSea), 3u);
|
||||||
|
|
||||||
|
@ -14,25 +14,25 @@ class cItemFoodHandler:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
constexpr cItemFoodHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||||
Super(a_ItemType),
|
Super(a_ItemType),
|
||||||
m_FoodInfo(a_FoodInfo)
|
m_FoodInfo(a_FoodInfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsFood(void) override
|
virtual bool IsFood(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
|
||||||
{
|
{
|
||||||
UNUSED(a_Item);
|
UNUSED(a_Item);
|
||||||
return m_FoodInfo;
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
@ -50,8 +50,11 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
FoodInfo m_FoodInfo;
|
FoodInfo m_FoodInfo;
|
||||||
|
|
||||||
|
~cItemFoodHandler() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class cItemSimpleFoodHandler final:
|
||||||
|
public cItemFoodHandler
|
||||||
|
{
|
||||||
|
using cItemFoodHandler::cItemFoodHandler;
|
||||||
|
};
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemFoodSeedsHandler:
|
class cItemFoodSeedsHandler final:
|
||||||
public cItemSeedsHandler
|
public cItemSeedsHandler
|
||||||
{
|
{
|
||||||
using Super = cItemSeedsHandler;
|
using Super = cItemSeedsHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemFoodSeedsHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
constexpr cItemFoodSeedsHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||||
Super(a_ItemType),
|
Super(a_ItemType),
|
||||||
m_FoodInfo(a_FoodInfo)
|
m_FoodInfo(a_FoodInfo)
|
||||||
{
|
{
|
||||||
@ -23,18 +23,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsFood(void) override
|
virtual bool IsFood(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual FoodInfo GetFoodInfo(const cItem * a_Item) override
|
virtual FoodInfo GetFoodInfo(const cItem * a_Item) const override
|
||||||
{
|
{
|
||||||
UNUSED(a_Item);
|
UNUSED(a_Item);
|
||||||
return m_FoodInfo;
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemFurnaceHandler :
|
class cItemFurnaceHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemGoldenAppleHandler():
|
constexpr cItemGoldenAppleHandler(int a_ItemType):
|
||||||
Super(E_ITEM_GOLDEN_APPLE, FoodInfo(4, 9.6))
|
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);
|
cItemHandler::EatItem(a_Player, a_Item);
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,8 @@ class cItemHandler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
friend class cItem;
|
||||||
|
|
||||||
/** Actions that may cause durability of an item may be lost, where the
|
/** 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
|
magnitude of the loss depends on the specific item used to perform the
|
||||||
action */
|
action */
|
||||||
@ -32,10 +34,10 @@ public:
|
|||||||
dlaBreakBlockInstant,
|
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).
|
/** 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.
|
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.
|
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.
|
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. */
|
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).
|
/** Called when the player tries to use the item (right mouse button).
|
||||||
Descendants can return false to abort the usage (default behavior). */
|
Descendants can return false to abort the usage (default behavior). */
|
||||||
@ -55,17 +57,17 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
);
|
) const;
|
||||||
|
|
||||||
/** Called when the client sends the SHOOT status in the lclk packet (releasing the bow). */
|
/** 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_BlockPos);
|
||||||
UNUSED(a_BlockFace);
|
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 */
|
/** 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_World);
|
||||||
UNUSED(a_Player);
|
UNUSED(a_Player);
|
||||||
@ -77,28 +79,28 @@ public:
|
|||||||
cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem,
|
cWorld * a_World, cPlayer * a_Player, const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
);
|
) const;
|
||||||
|
|
||||||
/** Called when a player attacks an entity with this item in hand. */
|
/** 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. */
|
/** 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
|
/** 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
|
was performed. This is only relevant for uses where the damage taken may
|
||||||
depend on the item used. */
|
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 */
|
/** Returns the maximum stack size for a given item */
|
||||||
virtual char GetMaxStackSize(void);
|
virtual char GetMaxStackSize(void) const;
|
||||||
|
|
||||||
struct FoodInfo
|
struct FoodInfo
|
||||||
{
|
{
|
||||||
int FoodLevel;
|
int FoodLevel;
|
||||||
double Saturation;
|
double Saturation;
|
||||||
|
|
||||||
FoodInfo(int a_FoodLevel, double a_Saturation) :
|
constexpr FoodInfo(int a_FoodLevel, double a_Saturation) :
|
||||||
FoodLevel(a_FoodLevel),
|
FoodLevel(a_FoodLevel),
|
||||||
Saturation(a_Saturation)
|
Saturation(a_Saturation)
|
||||||
{
|
{
|
||||||
@ -106,53 +108,44 @@ public:
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
/** Returns the FoodInfo for this item. (FoodRecovery and Saturation) */
|
/** 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 */
|
/** Lets the player eat a selected item. Returns true if the player ate the item */
|
||||||
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item);
|
virtual bool EatItem(cPlayer * a_Player, cItem * a_Item) const;
|
||||||
|
|
||||||
/** Indicates if this item is a tool */
|
|
||||||
virtual bool IsTool(void);
|
|
||||||
|
|
||||||
/** Indicates if this item is food */
|
/** Indicates if this item is food */
|
||||||
virtual bool IsFood(void);
|
virtual bool IsFood(void) const;
|
||||||
|
|
||||||
/** Indicates if this item is drinkable */
|
/** Indicates if this item is drinkable */
|
||||||
virtual bool IsDrinkable(short a_ItemDamage);
|
virtual bool IsDrinkable(short a_ItemDamage) const;
|
||||||
|
|
||||||
/** Blocks simply get placed */
|
/** 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? */
|
/** 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).
|
/** 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. */
|
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.
|
/** Returns the strength to break a specific block.
|
||||||
Defaults to 1 unless overriden. */
|
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:
|
protected:
|
||||||
|
|
||||||
int m_ItemType;
|
static const cItemHandler & For(int a_ItemType);
|
||||||
static cItemHandler * CreateItemHandler(int m_ItemType);
|
|
||||||
|
~cItemHandler() = default;
|
||||||
|
|
||||||
|
const int m_ItemType;
|
||||||
|
|
||||||
/** Performs the actual placement of this placeable item.
|
/** 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 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.
|
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. */
|
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);
|
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition) const;
|
||||||
|
|
||||||
static cItemHandler * m_ItemHandler[E_ITEM_LAST + 1];
|
|
||||||
static bool m_HandlerInitialized; // used to detect if the itemhandlers are initialized
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Short function
|
|
||||||
inline cItemHandler *ItemHandler(int a_ItemType) { return cItemHandler::GetItemHandler(a_ItemType); }
|
|
||||||
|
@ -9,17 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemHoeHandler:
|
class cItemHoeHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemHoeHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockPos.y >= cChunkDef::Height))
|
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)
|
switch (a_Action)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemHopperHandler :
|
class cItemHopperHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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));
|
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_HOPPER, BlockFaceToMetaData(a_ClickedBlockFace));
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemItemFrameHandler:
|
class cItemItemFrameHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemItemFrameHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// Can only place on a side face:
|
// Can only place on a side face:
|
||||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_YP) || (a_ClickedBlockFace == BLOCK_FACE_YM))
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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:
|
// Re-use the pumpkin converter for lanterns:
|
||||||
return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_JACK_O_LANTERN, cBlockPumpkinHandler::YawToMetaData(a_Player.GetYaw()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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 & World = *a_Player.GetWorld();
|
||||||
const auto ClickedBlockType = World.GetBlock(AddFaceDirection(a_PlacePosition, a_ClickedBlockFace, true));
|
const auto ClickedBlockType = World.GetBlock(AddFaceDirection(a_PlacePosition, a_ClickedBlockFace, true));
|
||||||
|
@ -7,23 +7,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemLeavesHandler:
|
class cItemLeavesHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemLeavesHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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(
|
return a_Player.PlaceBlock(
|
||||||
a_PlacePosition,
|
a_PlacePosition,
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemLeverHandler :
|
class cItemLeverHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemLighterHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +29,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
if (a_ClickedBlockFace < 0)
|
if (a_ClickedBlockFace < 0)
|
||||||
{
|
{
|
||||||
|
@ -9,14 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemLilypadHandler:
|
class cItemLilypadHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemLilypadHandler(int a_ItemType):
|
constexpr cItemLilypadHandler(int a_ItemType):
|
||||||
Super(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
|
return false; // Set as not placeable so OnItemUse is called
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// The client sends BLOCK_FACE_NONE when it determines it should do a tracing-based placement.
|
// The client sends BLOCK_FACE_NONE when it determines it should do a tracing-based placement.
|
||||||
// Otherwise, a normal block face is sent.
|
// Otherwise, a normal block face is sent.
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemMapHandler:
|
class cItemMapHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -16,12 +16,9 @@ class cItemMapHandler:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemMapHandler():
|
using Super::Super;
|
||||||
Super(E_ITEM_MAP)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
cMap * Map = a_World->GetMapManager().GetMapData(static_cast<unsigned>(a_Item.m_ItemDamage));
|
||||||
|
|
||||||
|
@ -5,25 +5,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemMilkHandler:
|
class cItemMilkHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemMilkHandler():
|
using Super::Super;
|
||||||
Super(E_ITEM_MILK)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool IsDrinkable(short a_ItemDamage) override
|
virtual bool IsDrinkable(short a_ItemDamage) const override
|
||||||
{
|
{
|
||||||
UNUSED(a_ItemDamage);
|
UNUSED(a_ItemDamage);
|
||||||
return true;
|
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);
|
UNUSED(a_Item);
|
||||||
a_Player->ClearEntityEffects();
|
a_Player->ClearEntityEffects();
|
||||||
|
@ -5,17 +5,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemMinecartHandler:
|
class cItemMinecartHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemMinecartHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -28,7 +25,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// Must be used on a block
|
// Must be used on a block
|
||||||
if (a_ClickedBlockFace < 0)
|
if (a_ClickedBlockFace < 0)
|
||||||
|
@ -9,23 +9,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemMobHeadHandler:
|
class cItemMobHeadHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemMobHeadHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
// Cannot place a head at "no face" and from the bottom:
|
||||||
if ((a_ClickedBlockFace == BLOCK_FACE_NONE) || (a_ClickedBlockFace == BLOCK_FACE_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.
|
/** Called after placing a regular head block with no mob spawning.
|
||||||
Adjusts the mob head entity based on the equipped item's data. */
|
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 HeadType = static_cast<eMobHeadType>(a_HeldItem.m_ItemDamage);
|
||||||
const auto BlockMeta = static_cast<NIBBLETYPE>(a_ClickedBlockFace);
|
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.
|
/** Spawns a wither if the wither skull placed at the specified coords completes wither's spawning formula.
|
||||||
Returns true if the wither was created. */
|
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:
|
// No wither can be created at Y < 2 - not enough space for the formula:
|
||||||
if (a_BlockPos.y < 2)
|
if (a_BlockPos.y < 2)
|
||||||
@ -131,7 +128,7 @@ public:
|
|||||||
cWorld & a_World, cPlayer & a_Player,
|
cWorld & a_World, cPlayer & a_Player,
|
||||||
Vector3i a_PlacedHeadPos,
|
Vector3i a_PlacedHeadPos,
|
||||||
int a_OffsetX, int a_OffsetZ
|
int a_OffsetX, int a_OffsetZ
|
||||||
)
|
) const
|
||||||
{
|
{
|
||||||
// Image for the wither at the X axis:
|
// Image for the wither at the X axis:
|
||||||
static const sSetBlock ImageWitherX[] =
|
static const sSetBlock ImageWitherX[] =
|
||||||
@ -189,7 +186,7 @@ public:
|
|||||||
cWorld & a_World, cPlayer & a_Player, const sSetBlock (& a_Image)[9],
|
cWorld & a_World, cPlayer & a_Player, const sSetBlock (& a_Image)[9],
|
||||||
Vector3i a_PlacedHeadPos,
|
Vector3i a_PlacedHeadPos,
|
||||||
int a_OffsetX, int a_OffsetZ
|
int a_OffsetX, int a_OffsetZ
|
||||||
)
|
) const
|
||||||
{
|
{
|
||||||
std::array<Vector3i, 9> PositionsToClear;
|
std::array<Vector3i, 9> PositionsToClear;
|
||||||
|
|
||||||
@ -280,7 +277,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/** Awards the achievement to all players close to the specified point. */
|
/** 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);
|
Vector3f Pos(a_BlockPos);
|
||||||
a_World.ForEachPlayer([=](cPlayer & a_Player)
|
a_World.ForEachPlayer([=](cPlayer & a_Player)
|
||||||
@ -323,7 +320,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsPlaceable(void) override
|
virtual bool IsPlaceable(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemNetherWartHandler:
|
class cItemNetherWartHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemNetherWartHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
// Only allow planting nether wart onto the top side of the block:
|
||||||
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
||||||
@ -39,7 +36,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsPlaceable(void) override
|
virtual bool IsPlaceable(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemObserverHandler :
|
class cItemObserverHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemPaintingHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +30,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// Paintings can't be flatly placed:
|
// Paintings can't be flatly placed:
|
||||||
if (
|
if (
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemPickaxeHandler:
|
class cItemPickaxeHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemPickaxeHandler(int a_ItemType):
|
constexpr cItemPickaxeHandler(int a_ItemType):
|
||||||
Super(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)
|
switch (a_Action)
|
||||||
{
|
{
|
||||||
@ -33,7 +33,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
char PickaxeLevel()
|
char PickaxeLevel() const
|
||||||
{
|
{
|
||||||
switch (m_ItemType)
|
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!
|
// NOTICE: Make sure to update cItemHandler::CanHarvestBlock() if adding new blocks here!
|
||||||
switch (a_BlockType)
|
switch (a_BlockType)
|
||||||
@ -155,7 +155,7 @@ public:
|
|||||||
return Super::CanHarvestBlock(a_BlockType);
|
return Super::CanHarvestBlock(a_BlockType);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool CanRepairWithRawMaterial(short a_ItemType) override
|
virtual bool CanRepairWithRawMaterial(short a_ItemType) const override
|
||||||
{
|
{
|
||||||
switch (m_ItemType)
|
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))
|
if (!IsBlockMaterialIron(a_Block) && (a_Block != E_BLOCK_ANVIL) && !IsBlockMaterialRock(a_Block))
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemPistonHandler :
|
class cItemPistonHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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()));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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));
|
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
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemPoisonousPotatoHandler():
|
constexpr cItemPoisonousPotatoHandler(int a_ItemType):
|
||||||
Super(E_ITEM_POISONOUS_POTATO, FoodInfo(2, 1.2))
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
|
@ -4,24 +4,21 @@
|
|||||||
#include "../Entities/EntityEffect.h"
|
#include "../Entities/EntityEffect.h"
|
||||||
|
|
||||||
|
|
||||||
class cItemPotionHandler:
|
class cItemPotionHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemPotionHandler():
|
using Super::Super;
|
||||||
Super(E_ITEM_POTION)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// cItemHandler overrides:
|
// 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
|
// Drinkable potion if 13th lowest bit is set
|
||||||
// Ref.: https://minecraft.gamepedia.com/Potions#Data_value_table
|
// Ref.: https://minecraft.gamepedia.com/Potions#Data_value_table
|
||||||
@ -39,7 +36,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
short PotionDamage = a_HeldItem.m_ItemDamage;
|
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;
|
short PotionDamage = a_Item->m_ItemDamage;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemPumpkinHandler:
|
class cItemPumpkinHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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:
|
// First try spawning a snow golem or an iron golem:
|
||||||
if (TrySpawnGolem(a_Player, a_PlacePosition))
|
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.
|
/** 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. */
|
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:
|
// 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))
|
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.
|
/** 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.
|
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. */
|
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_PumpkinPos.y > 1);
|
||||||
ASSERT(a_World.GetBlock(a_PumpkinPos.addedY(-1)) == E_BLOCK_SNOW_BLOCK);
|
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.
|
/** 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.
|
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. */
|
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_PumpkinPos.y > 1);
|
||||||
ASSERT(a_World.GetBlock(a_PumpkinPos.addedY(-1)) == E_BLOCK_IRON_BLOCK);
|
ASSERT(a_World.GetBlock(a_PumpkinPos.addedY(-1)) == E_BLOCK_IRON_BLOCK);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemQuartzHandler :
|
class cItemQuartzHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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);
|
const auto Meta = static_cast<NIBBLETYPE>(a_Player.GetEquippedItem().m_ItemDamage);
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemRailHandler :
|
class cItemRailHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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());
|
cChunkInterface ChunkInterface(a_Player.GetWorld()->GetChunkMap());
|
||||||
const auto RailType = static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType);
|
const auto RailType = static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType);
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemRawChickenHandler:
|
class cItemRawChickenHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemRawChickenHandler():
|
constexpr cItemRawChickenHandler(int a_ItemType):
|
||||||
Super(E_ITEM_RAW_CHICKEN, FoodInfo(2, 1.2))
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemRawFishHandler:
|
class cItemRawFishHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemRawFishHandler():
|
constexpr cItemRawFishHandler(int a_ItemType):
|
||||||
Super(E_ITEM_RAW_FISH, FoodInfo(0, 0))
|
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[] =
|
static const FoodInfo RawFishInfos[] =
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ public:
|
|||||||
return RawFishInfos[a_Item->m_ItemDamage];
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
|
@ -7,23 +7,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemRedstoneDustHandler:
|
class cItemRedstoneDustHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemRedstoneDustHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,23 +8,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemRedstoneRepeaterHandler:
|
class cItemRedstoneRepeaterHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemRedstoneRepeaterHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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()));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemRottenFleshHandler:
|
class cItemRottenFleshHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemRottenFleshHandler():
|
constexpr cItemRottenFleshHandler(int a_ItemType):
|
||||||
Super(E_ITEM_ROTTEN_FLESH, FoodInfo(4, 0.8))
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
|
@ -7,20 +7,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSaplingHandler:
|
class cItemSaplingHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSaplingHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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(
|
return a_Player.PlaceBlock(
|
||||||
a_PlacePosition,
|
a_PlacePosition,
|
||||||
|
@ -15,7 +15,7 @@ class cItemSeedsHandler:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSeedsHandler(int a_ItemType):
|
constexpr cItemSeedsHandler(int a_ItemType):
|
||||||
Super(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:
|
// Only allow planting seeds from the top side of the block:
|
||||||
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
if (a_ClickedBlockFace != BLOCK_FACE_TOP)
|
||||||
@ -54,12 +54,20 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsPlaceable(void) override
|
virtual bool IsPlaceable(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
~cItemSeedsHandler() = default;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
class cItemSimpleSeedsHandler final:
|
||||||
|
public cItemSeedsHandler
|
||||||
|
{
|
||||||
|
using cItemSeedsHandler::cItemSeedsHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,26 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemShearsHandler:
|
class cItemShearsHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemShearsHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsTool(void) override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +28,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
BLOCKTYPE Block;
|
BLOCKTYPE Block;
|
||||||
NIBBLETYPE BlockMeta;
|
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)
|
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)
|
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))
|
if ((a_Block == E_BLOCK_COBWEB) || IsBlockMaterialLeaves(a_Block))
|
||||||
{
|
{
|
||||||
|
@ -12,21 +12,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemShovelHandler:
|
class cItemShovelHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemShovelHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) override
|
virtual short GetDurabilityLossByAction(eDurabilityLostAction a_Action) const override
|
||||||
{
|
{
|
||||||
switch (a_Action)
|
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)
|
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)
|
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)
|
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.
|
/** 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.
|
Handles setting the correct orientation on placement.
|
||||||
Additionally supports the metadata specifying block sub-type in its lower 2 bits. */
|
Additionally supports the metadata specifying block sub-type in its lower 2 bits. */
|
||||||
class cItemSidewaysHandler :
|
class cItemSidewaysHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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)));
|
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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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)
|
if (a_ClickedBlockFace == BLOCK_FACE_TOP)
|
||||||
{
|
{
|
||||||
@ -60,7 +60,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsPlaceable(void) override
|
virtual bool IsPlaceable(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSlabHandler:
|
class cItemSlabHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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.
|
// 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
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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;
|
BLOCKTYPE Block;
|
||||||
NIBBLETYPE Meta;
|
NIBBLETYPE Meta;
|
||||||
|
@ -8,20 +8,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSoupHandler:
|
class cItemSoupHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSoupHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
constexpr cItemSoupHandler(int a_ItemType, FoodInfo a_FoodInfo):
|
||||||
Super(a_ItemType, 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.
|
// Skip over food handler, which does removal for us.
|
||||||
if (!cItemHandler::EatItem(a_Player, a_Item))
|
if (!cItemHandler::EatItem(a_Player, a_Item))
|
||||||
|
@ -9,21 +9,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSpawnEggHandler:
|
class cItemSpawnEggHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSpawnEggHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool OnItemUse(
|
virtual bool OnItemUse(
|
||||||
cWorld * a_World,
|
cWorld * a_World,
|
||||||
@ -32,7 +25,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
// Must click a valid block:
|
// Must click a valid block:
|
||||||
if (a_ClickedBlockFace < 0)
|
if (a_ClickedBlockFace < 0)
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSpiderEyeHandler:
|
class cItemSpiderEyeHandler final:
|
||||||
public cItemFoodHandler
|
public cItemFoodHandler
|
||||||
{
|
{
|
||||||
using Super = cItemFoodHandler;
|
using Super = cItemFoodHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSpiderEyeHandler():
|
constexpr cItemSpiderEyeHandler(int a_ItemType):
|
||||||
Super(E_ITEM_SPIDER_EYE, FoodInfo(2, 3.2))
|
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))
|
if (!Super::EatItem(a_Player, a_Item))
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemStairsHandler :
|
class cItemStairsHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -19,7 +19,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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());
|
NIBBLETYPE Meta = cBlockStairsHandler::YawToMetaData(a_Player.GetYaw());
|
||||||
|
|
||||||
|
@ -8,20 +8,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSwordHandler:
|
class cItemSwordHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSwordHandler(int a_ItemType):
|
using Super::Super;
|
||||||
Super(a_ItemType)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) const override
|
||||||
virtual bool CanHarvestBlock(BLOCKTYPE a_BlockType) override
|
|
||||||
{
|
{
|
||||||
if (a_BlockType == E_BLOCK_COBWEB)
|
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)
|
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)
|
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)
|
if (a_Block == E_BLOCK_COBWEB)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ class cItemThrowableHandler:
|
|||||||
|
|
||||||
public:
|
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),
|
Super(a_ItemType),
|
||||||
m_ProjectileKind(a_ProjectileKind),
|
m_ProjectileKind(a_ProjectileKind),
|
||||||
m_SpeedCoeff(a_SpeedCoeff)
|
m_SpeedCoeff(a_SpeedCoeff)
|
||||||
@ -32,7 +32,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
auto Pos = a_Player->GetThrowStartPos();
|
auto Pos = a_Player->GetThrowStartPos();
|
||||||
auto Speed = a_Player->GetLookVector() * m_SpeedCoeff;
|
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. */
|
/** The speed multiplier (to the player's normalized look vector) to set for the new projectile. */
|
||||||
double m_SpeedCoeff;
|
double m_SpeedCoeff;
|
||||||
|
|
||||||
|
~cItemThrowableHandler() = default;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemEggHandler:
|
class cItemEggHandler final:
|
||||||
public cItemThrowableHandler
|
public cItemThrowableHandler
|
||||||
{
|
{
|
||||||
using Super = cItemThrowableHandler;
|
using Super = cItemThrowableHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemEggHandler():
|
constexpr cItemEggHandler(int a_ItemType):
|
||||||
Super(E_ITEM_EGG, cProjectileEntity::pkEgg, 30)
|
Super(a_ItemType, cProjectileEntity::pkEgg, 30)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
@ -84,15 +86,15 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemSnowballHandler:
|
class cItemSnowballHandler final:
|
||||||
public cItemThrowableHandler
|
public cItemThrowableHandler
|
||||||
{
|
{
|
||||||
using Super = cItemThrowableHandler;
|
using Super = cItemThrowableHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemSnowballHandler():
|
constexpr cItemSnowballHandler(int a_ItemType):
|
||||||
Super(E_ITEM_SNOWBALL, cProjectileEntity::pkSnowball, 30)
|
Super(a_ItemType, cProjectileEntity::pkSnowball, 30)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
@ -101,15 +103,15 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemEnderPearlHandler:
|
class cItemEnderPearlHandler final:
|
||||||
public cItemThrowableHandler
|
public cItemThrowableHandler
|
||||||
{
|
{
|
||||||
using Super = cItemThrowableHandler;
|
using Super = cItemThrowableHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemEnderPearlHandler():
|
constexpr cItemEnderPearlHandler(int a_ItemType):
|
||||||
Super(E_ITEM_ENDER_PEARL, cProjectileEntity::pkEnderPearl, 30)
|
Super(a_ItemType, cProjectileEntity::pkEnderPearl, 30)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
@ -118,15 +120,15 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemBottleOEnchantingHandler:
|
class cItemBottleOEnchantingHandler final :
|
||||||
public cItemThrowableHandler
|
public cItemThrowableHandler
|
||||||
{
|
{
|
||||||
using Super = cItemThrowableHandler;
|
using Super = cItemThrowableHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemBottleOEnchantingHandler():
|
constexpr cItemBottleOEnchantingHandler(int a_ItemType):
|
||||||
Super(E_ITEM_BOTTLE_O_ENCHANTING, cProjectileEntity::pkExpBottle, 14)
|
Super(a_ItemType, cProjectileEntity::pkExpBottle, 14)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -135,15 +137,15 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemFireworkHandler:
|
class cItemFireworkHandler final:
|
||||||
public cItemThrowableHandler
|
public cItemThrowableHandler
|
||||||
{
|
{
|
||||||
using Super = cItemThrowableHandler;
|
using Super = cItemThrowableHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cItemFireworkHandler():
|
constexpr cItemFireworkHandler(int a_ItemType):
|
||||||
Super(E_ITEM_FIREWORK_ROCKET, cProjectileEntity::pkFirework, 0)
|
Super(a_ItemType, cProjectileEntity::pkFirework, 0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +160,7 @@ public:
|
|||||||
const cItem & a_HeldItem,
|
const cItem & a_HeldItem,
|
||||||
const Vector3i a_ClickedBlockPos,
|
const Vector3i a_ClickedBlockPos,
|
||||||
eBlockFace a_ClickedBlockFace
|
eBlockFace a_ClickedBlockFace
|
||||||
) override
|
) const override
|
||||||
{
|
{
|
||||||
if (a_World->GetBlock(a_ClickedBlockPos) == E_BLOCK_AIR)
|
if (a_World->GetBlock(a_ClickedBlockPos) == E_BLOCK_AIR)
|
||||||
{
|
{
|
||||||
@ -177,5 +179,4 @@ public:
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemTorchHandler :
|
class cItemTorchHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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();
|
const auto & World = *a_Player.GetWorld();
|
||||||
BLOCKTYPE ClickedBlockType;
|
BLOCKTYPE ClickedBlockType;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemTrapdoorHandler :
|
class cItemTrapdoorHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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;
|
NIBBLETYPE Meta;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemTripwireHookHandler :
|
class cItemTripwireHookHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = 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))
|
if ((a_ClickedBlockFace == BLOCK_FACE_YP) || (a_ClickedBlockFace == BLOCK_FACE_YM))
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cItemVineHandler :
|
class cItemVineHandler final :
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
@ -18,7 +18,7 @@ public:
|
|||||||
|
|
||||||
private:
|
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;
|
BLOCKTYPE Block;
|
||||||
NIBBLETYPE Meta;
|
NIBBLETYPE Meta;
|
||||||
|
@ -6,27 +6,27 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class cSimplePlaceableItemHandler :
|
class cSimplePlaceableItemHandler final:
|
||||||
public cItemHandler
|
public cItemHandler
|
||||||
{
|
{
|
||||||
using Super = cItemHandler;
|
using Super = cItemHandler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
cSimplePlaceableItemHandler(int a_ItemType, BLOCKTYPE a_BlockType) :
|
constexpr cSimplePlaceableItemHandler(int a_ItemType, BLOCKTYPE a_BlockType) :
|
||||||
Super(a_ItemType),
|
Super(a_ItemType),
|
||||||
m_BlockType(a_BlockType)
|
m_BlockType(a_BlockType)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual bool IsPlaceable(void) override
|
virtual bool IsPlaceable(void) const override
|
||||||
{
|
{
|
||||||
return true;
|
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);
|
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)
|
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 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)
|
while (Count > MaxStackSize)
|
||||||
{
|
{
|
||||||
a_Drops.emplace_back(a_Item, MaxStackSize, a_ItemHealth);
|
a_Drops.emplace_back(a_Item, MaxStackSize, a_ItemHealth);
|
||||||
|
@ -218,7 +218,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
{
|
{
|
||||||
if (m_Health < m_MaxHealth)
|
if (m_Health < m_MaxHealth)
|
||||||
{
|
{
|
||||||
Heal(ItemHandler(EquippedItemType)->GetFoodInfo(&EquippedItem).FoodLevel);
|
Heal(EquippedItem.GetHandler().GetFoodInfo(&EquippedItem).FoodLevel);
|
||||||
if (!a_Player.IsGameModeCreative())
|
if (!a_Player.IsGameModeCreative())
|
||||||
{
|
{
|
||||||
a_Player.GetInventory().RemoveOneEquippedItem();
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
||||||
|
@ -243,8 +243,6 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo)
|
|||||||
LOGD("Stopping plugin manager...");
|
LOGD("Stopping plugin manager...");
|
||||||
delete m_PluginManager; m_PluginManager = nullptr;
|
delete m_PluginManager; m_PluginManager = nullptr;
|
||||||
|
|
||||||
cItemHandler::Deinit();
|
|
||||||
|
|
||||||
LOG("Cleaning up...");
|
LOG("Cleaning up...");
|
||||||
delete m_Server; m_Server = nullptr;
|
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))
|
else if ((Slot.m_ItemType <= 0) || DraggingItem.IsEqual(Slot))
|
||||||
{
|
{
|
||||||
// Drop one item in slot
|
// Drop one item in slot
|
||||||
cItemHandler * Handler = ItemHandler(Slot.m_ItemType);
|
if ((DraggingItem.m_ItemCount > 0) && (Slot.m_ItemCount < Slot.GetMaxStackSize()))
|
||||||
if ((DraggingItem.m_ItemCount > 0) && (Slot.m_ItemCount < Handler->GetMaxStackSize()))
|
|
||||||
{
|
{
|
||||||
char OldSlotCount = Slot.m_ItemCount;
|
char OldSlotCount = Slot.m_ItemCount;
|
||||||
|
|
||||||
@ -177,8 +176,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Same type, add items:
|
// Same type, add items:
|
||||||
cItemHandler * Handler = ItemHandler(DraggingItem.m_ItemType);
|
int FreeSlots = DraggingItem.GetMaxStackSize() - Slot.m_ItemCount;
|
||||||
int FreeSlots = Handler->GetMaxStackSize() - Slot.m_ItemCount;
|
|
||||||
if (FreeSlots < 0)
|
if (FreeSlots < 0)
|
||||||
{
|
{
|
||||||
ASSERT(!"Bad item stack size - where did we get more items in a slot than allowed?");
|
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
|
// Different items
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||||
if (NumFit <= 0)
|
if (NumFit <= 0)
|
||||||
{
|
{
|
||||||
// Full stack already
|
// Full stack already
|
||||||
@ -636,8 +634,7 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player)
|
|||||||
}
|
}
|
||||||
else if (DraggingItem.IsEqual(Result))
|
else if (DraggingItem.IsEqual(Result))
|
||||||
{
|
{
|
||||||
cItemHandler * Handler = ItemHandler(Result.m_ItemType);
|
if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Result.GetMaxStackSize())
|
||||||
if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Handler->GetMaxStackSize())
|
|
||||||
{
|
{
|
||||||
DraggingItem.m_ItemCount += Result.m_ItemCount;
|
DraggingItem.m_ItemCount += Result.m_ItemCount;
|
||||||
Recipe.ConsumeIngredients(Grid);
|
Recipe.ConsumeIngredients(Grid);
|
||||||
@ -928,7 +925,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
|
|||||||
}
|
}
|
||||||
if (!DraggingItem.IsEmpty())
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -1004,7 +1001,7 @@ void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo
|
|||||||
// Different items
|
// Different items
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||||
if (NumFit <= 0)
|
if (NumFit <= 0)
|
||||||
{
|
{
|
||||||
// Full stack already
|
// Full stack already
|
||||||
@ -1151,7 +1148,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
|
|||||||
RepairCost += Sacrifice.m_RepairCost;
|
RepairCost += Sacrifice.m_RepairCost;
|
||||||
|
|
||||||
// Can we repair with sacrifce material?
|
// 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 / ...)
|
// 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);
|
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.
|
// It's lapis, put it in the lapis spot.
|
||||||
const cItem * Slot = GetSlot(1, a_Player);
|
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)
|
if (NumFit <= 0)
|
||||||
{
|
{
|
||||||
// Full stack already
|
// Full stack already
|
||||||
@ -2036,7 +2033,7 @@ void cSlotAreaFurnace::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||||
if (NumFit <= 0)
|
if (NumFit <= 0)
|
||||||
{
|
{
|
||||||
// Full stack already
|
// Full stack already
|
||||||
@ -2300,7 +2297,7 @@ void cSlotAreaBrewingstand::DistributeStack(cItem & a_ItemStack, cPlayer & a_Pla
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount;
|
char NumFit = Slot->GetMaxStackSize() - Slot->m_ItemCount;
|
||||||
if (NumFit <= 0)
|
if (NumFit <= 0)
|
||||||
{
|
{
|
||||||
// Full stack already
|
// Full stack already
|
||||||
|
@ -696,7 +696,7 @@ void cWindow::OnMiddlePaintEnd(cPlayer & a_Player)
|
|||||||
|
|
||||||
// Fill available slots with full stacks of the dragging item
|
// Fill available slots with full stacks of the dragging item
|
||||||
const auto & DraggingItem = a_Player.GetDraggingItem();
|
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 (0 < DistributeItemToSlots(a_Player, DraggingItem, StackSize, a_Player.GetInventoryPaintSlots(), false))
|
||||||
{
|
{
|
||||||
// If any items were distibuted, set dragging item empty
|
// If any items were distibuted, set dragging item empty
|
||||||
|
Loading…
Reference in New Issue
Block a user