* Add Player::drop

This commit is contained in:
iProgramInCpp
2023-07-31 17:13:10 +03:00
parent 297f7f3cf4
commit cb085a8956
6 changed files with 63 additions and 4 deletions

View File

@@ -59,8 +59,11 @@ enum
//...
AKEYCODE_9 = '9',
// note: You have to add these here instead of using the
// characters themselves, otherwise android won't pick it up
AKEYCODE_A = 'A',
//...
AKEYCODE_Q = 'Q',
AKEYCODE_T = 'T',
AKEYCODE_Z = 'Z',
AKEYCODE_F4 = VK_F4,

View File

@@ -381,6 +381,13 @@ void Minecraft::tickInput()
m_pLevelRenderer->allChanged();
}
#endif
#ifdef TEST_DROPPED_ITEMS
else if (keyCode == AKEYCODE_Q)
{
ItemInstance inst(m_pLocalPlayer->m_pInventory->getSelectedItemId(), 1, 0);
m_pLocalPlayer->drop(&inst);
}
#endif
}
if (m_options.field_19)

View File

@@ -220,6 +220,45 @@ void Player::displayClientMessage(const std::string& msg)
}
void Player::drop(ItemInstance* pItemInstance)
{
drop(pItemInstance, false);
}
void Player::drop(ItemInstance* pItemInstance, bool b)
{
if (!pItemInstance)
return;
ItemEntity* pItemEntity = new ItemEntity(m_pLevel, m_pos.x, m_pos.y - 0.3f + getHeadHeight(), m_pos.z, pItemInstance);
pItemEntity->field_E4 = 40;
if (b)
{
float throwPower = 0.5f * m_random.nextFloat();
float throwAngle = m_random.nextFloat();
pItemEntity->m_vel.x = -(throwPower * Mth::sin(2 * float(M_PI) * throwAngle));
pItemEntity->m_vel.z = (throwPower * Mth::cos(2 * float(M_PI) * throwAngle));
pItemEntity->m_vel.y = 0.2f;
}
else
{
pItemEntity->m_vel.x = -(Mth::sin(m_yaw / 180.0f * float(M_PI)) * Mth::cos(m_pitch / 180.0f * float(M_PI))) * 0.3f;
pItemEntity->m_vel.z = (Mth::cos(m_yaw / 180.0f * float(M_PI)) * Mth::cos(m_pitch / 180.0f * float(M_PI))) * 0.3f;
pItemEntity->m_vel.y = 0.1f - Mth::sin(m_pitch / 180.0f * float(M_PI)) * 0.3f;
float f1 = m_random.nextFloat();
float f2 = m_random.nextFloat();
pItemEntity->m_vel.x += 0.02f * f2 * Mth::cos(2 * float(M_PI) * f1);
pItemEntity->m_vel.y += 0.1f * (m_random.nextFloat() - m_random.nextFloat());
pItemEntity->m_vel.z += 0.02f * f2 * Mth::sin(2 * float(M_PI) * f1);
}
reallyDrop(pItemEntity);
}
void Player::drop()
{
@@ -250,6 +289,11 @@ void Player::prepareCustomTextures()
}
void Player::reallyDrop(ItemEntity* pEnt)
{
m_pLevel->addEntity(pEnt);
}
void Player::respawn()
{

View File

@@ -10,6 +10,7 @@
#include "Mob.hpp"
#include "Inventory.hpp"
#include "ItemEntity.hpp"
#include "RakNetTypes.h"
class Inventory; // in case we're included from Inventory.hpp
@@ -44,15 +45,15 @@ public:
bool canDestroy(Tile*);
void closeContainer();
void displayClientMessage(const std::string& msg);
// TODO: void drop(ItemInstance*);
// TODO: void drop(ItemInstance*, bool);
void drop(ItemInstance*);
void drop(ItemInstance*, bool);
void drop();
float getDestroySpeed();
int getInventorySlot(int x);
Pos getRespawnPosition();
int getScore();
void prepareCustomTextures();
// TODO: void reallyDrop(ItemEntity* pEnt);
void reallyDrop(ItemEntity* pEnt);
void respawn();
void rideTick();
void setDefaultHeadHeight();

View File

@@ -28,6 +28,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\compat\AKeyCodes.hpp" />
<ClInclude Include="..\GameMods.hpp" />
<ClInclude Include="..\platforms\windows\AppPlatform_windows.hpp" />
<ClInclude Include="..\platforms\windows\SoundSystem_windows.hpp" />
<ClInclude Include="..\source\App\App.hpp" />

View File

@@ -1922,6 +1922,9 @@
<ClInclude Include="..\platforms\windows\SoundSystem_windows.hpp">
<Filter>Header Files\App</Filter>
</ClInclude>
<ClInclude Include="..\GameMods.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\thirdparty\raknet\CMakeLists.txt">