From ee4d57a0761c6d82a1b449810cc5321d77b1cf9b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:17:57 +0000 Subject: Fixed pickups spawning for BlockEntities --- src/BlockEntities/BlockEntityWithItems.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h index 0846ae17e..f35412e03 100644 --- a/src/BlockEntities/BlockEntityWithItems.h +++ b/src/BlockEntities/BlockEntityWithItems.h @@ -48,7 +48,7 @@ public: cItems Pickups; m_Contents.CopyToItems(Pickups); m_Contents.Clear(); - m_World->SpawnItemPickups(Pickups, m_PosX, m_PosY, m_PosZ); + m_World->SpawnItemPickups(Pickups, m_PosX + 0.5, m_PosY + 0.5, m_PosZ + 0.5); // Spawn in centre of block } // tolua_begin -- cgit v1.2.3 From 57b8b3851179dacb1c07aba5808d61ba51d9b435 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:22:25 +0000 Subject: Updated comments for slabs --- src/ClientHandle.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 95d8f23e5..bcd0f7192 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -685,12 +685,10 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc int pX = a_BlockX; int pY = a_BlockY; int pZ = a_BlockZ; - AddFaceDirection(pX, pY, pZ, a_BlockFace); + AddFaceDirection(pX, pY, pZ, a_BlockFace); // Get the block in front of the clicked coordinates (m_bInverse defaulted to false) Handler = cBlockHandler::GetBlockHandler(World->GetBlock(pX, pY, pZ)); - - // 2013_01_05 _X: This looks weird - // Why do we ask the block "behind" the one being clicked if it is clicked through? Shouldn't we ask the primary block instead? + if (Handler->IsClickedThrough()) { Handler->OnDigging(World, m_Player, pX, pY, pZ); @@ -886,7 +884,10 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c ) ) { - // Coordinates at CLICKED block, don't move them anywhere + // Coordinates at clicked block, which was an eligible slab, and either top or bottom faces were clicked + // If clicked top face and slab occupies the top voxel, we want a slab to be placed above it (therefore increment Y) + // Else if clicked bottom face and slab occupies the bottom voxel, decrement Y for the same reason + // Don't touch coordinates if anything else because a dblslab opportunity is present if((ClickedBlockMeta & 0x08) && (a_BlockFace == BLOCK_FACE_TOP)) { ++a_BlockY; -- cgit v1.2.3 From 0376b847d76d0b47cd86ac862f3b0554bcfbe6aa Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:23:27 +0000 Subject: Removed exporting of a torch function --- src/Blocks/BlockTorch.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 72a313126..2e7c5b814 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -55,8 +55,8 @@ public: } - static NIBBLETYPE DirectionToMetaData(char a_Direction) // tolua_export - { // tolua_export + static NIBBLETYPE DirectionToMetaData(char a_Direction) + { switch (a_Direction) { case BLOCK_FACE_BOTTOM: ASSERT(!"Shouldn't be getting this face"); return 0; @@ -72,7 +72,7 @@ public: } }; return 0x0; - } // tolua_export + } static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export -- cgit v1.2.3 From 73dd2e9bed39c5f902a82568805f4328a0a79526 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:24:45 +0000 Subject: Removed another export and inline'd stuff --- src/Blocks/BlockTorch.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 2e7c5b814..342d88b6c 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -55,7 +55,7 @@ public: } - static NIBBLETYPE DirectionToMetaData(char a_Direction) + inline static NIBBLETYPE DirectionToMetaData(char a_Direction) { switch (a_Direction) { @@ -75,11 +75,11 @@ public: } - static char MetaDataToDirection(NIBBLETYPE a_MetaData) // tolua_export - { // tolua_export + inline static char MetaDataToDirection(NIBBLETYPE a_MetaData) + { switch (a_MetaData) { - case 0: return BLOCK_FACE_TOP; // by default, the torches stand on the ground + case 0: return BLOCK_FACE_TOP; // By default, the torches stand on the ground case E_META_TORCH_FLOOR: return BLOCK_FACE_TOP; case E_META_TORCH_EAST: return BLOCK_FACE_EAST; case E_META_TORCH_WEST: return BLOCK_FACE_WEST; @@ -92,7 +92,7 @@ public: } } return 0; - } // tolua_export + } static bool IsAttachedTo(const Vector3i & a_TorchPos, char a_TorchMeta, const Vector3i & a_BlockPos) -- cgit v1.2.3 From 77a7bfb3e546446412993fc0c30ba55298c76661 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:35:10 +0000 Subject: Cleaned up torch code and added comments --- src/Blocks/BlockTorch.h | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index 342d88b6c..9e543dfd7 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -38,7 +38,8 @@ public: else { // Not top or bottom faces, try to preserve whatever face was clicked - if (!TorchCanBePlacedAt(a_World, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace)) + AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); + if (!CanBePlacedOn(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace)) { // Torch couldn't be placed on whatever face was clicked, last ditch resort - find another face a_BlockFace = FindSuitableFace(a_World, a_BlockX, a_BlockY, a_BlockZ); @@ -95,31 +96,11 @@ public: } - static bool IsAttachedTo(const Vector3i & a_TorchPos, char a_TorchMeta, const Vector3i & a_BlockPos) - { - switch (a_TorchMeta) - { - case 0x0: - case E_META_TORCH_FLOOR: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 1, 0))); - case E_META_TORCH_EAST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, -1))); - case E_META_TORCH_WEST: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(0, 0, 1))); - case E_META_TORCH_NORTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(-1, 0, 0))); - case E_META_TORCH_SOUTH: return ((a_TorchPos - a_BlockPos).Equals(Vector3i(1, 0, 0))); - default: - { - ASSERT(!"Unhandled torch meta!"); - break; - } - } - return false; - } - - static bool CanBePlacedOn(BLOCKTYPE a_BlockType, char a_BlockFace) { if ( !g_BlockIsTorchPlaceable[a_BlockType] ) { - return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright + return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright (for glass, etc.); exceptions won't even be sent by client, no need to handle } else { @@ -128,22 +109,15 @@ public: } - static bool TorchCanBePlacedAt(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) - { - AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); - return CanBePlacedOn(a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ), a_BlockFace); - } - - /// Finds a suitable face to place the torch, returning BLOCK_FACE_NONE on failure static char FindSuitableFace(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) { - for (int i = 0; i <= 5; i++) + for (int i = BLOCK_FACE_YM; i <= BLOCK_FACE_XP; i++) // Loop through all directions { AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, true); BLOCKTYPE BlockInQuestion = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ); - if ( + if ( // If on a block that can only hold a torch if torch is standing on it, return that face ((BlockInQuestion == E_BLOCK_GLASS) || (BlockInQuestion == E_BLOCK_FENCE) || (BlockInQuestion == E_BLOCK_NETHER_BRICK_FENCE) || @@ -155,10 +129,12 @@ public: } else if ((g_BlockIsTorchPlaceable[BlockInQuestion]) && (i != BLOCK_FACE_BOTTOM)) { + // Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face return i; } else { + // Reset coords in preparation for next iteration AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, i, false); } } -- cgit v1.2.3 From 44d5fd1e879dbdafc72097edfb1ad35367503e95 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 19:59:14 +0000 Subject: Tools make a sound when breaking, fixes #266 --- src/Entities/Player.cpp | 5 ++++- src/Entities/ProjectileEntity.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 910613e98..bfacc3422 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1575,7 +1575,10 @@ void cPlayer::UseEquippedItem(void) return; } - GetInventory().DamageEquippedItem(); + if (GetInventory().DamageEquippedItem()) + { + m_World->BroadcastSoundEffect("random.break", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + } } diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index fb25aea35..1d49c2445 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -466,7 +466,7 @@ void cArrowEntity::OnHitSolidBlock(const Vector3d & a_HitPos, char a_HitFace) m_HitBlockPos = Vector3i(a_X, a_Y, a_Z); // Broadcast arrow hit sound - m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); + m_World->BroadcastSoundEffect("random.bowhit", (int)GetPosX() * 8, (int)GetPosY() * 8, (int)GetPosZ() * 8, 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64)); } -- cgit v1.2.3 From 6c7de446ae2a691296a25dc74022e09761ef8197 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:00:49 +0000 Subject: Spawn eggs use IsGameMode() Possible fix for #316. --- src/Items/ItemSpawnEgg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Items/ItemSpawnEgg.h b/src/Items/ItemSpawnEgg.h index 26dd15b7d..407d655de 100644 --- a/src/Items/ItemSpawnEgg.h +++ b/src/Items/ItemSpawnEgg.h @@ -28,14 +28,14 @@ public: AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); - if (a_BlockFace == BLOCK_FACE_BOTTOM) + if (a_BlockFace == BLOCK_FACE_YM) { a_BlockY--; } if (a_World->SpawnMob(a_BlockX + 0.5, a_BlockY, a_BlockZ + 0.5, (cMonster::eType)(a_Item.m_ItemDamage)) >= 0) { - if (a_Player->GetGameMode() != 1) + if (!a_Player->IsGameModeCreative()) { // The mob was spawned, "use" the item: a_Player->GetInventory().RemoveOneEquippedItem(); -- cgit v1.2.3 From 008c515b4b4c0fd0bb519591c9a3054b971ccf35 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:01:52 +0000 Subject: Fixed trapdoors not overriding OnUse --- src/Blocks/BlockTrapdoor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 58d770d23..4682faa3b 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -32,7 +32,7 @@ public: return true; } - void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) + virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { // Flip the ON bit on/off using the XOR bitwise operation NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) ^ 0x04); -- cgit v1.2.3 From 289e8cba211b0e3835088eb6eae4baac9963bd55 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:28:27 +0000 Subject: Fixed eating using wrong animation --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index bfacc3422..90d250eaa 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -572,7 +572,7 @@ void cPlayer::StartEating(void) m_EatingFinishTick = m_World->GetWorldAge() + EATING_TICKS; // Send the packets: - m_World->BroadcastPlayerAnimation(*this, 5); + m_World->BroadcastPlayerAnimation(*this, 3); m_World->BroadcastEntityMetadata(*this); } -- cgit v1.2.3 From 126577214acb1f3f1eb5c99062ddbed3cf1f3756 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:33:48 +0000 Subject: Re-implemented redstone duplicate checking --- src/Simulator/RedstoneSimulator.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 9fdbd1151..fef3e8b21 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -1165,6 +1165,20 @@ void cRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, int a_Block return; } + for (PoweredBlocksList::iterator itr = m_PoweredBlocks.begin(); itr != m_PoweredBlocks.end(); ++itr) // Check powered list + { + sPoweredBlocks & Change = *itr; + + if ( + Change.a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && + Change.a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) + ) + { + // Check for duplicates + return; + } + } + sPoweredBlocks RC; RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); @@ -1194,6 +1208,21 @@ void cRedstoneSimulator::SetBlockLinkedPowered( return; } + for (LinkedBlocksList::iterator itr = m_LinkedPoweredBlocks.begin(); itr != m_LinkedPoweredBlocks.end(); ++itr) // Check linked powered list + { + sLinkedPoweredBlocks & Change = *itr; + + if ( + Change.a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)) && + Change.a_MiddlePos.Equals(Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ)) && + Change.a_SourcePos.Equals(Vector3i(a_SourceX, a_SourceY, a_SourceZ)) + ) + { + // Check for duplicates + return; + } + } + sLinkedPoweredBlocks RC; RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); RC.a_MiddlePos = Vector3i(a_MiddleX, a_MiddleY, a_MiddleZ); -- cgit v1.2.3 From e2a557f46cb564caadd750114dd4a0e8225b9b4e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:39:42 +0000 Subject: Added pickup invalid item check They aren't spawned at all if their itemtype isn't valid; possibly fixes the client crashing with bad pickups. --- src/World.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/World.cpp b/src/World.cpp index 7982924ae..04eab1851 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1585,6 +1585,12 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_FlyAwaySpeed /= 1000; // Pre-divide, so that we don't have to divide each time inside the loop for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { + if (!IsValidItem(itr->m_ItemType)) + { + // Don't spawn pickup if item isn't even valid; should prevent client crashing too + continue; + } + float SpeedX = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); float SpeedY = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); float SpeedZ = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); @@ -1605,6 +1611,11 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double { for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { + if (!IsValidItem(itr->m_ItemType)) + { + continue; + } + cPickup * Pickup = new cPickup( a_BlockX, a_BlockY, a_BlockZ, *itr, IsPlayerCreated, (float)a_SpeedX, (float)a_SpeedY, (float)a_SpeedZ -- cgit v1.2.3 From ec226e00ab8d7808af92a90bc52aa54611561582 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 20:41:58 +0000 Subject: Puking now uses GetEyeHeight() --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 90d250eaa..a0cf24325 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1328,7 +1328,7 @@ void cPlayer::TossItem( double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player + m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } -- cgit v1.2.3 From b115f3d636809e3cfaab80d401347a2d6e6f7df0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 21:31:55 +0000 Subject: Added trapdoor cursor Y detection --- src/Blocks/BlockTrapdoor.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 4682faa3b..57718b45f 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -50,12 +50,10 @@ public: a_BlockType = m_BlockType; a_BlockMeta = BlockFaceToMetaData(a_BlockFace); - /* TODO: fix CursorY issues and uncomment this if (a_CursorY > 7) { a_BlockMeta |= 0x8; } - */ return true; } -- cgit v1.2.3 From b02873172639db2ac7a494389899c2175e0ddd8f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 22:29:15 +0000 Subject: Fixed duplication glitch with QueueSetBlock If a coordinate was queued, and then the block there was broken, it would reappear: double items! Also now just sets meta if previous and current blocktypes matched. --- src/Blocks/BlockButton.h | 4 ++-- src/Chunk.cpp | 31 ++++++++++++++++++++++++++----- src/Chunk.h | 7 ++++--- src/ChunkMap.cpp | 4 ++-- src/ChunkMap.h | 2 +- src/World.cpp | 4 ++-- src/World.h | 2 +- 7 files changed, 38 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index ec897835a..c898a0466 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -18,14 +18,14 @@ public: virtual void OnUse(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override { - // Flip the ON bit on/off using the XOR bitwise operation + // Set p the ON bit to on NIBBLETYPE Meta = (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x08); a_World->SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta); a_World->BroadcastSoundEffect("random.click", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, (Meta & 0x08) ? 0.6f : 0.5f); // Queue a button reset (unpress) - a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30); + a_World->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, m_BlockType, (a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0x07), m_BlockType == E_BLOCK_STONE_BUTTON ? 20 : 30, m_BlockType); } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 5c9eb892b..53c7f3a82 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -701,9 +701,30 @@ void cChunk::ProcessQueuedSetBlocks(void) { if (itr->m_Tick <= CurrTick) { - // Current world age is bigger than/equal to target world age - delay time reached - SetBlock(itr->m_RelX, itr->m_RelY, itr->m_RelZ, itr->m_BlockType, itr->m_BlockMeta); - itr = m_SetBlockQueue.erase(itr); + if (itr->m_PreviousType != E_BLOCK_AIR) // PreviousType defaults to -1 if not specified + { + if (GetBlock(itr->m_RelX, itr->m_RelY, itr->m_RelZ) == itr->m_PreviousType) + { + // Current world age is bigger than/equal to target world age - delay time reached AND + // Previous block type was the same as current block type (to prevent duplication) + // Since blocktypes were the same, we just need to set the meta + SetMeta(itr->m_RelX, itr->m_RelY, itr->m_RelZ, itr->m_BlockMeta); + itr = m_SetBlockQueue.erase(itr); + LOGD("Successfully set queued block - previous and current types matched"); + } + else + { + itr = m_SetBlockQueue.erase(itr); + LOGD("Failure setting queued block - previous and current blocktypes didn't match"); + } + } + else + { + // Current world age is bigger than/equal to target world age - delay time reached + SetBlock(itr->m_RelX, itr->m_RelY, itr->m_RelZ, itr->m_BlockType, itr->m_BlockMeta); + itr = m_SetBlockQueue.erase(itr); + LOGD("Successfully set queued block - previous type ignored"); + } } else { @@ -1410,9 +1431,9 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, -void cChunk::QueueSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick) +void cChunk::QueueSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType) { - m_SetBlockQueue.push_back(sSetBlockQueueItem(a_RelX, a_RelY, a_RelZ, a_BlockType, a_BlockMeta, a_Tick)); + m_SetBlockQueue.push_back(sSetBlockQueueItem(a_RelX, a_RelY, a_RelZ, a_BlockType, a_BlockMeta, a_Tick, a_PreviousBlockType)); } diff --git a/src/Chunk.h b/src/Chunk.h index f13eb9a03..7ff14024c 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -149,7 +149,7 @@ public: void SetBlock( const Vector3i & a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta ) { SetBlock( a_RelBlockPos.x, a_RelBlockPos.y, a_RelBlockPos.z, a_BlockType, a_BlockMeta ); } /// Queues a block change till the specified world tick - void QueueSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick); + void QueueSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); /// Queues block for ticking (m_ToTickQueue) void QueueTickBlock(int a_RelX, int a_RelY, int a_RelZ); @@ -363,9 +363,10 @@ private: BLOCKTYPE m_BlockType; NIBBLETYPE m_BlockMeta; Int64 m_Tick; + BLOCKTYPE m_PreviousType; - sSetBlockQueueItem(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick) : - m_RelX(a_RelX), m_RelY(a_RelY), m_RelZ(a_RelZ), m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta), m_Tick(a_Tick) + sSetBlockQueueItem(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType) : + m_RelX(a_RelX), m_RelY(a_RelY), m_RelZ(a_RelZ), m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta), m_Tick(a_Tick), m_PreviousType(a_PreviousBlockType) { } } ; diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index a6caa5ef7..f3241bd54 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -1173,7 +1173,7 @@ void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_B -void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick) +void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType) { int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); @@ -1182,7 +1182,7 @@ void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYP cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); if ((Chunk != NULL) && Chunk->IsValid()) { - Chunk->QueueSetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_Tick); + Chunk->QueueSetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_Tick, a_PreviousBlockType); } } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index b3fe25393..2a529f43d 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -138,7 +138,7 @@ public: NIBBLETYPE GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_BlockZ); void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockMeta); void SetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); - void QueueSetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick); + void QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta, Int64 a_Tick, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); bool GetBlockTypeMeta (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); bool GetBlockInfo (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); diff --git a/src/World.cpp b/src/World.cpp index 04eab1851..0cf34b861 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1470,9 +1470,9 @@ void cWorld::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBB -void cWorld::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay) +void cWorld::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType) { - m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, GetWorldAge() + a_TickDelay); + m_ChunkMap->QueueSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, GetWorldAge() + a_TickDelay, a_PreviousBlockType); } diff --git a/src/World.h b/src/World.h index ea0db53e6..c865bb73f 100644 --- a/src/World.h +++ b/src/World.h @@ -317,7 +317,7 @@ public: /** Queues a SetBlock() with the specified parameters after the specified number of ticks. Calls SetBlock(), so performs full processing of the replaced block. */ - void QueueSetBlock(int a_BlockX, int a_BLockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay); + void QueueSetBlock(int a_BlockX, int a_BLockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_TickDelay, BLOCKTYPE a_PreviousBlockType = E_BLOCK_AIR); BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ); -- cgit v1.2.3 From a5dd0e2b886261aeb04ca9cbbe981719dd97e99b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 22:45:55 +0000 Subject: Fixed bed leave animation --- src/ClientHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index bcd0f7192..7511ab8b5 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1276,7 +1276,7 @@ void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) } case 3: // Leave bed { - m_Player->GetWorld()->BroadcastPlayerAnimation(*m_Player, 3); + m_Player->GetWorld()->BroadcastPlayerAnimation(*m_Player, 2); break; } case 4: // Start sprinting -- cgit v1.2.3 From 30ead790490f04248b861db79fddde9148b552f4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 6 Dec 2013 23:47:07 +0000 Subject: Renamed animation function Renamed BroadcastPlayerAnimation to BroadcastEntityAnimation. Not just players can have animations, you know. --- src/Bindings.cpp | 43 +++++++++++++++++++++++++++++++++---- src/Bindings.h | 2 +- src/Chunk.cpp | 4 ++-- src/Chunk.h | 2 +- src/ChunkMap.cpp | 6 +++--- src/ChunkMap.h | 2 +- src/ClientHandle.cpp | 14 ++++++------ src/ClientHandle.h | 2 +- src/Entities/Player.cpp | 6 +++--- src/Plugin.h | 2 +- src/PluginLua.cpp | 8 +++---- src/PluginLua.h | 2 +- src/PluginManager.cpp | 6 +++--- src/PluginManager.h | 4 ++-- src/Protocol/Protocol.h | 2 +- src/Protocol/Protocol125.cpp | 4 ++-- src/Protocol/Protocol125.h | 2 +- src/Protocol/Protocol17x.cpp | 4 ++-- src/Protocol/Protocol17x.h | 2 +- src/Protocol/ProtocolRecognizer.cpp | 4 ++-- src/Protocol/ProtocolRecognizer.h | 2 +- src/World.cpp | 4 ++-- src/World.h | 2 +- 23 files changed, 82 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/Bindings.cpp b/src/Bindings.cpp index 6bee7d71d..51a1dbd71 100644 --- a/src/Bindings.cpp +++ b/src/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 11/30/13 15:42:56. +** Generated automatically by tolua++-1.0.92 on 12/06/13 23:06:37. */ #ifndef __cplusplus @@ -11803,6 +11803,38 @@ static int tolua_AllToLua_cWorld_IsDeepSnowEnabled00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: ShouldLavaSpawnFire of class cWorld */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_ShouldLavaSpawnFire00 +static int tolua_AllToLua_cWorld_ShouldLavaSpawnFire00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ShouldLavaSpawnFire'", NULL); +#endif + { + bool tolua_ret = (bool) self->ShouldLavaSpawnFire(); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'ShouldLavaSpawnFire'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: GetDimension of class cWorld */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetDimension00 static int tolua_AllToLua_cWorld_GetDimension00(lua_State* tolua_S) @@ -12193,7 +12225,8 @@ static int tolua_AllToLua_cWorld_QueueSetBlock00(lua_State* tolua_S) !tolua_isnumber(tolua_S,5,0,&tolua_err) || !tolua_isnumber(tolua_S,6,0,&tolua_err) || !tolua_isnumber(tolua_S,7,0,&tolua_err) || - !tolua_isnoobj(tolua_S,8,&tolua_err) + !tolua_isnumber(tolua_S,8,1,&tolua_err) || + !tolua_isnoobj(tolua_S,9,&tolua_err) ) goto tolua_lerror; else @@ -12206,11 +12239,12 @@ static int tolua_AllToLua_cWorld_QueueSetBlock00(lua_State* tolua_S) unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,5,0)); unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,6,0)); int a_TickDelay = ((int) tolua_tonumber(tolua_S,7,0)); + unsigned char a_PreviousBlockType = (( unsigned char) tolua_tonumber(tolua_S,8,E_BLOCK_AIR)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'QueueSetBlock'", NULL); #endif { - self->QueueSetBlock(a_BlockX,a_BLockY,a_BlockZ,a_BlockType,a_BlockMeta,a_TickDelay); + self->QueueSetBlock(a_BlockX,a_BLockY,a_BlockZ,a_BlockType,a_BlockMeta,a_TickDelay,a_PreviousBlockType); } } return 0; @@ -30765,6 +30799,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_constant(tolua_S,"HOOK_COLLECTING_PICKUP",cPluginManager::HOOK_COLLECTING_PICKUP); tolua_constant(tolua_S,"HOOK_CRAFTING_NO_RECIPE",cPluginManager::HOOK_CRAFTING_NO_RECIPE); tolua_constant(tolua_S,"HOOK_DISCONNECT",cPluginManager::HOOK_DISCONNECT); + tolua_constant(tolua_S,"HOOK_ENTITY_ANIMATION",cPluginManager::HOOK_ENTITY_ANIMATION); tolua_constant(tolua_S,"HOOK_EXECUTE_COMMAND",cPluginManager::HOOK_EXECUTE_COMMAND); tolua_constant(tolua_S,"HOOK_EXPLODED",cPluginManager::HOOK_EXPLODED); tolua_constant(tolua_S,"HOOK_EXPLODING",cPluginManager::HOOK_EXPLODING); @@ -30773,7 +30808,6 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_constant(tolua_S,"HOOK_HOPPER_PUSHING_ITEM",cPluginManager::HOOK_HOPPER_PUSHING_ITEM); tolua_constant(tolua_S,"HOOK_KILLING",cPluginManager::HOOK_KILLING); tolua_constant(tolua_S,"HOOK_LOGIN",cPluginManager::HOOK_LOGIN); - tolua_constant(tolua_S,"HOOK_PLAYER_ANIMATION",cPluginManager::HOOK_PLAYER_ANIMATION); tolua_constant(tolua_S,"HOOK_PLAYER_BREAKING_BLOCK",cPluginManager::HOOK_PLAYER_BREAKING_BLOCK); tolua_constant(tolua_S,"HOOK_PLAYER_BROKEN_BLOCK",cPluginManager::HOOK_PLAYER_BROKEN_BLOCK); tolua_constant(tolua_S,"HOOK_PLAYER_EATING",cPluginManager::HOOK_PLAYER_EATING); @@ -30855,6 +30889,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"IsGameModeAdventure",tolua_AllToLua_cWorld_IsGameModeAdventure00); tolua_function(tolua_S,"IsPVPEnabled",tolua_AllToLua_cWorld_IsPVPEnabled00); tolua_function(tolua_S,"IsDeepSnowEnabled",tolua_AllToLua_cWorld_IsDeepSnowEnabled00); + tolua_function(tolua_S,"ShouldLavaSpawnFire",tolua_AllToLua_cWorld_ShouldLavaSpawnFire00); tolua_function(tolua_S,"GetDimension",tolua_AllToLua_cWorld_GetDimension00); tolua_function(tolua_S,"GetHeight",tolua_AllToLua_cWorld_GetHeight00); tolua_function(tolua_S,"BroadcastChat",tolua_AllToLua_cWorld_BroadcastChat00); diff --git a/src/Bindings.h b/src/Bindings.h index 4b6fbb322..f199b58b1 100644 --- a/src/Bindings.h +++ b/src/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 11/30/13 15:42:57. +** Generated automatically by tolua++-1.0.92 on 12/06/13 23:06:38. */ /* Exported function */ diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 53c7f3a82..1c03753c7 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -2668,7 +2668,7 @@ void cChunk::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHand -void cChunk::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude) +void cChunk::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude) { for (cClientHandleList::const_iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr ) { @@ -2676,7 +2676,7 @@ void cChunk::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation { continue; } - (*itr)->SendPlayerAnimation(a_Player, a_Animation); + (*itr)->SendEntityAnimation(a_Entity, a_Animation); } // for itr - LoadedByClient[] } diff --git a/src/Chunk.h b/src/Chunk.h index 7ff14024c..9e5d117c5 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -271,7 +271,7 @@ public: void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastPlayerAnimation (const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // a_Src coords are Block * 8 void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); void BroadcastSpawnEntity (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp index f3241bd54..3ad02ac0e 100644 --- a/src/ChunkMap.cpp +++ b/src/ChunkMap.cpp @@ -573,16 +573,16 @@ void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientH -void cChunkMap::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude) +void cChunkMap::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude) { cCSLock Lock(m_CSLayers); - cChunkPtr Chunk = GetChunkNoGen(a_Player.GetChunkX(), ZERO_CHUNK_Y, a_Player.GetChunkZ()); + cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); if (Chunk == NULL) { return; } // It's perfectly legal to broadcast packets even to invalid chunks! - Chunk->BroadcastPlayerAnimation(a_Player, a_Animation, a_Exclude); + Chunk->BroadcastEntityAnimation(a_Entity, a_Animation, a_Exclude); } diff --git a/src/ChunkMap.h b/src/ChunkMap.h index 2a529f43d..ef070194b 100644 --- a/src/ChunkMap.h +++ b/src/ChunkMap.h @@ -70,7 +70,7 @@ public: void BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); void BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); void BroadcastSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // a_Src coords are Block * 8 void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); void BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 7511ab8b5..f11b7b85f 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1053,13 +1053,13 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_ void cClientHandle::HandleAnimation(char a_Animation) { - if (cPluginManager::Get()->CallHookPlayerAnimation(*m_Player, a_Animation)) + if (cPluginManager::Get()->CallHookEntityAnimation(*m_Player, a_Animation)) { // Plugin disagrees, bail out return; } - m_Player->GetWorld()->BroadcastPlayerAnimation(*m_Player, a_Animation, this); + m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, a_Animation, this); } @@ -1264,19 +1264,19 @@ void cClientHandle::HandleEntityAction(int a_EntityID, char a_ActionID) switch (a_ActionID) { - case 1: // crouch + case 1: // Crouch { m_Player->SetCrouch(true); break; } - case 2: // uncrouch + case 2: // Uncrouch { m_Player->SetCrouch(false); break; } case 3: // Leave bed { - m_Player->GetWorld()->BroadcastPlayerAnimation(*m_Player, 2); + m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2); break; } case 4: // Start sprinting @@ -1813,9 +1813,9 @@ void cClientHandle::SendPickupSpawn(const cPickup & a_Pickup) -void cClientHandle::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { - m_Protocol->SendPlayerAnimation(a_Player, a_Animation); + m_Protocol->SendEntityAnimation(a_Entity, a_Animation); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index b3550110d..4498c15c2 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -114,7 +114,7 @@ public: void SendHealth (void); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); void SendPickupSpawn (const cPickup & a_Pickup); - void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation); + void SendEntityAnimation (const cEntity & a_Entity, char a_Animation); void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline); void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+) void SendPlayerMoveLook (void); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index a0cf24325..4684567e6 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -572,7 +572,7 @@ void cPlayer::StartEating(void) m_EatingFinishTick = m_World->GetWorldAge() + EATING_TICKS; // Send the packets: - m_World->BroadcastPlayerAnimation(*this, 3); + m_World->BroadcastEntityAnimation(*this, 3); m_World->BroadcastEntityMetadata(*this); } @@ -587,7 +587,7 @@ void cPlayer::FinishEating(void) // Send the packets: m_ClientHandle->SendEntityStatus(*this, ENTITY_STATUS_EATING_ACCEPTED); - m_World->BroadcastPlayerAnimation(*this, 0); + m_World->BroadcastEntityAnimation(*this, 0); m_World->BroadcastEntityMetadata(*this); // consume the item: @@ -616,7 +616,7 @@ void cPlayer::FinishEating(void) void cPlayer::AbortEating(void) { m_EatingFinishTick = -1; - m_World->BroadcastPlayerAnimation(*this, 0); + m_World->BroadcastEntityAnimation(*this, 0); m_World->BroadcastEntityMetadata(*this); } diff --git a/src/Plugin.h b/src/Plugin.h index ec55e256d..8dd68e6f1 100644 --- a/src/Plugin.h +++ b/src/Plugin.h @@ -65,7 +65,7 @@ public: virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) = 0; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) = 0; virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) = 0; - virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0; + virtual bool OnEntityAnimation (cEntity & a_Entity, int a_Animation) = 0; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0; virtual bool OnPlayerEating (cPlayer & a_Player) = 0; diff --git a/src/PluginLua.cpp b/src/PluginLua.cpp index 110010087..7fc7bc5f1 100644 --- a/src/PluginLua.cpp +++ b/src/PluginLua.cpp @@ -550,14 +550,14 @@ bool cPluginLua::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, const -bool cPluginLua::OnPlayerAnimation(cPlayer & a_Player, int a_Animation) +bool cPluginLua::OnEntityAnimation(cEntity & a_Entity, int a_Animation) { cCSLock Lock(m_CriticalSection); bool res = false; - cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_ANIMATION]; + cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_ENTITY_ANIMATION]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_Player, a_Animation, cLuaState::Return, res); + m_LuaState.Call((int)(**itr), &a_Entity, a_Animation, cLuaState::Return, res); if (res) { return true; @@ -1287,11 +1287,11 @@ const char * cPluginLua::GetHookFnName(int a_HookType) case cPluginManager::HOOK_COLLECTING_PICKUP: return "OnCollectingPickup"; case cPluginManager::HOOK_CRAFTING_NO_RECIPE: return "OnCraftingNoRecipe"; case cPluginManager::HOOK_DISCONNECT: return "OnDisconnect"; + case cPluginManager::HOOK_ENTITY_ANIMATION: return "OnEntityAnimation"; case cPluginManager::HOOK_EXECUTE_COMMAND: return "OnExecuteCommand"; case cPluginManager::HOOK_HANDSHAKE: return "OnHandshake"; case cPluginManager::HOOK_KILLING: return "OnKilling"; case cPluginManager::HOOK_LOGIN: return "OnLogin"; - case cPluginManager::HOOK_PLAYER_ANIMATION: return "OnPlayerAnimation"; case cPluginManager::HOOK_PLAYER_BREAKING_BLOCK: return "OnPlayerBreakingBlock"; case cPluginManager::HOOK_PLAYER_BROKEN_BLOCK: return "OnPlayerBrokenBlock"; case cPluginManager::HOOK_PLAYER_EATING: return "OnPlayerEating"; diff --git a/src/PluginLua.h b/src/PluginLua.h index 6d135ab75..95e7e789f 100644 --- a/src/PluginLua.h +++ b/src/PluginLua.h @@ -61,7 +61,7 @@ public: virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) override; virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override; virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override; - virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override; + virtual bool OnEntityAnimation (cEntity & a_Entity, int a_Animation) override; virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override; virtual bool OnPlayerEating (cPlayer & a_Player) override; diff --git a/src/PluginManager.cpp b/src/PluginManager.cpp index b57a9d7d8..5bf8a0232 100644 --- a/src/PluginManager.cpp +++ b/src/PluginManager.cpp @@ -603,16 +603,16 @@ bool cPluginManager::CallHookLogin(cClientHandle * a_Client, int a_ProtocolVersi -bool cPluginManager::CallHookPlayerAnimation(cPlayer & a_Player, int a_Animation) +bool cPluginManager::CallHookEntityAnimation(cEntity & a_Entity, int a_Animation) { - HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_ANIMATION); + HookMap::iterator Plugins = m_Hooks.find(HOOK_ENTITY_ANIMATION); if (Plugins == m_Hooks.end()) { return false; } for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnPlayerAnimation(a_Player, a_Animation)) + if ((*itr)->OnEntityAnimation(a_Entity, a_Animation)) { return true; } diff --git a/src/PluginManager.h b/src/PluginManager.h index 12e4da71b..d2694e818 100644 --- a/src/PluginManager.h +++ b/src/PluginManager.h @@ -68,6 +68,7 @@ public: // tolua_export HOOK_COLLECTING_PICKUP, HOOK_CRAFTING_NO_RECIPE, HOOK_DISCONNECT, + HOOK_ENTITY_ANIMATION, HOOK_EXECUTE_COMMAND, HOOK_EXPLODED, HOOK_EXPLODING, @@ -76,7 +77,6 @@ public: // tolua_export HOOK_HOPPER_PUSHING_ITEM, HOOK_KILLING, HOOK_LOGIN, - HOOK_PLAYER_ANIMATION, HOOK_PLAYER_BREAKING_BLOCK, HOOK_PLAYER_BROKEN_BLOCK, HOOK_PLAYER_EATING, @@ -162,7 +162,7 @@ public: // tolua_export bool CallHookHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum); bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer); bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username); - bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation); + bool CallHookEntityAnimation (cEntity & a_Entity, int a_Animation); bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); bool CallHookPlayerEating (cPlayer & a_Player); diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index 9d8183361..ff6541aeb 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -79,7 +79,7 @@ public: virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; virtual void SendPickupSpawn (const cPickup & a_Pickup) = 0; virtual void SendPlayerAbilities (void) = 0; - virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) = 0; + virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) = 0; virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) = 0; virtual void SendPlayerMaxSpeed (void) = 0; ///< Informs the client of the maximum player speed (1.6.1+) virtual void SendPlayerMoveLook (void) = 0; diff --git a/src/Protocol/Protocol125.cpp b/src/Protocol/Protocol125.cpp index b1dd17ea1..9334e6f2d 100644 --- a/src/Protocol/Protocol125.cpp +++ b/src/Protocol/Protocol125.cpp @@ -578,11 +578,11 @@ void cProtocol125::SendPickupSpawn(const cPickup & a_Pickup) -void cProtocol125::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +void cProtocol125::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_ANIMATION); - WriteInt (a_Player.GetUniqueID()); + WriteInt (a_Entity.GetUniqueID()); WriteByte(a_Animation); Flush(); } diff --git a/src/Protocol/Protocol125.h b/src/Protocol/Protocol125.h index 5a9218f5b..32efef4e8 100644 --- a/src/Protocol/Protocol125.h +++ b/src/Protocol/Protocol125.h @@ -55,7 +55,7 @@ public: virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override {} // This protocol doesn't support such message - virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) override; + virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) override; virtual void SendPlayerMaxSpeed (void) override; virtual void SendPlayerMoveLook (void) override; diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 5f5864f2a..68f15cb69 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -489,10 +489,10 @@ void cProtocol172::SendPlayerAbilities(void) -void cProtocol172::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +void cProtocol172::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { cPacketizer Pkt(*this, 0x0b); // Animation packet - Pkt.WriteVarInt(a_Player.GetUniqueID()); + Pkt.WriteVarInt(a_Entity.GetUniqueID()); Pkt.WriteChar(a_Animation); } diff --git a/src/Protocol/Protocol17x.h b/src/Protocol/Protocol17x.h index 9c1eaa99a..9a189ab24 100644 --- a/src/Protocol/Protocol17x.h +++ b/src/Protocol/Protocol17x.h @@ -64,7 +64,7 @@ public: virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; - virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) override; + virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) override; virtual void SendPlayerMaxSpeed (void) override; virtual void SendPlayerMoveLook (void) override; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 489149d74..683700d37 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -396,10 +396,10 @@ void cProtocolRecognizer::SendPlayerAbilities(void) -void cProtocolRecognizer::SendPlayerAnimation(const cPlayer & a_Player, char a_Animation) +void cProtocolRecognizer::SendEntityAnimation(const cEntity & a_Entity, char a_Animation) { ASSERT(m_Protocol != NULL); - m_Protocol->SendPlayerAnimation(a_Player, a_Animation); + m_Protocol->SendEntityAnimation(a_Entity, a_Animation); } diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index 9ca0c1c88..83fc23c22 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -90,7 +90,7 @@ public: virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendPlayerAbilities (void) override; - virtual void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation) override; + virtual void SendEntityAnimation (const cEntity & a_Entity, char a_Animation) override; virtual void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline) override; virtual void SendPlayerMaxSpeed (void) override; virtual void SendPlayerMoveLook (void) override; diff --git a/src/World.cpp b/src/World.cpp index 0cf34b861..2da4a89be 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1858,9 +1858,9 @@ void cWorld::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHand -void cWorld::BroadcastPlayerAnimation(const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude) +void cWorld::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude) { - m_ChunkMap->BroadcastPlayerAnimation(a_Player, a_Animation, a_Exclude); + m_ChunkMap->BroadcastEntityAnimation(a_Entity, a_Animation, a_Exclude); } diff --git a/src/World.h b/src/World.h index c865bb73f..fadb8aac6 100644 --- a/src/World.h +++ b/src/World.h @@ -159,7 +159,7 @@ public: void BroadcastEntityRelMoveLook (const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude = NULL); void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL); void BroadcastEntityVelocity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); - void BroadcastPlayerAnimation (const cPlayer & a_Player, char a_Animation, const cClientHandle * a_Exclude = NULL); + void BroadcastEntityAnimation (const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude = NULL); void BroadcastPlayerListItem (const cPlayer & a_Player, bool a_IsOnline, const cClientHandle * a_Exclude = NULL); void BroadcastSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch, const cClientHandle * a_Exclude = NULL); // tolua_export a_Src coords are Block * 8 void BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data, const cClientHandle * a_Exclude = NULL); // tolua_export -- cgit v1.2.3 From 347e80bdd88f894394373745859f405dc82c1819 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 00:18:58 +0000 Subject: Added basic ender chests Note that they just mirror chests now, so no per player inventory. --- src/BlockEntities/BlockEntity.cpp | 22 +++--- src/BlockEntities/EnderChestEntity.cpp | 130 +++++++++++++++++++++++++++++++++ src/BlockEntities/EnderChestEntity.h | 59 +++++++++++++++ src/Blocks/BlockEnderchest.h | 49 ++++++++++++- src/Blocks/BlockFurnace.h | 1 - src/Chunk.cpp | 2 + src/UI/SlotArea.cpp | 33 +++++++++ src/UI/SlotArea.h | 18 +++++ src/UI/Window.cpp | 38 ++++++++++ src/UI/Window.h | 17 +++++ 10 files changed, 355 insertions(+), 14 deletions(-) create mode 100644 src/BlockEntities/EnderChestEntity.cpp create mode 100644 src/BlockEntities/EnderChestEntity.h (limited to 'src') diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index 41a488717..5d7e4a37a 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -8,6 +8,7 @@ #include "ChestEntity.h" #include "DispenserEntity.h" #include "DropperEntity.h" +#include "EnderChestEntity.h" #include "FurnaceEntity.h" #include "HopperEntity.h" #include "JukeboxEntity.h" @@ -22,16 +23,17 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE { switch (a_BlockType) { - case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_DISPENSER: return new cDispenserEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); - case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_NOTE_BLOCK: return new cNoteEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); - case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_NOTE_BLOCK: return new cNoteEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); } LOGD("%s: Requesting creation of an unknown block entity - block type %d (%s)", __FUNCTION__, a_BlockType, ItemTypeToString(a_BlockType).c_str() diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp new file mode 100644 index 000000000..e53930798 --- /dev/null +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -0,0 +1,130 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "EnderChestEntity.h" +#include "../Item.h" +#include "../Entities/Player.h" +#include "../UI/Window.h" +#include "json/json.h" + + + + + +cEnderChestEntity::cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World) +{ + cBlockEntityWindowOwner::SetBlockEntity(this); +} + + + + + +cEnderChestEntity::~cEnderChestEntity() +{ + cWindow * Window = GetWindow(); + if (Window != NULL) + { + Window->OwnerDestroyed(); + } +} + + + + + +bool cEnderChestEntity::LoadFromJson(const Json::Value & a_Value) +{ + m_PosX = a_Value.get("x", 0).asInt(); + m_PosY = a_Value.get("y", 0).asInt(); + m_PosZ = a_Value.get("z", 0).asInt(); + + Json::Value AllSlots = a_Value.get("Slots", 0); + int SlotIdx = 0; + for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr) + { + cItem Item; + Item.FromJson(*itr); + SetSlot(SlotIdx, Item); + SlotIdx++; + } + return true; +} + + + + + +void cEnderChestEntity::SaveToJson(Json::Value & a_Value) +{ + a_Value["x"] = m_PosX; + a_Value["y"] = m_PosY; + a_Value["z"] = m_PosZ; + + Json::Value AllSlots; + for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--) + { + Json::Value Slot; + m_Contents.GetSlot(i).GetJson(Slot); + AllSlots.append(Slot); + } + a_Value["Slots"] = AllSlots; +} + + + + + +void cEnderChestEntity::SendTo(cClientHandle & a_Client) +{ + // The chest entity doesn't need anything sent to the client when it's created / gets in the viewdistance + // All the actual handling is in the cWindow UI code that gets called when the chest is rclked + + UNUSED(a_Client); +} + + + + + +void cEnderChestEntity::UsedBy(cPlayer * a_Player) +{ + // If the window is not created, open it anew: + cWindow * Window = GetWindow(); + if (Window == NULL) + { + OpenNewWindow(); + Window = GetWindow(); + } + + // Open the window for the player: + if (Window != NULL) + { + if (a_Player->GetWindow() != Window) + { + a_Player->OpenWindow(Window); + } + } + + // This is rather a hack + // Instead of marking the chunk as dirty upon chest contents change, we mark it dirty now + // We cannot properly detect contents change, but such a change doesn't happen without a player opening the chest first. + // The few false positives aren't much to worry about + int ChunkX, ChunkZ; + cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); + m_World->MarkChunkDirty(ChunkX, ChunkZ); +} + + + + + +void cEnderChestEntity::OpenNewWindow(void) +{ + OpenWindow(new cEnderChestWindow(this)); +} + + + + diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h new file mode 100644 index 000000000..683b652b2 --- /dev/null +++ b/src/BlockEntities/EnderChestEntity.h @@ -0,0 +1,59 @@ + +#pragma once + +#include "BlockEntityWithItems.h" +#include "../UI/WindowOwner.h" + + + + + +namespace Json +{ + class Value; +}; + +class cClientHandle; +class cServer; +class cNBTData; + + + + + +class cEnderChestEntity : // tolua_export + public cBlockEntityWindowOwner, + // tolua_begin + public cBlockEntityWithItems +{ + typedef cBlockEntityWithItems super; + +public: + enum { + ContentsHeight = 3, + ContentsWidth = 9, + } ; + + // tolua_end + + /// Constructor used for normal operation + cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); + + virtual ~cEnderChestEntity(); + + static const char * GetClassStatic(void) { return "cEnderChestEntity"; } + + bool LoadFromJson(const Json::Value & a_Value); + + // cBlockEntity overrides: + virtual void SaveToJson(Json::Value & a_Value) override; + virtual void SendTo(cClientHandle & a_Client) override; + virtual void UsedBy(cPlayer * a_Player) override; + + /// Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. + void OpenNewWindow(void); +} ; // tolua_export + + + + diff --git a/src/Blocks/BlockEnderchest.h b/src/Blocks/BlockEnderchest.h index 0ce813f1c..50d8e38e0 100644 --- a/src/Blocks/BlockEnderchest.h +++ b/src/Blocks/BlockEnderchest.h @@ -1,18 +1,18 @@ #pragma once -#include "BlockHandler.h" +#include "BlockEntity.h" class cBlockEnderchestHandler : - public cBlockHandler + public cBlockEntityHandler { public: cBlockEnderchestHandler(BLOCKTYPE a_BlockType) - : cBlockHandler(a_BlockType) + : cBlockEntityHandler(a_BlockType) { } @@ -21,6 +21,49 @@ public: //todo: Drop Ender Chest if using silk touch pickaxe a_Pickups.push_back(cItem(E_BLOCK_OBSIDIAN, 8, 0)); } + + virtual bool GetPlacementBlockTypeMeta( + cWorld * a_World, cPlayer * a_Player, + int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, + int a_CursorX, int a_CursorY, int a_CursorZ, + BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta + ) override + { + a_BlockType = m_BlockType; + a_BlockMeta = RotationToMetaData(a_Player->GetRotation()); + return true; + } + + virtual const char * GetStepSound(void) override + { + return "step.stone"; + } + + static NIBBLETYPE RotationToMetaData(double a_Rotation) + { + a_Rotation += 90 + 45; // So its not aligned with axis + + if (a_Rotation > 360.f) + { + a_Rotation -= 360.f; + } + if ((a_Rotation >= 0.f) && (a_Rotation < 90.f)) + { + return 0x4; + } + else if ((a_Rotation >= 180) && (a_Rotation < 270)) + { + return 0x5; + } + else if ((a_Rotation >= 90) && (a_Rotation < 180)) + { + return 0x2; + } + else + { + return 0x3; + } + } } ; diff --git a/src/Blocks/BlockFurnace.h b/src/Blocks/BlockFurnace.h index fe35893d5..5b067d7b7 100644 --- a/src/Blocks/BlockFurnace.h +++ b/src/Blocks/BlockFurnace.h @@ -4,7 +4,6 @@ #include "BlockEntity.h" #include "../World.h" #include "../Piston.h" -#include "../Entities/Player.h" diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 1c03753c7..4eb11718d 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1301,6 +1301,7 @@ void cChunk::CreateBlockEntities(void) case E_BLOCK_CHEST: case E_BLOCK_DISPENSER: case E_BLOCK_DROPPER: + case E_BLOCK_ENDER_CHEST: case E_BLOCK_LIT_FURNACE: case E_BLOCK_FURNACE: case E_BLOCK_HOPPER: @@ -1413,6 +1414,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, case E_BLOCK_CHEST: case E_BLOCK_DISPENSER: case E_BLOCK_DROPPER: + case E_BLOCK_ENDER_CHEST: case E_BLOCK_LIT_FURNACE: case E_BLOCK_FURNACE: case E_BLOCK_HOPPER: diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 7fd7cd996..e743f4bb3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -8,6 +8,7 @@ #include "../Entities/Player.h" #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/DropSpenserEntity.h" +#include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/FurnaceEntity.h" #include "../Items/ItemHandler.h" #include "Window.h" @@ -556,6 +557,38 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaEnderChest: + +cSlotAreaEnderChest::cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow) : + cSlotArea(27, a_ParentWindow), + m_EnderChest(a_EnderChest) +{ +} + + + + + +const cItem * cSlotAreaEnderChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +{ + // a_SlotNum ranges from 0 to 26, use that to index the chest entity's inventory directly: + return &(m_EnderChest->GetSlot(a_SlotNum)); +} + + + + + +void cSlotAreaEnderChest::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) +{ + m_EnderChest->SetSlot(a_SlotNum, a_Item); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaFurnace: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index b1944d901..d31c87e0c 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -16,6 +16,7 @@ class cWindow; class cPlayer; class cChestEntity; class cDropSpenserEntity; +class cEnderChestEntity; class cFurnaceEntity; class cCraftingRecipe; @@ -286,6 +287,23 @@ protected: +class cSlotAreaEnderChest : + public cSlotArea +{ +public: + cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow); + + virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; + +protected: + cEnderChestEntity * m_EnderChest; +}; + + + + + class cSlotAreaFurnace : public cSlotArea, public cItemGrid::cListener diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index f5c62692f..5ca31fa3e 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -11,6 +11,7 @@ #include "../Items/ItemHandler.h" #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/DropSpenserEntity.h" +#include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/HopperEntity.h" @@ -853,6 +854,43 @@ cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cEnderChestWindow: + +cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest) : + cWindow(wtChest, "Ender Chest"), + m_World(a_EnderChest->GetWorld()), + m_BlockX(a_EnderChest->GetPosX()), + m_BlockY(a_EnderChest->GetPosY()), + m_BlockZ(a_EnderChest->GetPosZ()) +{ + m_SlotAreas.push_back(new cSlotAreaEnderChest(a_EnderChest, *this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); + + // Play the opening sound: + m_World->BroadcastSoundEffect("random.chestopen", m_BlockX * 8, m_BlockY * 8, m_BlockZ * 8, 1, 1); + + // Send out the chest-open packet: + m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, E_BLOCK_ENDER_CHEST); +} + + + + + +cEnderChestWindow::~cEnderChestWindow() +{ + // Send out the chest-close packet: + m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, E_BLOCK_ENDER_CHEST); + + m_World->BroadcastSoundEffect("random.chestclosed", m_BlockX * 8, m_BlockY * 8, m_BlockZ * 8, 1, 1); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cHopperWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index c44b900d7..030182888 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -20,6 +20,7 @@ class cWindowOwner; class cClientHandle; class cChestEntity; class cDropSpenserEntity; +class cEnderChestEntity; class cFurnaceEntity; class cHopperEntity; class cSlotArea; @@ -283,6 +284,22 @@ protected: +class cEnderChestWindow : + public cWindow +{ +public: + cEnderChestWindow(cEnderChestEntity * a_EnderChest); + ~cEnderChestWindow(); + +protected: + cWorld * m_World; + int m_BlockX, m_BlockY, m_BlockZ; // Position of the enderchest, for the window-close packet +}; + + + + + class cInventoryWindow : public cWindow { -- cgit v1.2.3 From 1932cc38a1fba31a61be2f1a5d17ced46d5915ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 14:41:58 +0000 Subject: Fixed trapdoors not toggling The redstone simulator kept on resetting them. --- src/ClientHandle.cpp | 2 +- src/Simulator/RedstoneSimulator.cpp | 106 ++++++++++++++++++++++++++++++------ src/Simulator/RedstoneSimulator.h | 12 ++++ 3 files changed, 103 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index f11b7b85f..eba895fcd 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -205,7 +205,7 @@ void cClientHandle::Kick(const AString & a_Reason) { if (m_State >= csAuthenticating) // Don't log pings { - LOG("Kicking user \"%s\" for \"%s\"", m_Username.c_str(), StripColorCodes(a_Reason).c_str()); + LOGINFO("Kicking player %s for \"%s\"", m_Username.c_str(), StripColorCodes(a_Reason).c_str()); } SendDisconnect(a_Reason); } diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index fef3e8b21..771be6ac1 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -160,6 +160,29 @@ void cRedstoneSimulator::SimulateChunk(float a_Dt, int a_ChunkX, int a_ChunkZ, c } } + for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end();) + { + sSimulatedPlayerToggleableList & Change = *itr; + + int RelX = Change.a_BlockPos.x - a_ChunkX * cChunkDef::Width; + int RelZ = Change.a_BlockPos.z - a_ChunkZ * cChunkDef::Width; + + BLOCKTYPE SourceBlockType; + if (!a_Chunk->UnboundedRelGetBlockType(RelX, Change.a_BlockPos.y, RelZ, SourceBlockType)) + { + continue; + } + else if (!IsAllowedBlock(SourceBlockType)) + { + LOGD("cRedstoneSimulator: Erased block %s from toggleable simulated list due to power state change", ItemToFullString(SourceBlockType).c_str()); + itr = m_SimulatedPlayerToggleableBlocks.erase(itr); + } + else + { + ++itr; + } + } + for (cRedstoneSimulatorChunkData::iterator dataitr = ChunkData.begin(), end = ChunkData.end(); dataitr != end;) { BLOCKTYPE BlockType = a_Chunk->GetBlock(dataitr->x, dataitr->y, dataitr->z); @@ -314,7 +337,6 @@ void cRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_B // Block torch on not powered, can be turned on again! m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); } - return; } @@ -325,7 +347,6 @@ void cRedstoneSimulator::HandleRedstoneBlock(int a_BlockX, int a_BlockY, int a_B { SetAllDirsAsPowered(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); SetBlockPowered(a_BlockX, a_BlockY, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BLOCK_OF_REDSTONE); // Set self as powered - return; } @@ -345,7 +366,6 @@ void cRedstoneSimulator::HandleRedstoneLever(int a_BlockX, int a_BlockY, int a_B SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZM, E_BLOCK_LEVER); SetDirectionLinkedPowered(a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_ZP, E_BLOCK_LEVER); } - return; } @@ -497,7 +517,6 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl } } } - return; } @@ -556,7 +575,6 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); } } - return; } @@ -574,7 +592,6 @@ void cRedstoneSimulator::HandlePiston(int a_BlockX, int a_BlockY, int a_BlockZ) { Piston.RetractPiston(a_BlockX, a_BlockY, a_BlockZ); } - return; } @@ -598,7 +615,6 @@ void cRedstoneSimulator::HandleDropSpenser(int a_BlockX, int a_BlockY, int a_Blo } DrSpSP (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)); m_World.DoWithDropSpenserAt(a_BlockX, a_BlockY, a_BlockZ, DrSpSP); - return; } @@ -621,7 +637,6 @@ void cRedstoneSimulator::HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_Bl m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); } } - return; } @@ -636,7 +651,6 @@ void cRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ) m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); } - return; } @@ -689,7 +703,6 @@ void cRedstoneSimulator::HandleDoor(int a_BlockX, int a_BlockY, int a_BlockZ) } } } - return; } @@ -732,11 +745,19 @@ void cRedstoneSimulator::HandleTrapdoor(int a_BlockX, int a_BlockY, int a_BlockZ { if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x4); + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, true)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) | 0x4); + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, true); + } } else { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0xB); // Take into account that the fourth bit is needed for trapdoors too + if (!AreCoordsSimulated(a_BlockX, a_BlockY, a_BlockZ, false)) + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ) & 0xB); // Take into account that the fourth bit is needed for trapdoors too + SetPlayerToggleableBlockAsSimulated(a_BlockX, a_BlockY, a_BlockZ, false); + } } } @@ -892,6 +913,31 @@ bool cRedstoneSimulator::IsPistonPowered(int a_BlockX, int a_BlockY, int a_Block +bool cRedstoneSimulator::AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered) +{ + for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + { + sSimulatedPlayerToggleableList & Change = *itr; + + if (Change.a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (Change.WasLastStatePowered != IsCurrentStatePowered) // Was the last power state different to the current? + { + return false; // It was, coordinates are no longer simulated + } + else + { + return true; // It wasn't, don't resimulate block, and allow players to toggle + } + } + } + return false; // Block wasn't even in the list, not simulated +} + + + + + void cRedstoneSimulator::SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceType) { switch (a_Direction) @@ -1124,7 +1170,6 @@ void cRedstoneSimulator::SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, i break; } } - return; } @@ -1150,7 +1195,6 @@ void cRedstoneSimulator::SetAllDirsAsPowered(int a_BlockX, int a_BlockY, int a_B { SetBlockPowered(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y, a_BlockZ + gCrossCoords[i].z, a_BlockX, a_BlockY, a_BlockZ, a_SourceBlock); } - return; } @@ -1184,7 +1228,6 @@ void cRedstoneSimulator::SetBlockPowered(int a_BlockX, int a_BlockY, int a_Block RC.a_SourcePos = Vector3i(a_SourceX, a_SourceY, a_SourceZ); RC.a_SourceBlock = a_SourceBlock; m_PoweredBlocks.push_back(RC); - return; } @@ -1230,7 +1273,38 @@ void cRedstoneSimulator::SetBlockLinkedPowered( RC.a_SourceBlock = a_SourceBlock; RC.a_MiddleBlock = a_MiddleBlock; m_LinkedPoweredBlocks.push_back(RC); - return; +} + + + + + +void cRedstoneSimulator::SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered) +{ + for (SimulatedPlayerToggleableList::iterator itr = m_SimulatedPlayerToggleableBlocks.begin(); itr != m_SimulatedPlayerToggleableBlocks.end(); ++itr) + { + sSimulatedPlayerToggleableList & Change = *itr; + + if (Change.a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (Change.WasLastStatePowered != WasLastStatePowered) + { + // If power states different, erase the old listing in preparation to add new one + m_SimulatedPlayerToggleableBlocks.erase(itr); + break; + } + else + { + // If states the same, just ignore + return; + } + } + } + + sSimulatedPlayerToggleableList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.WasLastStatePowered = WasLastStatePowered; + m_SimulatedPlayerToggleableBlocks.push_back(RC); } diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index 59400b614..e094150e8 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -50,12 +50,20 @@ private: BLOCKTYPE a_SourceBlock; BLOCKTYPE a_MiddleBlock; }; + + struct sSimulatedPlayerToggleableList + { + Vector3i a_BlockPos; + bool WasLastStatePowered; + }; typedef std::vector PoweredBlocksList; typedef std::vector LinkedBlocksList; + typedef std::vector SimulatedPlayerToggleableList; PoweredBlocksList m_PoweredBlocks; LinkedBlocksList m_LinkedPoweredBlocks; + SimulatedPlayerToggleableList m_SimulatedPlayerToggleableBlocks; virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; @@ -102,6 +110,8 @@ private: void SetBlockPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock); /// Marks a block as being powered through another block void SetBlockLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, int a_MiddleX, int a_MiddleY, int a_MiddleZ, int a_SourceX, int a_SourceY, int a_SourceZ, BLOCKTYPE a_SourceBlock, BLOCKTYPE a_MiddeBlock); + /// Marks a block as simulated, who should not be simulated further unless their power state changes, to accomodate a player manually toggling the block without triggering the simulator toggling it back + void SetPlayerToggleableBlockAsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool WasLastStatePowered); /// Marks the second block in a direction as linked powered void SetDirectionLinkedPowered(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Direction, BLOCKTYPE a_SourceBlock); /// Marks all blocks immediately surrounding a coordinate as powered @@ -109,6 +119,8 @@ private: /// Returns if a coordinate is powered or linked powered bool AreCoordsPowered(int a_BlockX, int a_BlockY, int a_BlockZ); + /// Returns if a coordinate was marked as simulated (for blocks toggleable by players) + bool AreCoordsSimulated(int a_BlockX, int a_BlockY, int a_BlockZ, bool IsCurrentStatePowered); /// Returns if a repeater is powered bool IsRepeaterPowered(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_Meta); /// Returns if a piston is powered -- cgit v1.2.3 From a61082ffee9c8182d053b4b335bd80bced376606 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 14:55:19 +0000 Subject: Changed some FastSetBlocks to SetBlock Should fix some duplication glitches. --- src/Simulator/RedstoneSimulator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 771be6ac1..63e4f04a8 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -627,14 +627,14 @@ void cRedstoneSimulator::HandleRedstoneLamp(int a_BlockX, int a_BlockY, int a_Bl { if (AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_ON, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_ON, 0); } } else { if (!AreCoordsPowered(a_BlockX, a_BlockY, a_BlockZ)) { - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_LAMP_OFF, 0); } } } @@ -649,7 +649,7 @@ void cRedstoneSimulator::HandleTNT(int a_BlockX, int a_BlockY, int a_BlockZ) { m_World.BroadcastSoundEffect("random.fuse", a_BlockX * 8, a_BlockY * 8, a_BlockZ * 8, 0.5f, 0.6f); m_World.SpawnPrimedTNT(a_BlockX + 0.5, a_BlockY + 0.5, a_BlockZ + 0.5, 4); // 4 seconds to boom - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_AIR, 0); } } -- cgit v1.2.3 From 5bed85aba0720dc22db56dcaec28675c189491c4 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 18:03:56 +0000 Subject: Fixed some new 1.7 client crash bugs Some technical blocks were removed; trying to render them as items caused a crash. --- src/Blocks/BlockHandler.cpp | 2 ++ src/Blocks/BlockPiston.h | 6 ++++++ src/Blocks/BlockRedstoneLamp.h | 27 +++++++++++++++++++++++++++ src/Piston.cpp | 3 ++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/Blocks/BlockRedstoneLamp.h (limited to 'src') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 4a6d49449..43f9eda37 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -48,6 +48,7 @@ #include "BlockPumpkin.h" #include "BlockRail.h" #include "BlockRedstone.h" +#include "BlockRedstoneLamp.h" #include "BlockRedstoneRepeater.h" #include "BlockRedstoneTorch.h" #include "BlockSand.h" @@ -171,6 +172,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE_GLOWING: return new cBlockOreHandler (a_BlockType); + case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); case E_BLOCK_REDSTONE_REPEATER_OFF: return new cBlockRedstoneRepeaterHandler(a_BlockType); case E_BLOCK_REDSTONE_REPEATER_ON: return new cBlockRedstoneRepeaterHandler(a_BlockType); case E_BLOCK_REDSTONE_TORCH_OFF: return new cBlockRedstoneTorchHandler (a_BlockType); diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index 109f5ea8b..36fa6a572 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -36,6 +36,12 @@ public: cBlockPistonHeadHandler(void); virtual void OnDestroyedByPlayer(cWorld * a_World, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override; + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + // No pickups + // Also with 1.7, the item forms of these tecnical blocks have been removed, so giving someone this will crash their client... + } } ; diff --git a/src/Blocks/BlockRedstoneLamp.h b/src/Blocks/BlockRedstoneLamp.h new file mode 100644 index 000000000..69a2b27c2 --- /dev/null +++ b/src/Blocks/BlockRedstoneLamp.h @@ -0,0 +1,27 @@ + +#pragma once + +#include "BlockHandler.h" + + + + + +class cBlockRedstoneLampHandler : + public cBlockHandler +{ +public: + cBlockRedstoneLampHandler(BLOCKTYPE a_BlockType) + : cBlockHandler(a_BlockType) + { + } + + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override + { + a_Pickups.push_back(cItem(E_BLOCK_REDSTONE_LAMP_OFF, 1, 0)); + } +}; + + + + diff --git a/src/Piston.cpp b/src/Piston.cpp index 63ffbad0b..b893af73a 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -113,7 +113,7 @@ void cPiston::ExtendPiston(int pistx, int pisty, int pistz) AddDir(pistx, pisty, pistz, pistonMeta, -1); // "pist" now at piston body, "ext" at future extension - m_World->SetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 0x8); + m_World->SetBlock(pistx, pisty, pistz, pistonBlock, pistonMeta | 0x8); m_World->QueueSetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, pistonMeta | (IsSticky(pistonBlock) ? 8 : 0), PISTON_TICK_DELAY); } @@ -126,6 +126,7 @@ void cPiston::RetractPiston(int pistx, int pisty, int pistz) BLOCKTYPE pistonBlock; NIBBLETYPE pistonMeta; m_World->GetBlockTypeMeta(pistx, pisty, pistz, pistonBlock, pistonMeta); + if (!IsExtended(pistonMeta)) { // Already retracted, bail out -- cgit v1.2.3 From 16db8533e1a9cde333d64dc5a8c8722aa15556cb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 20:29:09 +0000 Subject: Improved piston animations --- src/Piston.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Piston.cpp b/src/Piston.cpp index b893af73a..b15e7d95e 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -15,7 +15,7 @@ /// Number of ticks that the piston extending / retracting waits before setting the block -const int PISTON_TICK_DELAY = 6; +const int PISTON_TICK_DELAY = 1; @@ -142,16 +142,16 @@ void cPiston::RetractPiston(int pistx, int pisty, int pistz) } AddDir(pistx, pisty, pistz, pistonMeta, -1); - m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), pistonBlock); - m_World->BroadcastSoundEffect("tile.piston.in", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); m_World->SetBlock(pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8)); + m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), pistonBlock); + m_World->BroadcastSoundEffect("tile.piston.in", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); AddDir(pistx, pisty, pistz, pistonMeta, 1); // Retract the extension, pull block if appropriate if (IsSticky(pistonBlock)) { int tempx = pistx, tempy = pisty, tempz = pistz; - AddDir( tempx, tempy, tempz, pistonMeta, 1); + AddDir(tempx, tempy, tempz, pistonMeta, 1); BLOCKTYPE tempBlock; NIBBLETYPE tempMeta; m_World->GetBlockTypeMeta(tempx, tempy, tempz, tempBlock, tempMeta); -- cgit v1.2.3 From 405f67dac83db8f7805feca6747be3bec21559af Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 22:35:01 +0000 Subject: Fixed water starting fires --- src/Blocks/BlockHandler.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 43f9eda37..62b57139e 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -187,7 +187,6 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_SNOW: return new cBlockSnowHandler (a_BlockType); case E_BLOCK_SPRUCE_WOOD_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_STATIONARY_LAVA: return new cBlockLavaHandler (a_BlockType); - case E_BLOCK_STATIONARY_WATER: return new cBlockLavaHandler (a_BlockType); case E_BLOCK_STICKY_PISTON: return new cBlockPistonHandler (a_BlockType); case E_BLOCK_STONE: return new cBlockStoneHandler (a_BlockType); case E_BLOCK_STONE_BRICK_STAIRS: return new cBlockStairsHandler (a_BlockType); -- cgit v1.2.3 From b779d84663024751e814a324717c1b9b4dcad6a6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 22:35:24 +0000 Subject: Console trims its commands before executing 'em --- src/Root.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Root.cpp b/src/Root.cpp index f15bfd366..1c81878f9 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -77,11 +77,11 @@ void cRoot::InputThread(void * a_Params) while (!(self.m_bStop || self.m_bRestart) && std::cin.good()) { - std::string Command; + AString Command; std::getline(std::cin, Command); if (!Command.empty()) - { - self.ExecuteConsoleCommand(Command, Output); + { + self.ExecuteConsoleCommand(TrimString(Command), Output); } } -- cgit v1.2.3 From 838d4d5d1d9be001357d6795a343244a43652e2f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 7 Dec 2013 23:45:33 +0000 Subject: Bonemeal has particles, fixes #393 --- src/Items/ItemDye.h | 5 ++--- src/World.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Items/ItemDye.h b/src/Items/ItemDye.h index 99b8d2543..190cdc510 100644 --- a/src/Items/ItemDye.h +++ b/src/Items/ItemDye.h @@ -21,14 +21,13 @@ 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 { - // TODO: Handle coloring the sheep, too (OnItemUseOnEntity maybe) - // Handle growing the plants: if (a_Item.m_ItemDamage == E_META_DYE_WHITE) { if (a_World->GrowRipePlant(a_BlockX, a_BlockY, a_BlockZ, true)) { - if (a_Player->GetGameMode() != gmCreative) + // Particle effects are in GrowRipePlant + if (!a_Player->IsGameModeCreative()) { a_Player->GetInventory().RemoveOneEquippedItem(); return true; diff --git a/src/World.cpp b/src/World.cpp index 2da4a89be..41f08d97f 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1259,6 +1259,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy if (BlockMeta < 7) { FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7); + BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0); } return true; } @@ -1272,6 +1273,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy if (BlockMeta < 7) { FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7); + BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0); } return true; } @@ -1285,6 +1287,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy return false; } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7); + BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0); } else { @@ -1306,6 +1309,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy if (BlockMeta < 7) { FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7); + BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0); } return true; } @@ -1319,6 +1323,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy return false; } FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7); + BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0); } else { @@ -1377,6 +1382,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy } } // switch (random spawn block type) FastSetBlock(a_BlockX + OfsX, a_BlockY + OfsY + 1, a_BlockZ + OfsZ, SpawnType, SpawnMeta); + BroadcastSoundParticleEffect(2005, a_BlockX + OfsX, a_BlockY + OfsY, a_BlockZ + OfsZ, 0); } // for i - 50 times return true; } -- cgit v1.2.3 From 0148685d4ea47c9f81fabb5065fd733e00441da8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 8 Dec 2013 00:32:02 +0000 Subject: Fixed falling block metas, fixes #406 --- src/Protocol/Protocol17x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 68f15cb69..233155c90 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -664,7 +664,7 @@ void cProtocol172::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) Pkt.WriteFPInt(a_FallingBlock.GetPosZ()); Pkt.WriteByteAngle(a_FallingBlock.GetYaw()); Pkt.WriteByteAngle(a_FallingBlock.GetPitch()); - Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 12)); + Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 16)); // Or 0x10 Pkt.WriteShort((short)(a_FallingBlock.GetSpeedX() * 400)); Pkt.WriteShort((short)(a_FallingBlock.GetSpeedY() * 400)); Pkt.WriteShort((short)(a_FallingBlock.GetSpeedZ() * 400)); -- cgit v1.2.3 From f64dd786aadc4fafc4e7b771fe50b7c6ae95ccad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 8 Dec 2013 13:37:10 +0000 Subject: Fixed tabcompletion packet, fixes #356 --- src/Protocol/Protocol17x.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 233155c90..75983e9a3 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -744,17 +744,13 @@ void cProtocol172::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp void cProtocol172::SendTabCompletionResults(const AStringVector & a_Results) { - AString Results; - Results.reserve(500); // Make a moderate reservation to avoid excessive reallocations + cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet + Pkt.WriteVarInt(a_Results.size()); + for (AStringVector::const_iterator itr = a_Results.begin(), end = a_Results.end(); itr != end; ++itr) { - Results.append(*itr); - Results.push_back(0); + Pkt.WriteString(*itr); } - - cPacketizer Pkt(*this, 0x3a); // Tab-Complete packet - Pkt.WriteVarInt(a_Results.size()); - Pkt.WriteString(Results); } -- cgit v1.2.3 From 9c1b7c8b6e43d740c55e75ec594dce2ea482f11e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 8 Dec 2013 14:07:32 +0000 Subject: Readded redstone lamp handler --- src/Blocks/BlockHandler.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 37d948d79..99559ed02 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -48,6 +48,7 @@ #include "BlockPumpkin.h" #include "BlockRail.h" #include "BlockRedstone.h" +#include "BlockRedstoneLamp.h" #include "BlockRedstoneRepeater.h" #include "BlockRedstoneTorch.h" #include "BlockSand.h" @@ -169,6 +170,7 @@ cBlockHandler * cBlockHandler::CreateBlockHandler(BLOCKTYPE a_BlockType) case E_BLOCK_PUMPKIN_STEM: return new cBlockStemsHandler (a_BlockType); case E_BLOCK_QUARTZ_STAIRS: return new cBlockStairsHandler (a_BlockType); case E_BLOCK_RAIL: return new cBlockRailHandler (a_BlockType); + case E_BLOCK_REDSTONE_LAMP_ON: return new cBlockRedstoneLampHandler (a_BlockType); // We need this to change pickups to an off lamp; else 1.7+ clients crash case E_BLOCK_REDSTONE_ORE: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_ORE_GLOWING: return new cBlockOreHandler (a_BlockType); case E_BLOCK_REDSTONE_REPEATER_OFF: return new cBlockRedstoneRepeaterHandler(a_BlockType); -- cgit v1.2.3