diff options
Diffstat (limited to 'src/Blocks')
-rw-r--r-- | src/Blocks/BlockAnvil.h | 1 | ||||
-rw-r--r-- | src/Blocks/BlockBed.cpp | 24 | ||||
-rw-r--r-- | src/Blocks/BlockBed.h | 25 | ||||
-rw-r--r-- | src/Blocks/BlockBigFlower.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockDirt.h | 8 | ||||
-rw-r--r-- | src/Blocks/BlockEnchantmentTable.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockFarmland.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockFluid.h | 4 | ||||
-rw-r--r-- | src/Blocks/BlockPiston.cpp | 16 | ||||
-rw-r--r-- | src/Blocks/BlockPiston.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockPortal.h | 2 | ||||
-rw-r--r-- | src/Blocks/BlockWorkbench.h | 2 | ||||
-rw-r--r-- | src/Blocks/WorldInterface.h | 12 |
13 files changed, 61 insertions, 41 deletions
diff --git a/src/Blocks/BlockAnvil.h b/src/Blocks/BlockAnvil.h index 20514580e..abfa0f782 100644 --- a/src/Blocks/BlockAnvil.h +++ b/src/Blocks/BlockAnvil.h @@ -4,6 +4,7 @@ #include "BlockHandler.h" #include "../World.h" #include "../Entities/Player.h" +#include "../UI/AnvilWindow.h" diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp index 57b9855d0..e56f4bfe0 100644 --- a/src/Blocks/BlockBed.cpp +++ b/src/Blocks/BlockBed.cpp @@ -1,14 +1,9 @@ #include "Globals.h" #include "BlockBed.h" - - - #include "BroadcastInterface.h" -#include "ChunkInterface.h" #include "Entities/../World.h" #include "Entities/Player.h" -#include "WorldInterface.h" @@ -64,21 +59,22 @@ class cPlayerBedStateUnsetter : public cPlayerListCallback { public: - cPlayerBedStateUnsetter(Vector3i a_Position, cWorldInterface & a_WorldInterface) : - m_Position(a_Position), m_WorldInterface(a_WorldInterface) + cPlayerBedStateUnsetter(Vector3i a_Position, cChunkInterface & a_ChunkInterface) : + m_Position(a_Position), + m_ChunkInterface(a_ChunkInterface) { } virtual bool Item(cPlayer * a_Player) override { + cBlockBedHandler::SetBedOccupationState(m_ChunkInterface, a_Player->GetLastBedPos(), false); a_Player->SetIsInBed(false); - m_WorldInterface.GetBroadcastManager().BroadcastEntityAnimation(*a_Player, 2); return false; } private: Vector3i m_Position; - cWorldInterface & m_WorldInterface; + cChunkInterface & m_ChunkInterface; }; @@ -97,7 +93,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface if (a_WorldInterface.GetTimeOfDay() > 13000) { NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); - if (Meta & 0x4) + if ((Meta & 0x4) == 0x4) { a_Player->SendMessageFailure("This bed is occupied"); } @@ -105,7 +101,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface { Vector3i PillowDirection(0, 0, 0); - if (Meta & 0x8) + if ((Meta & 0x8) == 0x8) { // Is pillow a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ); @@ -122,15 +118,15 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface } } - a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4); // Where 0x4 = occupied bit - a_Player->SetIsInBed(true); a_Player->SetBedPos(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); + SetBedOccupationState(a_ChunkInterface, a_Player->GetLastBedPos(), true); + a_Player->SetIsInBed(true); a_Player->SendMessageSuccess("Home position set successfully"); cTimeFastForwardTester Tester; if (a_WorldInterface.ForEachPlayer(Tester)) { - cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_WorldInterface); + cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_ChunkInterface); a_WorldInterface.ForEachPlayer(Unsetter); a_WorldInterface.SetTimeOfDay(0); a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x0b); // Clear the "occupied" bit of the bed's block diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 5b746110a..46f361686 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -4,9 +4,9 @@ #include "BlockHandler.h" #include "MetaRotator.h" #include "Item.h" +#include "ChunkInterface.h" -class cChunkInterface; class cPlayer; class cWorldInterface; @@ -21,17 +21,14 @@ public: : cMetaRotator<cBlockHandler, 0x3, 0x02, 0x03, 0x00, 0x01, true>(a_BlockType) { } - - + virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override; - virtual bool IsUseable(void) override { return true; } - virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override { @@ -39,14 +36,12 @@ public: a_Pickups.push_back(cItem(E_ITEM_BED, 1, 0)); } - virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override { return true; } - // Bed specific helper functions static NIBBLETYPE RotationToMetaData(double a_Rotation) { @@ -61,7 +56,6 @@ public: return ((char)a_Rotation + 2) % 4; } - static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData) { switch (a_MetaData) @@ -73,6 +67,21 @@ public: } return Vector3i(); } + + static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, const Vector3i & a_BedPosition, bool a_IsOccupied) + { + auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z); + if (a_IsOccupied) + { + Meta |= 0x04; // Where 0x4 = occupied bit + } + else + { + Meta &= 0x0b; // Clear the "occupied" bit of the bed's block + } + + a_ChunkInterface.SetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z, Meta); + } } ; diff --git a/src/Blocks/BlockBigFlower.h b/src/Blocks/BlockBigFlower.h index 5240ddf53..6c5cc6b68 100644 --- a/src/Blocks/BlockBigFlower.h +++ b/src/Blocks/BlockBigFlower.h @@ -81,7 +81,7 @@ public: virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR) && (a_RelY < cChunkDef::Height) && ((a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR) || (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_BIG_FLOWER))); + return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) != E_BLOCK_AIR) && (a_RelY < cChunkDef::Height - 1) && ((a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_AIR) || (a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ) == E_BLOCK_BIG_FLOWER))); } diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 12bca92dd..32512a2ef 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -59,7 +59,7 @@ public: a_Chunk.GetWorld()->QueueLightChunk(a_Chunk.GetPosX(), a_Chunk.GetPosZ()); return; } - else if (std::max(a_Chunk.GetBlockLight(a_RelX, a_RelY + 1, a_RelZ), a_Chunk.GetTimeAlteredLight(a_Chunk.GetSkyLight(a_RelX, a_RelY + 1, a_RelZ))) < 9) + else if ((a_RelY < cChunkDef::Height - 1) && std::max(a_Chunk.GetBlockLight(a_RelX, a_RelY + 1, a_RelZ), a_Chunk.GetTimeAlteredLight(a_Chunk.GetSkyLight(a_RelX, a_RelY + 1, a_RelZ))) < 9) { // Source block is not bright enough to spread return; @@ -69,9 +69,9 @@ public: cFastRandom rand; for (int i = 0; i < 2; i++) // Pick two blocks to grow to { - int OfsX = rand.NextInt(3, a_RelX) - 1; // [-1 .. 1] - int OfsY = rand.NextInt(5, a_RelY) - 3; // [-3 .. 1] - int OfsZ = rand.NextInt(3, a_RelZ) - 1; // [-1 .. 1] + int OfsX = rand.NextInt(3) - 1; // [-1 .. 1] + int OfsY = rand.NextInt(5) - 3; // [-3 .. 1] + int OfsZ = rand.NextInt(3) - 1; // [-1 .. 1] BLOCKTYPE DestBlock; NIBBLETYPE DestMeta; diff --git a/src/Blocks/BlockEnchantmentTable.h b/src/Blocks/BlockEnchantmentTable.h index 81d2cb9a0..40001f356 100644 --- a/src/Blocks/BlockEnchantmentTable.h +++ b/src/Blocks/BlockEnchantmentTable.h @@ -2,7 +2,7 @@ #pragma once #include "BlockHandler.h" -#include "../UI/Window.h" +#include "../UI/EnchantingWindow.h" #include "../Entities/Player.h" diff --git a/src/Blocks/BlockFarmland.h b/src/Blocks/BlockFarmland.h index 02a48a4af..23a7392da 100644 --- a/src/Blocks/BlockFarmland.h +++ b/src/Blocks/BlockFarmland.h @@ -45,7 +45,7 @@ public: } // Farmland too dry. If nothing is growing on top, turn back to dirt: - BLOCKTYPE UpperBlock = (a_RelY >= cChunkDef::Height) ? E_BLOCK_AIR : a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ); + BLOCKTYPE UpperBlock = (a_RelY >= cChunkDef::Height - 1) ? E_BLOCK_AIR : a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ); switch (UpperBlock) { case E_BLOCK_CROPS: diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index 8c0aae041..2823baedc 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -99,7 +99,7 @@ public: // Check if it's fuel: BLOCKTYPE BlockType; if ( - ((a_RelY + y < 0) || (a_RelY + y > cChunkDef::Height)) || + ((a_RelY + y < 0) || (a_RelY + y >= cChunkDef::Height)) || !a_Chunk.UnboundedRelGetBlockType(a_RelX + x, a_RelY + y, a_RelZ + z, BlockType) || !cFireSimulator::IsFuel(BlockType) ) @@ -126,7 +126,7 @@ public: for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++) { if ( - ((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y <= cChunkDef::Height)) && + ((RelY + CrossCoords[i].y >= 0) && (RelY + CrossCoords[i].y < cChunkDef::Height)) && a_Chunk.UnboundedRelGetBlockType(RelX + CrossCoords[i].x, RelY + CrossCoords[i].y, RelZ + CrossCoords[i].z, BlockType) && (BlockType == E_BLOCK_AIR) ) diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 8d245cabe..d9f4913d8 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -61,6 +61,16 @@ void cBlockPistonHandler::OnDestroyed(cChunkInterface & a_ChunkInterface, cWorld +void cBlockPistonHandler::ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) +{ + // Returning Piston Item without Direction-Metavalue + a_Pickups.push_back(cItem(m_BlockType, 1)); +} + + + + + bool cBlockPistonHandler::GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, @@ -169,7 +179,7 @@ void cBlockPistonHandler::ExtendPiston(int a_BlockX, int a_BlockY, int a_BlockZ, a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, pistonBlock, pistonMeta | 0x8); a_World->SetBlock(extx, exty, extz, E_BLOCK_PISTON_EXTENSION, pistonMeta | (IsSticky(pistonBlock) ? 8 : 0), false); - a_World->ScheduleTask(PISTON_TICK_DELAY, new cWorld::cTaskSendBlockToAllPlayers(ScheduledBlocks)); + a_World->ScheduleTask(PISTON_TICK_DELAY, std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks)); } @@ -219,7 +229,7 @@ void cBlockPistonHandler::RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ std::vector<Vector3i> ScheduledBlocks; ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); ScheduledBlocks.push_back(Vector3i(tempx, tempy, tempz)); - a_World->ScheduleTask(PISTON_TICK_DELAY + 1, new cWorld::cTaskSendBlockToAllPlayers(ScheduledBlocks)); + a_World->ScheduleTask(PISTON_TICK_DELAY + 1, std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks)); return; } } @@ -229,7 +239,7 @@ void cBlockPistonHandler::RetractPiston(int a_BlockX, int a_BlockY, int a_BlockZ std::vector<Vector3i> ScheduledBlocks; ScheduledBlocks.push_back(Vector3i(a_BlockX, a_BlockY, a_BlockZ)); - a_World->ScheduleTask(PISTON_TICK_DELAY + 1, new cWorld::cTaskSendBlockToAllPlayers(ScheduledBlocks)); + a_World->ScheduleTask(PISTON_TICK_DELAY + 1, std::make_shared<cWorld::cTaskSendBlockToAllPlayers>(ScheduledBlocks)); } diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h index f868f4d8e..9a891025a 100644 --- a/src/Blocks/BlockPiston.h +++ b/src/Blocks/BlockPiston.h @@ -15,6 +15,8 @@ public: virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override; + virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override; + virtual bool GetPlacementBlockTypeMeta( cChunkInterface & a_ChunkInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, diff --git a/src/Blocks/BlockPortal.h b/src/Blocks/BlockPortal.h index 97ba26ee3..581a29447 100644 --- a/src/Blocks/BlockPortal.h +++ b/src/Blocks/BlockPortal.h @@ -55,7 +55,7 @@ public: virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override { - if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height)) + if ((a_RelY <= 0) || (a_RelY >= cChunkDef::Height - 1)) { return false; // In case someone places a portal with meta 1 or 2 at boundaries, and server tries to get invalid coords at Y - 1 or Y + 1 } diff --git a/src/Blocks/BlockWorkbench.h b/src/Blocks/BlockWorkbench.h index 699badaf2..e40e15606 100644 --- a/src/Blocks/BlockWorkbench.h +++ b/src/Blocks/BlockWorkbench.h @@ -2,7 +2,7 @@ #pragma once #include "BlockHandler.h" -#include "../UI/Window.h" +#include "../UI/CraftingWindow.h" #include "../Entities/Player.h" diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index 106c314e7..44c118195 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -30,14 +30,16 @@ public: /** Spawns item pickups for each item in the list. May compress pickups if too many entities: */ virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false) = 0; - /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: */ + /** Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified. */ virtual void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false) = 0; - /** Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise */ - virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) = 0; + /** Spawns a mob of the specified type. + Returns the mob's UniqueID if recognized and spawned, or cEntity::INVALID_ID on failure. */ + virtual UInt32 SpawnMob(double a_PosX, double a_PosY, double a_PosZ, eMonsterType a_MonsterType) = 0; - /** Spawns an experience orb at the given location with the given reward. It returns the UniqueID of the spawned experience orb. */ - virtual int SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) = 0; + /** Spawns an experience orb at the given location with the given reward. + Returns the UniqueID of the spawned experience orb, or cEntity::INVALID_ID on failure. */ + virtual UInt32 SpawnExperienceOrb(double a_X, double a_Y, double a_Z, int a_Reward) = 0; /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ virtual bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) = 0; |