diff options
Diffstat (limited to '')
-rw-r--r-- | source/Defines.h | 40 | ||||
-rw-r--r-- | source/Entities/ProjectileEntity.cpp | 120 | ||||
-rw-r--r-- | source/Entities/ProjectileEntity.h | 55 | ||||
-rw-r--r-- | source/Items/ItemHandler.cpp | 2 | ||||
-rw-r--r-- | source/Items/ItemThrowable.h | 44 |
5 files changed, 226 insertions, 35 deletions
diff --git a/source/Defines.h b/source/Defines.h index 5621aeac1..06410cab4 100644 --- a/source/Defines.h +++ b/source/Defines.h @@ -59,20 +59,20 @@ enum enum eBlockFace { BLOCK_FACE_NONE = -1, // Interacting with no block face - swinging the item in the air - BLOCK_FACE_XM = 5, // Interacting with the X- face of the block - BLOCK_FACE_XP = 4, // Interacting with the X+ face of the block + BLOCK_FACE_XM = 4, // Interacting with the X- face of the block + BLOCK_FACE_XP = 5, // Interacting with the X+ face of the block BLOCK_FACE_YM = 0, // Interacting with the Y- face of the block BLOCK_FACE_YP = 1, // Interacting with the Y+ face of the block - BLOCK_FACE_ZM = 3, // Interacting with the Z- face of the block - BLOCK_FACE_ZP = 2, // Interacting with the Z+ face of the block + BLOCK_FACE_ZM = 2, // Interacting with the Z- face of the block + BLOCK_FACE_ZP = 3, // Interacting with the Z+ face of the block // Synonyms using the (deprecated) world directions: BLOCK_FACE_BOTTOM = BLOCK_FACE_YM, // Interacting with the bottom face of the block BLOCK_FACE_TOP = BLOCK_FACE_YP, // Interacting with the top face of the block - BLOCK_FACE_NORTH = BLOCK_FACE_ZP, // Interacting with the northern face of the block - BLOCK_FACE_SOUTH = BLOCK_FACE_ZM, // Interacting with the southern face of the block - BLOCK_FACE_WEST = BLOCK_FACE_XP, // Interacting with the western face of the block - BLOCK_FACE_EAST = BLOCK_FACE_XM, // Interacting with the eastern face of the block + BLOCK_FACE_NORTH = BLOCK_FACE_ZM, // Interacting with the northern face of the block + BLOCK_FACE_SOUTH = BLOCK_FACE_ZP, // Interacting with the southern face of the block + BLOCK_FACE_WEST = BLOCK_FACE_XM, // Interacting with the western face of the block + BLOCK_FACE_EAST = BLOCK_FACE_XP, // Interacting with the eastern face of the block } ; @@ -305,12 +305,12 @@ inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cha { switch (a_BlockFace) { - case BLOCK_FACE_BOTTOM: a_BlockY--; break; - case BLOCK_FACE_TOP: a_BlockY++; break; - case BLOCK_FACE_EAST: a_BlockX++; break; - case BLOCK_FACE_WEST: a_BlockX--; break; - case BLOCK_FACE_NORTH: a_BlockZ--; break; - case BLOCK_FACE_SOUTH: a_BlockZ++; break; + case BLOCK_FACE_YP: a_BlockY++; break; + case BLOCK_FACE_YM: a_BlockY--; break; + case BLOCK_FACE_ZM: a_BlockZ--; break; + case BLOCK_FACE_ZP: a_BlockZ++; break; + case BLOCK_FACE_XP: a_BlockX++; break; + case BLOCK_FACE_XM: a_BlockX--; break; default: { LOGWARNING("%s: Unknown face: %d", __FUNCTION__, a_BlockFace); @@ -323,12 +323,12 @@ inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, cha { switch (a_BlockFace) { - case BLOCK_FACE_BOTTOM: a_BlockY++; break; - case BLOCK_FACE_TOP: a_BlockY--; break; - case BLOCK_FACE_EAST: a_BlockX--; break; - case BLOCK_FACE_WEST: a_BlockX++; break; - case BLOCK_FACE_NORTH: a_BlockZ++; break; - case BLOCK_FACE_SOUTH: a_BlockZ--; break; + case BLOCK_FACE_YP: a_BlockY--; break; + case BLOCK_FACE_YM: a_BlockY++; break; + case BLOCK_FACE_ZM: a_BlockZ++; break; + case BLOCK_FACE_ZP: a_BlockZ--; break; + case BLOCK_FACE_XP: a_BlockX--; break; + case BLOCK_FACE_XM: a_BlockX++; break; default: { LOGWARNING("%s: Unknown inv face: %d", __FUNCTION__, a_BlockFace); diff --git a/source/Entities/ProjectileEntity.cpp b/source/Entities/ProjectileEntity.cpp index 9d927e39b..fb25aea35 100644 --- a/source/Entities/ProjectileEntity.cpp +++ b/source/Entities/ProjectileEntity.cpp @@ -230,6 +230,8 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, case pkSnowball: return new cThrownSnowballEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkGhastFireball: return new cGhastFireballEntity (a_Creator, a_X, a_Y, a_Z, Speed); case pkFireCharge: return new cFireChargeEntity (a_Creator, a_X, a_Y, a_Z, Speed); + case pkExpBottle: return new cExpBottleEntity (a_Creator, a_X, a_Y, a_Z, Speed); + case pkFirework: return new cFireworkEntity (a_Creator, a_X, a_Y, a_Z ); // TODO: the rest } @@ -446,29 +448,19 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) { + if (a_HitFace == BLOCK_FACE_NONE) { return; } + super::OnHitSolidBlock(a_HitPos, a_HitFace); int a_X = (int)a_HitPos.x, a_Y = (int)a_HitPos.y, a_Z = (int)a_HitPos.z; - - // Projectiles mistakenly think a face faces the direction a player faces when looking directly at said face - // This therefore breaks YP & YM of AddFaceDirection - see #350 for more details + switch (a_HitFace) { - case BLOCK_FACE_NONE: break; // Block tracer sometimes returns this, in this case, the coords will be correct - case BLOCK_FACE_YP: - { - a_Y--; - break; - } + case BLOCK_FACE_XM: // Strangely, bounding boxes / block tracers return the actual block for these two directions, so AddFace not needed case BLOCK_FACE_YM: { - a_Y++; - break; - } - default: - { - AddFaceDirection(a_X, a_Y, a_Z, a_HitFace); break; } + default: AddFaceDirection(a_X, a_Y, a_Z, a_HitFace, true); } m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); @@ -673,6 +665,104 @@ void cThrownSnowballEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_Hi /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cBottleOEnchantingEntity : + +cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : +super(pkExpBottle, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ + SetSpeed(a_Speed); +} + + + + + +void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +{ + // TODO: Spawn experience orbs + + Destroy(); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cFireworkEntity : + +cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z) : +super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25) +{ +} + + + + + +void cFireworkEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) +{ + if ((a_HitFace != BLOCK_FACE_BOTTOM) && (a_HitFace != BLOCK_FACE_NONE)) + { + return; + } + + SetSpeed(0, 0, 0); + SetPosition(GetPosX(), GetPosY() - 0.5, GetPosZ()); + + std::cout << a_HitPos.x << " " << a_HitPos.y << " " << a_HitPos.z << std::endl; + + m_IsInGround = true; + + BroadcastMovementUpdate(); +} + + + + + +void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) +{ + if (m_IsInGround) + { + if (a_Chunk.GetBlock((int)GetPosX(), (int)GetPosY() + 1, (int)GetPosZ()) == E_BLOCK_AIR) + { + m_IsInGround = false; + } + else + { + return; + } + } + + Vector3d PerTickSpeed = GetSpeed() / 20; + Vector3d Pos = GetPosition(); + + // Trace the tick's worth of movement as a line: + Vector3d NextPos = Pos + PerTickSpeed; + cProjectileTracerCallback TracerCallback(this); + if (!cLineBlockTracer::Trace(*m_World, TracerCallback, Pos, NextPos)) + { + // Something has been hit, abort all other processing + return; + } + // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its SlowdownCoeff + + // Update the position: + SetPosition(NextPos); + + // Add slowdown and gravity effect to the speed: + Vector3d NewSpeed(GetSpeed()); + NewSpeed.y += 2; + NewSpeed *= TracerCallback.GetSlowdownCoeff(); + SetSpeed(NewSpeed); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cGhastFireballEntity : cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : diff --git a/source/Entities/ProjectileEntity.h b/source/Entities/ProjectileEntity.h index f62b53a42..959e81ae5 100644 --- a/source/Entities/ProjectileEntity.h +++ b/source/Entities/ProjectileEntity.h @@ -34,6 +34,7 @@ public: pkEnderPearl = 65, pkExpBottle = 75, pkSplashPotion = 73, + pkFirework = 76, pkWitherSkull = 66, pkFishingFloat = 90, } ; @@ -159,6 +160,7 @@ protected: /// Timer for pickup collection animation or five minute timeout float m_Timer; + /// Timer for client arrow position confirmation via TeleportEntity float m_HitGroundTimer; /// If true, the arrow is in the process of being collected - don't go to anyone else @@ -262,6 +264,59 @@ protected: +class cExpBottleEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cExpBottleEntity); + + cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + + // tolua_begin + +}; + + + + + +class cFireworkEntity : + public cProjectileEntity +{ + typedef cProjectileEntity super; + +public: + + // tolua_end + + CLASS_PROTODEF(cFireworkEntity); + + cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z); + +protected: + + // cProjectileEntity overrides: + virtual void OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) override; + virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + + // tolua_begin + +}; + + + + + class cGhastFireballEntity : public cProjectileEntity { diff --git a/source/Items/ItemHandler.cpp b/source/Items/ItemHandler.cpp index 13f5293b9..92ba94999 100644 --- a/source/Items/ItemHandler.cpp +++ b/source/Items/ItemHandler.cpp @@ -90,6 +90,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_BLOCK_WOOL: return new cItemClothHandler(a_ItemType); case E_ITEM_BED: return new cItemBedHandler(a_ItemType); case E_ITEM_BOAT: return new cItemBoatHandler(a_ItemType); + case E_ITEM_BOTTLE_O_ENCHANTING: return new cItemBottleOEnchantingHandler(); case E_ITEM_BOW: return new cItemBowHandler; case E_ITEM_BREWING_STAND: return new cItemBrewingStandHandler(a_ItemType); case E_ITEM_CAULDRON: return new cItemCauldronHandler(a_ItemType); @@ -97,6 +98,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType) case E_ITEM_DYE: return new cItemDyeHandler(a_ItemType); case E_ITEM_EGG: return new cItemEggHandler(); case E_ITEM_ENDER_PEARL: return new cItemEnderPearlHandler(); + case E_ITEM_FIREWORK_ROCKET: return new cItemFireworkHandler(); case E_ITEM_FLINT_AND_STEEL: return new cItemLighterHandler(a_ItemType); case E_ITEM_FLOWER_POT: return new cItemFlowerPotHandler(a_ItemType); case E_ITEM_REDSTONE_DUST: return new cItemRedstoneDustHandler(a_ItemType); diff --git a/source/Items/ItemThrowable.h b/source/Items/ItemThrowable.h index 85579daf2..fc24e775a 100644 --- a/source/Items/ItemThrowable.h +++ b/source/Items/ItemThrowable.h @@ -94,3 +94,47 @@ public: + +class cItemBottleOEnchantingHandler : + public cItemThrowableHandler +{ + typedef cItemThrowableHandler super; +public: + cItemBottleOEnchantingHandler(void) : + super(E_ITEM_BOTTLE_O_ENCHANTING, cProjectileEntity::pkExpBottle, 10) + { + } +}; + + + + + +class cItemFireworkHandler : + public cItemThrowableHandler +{ + typedef cItemThrowableHandler super; +public: + cItemFireworkHandler(void) : + super(E_ITEM_FIREWORK_ROCKET, cProjectileEntity::pkFirework, 0) + { + } + + 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_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ) == E_BLOCK_AIR) + { + return false; + } + + if (!a_Player->IsGameModeCreative()) + { + a_Player->GetInventory().RemoveOneEquippedItem(); + } + + a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, 0); + + return true; + } + +};
\ No newline at end of file |