From 77b3db7e25c401d4ff78ee4fe291880df441a6fe Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 2 Nov 2013 14:08:00 +0000 Subject: Multiple fixes * Fixed #282 * Fixed bow not taking damage * Enhanced Player.cpp code --- source/Entities/Player.cpp | 21 +++++++++------------ source/Item.cpp | 1 + source/Items/ItemBow.h | 1 + source/Items/ItemThrowable.h | 6 ++++++ 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index d94bc944c..ffd829663 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -297,7 +297,6 @@ void cPlayer::CancelChargingBow(void) void cPlayer::SetTouchGround(bool a_bTouchGround) { - // If just m_bTouchGround = a_bTouchGround; if (!m_bTouchGround) @@ -307,12 +306,11 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) m_LastJumpHeight = (float)GetPosY(); } cWorld * World = GetWorld(); - if ((GetPosY() >= 0) && (GetPosY() < 256)) + if ((GetPosY() >= 0) && (GetPosY() < cChunkDef::Height)) { - BLOCKTYPE BlockType = World->GetBlock( float2int(GetPosX()), float2int(GetPosY()), float2int(GetPosZ()) ); + BLOCKTYPE BlockType = World->GetBlock(float2int(GetPosX()), float2int(GetPosY()), float2int(GetPosZ())); if (BlockType != E_BLOCK_AIR) { - // LOGD("TouchGround set to true by server"); m_bTouchGround = true; } if ( @@ -320,21 +318,20 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) (BlockType == E_BLOCK_STATIONARY_WATER) || (BlockType == E_BLOCK_LADDER) || (BlockType == E_BLOCK_VINES) - ) + ) { - // LOGD("Water / Ladder / Torch"); m_LastGroundHeight = (float)GetPosY(); } } } - - if (m_bTouchGround) + else { float Dist = (float)(m_LastGroundHeight - floor(GetPosY())); int Damage = (int)(Dist - 3.f); - if(m_LastJumpHeight > m_LastGroundHeight) Damage++; + if (m_LastJumpHeight > m_LastGroundHeight) Damage++; m_LastJumpHeight = (float)GetPosY(); - if (Damage > 0) + + if ((Damage > 0) && (!IsGameModeCreative())) { TakeDamage(dtFalling, NULL, Damage, Damage, 0); } @@ -1416,11 +1413,11 @@ cPlayer::StringList cPlayer::GetResolvedPermissions() void cPlayer::UseEquippedItem(void) { - if (GetGameMode() == gmCreative) // No damage in creative + if (IsGameModeCreative()) // No damage in creative { return; } - + GetInventory().DamageEquippedItem(); } diff --git a/source/Item.cpp b/source/Item.cpp index 31a09a608..5e0beb028 100644 --- a/source/Item.cpp +++ b/source/Item.cpp @@ -38,6 +38,7 @@ short cItem::GetMaxDamage(void) const { switch (m_ItemType) { + case E_ITEM_BOW: return 384; case E_ITEM_DIAMOND_AXE: return 1563; case E_ITEM_DIAMOND_HOE: return 1563; case E_ITEM_DIAMOND_PICKAXE: return 1563; diff --git a/source/Items/ItemBow.h b/source/Items/ItemBow.h index 845192ef7..1add0dc6d 100644 --- a/source/Items/ItemBow.h +++ b/source/Items/ItemBow.h @@ -71,6 +71,7 @@ public: return; } a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow); + a_Player->UseEquippedItem(); } } ; diff --git a/source/Items/ItemThrowable.h b/source/Items/ItemThrowable.h index dacdb6157..85579daf2 100644 --- a/source/Items/ItemThrowable.h +++ b/source/Items/ItemThrowable.h @@ -28,9 +28,15 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override { + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + Vector3d Pos = a_Player->GetThrowStartPos(); Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, &Speed); + return true; } -- cgit v1.2.3 From 96cd7d65a3823048bd7d59e99ca3406cf0031a55 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 2 Nov 2013 14:09:07 +0000 Subject: Fixed dropspensing speed and position --- source/BlockEntities/DropSpenserEntity.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/BlockEntities/DropSpenserEntity.cpp b/source/BlockEntities/DropSpenserEntity.cpp index a9fcdab17..25def9999 100644 --- a/source/BlockEntities/DropSpenserEntity.cpp +++ b/source/BlockEntities/DropSpenserEntity.cpp @@ -89,6 +89,8 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk) int SmokeDir = 0; switch (Meta) { + case E_META_DROPSPENSER_FACING_YP: SmokeDir = 4; break; // YP & YM don't have associated smoke dirs, just do 4 (centre of block) + case E_META_DROPSPENSER_FACING_YM: SmokeDir = 4; break; case E_META_DROPSPENSER_FACING_XM: SmokeDir = 3; break; case E_META_DROPSPENSER_FACING_XP: SmokeDir = 5; break; case E_META_DROPSPENSER_FACING_ZM: SmokeDir = 1; break; @@ -237,7 +239,26 @@ void cDropSpenserEntity::DropFromSlot(cChunk & a_Chunk, int a_SlotNum) cItems Pickups; Pickups.push_back(m_Contents.RemoveOneItem(a_SlotNum)); - m_World->SpawnItemPickups(Pickups, DispX, DispY, DispZ); + + const int PickupSpeed = m_World->GetTickRandomNumber(4) + 2; // At least 2, at most 6 + int PickupSpeedX = 0, PickupSpeedY = 0, PickupSpeedZ = 0; + switch (Meta) + { + case E_META_DROPSPENSER_FACING_YP: PickupSpeedY = PickupSpeed; break; + case E_META_DROPSPENSER_FACING_YM: PickupSpeedY = -PickupSpeed; break; + case E_META_DROPSPENSER_FACING_XM: PickupSpeedX = -PickupSpeed; break; + case E_META_DROPSPENSER_FACING_XP: PickupSpeedX = PickupSpeed; break; + case E_META_DROPSPENSER_FACING_ZM: PickupSpeedZ = -PickupSpeed; break; + case E_META_DROPSPENSER_FACING_ZP: PickupSpeedZ = PickupSpeed; break; + } + + double MicroX, MicroY, MicroZ; + MicroX = DispX + 0.5; + MicroY = DispY + 0.4; // Slightly less than half, to accomodate actual texture hole on DropSpenser + MicroZ = DispZ + 0.5; + + + m_World->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ, PickupSpeedX, PickupSpeedY, PickupSpeedZ); } -- cgit v1.2.3 From f38375a2ecaca692f905d687101315b801c3e724 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 2 Nov 2013 16:01:40 +0000 Subject: Fixed bow damage in creative Also reverted indenting change --- source/Entities/Player.cpp | 2 +- source/Items/ItemBow.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index ffd829663..2e4199629 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -318,7 +318,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) (BlockType == E_BLOCK_STATIONARY_WATER) || (BlockType == E_BLOCK_LADDER) || (BlockType == E_BLOCK_VINES) - ) + ) { m_LastGroundHeight = (float)GetPosY(); } diff --git a/source/Items/ItemBow.h b/source/Items/ItemBow.h index 1add0dc6d..7bce127b1 100644 --- a/source/Items/ItemBow.h +++ b/source/Items/ItemBow.h @@ -71,7 +71,11 @@ public: return; } a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow); - a_Player->UseEquippedItem(); + + if (!a_Player->IsGameModeCreative()) + { + a_Player->UseEquippedItem(); + } } } ; -- cgit v1.2.3