From 679085b520f32e898a88823b1c2d23a12a1764f1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 18 Aug 2013 00:33:14 +0100 Subject: Bugfix Update [SEE DESC} Added stained clay, coal block, and hardened clay Block IDs Added stained clay and carpet block Metas Fixed bug with sticky retract bailing out but not unsetting arm Fixed autocomplete not working when not at the first character, fixes #64 Added furnace recipes for hardened clay and coal and coal blocks --- source/BlockID.h | 44 +++++++++++++++++++++++++++++++++++++++++--- source/Piston.cpp | 1 + source/World.cpp | 15 +++++++++++---- 3 files changed, 53 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/BlockID.h b/source/BlockID.h index b1c952857..8a60c16ce 100644 --- a/source/BlockID.h +++ b/source/BlockID.h @@ -169,8 +169,11 @@ enum ENUM_BLOCK_ID E_BLOCK_ACTIVATOR_RAIL = 157, E_BLOCK_DROPPER = 158, - - E_BLOCK_CARPET = 171, + E_BLOCK_STAINED_CLAY = 159, + E_BLOCK_HAY_BALE = 170 + E_BLOCK_CARPET = 171, + E_BLOCK_HARDENED_CLAY = 172, + E_BLOCK_BLOCK_OF_COAL = 173, // Keep these two as the last values, without a number - they will get their correct number assigned automagically by C++ // IsValidBlock() depends on this @@ -507,7 +510,42 @@ enum E_META_WOOL_RED = 14, E_META_WOOL_BLACK = 15, - + // E_BLOCK_CARPET metas: + E_META_CARPET_WHITE = 0, + E_META_CARPET_ORANGE = 1, + E_META_CARPET_MAGENTA = 2, + E_META_CARPET_LIGHTBLUE = 3, + E_META_CARPET_YELLOW = 4, + E_META_CARPET_LIGHTGREEN = 5, + E_META_CARPET_PINK = 6, + E_META_CARPET_GRAY = 7, + E_META_CARPET_LIGHTGRAY = 8, + E_META_CARPET_CYAN = 9, + E_META_CARPET_PURPLE = 10, + E_META_CARPET_BLUE = 11, + E_META_CARPET_BROWN = 12, + E_META_CARPET_GREEN = 13, + E_META_CARPET_RED = 14, + E_META_CARPET_BLACK = 15, + + // E_BLOCK_STAINED_CLAY metas + E_META_STAINED_CLAY_WHITE = 0, + E_META_STAINED_CLAY_ORANGE = 1, + E_META_STAINED_CLAY_MAGENTA = 2, + E_META_STAINED_CLAY_LIGHTBLUE = 3, + E_META_STAINED_CLAY_YELLOW = 4, + E_META_STAINED_CLAY_LIGHTGREEN = 5, + E_META_STAINED_CLAY_PINK = 6, + E_META_STAINED_CLAY_GRAY = 7, + E_META_STAINED_CLAY_LIGHTGRAY = 8, + E_META_STAINED_CLAY_CYAN = 9, + E_META_STAINED_CLAY_PURPLE = 10, + E_META_STAINED_CLAY_BLUE = 11, + E_META_STAINED_CLAY_BROWN = 12, + E_META_STAINED_CLAY_GREEN = 13, + E_META_STAINED_CLAY_RED = 14, + E_META_STAINED_CLAY_BLACK = 15, + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Item metas: diff --git a/source/Piston.cpp b/source/Piston.cpp index 7ffa9febd..058f92a0e 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -173,6 +173,7 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) ) { // These cannot be moved by the sticky piston, bail out + m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); return; } diff --git a/source/World.cpp b/source/World.cpp index 702e94b56..5c15a3965 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -2635,12 +2635,19 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr) { - if (NoCaseCompare((*itr)->GetName().substr(0, a_Text.length()), a_Text) != 0) + for (unsigned int selected = 0; selected < a_Text.length(); selected++ ) { - // Player name doesn't match - continue; + std::string playername ((*itr)->GetName()); + std::string cut (a_Text.substr(selected, a_Text.length())); + std::size_t found = playername.find(cut); + if (found!=0) + { + //Player name doesn't match + continue; + } + a_Results.push_back((*itr)->GetName()); + break; } - a_Results.push_back((*itr)->GetName()); } } -- cgit v1.2.3 From 9e0b8b5bee6fec15df846334cffc2d8e913c0328 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 18 Aug 2013 11:58:19 +0100 Subject: Enhancements to Tabcompletion and Compile Fix Tab complete now finds the last word and matches accordingly, with a 20% increase in speed! Fixed missing comma breaking compilation --- source/BlockID.h | 2 +- source/World.cpp | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'source') diff --git a/source/BlockID.h b/source/BlockID.h index 8a60c16ce..3c4381ae1 100644 --- a/source/BlockID.h +++ b/source/BlockID.h @@ -170,7 +170,7 @@ enum ENUM_BLOCK_ID E_BLOCK_DROPPER = 158, E_BLOCK_STAINED_CLAY = 159, - E_BLOCK_HAY_BALE = 170 + E_BLOCK_HAY_BALE = 170, E_BLOCK_CARPET = 171, E_BLOCK_HARDENED_CLAY = 172, E_BLOCK_BLOCK_OF_COAL = 173, diff --git a/source/World.cpp b/source/World.cpp index 5c15a3965..6b82dce0f 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -2635,19 +2635,15 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr) { - for (unsigned int selected = 0; selected < a_Text.length(); selected++ ) + unsigned LastSpace = a_Text.find_last_of(" "); + std::string LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); + std::string PlayerName ((*itr)->GetName()); + std::size_t Found = PlayerName.find(LastWord); + if (Found!=0) { - std::string playername ((*itr)->GetName()); - std::string cut (a_Text.substr(selected, a_Text.length())); - std::size_t found = playername.find(cut); - if (found!=0) - { - //Player name doesn't match - continue; - } - a_Results.push_back((*itr)->GetName()); - break; + continue; } + a_Results.push_back((*itr)->GetName()); } } -- cgit v1.2.3 From 8a3174164b0ee3e902031d631c690ed555b74f05 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 18 Aug 2013 14:52:38 +0100 Subject: Properly fixed piston non-animation Fixes #57 --- source/Chunk.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ source/Chunk.h | 2 ++ source/ChunkMap.cpp | 18 ++++++++++++++++++ source/ChunkMap.h | 1 + source/Piston.cpp | 39 ++++++++++++++++++++++++++----------- source/World.cpp | 28 ++++++++++++++++++++++----- source/World.h | 1 + 7 files changed, 128 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/Chunk.cpp b/source/Chunk.cpp index 62d411b0c..7bff3fdc9 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -1607,6 +1607,61 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT +void cChunk::SetServerBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) +{ + ASSERT(!((a_RelX < 0) || (a_RelX >= Width) || (a_RelY < 0) || (a_RelY >= Height) || (a_RelZ < 0) || (a_RelZ >= Width))); + + ASSERT(IsValid()); + + const int index = MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); + const BLOCKTYPE OldBlockType = cChunkDef::GetBlock(m_BlockTypes, index); + const BLOCKTYPE OldBlockMeta = GetNibble(m_BlockMeta, index); + if ((OldBlockType == a_BlockType) && (OldBlockMeta == a_BlockMeta)) + { + return; + } + + MarkDirty(); + + m_BlockTypes[index] = a_BlockType; + + SetNibble(m_BlockMeta, index, a_BlockMeta); + + // ONLY recalculate lighting if it's necessary! + if( + (g_BlockLightValue[OldBlockType ] != g_BlockLightValue[a_BlockType]) || + (g_BlockSpreadLightFalloff[OldBlockType] != g_BlockSpreadLightFalloff[a_BlockType]) || + (g_BlockTransparent[OldBlockType] != g_BlockTransparent[a_BlockType]) + ) + { + m_IsLightValid = false; + } + + // Update heightmap, if needed: + if (a_RelY >= m_HeightMap[a_RelX + a_RelZ * Width]) + { + if (a_BlockType != E_BLOCK_AIR) + { + m_HeightMap[a_RelX + a_RelZ * Width] = (unsigned char)a_RelY; + } + else + { + for (int y = a_RelY - 1; y > 0; --y) + { + if (m_BlockTypes[MakeIndexNoCheck(a_RelX, y, a_RelZ)] != E_BLOCK_AIR) + { + m_HeightMap[a_RelX + a_RelZ * Width] = (unsigned char)y; + break; + } + } // for y - column in m_BlockData + } + } +} + + + + + void cChunk::SendBlockTo(int a_RelX, int a_RelY, int a_RelZ, cClientHandle * a_Client) { // The coords must be valid, because the upper level already does chunk lookup. No need to check them again. diff --git a/source/Chunk.h b/source/Chunk.h index c4eeab6ae..61f11d6d5 100644 --- a/source/Chunk.h +++ b/source/Chunk.h @@ -148,6 +148,8 @@ public: void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); void GetBlockInfo (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight); + void SetServerBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta ); + /** Returns the chunk into which the specified block belongs, by walking the neighbors. Will return self if appropriate. Returns NULL if not reachable through neighbors. */ diff --git a/source/ChunkMap.cpp b/source/ChunkMap.cpp index 5a16495e6..4180ae327 100644 --- a/source/ChunkMap.cpp +++ b/source/ChunkMap.cpp @@ -1171,6 +1171,24 @@ void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_B +void cChunkMap::SetServerBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta) +{ + int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; + cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ ); + + cCSLock Lock(m_CSLayers); + cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ ); + if ((Chunk != NULL) && Chunk->IsValid()) + { + Chunk->SetServerBlock(X, Y, Z, a_BlockType, a_BlockMeta ); + m_World->GetSimulatorManager()->WakeUp(a_BlockX, a_BlockY, a_BlockZ, Chunk); + } +} + + + + + bool cChunkMap::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ; diff --git a/source/ChunkMap.h b/source/ChunkMap.h index 208d2824e..07ad4feaa 100644 --- a/source/ChunkMap.h +++ b/source/ChunkMap.h @@ -135,6 +135,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 SetServerBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta); 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/source/Piston.cpp b/source/Piston.cpp index 058f92a0e..4c8d56261 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -114,7 +114,7 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) { AddDir(pistx, pisty, pistz, pistonMeta & 7, -1) //Move one set of coords one back from breakable dropped block m_World->GetBlockTypeMeta(pistx, pisty, pistz, currBlock, currBlockMeta); //Get the block - m_World->SetBlock( oldx, oldy, oldz, currBlock, currBlockMeta); //Set the block at the location of the original coords + m_World->SetServerBlock( oldx, oldy, oldz, currBlock, currBlockMeta); //Set the block at the location of the original coords oldx = pistx; //Shift the selectors down a block and repeat oldy = pisty; oldz = pistz; @@ -126,10 +126,19 @@ void cPiston::ExtendPiston( int pistx, int pisty, int pistz ) int extz = pistz; AddDir(pistx, pisty, pistz, pistonMeta & 7, -1) //Move back one block to the piston base - m_World->BroadcastBlockAction(pistx, pisty, pistz, 0, pistonMeta, E_BLOCK_PISTON); //Set the base + + if (pistonBlock == E_BLOCK_STICKY_PISTON) + { + m_World->BroadcastBlockAction(pistx, pisty, pistz, 0, pistonMeta, E_BLOCK_STICKY_PISTON); + } + else + { + m_World->BroadcastBlockAction(pistx, pisty, pistz, 0, pistonMeta, E_BLOCK_PISTON); + } + m_World->BroadcastSoundEffect("tile.piston.out", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); - m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 0x8 ); - m_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta); //Set the arm + m_World->FastSetBlock( pistx, pisty, pistz, pistonBlock, pistonMeta | 0x8 ); //Set the base + m_World->SetServerBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, isSticky + pistonMeta); //Set the arm } @@ -146,9 +155,18 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) // Already retracted, bail out return; } - m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), E_BLOCK_PISTON); + + if (pistonBlock == E_BLOCK_STICKY_PISTON) + { + m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), E_BLOCK_STICKY_PISTON); + } + else + { + m_World->BroadcastBlockAction(pistx, pisty, pistz, 1, pistonMeta & ~(8), E_BLOCK_PISTON); + } + m_World->BroadcastSoundEffect("tile.piston.in", pistx * 8, pisty * 8, pistz * 8, 0.5f, 0.7f); - m_World->FastSetBlock(pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8)); //Set the base + m_World->SetServerBlock(pistx, pisty, pistz, pistonBlock, pistonMeta & ~(8)); //Set the base AddDir(pistx, pisty, pistz, pistonMeta & 7, 1) //Move forwards to the extension coord if (m_World->GetBlock(pistx, pisty, pistz) != E_BLOCK_PISTON_EXTENSION) @@ -173,17 +191,16 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) ) { // These cannot be moved by the sticky piston, bail out - m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); + m_World->SetServerBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); return; } - m_World->SetBlock(pistx, pisty, pistz, tempblock, tempmeta); - m_World->SetBlock(tempx, tempy, tempz, E_BLOCK_AIR, 0); + m_World->SetServerBlock(pistx, pisty, pistz, tempblock, tempmeta); + m_World->SetServerBlock(tempx, tempy, tempz, E_BLOCK_AIR, 0); } else { - - m_World->SetBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); + m_World->SetServerBlock(pistx, pisty, pistz, E_BLOCK_AIR, 0); } } diff --git a/source/World.cpp b/source/World.cpp index 6b82dce0f..97186fa24 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -1385,6 +1385,21 @@ void cWorld::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBB +void cWorld::SetServerBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) +{ + if (a_BlockType == E_BLOCK_AIR) + { + BlockHandler(GetBlock(a_X, a_Y, a_Z))->OnDestroyed(this, a_X, a_Y, a_Z); + } + m_ChunkMap->SetServerBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta); + + BlockHandler(a_BlockType)->OnPlaced(this, a_X, a_Y, a_Z, a_BlockType, a_BlockMeta); +} + + + + + BLOCKTYPE cWorld::GetBlock(int a_X, int a_Y, int a_Z) { // First check if it isn't queued in the m_FastSetBlockQueue: @@ -2635,15 +2650,18 @@ void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Resul cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr) { - unsigned LastSpace = a_Text.find_last_of(" "); - std::string LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); + size_t LastSpace = a_Text.find_last_of(" "); //Find the position of the last space + + std::string LastWord = a_Text.substr(LastSpace + 1, a_Text.length()); //Find the last word std::string PlayerName ((*itr)->GetName()); - std::size_t Found = PlayerName.find(LastWord); + std::size_t Found = PlayerName.find(LastWord); //Try to find last word in playername + if (Found!=0) { - continue; + continue; //No match } - a_Results.push_back((*itr)->GetName()); + + a_Results.push_back((*itr)->GetName()); //Match! } } diff --git a/source/World.h b/source/World.h index 5d3de06d0..34e350a04 100644 --- a/source/World.h +++ b/source/World.h @@ -313,6 +313,7 @@ public: // tolua_begin void SetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); void FastSetBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void SetServerBlock (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); BLOCKTYPE GetBlock (int a_BlockX, int a_BlockY, int a_BlockZ); NIBBLETYPE GetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ); void SetBlockMeta (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE a_MetaData); -- cgit v1.2.3 From fbbf12f3a6b1dd28f020b08ae73b075c60983a67 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 18 Aug 2013 15:04:38 +0100 Subject: Added checks to bail out if block entities are being pushed by a piston --- source/Piston.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Piston.cpp b/source/Piston.cpp index 4c8d56261..f83eb016d 100644 --- a/source/Piston.cpp +++ b/source/Piston.cpp @@ -62,7 +62,18 @@ unsigned short cPiston::FirstPassthroughBlock(int pistonX, int pistonY, int pist { AddDir( pistonX, pistonY, pistonZ, pistonmeta, 1) //Set the coords one further from the piston direction m_World->GetBlockTypeMeta(pistonX, pistonY, pistonZ, currBlock, currMeta); - if ((currBlock == E_BLOCK_BEDROCK) || (currBlock == E_BLOCK_OBSIDIAN) || (currBlock == E_BLOCK_PISTON_EXTENSION) || ( (currMeta & 0x8) != 0x0 )) + if ((currBlock == E_BLOCK_BEDROCK) || + (currBlock == E_BLOCK_OBSIDIAN) || + (currBlock == E_BLOCK_PISTON_EXTENSION) || + ( (currMeta & 0x8) != 0x0 ) || //Seems to include signs as well + (currBlock == E_BLOCK_CHEST) || + (currBlock == E_BLOCK_DISPENSER) || + (currBlock == E_BLOCK_DROPPER) || + (currBlock == E_BLOCK_FURNACE) || + (currBlock == E_BLOCK_LIT_FURNACE) || + (currBlock == E_BLOCK_HOPPER) || + (currBlock == E_BLOCK_JUKEBOX) || + (currBlock == E_BLOCK_NOTE_BLOCK)) { return 9001; } @@ -187,7 +198,15 @@ void cPiston::RetractPiston( int pistx, int pisty, int pistz ) (tempblock == E_BLOCK_BEDROCK) || (tempblock == E_BLOCK_PISTON_EXTENSION) || (g_BlockPistonBreakable[tempblock]) || - ((tempmeta & 0x8) != 0x0 ) + ( (tempmeta & 0x8) != 0x0 ) || //Seems to include signs as well + (tempblock == E_BLOCK_CHEST) || + (tempblock == E_BLOCK_DISPENSER) || + (tempblock == E_BLOCK_DROPPER) || + (tempblock == E_BLOCK_FURNACE) || + (tempblock == E_BLOCK_LIT_FURNACE) || + (tempblock == E_BLOCK_HOPPER) || + (tempblock == E_BLOCK_JUKEBOX) || + (tempblock == E_BLOCK_NOTE_BLOCK) ) { // These cannot be moved by the sticky piston, bail out -- cgit v1.2.3