Skip to content

Commit

Permalink
Support swap item between main hand and offhand by press key "F" (cub…
Browse files Browse the repository at this point in the history
…erite#4241)

Hi,

I found cuberite don't support to press key "F" to swap items on main hand and offhand, so I implemented this feature.

Best regards
Changyong
  • Loading branch information
changyongGuo authored and peterbell10 committed Jun 24, 2018
1 parent 24603a7 commit 2d3013d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ beeduck
bibo38
birkett (Anthony Birkett)
Bond_009
changyongGuo
Cocosushi6
derouinw
Diusrex
Expand Down
10 changes: 10 additions & 0 deletions Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,16 @@ local Hash = cCryptoHash.sha1HexString("DataToHash")
},
Notes = "Returns the weapon that the entity has equipped. Returns an empty cItem if no weapon equipped or not applicable.",
},
GetOffHandEquipedItem =
{
Returns =
{
{
Type = "cItem",
},
},
Notes = "Returns the item that the entity has equipped on off-hand. Returns an empty cItem if no item equipped or not applicable.",
},
GetGravity =
{
Returns =
Expand Down
9 changes: 8 additions & 1 deletion src/ClientHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,14 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB

case DIG_STATUS_SWAP_ITEM_IN_HAND:
{
// TODO: Not yet implemented

cItem EquippedItem = m_Player->GetEquippedItem();
cItem OffhandItem = m_Player->GetOffHandEquipedItem();

cInventory & Intentory = m_Player->GetInventory();
Intentory.SetShieldSlot(EquippedItem);
Intentory.SetHotbarSlot(Intentory.GetEquippedSlotNum(), OffhandItem);

return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ class cEntity
/** Returns the currently equipped boots; empty item if none */
virtual cItem GetEquippedBoots(void) const { return cItem(); }

/** Returns the currently offhand equipped item; empty item if none */
virtual cItem GetOffHandEquipedItem(void) const { return cItem(); }

/** Applies damage to the armor after the armor blocked the given amount */
virtual void ApplyArmorDamage(int DamageBlocked);

Expand Down
3 changes: 3 additions & 0 deletions src/Entities/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class cPlayer :
/** Returns the currently equipped boots; empty item if none */
virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); }

/** Returns the currently offhand equipped item; empty item if none */
virtual cItem GetOffHandEquipedItem(void) const override { return m_Inventory.GetShieldSlot(); }

virtual void ApplyArmorDamage(int DamageBlocked) override;

// tolua_begin
Expand Down

0 comments on commit 2d3013d

Please sign in to comment.