diff options
Diffstat (limited to 'src')
30 files changed, 362 insertions, 256 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index e0ae2c5b6..897af27c4 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -707,11 +707,11 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R if (IsDummyMetas) { - MergeByStrategy<true>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); + MergeByStrategy<false>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); } else { - MergeByStrategy<false>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); + MergeByStrategy<true>(a_Src, a_RelX, a_RelY, a_RelZ, a_Strategy, SrcMetas, DstMetas); } } diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index def98fdf5..e8d9a7ec4 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -110,10 +110,13 @@ void cBlockInfo::Initialize(void) // Transparent blocks ms_Info[E_BLOCK_ACTIVATOR_RAIL ].m_Transparent = true; ms_Info[E_BLOCK_AIR ].m_Transparent = true; + ms_Info[E_BLOCK_ANVIL ].m_Transparent = true; ms_Info[E_BLOCK_BIG_FLOWER ].m_Transparent = true; ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_Transparent = true; + ms_Info[E_BLOCK_CAKE ].m_Transparent = true; ms_Info[E_BLOCK_CARROTS ].m_Transparent = true; ms_Info[E_BLOCK_CHEST ].m_Transparent = true; + ms_Info[E_BLOCK_COBBLESTONE_WALL ].m_Transparent = true; ms_Info[E_BLOCK_COBWEB ].m_Transparent = true; ms_Info[E_BLOCK_CROPS ].m_Transparent = true; ms_Info[E_BLOCK_DANDELION ].m_Transparent = true; @@ -126,6 +129,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_FLOWER_POT ].m_Transparent = true; ms_Info[E_BLOCK_GLASS ].m_Transparent = true; ms_Info[E_BLOCK_GLASS_PANE ].m_Transparent = true; + ms_Info[E_BLOCK_HEAD ].m_Transparent = true; ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_Transparent = true; ms_Info[E_BLOCK_ICE ].m_Transparent = true; ms_Info[E_BLOCK_IRON_DOOR ].m_Transparent = true; @@ -196,12 +200,14 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_BED ].m_PistonBreakable = true; ms_Info[E_BLOCK_BIG_FLOWER ].m_PistonBreakable = true; ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_PistonBreakable = true; + ms_Info[E_BLOCK_CAKE ].m_PistonBreakable = true; ms_Info[E_BLOCK_COBWEB ].m_PistonBreakable = true; ms_Info[E_BLOCK_CROPS ].m_PistonBreakable = true; ms_Info[E_BLOCK_DANDELION ].m_PistonBreakable = true; ms_Info[E_BLOCK_DEAD_BUSH ].m_PistonBreakable = true; ms_Info[E_BLOCK_FIRE ].m_PistonBreakable = true; ms_Info[E_BLOCK_FLOWER ].m_PistonBreakable = true; + ms_Info[E_BLOCK_HEAD ].m_PistonBreakable = true; ms_Info[E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE].m_PistonBreakable = true; ms_Info[E_BLOCK_INACTIVE_COMPARATOR ].m_PistonBreakable = true; ms_Info[E_BLOCK_IRON_DOOR ].m_PistonBreakable = true; @@ -243,6 +249,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_CACTUS ].m_IsSnowable = false; ms_Info[E_BLOCK_CHEST ].m_IsSnowable = false; ms_Info[E_BLOCK_CROPS ].m_IsSnowable = false; + ms_Info[E_BLOCK_COBBLESTONE_WALL ].m_IsSnowable = false; ms_Info[E_BLOCK_DANDELION ].m_IsSnowable = false; ms_Info[E_BLOCK_FIRE ].m_IsSnowable = false; ms_Info[E_BLOCK_FLOWER ].m_IsSnowable = false; @@ -276,6 +283,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_POWERED_RAIL ].m_IsSnowable = false; ms_Info[E_BLOCK_DETECTOR_RAIL ].m_IsSnowable = false; ms_Info[E_BLOCK_COBWEB ].m_IsSnowable = false; + ms_Info[E_BLOCK_HEAD ].m_IsSnowable = false; // Blocks that don't drop without a special tool: @@ -283,6 +291,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_CAULDRON ].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_COAL_ORE ].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_COBBLESTONE ].m_RequiresSpecialTool = true; + ms_Info[E_BLOCK_COBBLESTONE_WALL ].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_COBBLESTONE_STAIRS ].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_COBWEB ].m_RequiresSpecialTool = true; ms_Info[E_BLOCK_DIAMOND_BLOCK ].m_RequiresSpecialTool = true; @@ -325,6 +334,7 @@ void cBlockInfo::Initialize(void) ms_Info[E_BLOCK_AIR ].m_IsSolid = false; ms_Info[E_BLOCK_BIG_FLOWER ].m_IsSolid = false; ms_Info[E_BLOCK_BROWN_MUSHROOM ].m_IsSolid = false; + ms_Info[E_BLOCK_CAKE ].m_IsSolid = false; ms_Info[E_BLOCK_CARROTS ].m_IsSolid = false; ms_Info[E_BLOCK_COBWEB ].m_IsSolid = false; ms_Info[E_BLOCK_CROPS ].m_IsSolid = false; diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h index 92804aaac..51e79b888 100644 --- a/src/Blocks/BlockBed.h +++ b/src/Blocks/BlockBed.h @@ -39,6 +39,13 @@ public: } + virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override + { + return true; + } + + + // Bed specific helper functions static NIBBLETYPE RotationToMetaData(double a_Rotation) { diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index aa24b8668..2d4fccbac 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -35,8 +35,10 @@ public: // Grass becomes dirt if there is something on top of it: if (a_RelY < cChunkDef::Height - 1) { - BLOCKTYPE Above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ); - if ((!cBlockInfo::IsTransparent(Above) && !cBlockInfo::IsOneHitDig(Above)) || IsBlockWater(Above)) + BLOCKTYPE Above; + NIBBLETYPE AboveMeta; + a_Chunk.GetBlockTypeMeta(a_RelX, a_RelY + 1, a_RelZ, Above, AboveMeta); + if (!cBlockInfo::GetHandler(Above)->CanDirtGrowGrass(AboveMeta)) { a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL); return; @@ -77,7 +79,7 @@ public: BLOCKTYPE AboveDest; NIBBLETYPE AboveMeta; Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta); - if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest)) + if (cBlockInfo::GetHandler(AboveDest)->CanDirtGrowGrass(AboveMeta)) { if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, ssGrassSpread)) { diff --git a/src/Blocks/BlockFluid.h b/src/Blocks/BlockFluid.h index d486d642d..d0c4ea55b 100644 --- a/src/Blocks/BlockFluid.h +++ b/src/Blocks/BlockFluid.h @@ -49,6 +49,12 @@ public: } super::Check(a_ChunkInterface, a_PluginInterface, a_RelX, a_RelY, a_RelZ, a_Chunk); } + + + virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override + { + return false; + } } ; diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index a764c6f44..304e35e84 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -400,6 +400,15 @@ bool cBlockHandler::CanBeAt(cChunkInterface & a_ChunkInterface, int a_BlockX, in +bool cBlockHandler::CanDirtGrowGrass(NIBBLETYPE a_Meta) +{ + return ((cBlockInfo::IsTransparent(m_BlockType)) || (cBlockInfo::IsOneHitDig(m_BlockType))); +} + + + + + bool cBlockHandler::IsUseable() { return false; diff --git a/src/Blocks/BlockHandler.h b/src/Blocks/BlockHandler.h index 3a3efb3cc..fb6cae729 100644 --- a/src/Blocks/BlockHandler.h +++ b/src/Blocks/BlockHandler.h @@ -85,6 +85,9 @@ public: /// Checks if the block can stay at the specified relative coords in the chunk virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk); + + /** Can the dirt under this block grow to grass? */ + virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta); /** Checks if the block can be placed at this point. Default: CanBeAt(...) diff --git a/src/Blocks/BlockSlab.h b/src/Blocks/BlockSlab.h index 76f5ed0e7..b6bd12588 100644 --- a/src/Blocks/BlockSlab.h +++ b/src/Blocks/BlockSlab.h @@ -97,6 +97,12 @@ public: return ""; } + + virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override + { + return (a_Meta & 0x8); + } + /// Returns true if the specified blocktype is one of the slabs handled by this handler static bool IsAnySlabType(BLOCKTYPE a_BlockType) diff --git a/src/Blocks/BlockStairs.h b/src/Blocks/BlockStairs.h index 09ff254a6..a49fda5ae 100644 --- a/src/Blocks/BlockStairs.h +++ b/src/Blocks/BlockStairs.h @@ -77,6 +77,11 @@ public: // Reset meta to 0 a_Pickups.push_back(cItem(m_BlockType, 1, 0)); } + + virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override + { + return true; + } static NIBBLETYPE RotationToMetaData(double a_Rotation) { diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index b0af8f271..53a638ee5 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -802,7 +802,7 @@ void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRe break; } case E_ITEM_PAPER: break; - default: LOG("Unexpected item in firework rocket a_Recipe, was the crafting file fireworks section changed?"); break; + default: LOG("Unexpected item in firework rocket recipe, was the crafting file's fireworks section changed?"); break; } } } @@ -837,7 +837,7 @@ void cCraftingRecipes::HandleFireworks(const cItem * a_CraftingGrid, cCraftingRe case E_ITEM_GOLD_NUGGET: a_Recipe->m_Result.m_FireworkItem.m_Type = 2; break; case E_ITEM_FEATHER: a_Recipe->m_Result.m_FireworkItem.m_Type = 4; break; case E_ITEM_HEAD: a_Recipe->m_Result.m_FireworkItem.m_Type = 3; break; - default: LOG("Unexpected item in firework star a_Recipe, was the crafting file fireworks section changed?"); break; // ermahgerd BARD ardmins + default: LOG("Unexpected item in firework star recipe, was the crafting file's fireworks section changed?"); break; // ermahgerd BARD ardmins } } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 5c675a387..4cf10a219 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Entity.h" @@ -10,7 +11,6 @@ #include "../Simulator/FluidSimulator.h" #include "../Bindings/PluginManager.h" #include "../Tracer.h" -#include "Minecart.h" #include "Player.h" @@ -32,16 +32,10 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_Attachee(NULL) , m_bDirtyHead(true) , m_bDirtyOrientation(true) - , m_bDirtyPosition(true) - , m_bDirtySpeed(true) - , m_bOnGround( false ) - , m_Gravity( -9.81f ) - , m_LastPosX( 0.0 ) - , m_LastPosY( 0.0 ) - , m_LastPosZ( 0.0 ) - , m_TimeLastTeleportPacket(0) - , m_TimeLastMoveReltPacket(0) - , m_TimeLastSpeedPacket(0) + , m_bHasSentNoSpeed(true) + , m_bOnGround(false) + , m_Gravity(-9.81f) + , m_LastPos(a_X, a_Y, a_Z) , m_IsInitialized(false) , m_EntityType(a_EntityType) , m_World(NULL) @@ -55,7 +49,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d , m_IsSubmerged(false) , m_AirLevel(0) , m_AirTickTimer(0) - , m_HeadYaw( 0.0 ) + , m_HeadYaw(0.0) , m_Rot(0.0, 0.0, 0.0) , m_Pos(a_X, a_Y, a_Z) , m_WaterSpeed(0, 0, 0) @@ -794,30 +788,43 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NextSpeed += m_WaterSpeed; - if( NextSpeed.SqrLength() > 0.f ) + if (NextSpeed.SqrLength() > 0.f) { - cTracer Tracer( GetWorld() ); - bool HasHit = Tracer.Trace( NextPos, NextSpeed, 2 ); - if (HasHit) // Oh noez! we hit something + cTracer Tracer(GetWorld()); + // Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse + int DistanceToTrace = (int)(ceil((NextSpeed * a_Dt).SqrLength()) * 2); + bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace); + + if (HasHit) { - // Set to hit position + // Oh noez! We hit something: verify that the (hit position - current) was smaller or equal to the (position that we should travel without obstacles - current) + // This is because previously, we traced with a length that was rounded up (due to integer limitations), and in the case that something was hit, we don't want to overshoot our projected movement if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength()) { + // Block hit was within our projected path + // Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1. + // For example: HitNormal.y = -1 : BLOCK_FACE_YM; HitNormal.y = 1 : BLOCK_FACE_YP if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f; if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; - if (Tracer.HitNormal.y > 0) // means on ground + if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground { m_bOnGround = true; } - NextPos.Set(Tracer.RealHit.x,Tracer.RealHit.y,Tracer.RealHit.z); - NextPos.x += Tracer.HitNormal.x * 0.3f; - NextPos.y += Tracer.HitNormal.y * 0.05f; // Any larger produces entity vibration-upon-the-spot - NextPos.z += Tracer.HitNormal.z * 0.3f; + + // Now, set our position to the hit block (i.e. move part way along our intended trajectory) + NextPos.Set(Tracer.RealHit.x, Tracer.RealHit.y, Tracer.RealHit.z); + NextPos.x += Tracer.HitNormal.x * 0.1; + NextPos.y += Tracer.HitNormal.y * 0.05; + NextPos.z += Tracer.HitNormal.z * 0.1; } else { + // We have hit a block but overshot our intended trajectory, move normally, safe in the warm cocoon of knowledge that we won't appear to teleport forwards on clients, + // and that this piece of software will come to be hailed as the epitome of performance and functionality in C++, never before seen, and of such a like that will never + // be henceforth seen again in the time of programmers and man alike + // </&sensationalist> NextPos += (NextSpeed * a_Dt); } } @@ -1010,9 +1017,9 @@ void cEntity::SetSwimState(cChunk & a_Chunk) { // This sometimes happens on Linux machines // Ref.: http://forum.mc-server.org/showthread.php?tid=1244 - LOGD("SetSwimState failure: RelX = %d, RelZ = %d, LastPos = {%.02f, %.02f}, Pos = %.02f, %.02f}", - RelX, RelY, m_LastPosX, m_LastPosZ, GetPosX(), GetPosZ() - ); + LOGD("SetSwimState failure: RelX = %d, RelZ = %d, Pos = %.02f, %.02f}", + RelX, RelY, GetPosX(), GetPosZ() + ); m_IsSwimming = false; m_IsSubmerged = false; return; @@ -1178,72 +1185,70 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude) { - // Send velocity packet every two ticks if: speed is not negligible or speed was set (as indicated by the DirtySpeed flag) - if (((m_Speed.SqrLength() > 0.0004f) || m_bDirtySpeed) && ((m_World->GetWorldAge() - m_TimeLastSpeedPacket) >= 2)) + // Process packet sending every two ticks + if (GetWorld()->GetWorldAge() % 2 == 0) { - m_World->BroadcastEntityVelocity(*this,a_Exclude); - m_bDirtySpeed = false; - m_TimeLastSpeedPacket = m_World->GetWorldAge(); - } - - // Have to process position related packets this every two ticks - if (m_World->GetWorldAge() % 2 == 0) - { - int DiffX = (int) (floor(GetPosX() * 32.0) - floor(m_LastPosX * 32.0)); - int DiffY = (int) (floor(GetPosY() * 32.0) - floor(m_LastPosY * 32.0)); - int DiffZ = (int) (floor(GetPosZ() * 32.0) - floor(m_LastPosZ * 32.0)); - Int64 DiffTeleportPacket = m_World->GetWorldAge() - m_TimeLastTeleportPacket; - // 4 blocks is max Relative So if the Diff is greater than 127 or. Send an absolute position every 20 seconds - if (DiffTeleportPacket >= 400 || - ((DiffX > 127) || (DiffX < -128) || - (DiffY > 127) || (DiffY < -128) || - (DiffZ > 127) || (DiffZ < -128))) + double SpeedSqr = GetSpeed().SqrLength(); + if (SpeedSqr == 0.0) { - // - m_World->BroadcastTeleportEntity(*this,a_Exclude); - m_TimeLastTeleportPacket = m_World->GetWorldAge(); - m_TimeLastMoveReltPacket = m_TimeLastTeleportPacket; //Must synchronize. - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_bDirtyPosition = false; - m_bDirtyOrientation = false; + // Speed is zero, send this to clients once only as well as an absolute position + if (!m_bHasSentNoSpeed) + { + m_World->BroadcastEntityVelocity(*this, a_Exclude); + m_World->BroadcastTeleportEntity(*this, a_Exclude); + m_bHasSentNoSpeed = true; + } } else { - Int64 DiffMoveRelPacket = m_World->GetWorldAge() - m_TimeLastMoveReltPacket; - //if the change is big enough. - if ((abs(DiffX) >= 4 || abs(DiffY) >= 4 || abs(DiffZ) >= 4 || DiffMoveRelPacket >= 60) && m_bDirtyPosition) + // Movin' + m_World->BroadcastEntityVelocity(*this, a_Exclude); + m_bHasSentNoSpeed = false; + } + + // TODO: Pickups move disgracefully if relative move packets are sent as opposed to just velocity. Have a system to send relmove only when SetPosXXX() is called with a large difference in position + int DiffX = (int)(floor(GetPosX() * 32.0) - floor(m_LastPos.x * 32.0)); + int DiffY = (int)(floor(GetPosY() * 32.0) - floor(m_LastPos.y * 32.0)); + int DiffZ = (int)(floor(GetPosZ() * 32.0) - floor(m_LastPos.z * 32.0)); + + if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved? + { + if ((abs(DiffX) <= 127) && (abs(DiffY) <= 127) && (abs(DiffZ) <= 127)) // Limitations of a Byte { + // Difference within Byte limitations, use a relative move packet if (m_bDirtyOrientation) { - m_World->BroadcastEntityRelMoveLook(*this, (char)DiffX, (char)DiffY, (char)DiffZ,a_Exclude); + m_World->BroadcastEntityRelMoveLook(*this, (char)DiffX, (char)DiffY, (char)DiffZ, a_Exclude); m_bDirtyOrientation = false; } else { - m_World->BroadcastEntityRelMove(*this, (char)DiffX, (char)DiffY, (char)DiffZ,a_Exclude); + m_World->BroadcastEntityRelMove(*this, (char)DiffX, (char)DiffY, (char)DiffZ, a_Exclude); } - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_bDirtyPosition = false; - m_TimeLastMoveReltPacket = m_World->GetWorldAge(); + // Clients seem to store two positions, one for the velocity packet and one for the teleport/relmove packet + // The latter is only changed with a relmove/teleport, and m_LastPos stores this position + m_LastPos = GetPosition(); } else { - if (m_bDirtyOrientation) - { - m_World->BroadcastEntityLook(*this,a_Exclude); - m_bDirtyOrientation = false; - } - } + // Too big a movement, do a teleport + m_World->BroadcastTeleportEntity(*this, a_Exclude); + m_LastPos = GetPosition(); // See above + m_bDirtyOrientation = false; + } } + if (m_bDirtyHead) { - m_World->BroadcastEntityHeadLook(*this,a_Exclude); + m_World->BroadcastEntityHeadLook(*this, a_Exclude); m_bDirtyHead = false; } + if (m_bDirtyOrientation) + { + // Send individual update in case above (sending with rel-move packet) wasn't done + GetWorld()->BroadcastEntityLook(*this, a_Exclude); + m_bDirtyOrientation = false; + } } } @@ -1383,7 +1388,7 @@ void cEntity::SetRoll(double a_Roll) void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) { m_Speed.Set(a_SpeedX, a_SpeedY, a_SpeedZ); - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1393,7 +1398,7 @@ void cEntity::SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) void cEntity::SetSpeedX(double a_SpeedX) { m_Speed.x = a_SpeedX; - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1403,7 +1408,7 @@ void cEntity::SetSpeedX(double a_SpeedX) void cEntity::SetSpeedY(double a_SpeedY) { m_Speed.y = a_SpeedY; - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1413,7 +1418,7 @@ void cEntity::SetSpeedY(double a_SpeedY) void cEntity::SetSpeedZ(double a_SpeedZ) { m_Speed.z = a_SpeedZ; - m_bDirtySpeed = true; + WrapSpeed(); } @@ -1433,7 +1438,7 @@ void cEntity::SetWidth(double a_Width) void cEntity::AddPosX(double a_AddPosX) { m_Pos.x += a_AddPosX; - m_bDirtyPosition = true; + } @@ -1442,7 +1447,7 @@ void cEntity::AddPosX(double a_AddPosX) void cEntity::AddPosY(double a_AddPosY) { m_Pos.y += a_AddPosY; - m_bDirtyPosition = true; + } @@ -1451,7 +1456,7 @@ void cEntity::AddPosY(double a_AddPosY) void cEntity::AddPosZ(double a_AddPosZ) { m_Pos.z += a_AddPosZ; - m_bDirtyPosition = true; + } @@ -1462,7 +1467,7 @@ void cEntity::AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ) m_Pos.x += a_AddPosX; m_Pos.y += a_AddPosY; m_Pos.z += a_AddPosZ; - m_bDirtyPosition = true; + } @@ -1472,8 +1477,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed { m_Speed.x += a_AddSpeedX; m_Speed.y += a_AddSpeedY; - m_Speed.z += a_AddSpeedZ; - m_bDirtySpeed = true; + m_Speed.z += a_AddSpeedZ; WrapSpeed(); } @@ -1483,8 +1487,7 @@ void cEntity::AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeed void cEntity::AddSpeedX(double a_AddSpeedX) { - m_Speed.x += a_AddSpeedX; - m_bDirtySpeed = true; + m_Speed.x += a_AddSpeedX; WrapSpeed(); } @@ -1494,8 +1497,7 @@ void cEntity::AddSpeedX(double a_AddSpeedX) void cEntity::AddSpeedY(double a_AddSpeedY) { - m_Speed.y += a_AddSpeedY; - m_bDirtySpeed = true; + m_Speed.y += a_AddSpeedY; WrapSpeed(); } @@ -1505,8 +1507,7 @@ void cEntity::AddSpeedY(double a_AddSpeedY) void cEntity::AddSpeedZ(double a_AddSpeedZ) { - m_Speed.z += a_AddSpeedZ; - m_bDirtySpeed = true; + m_Speed.z += a_AddSpeedZ; WrapSpeed(); } @@ -1561,8 +1562,7 @@ Vector3d cEntity::GetLookVector(void) const // Set position void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ) { - m_Pos.Set(a_PosX, a_PosY, a_PosZ); - m_bDirtyPosition = true; + m_Pos.Set(a_PosX, a_PosY, a_PosZ); } @@ -1571,8 +1571,7 @@ void cEntity::SetPosition(double a_PosX, double a_PosY, double a_PosZ) void cEntity::SetPosX(double a_PosX) { - m_Pos.x = a_PosX; - m_bDirtyPosition = true; + m_Pos.x = a_PosX; } @@ -1581,8 +1580,7 @@ void cEntity::SetPosX(double a_PosX) void cEntity::SetPosY(double a_PosY) { - m_Pos.y = a_PosY; - m_bDirtyPosition = true; + m_Pos.y = a_PosY; } @@ -1592,7 +1590,6 @@ void cEntity::SetPosY(double a_PosY) void cEntity::SetPosZ(double a_PosZ) { m_Pos.z = a_PosZ; - m_bDirtyPosition = true; } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index a682701de..df03d635b 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -430,22 +430,29 @@ protected: /// The entity which is attached to this entity (rider), NULL if none cEntity * m_Attachee; - // Flags that signal that we haven't updated the clients with the latest. - bool m_bDirtyHead; - bool m_bDirtyOrientation; - bool m_bDirtyPosition; - bool m_bDirtySpeed; - - bool m_bOnGround; - float m_Gravity; + /** Stores whether head yaw has been set manually */ + bool m_bDirtyHead; + + /** Stores whether our yaw/pitch/roll (body orientation) has been set manually */ + bool m_bDirtyOrientation; - // Last Position. - double m_LastPosX, m_LastPosY, m_LastPosZ; + /** Stores whether we have sent a Velocity packet with a speed of zero (no speed) to the client + Ensures that said packet is sent only once */ + bool m_bHasSentNoSpeed; - // This variables keep track of the last time a packet was sent - Int64 m_TimeLastTeleportPacket, m_TimeLastMoveReltPacket, m_TimeLastSpeedPacket; // In ticks + /** Stores if the entity is on the ground */ + bool m_bOnGround; + + /** Stores gravity that is applied to an entity every tick + For realistic effects, this should be negative. For spaaaaaaace, this can be zero or even positive */ + float m_Gravity; + + /** Last position sent to client via the Relative Move or Teleport packets (not Velocity) + Only updated if cEntity::BroadcastMovementUpdate() is called! */ + Vector3d m_LastPos; - bool m_IsInitialized; // Is set to true when it's initialized, until it's destroyed (Initialize() till Destroy() ) + /** True when entity is initialised (Initialize()) and false when destroyed pending deletion (Destroy()) */ + bool m_IsInitialized; eEntityType m_EntityType; @@ -469,12 +476,14 @@ protected: /// Time, in ticks, since the last damage dealt by the void. Reset to zero when moving out of the void. int m_TicksSinceLastVoidDamage; + virtual void Destroyed(void) {} // Called after the entity has been destroyed void SetWorld(cWorld * a_World) { m_World = a_World; } /** Called in each tick to handle air-related processing i.e. drowning */ virtual void HandleAir(); + /** Called once per tick to set IsSwimming and IsSubmerged */ virtual void SetSwimState(cChunk & a_Chunk); diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 3623c869a..10f79aedc 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -34,8 +34,6 @@ cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) void cExpOrb::SpawnOn(cClientHandle & a_Client) { a_Client.SendExperienceOrb(*this); - m_bDirtyPosition = false; - m_bDirtySpeed = false; m_bDirtyOrientation = false; m_bDirtyHead = false; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 08b7d3984..6ac11c270 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -76,11 +76,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) cTimer t1; m_LastPlayerListTime = t1.GetNowTime(); - - m_TimeLastTeleportPacket = 0; m_PlayerName = a_PlayerName; - m_bDirtyPosition = true; // So chunks are streamed to player at spawn if (!LoadFromDisk()) { @@ -209,25 +206,22 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) m_BowCharge += 1; } - //handle updating experience + // Handle updating experience if (m_bDirtyExperience) { SendExperience(); } - if (m_bDirtyPosition) + if (GetPosition() != m_LastPos) // Change in position from last tick? { // Apply food exhaustion from movement: ApplyFoodExhaustionFromMovement(); cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this); - BroadcastMovementUpdate(m_ClientHandle); m_ClientHandle->StreamChunks(); } - else - { - BroadcastMovementUpdate(m_ClientHandle); - } + + BroadcastMovementUpdate(m_ClientHandle); if (m_Health > 0) // make sure player is alive { @@ -1596,10 +1590,7 @@ bool cPlayer::LoadFromDisk() SetPosX(JSON_PlayerPosition[(unsigned int)0].asDouble()); SetPosY(JSON_PlayerPosition[(unsigned int)1].asDouble()); SetPosZ(JSON_PlayerPosition[(unsigned int)2].asDouble()); - m_LastPosX = GetPosX(); - m_LastPosY = GetPosY(); - m_LastPosZ = GetPosZ(); - m_LastFoodPos = GetPosition(); + m_LastPos = GetPosition(); } Json::Value & JSON_PlayerRotation = root["rotation"]; @@ -1860,17 +1851,16 @@ void cPlayer::ApplyFoodExhaustionFromMovement() { return; } - - // Calculate the distance travelled, update the last pos: - Vector3d Movement(GetPosition() - m_LastFoodPos); - Movement.y = 0; // Only take XZ movement into account - m_LastFoodPos = GetPosition(); - + // If riding anything, apply no food exhaustion if (m_AttachedTo != NULL) { return; } + + // Calculate the distance travelled, update the last pos: + Vector3d Movement(GetPosition() - m_LastPos); + Movement.y = 0; // Only take XZ movement into account // Apply the exhaustion based on distance travelled: double BaseExhaustion = Movement.Length(); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 3029abfe0..6fc7e2875 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -423,9 +423,6 @@ protected: /** Number of ticks remaining for the foodpoisoning effect; zero if not foodpoisoned */ int m_FoodPoisonedTicksRemaining; - /** Last position that has been recorded for food-related processing: */ - Vector3d m_LastFoodPos; - float m_LastJumpHeight; float m_LastGroundHeight; bool m_bTouchGround; diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp index 02f31f5bb..fd9a4e7ac 100644 --- a/src/Entities/TNTEntity.cpp +++ b/src/Entities/TNTEntity.cpp @@ -30,8 +30,6 @@ cTNTEntity::cTNTEntity(const Vector3d & a_Pos, int a_FuseTicks) : void cTNTEntity::SpawnOn(cClientHandle & a_ClientHandle) { a_ClientHandle.SendSpawnObject(*this, 50, 1, 0, 0); // 50 means TNT - m_bDirtyPosition = false; - m_bDirtySpeed = false; m_bDirtyOrientation = false; m_bDirtyHead = false; } diff --git a/src/Generating/PieceGenerator.cpp b/src/Generating/PieceGenerator.cpp index 8e9a48be6..db45cd08b 100644 --- a/src/Generating/PieceGenerator.cpp +++ b/src/Generating/PieceGenerator.cpp @@ -388,7 +388,8 @@ bool cPieceGenerator::TryPlacePieceAtConnector( // Get a list of available connections: const int * RotTable = DirectionRotationTable[a_Connector.m_Direction]; cConnections Connections; - cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(a_Connector.m_Type); + int WantedConnectorType = -a_Connector.m_Type; + cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType); Connections.reserve(AvailablePieces.size()); Vector3i ConnPos = a_Connector.m_Pos; // The position at which the new connector should be placed - 1 block away from the connector AddFaceDirection(ConnPos.x, ConnPos.y, ConnPos.z, a_Connector.m_Direction); @@ -406,7 +407,7 @@ bool cPieceGenerator::TryPlacePieceAtConnector( cPiece::cConnectors Connectors = (*itrP)->GetConnectors(); for (cPiece::cConnectors::iterator itrC = Connectors.begin(), endC = Connectors.end(); itrC != endC; ++itrC) { - if (itrC->m_Type != a_Connector.m_Type) + if (itrC->m_Type != WantedConnectorType) { continue; } diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h index f4433b947..16bec3bb4 100644 --- a/src/Generating/PieceGenerator.h +++ b/src/Generating/PieceGenerator.h @@ -38,7 +38,8 @@ public: /** Position relative to the piece */ Vector3i m_Pos; - /** Type of the connector. Any arbitrary number; the generator connects only connectors of the same type. */ + /** Type of the connector. Any arbitrary number; the generator connects only connectors of opposite + (negative) types. */ int m_Type; /** Direction in which the connector is facing. diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 44d5097de..0f20603be 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -174,44 +174,47 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const cPlacedPiece * a_Placement) const a_Dest.WriteBlockArea(Image, Placement.x, Placement.y, Placement.z, m_MergeStrategy); // If requested, draw the floor (from the bottom of the prefab down to the nearest non-air) - int MaxX = Image.GetSizeX(); - int MaxZ = Image.GetSizeZ(); - for (int z = 0; z < MaxZ; z++) + if (m_ShouldExtendFloor) { - int RelZ = Placement.z + z; - if ((RelZ < 0) || (RelZ >= cChunkDef::Width)) + int MaxX = Image.GetSizeX(); + int MaxZ = Image.GetSizeZ(); + for (int z = 0; z < MaxZ; z++) { - // Z coord outside the chunk - continue; - } - for (int x = 0; x < MaxX; x++) - { - int RelX = Placement.x + x; - if ((RelX < 0) || (RelX >= cChunkDef::Width)) - { - // X coord outside the chunk - continue; - } - BLOCKTYPE BlockType; - NIBBLETYPE BlockMeta; - Image.GetRelBlockTypeMeta(x, 0, z, BlockType, BlockMeta); - if ((BlockType == E_BLOCK_AIR) || (BlockType == E_BLOCK_SPONGE)) + int RelZ = Placement.z + z; + if ((RelZ < 0) || (RelZ >= cChunkDef::Width)) { - // Do not expand air nor sponge blocks + // Z coord outside the chunk continue; } - for (int y = Placement.y - 1; y >= 0; y--) + for (int x = 0; x < MaxX; x++) { - BLOCKTYPE ExistingBlock = a_Dest.GetBlockType(RelX, y, RelZ); - if (ExistingBlock != E_BLOCK_AIR) + int RelX = Placement.x + x; + if ((RelX < 0) || (RelX >= cChunkDef::Width)) + { + // X coord outside the chunk + continue; + } + BLOCKTYPE BlockType; + NIBBLETYPE BlockMeta; + Image.GetRelBlockTypeMeta(x, 0, z, BlockType, BlockMeta); + if ((BlockType == E_BLOCK_AIR) || (BlockType == E_BLOCK_SPONGE)) { - // End the expansion for this column, reached the end - break; + // Do not expand air nor sponge blocks + continue; } - a_Dest.SetBlockTypeMeta(RelX, y, RelZ, BlockType, BlockMeta); - } // for y - } // for x - } // for z + for (int y = Placement.y - 1; y >= 0; y--) + { + BLOCKTYPE ExistingBlock = a_Dest.GetBlockType(RelX, y, RelZ); + if (ExistingBlock != E_BLOCK_AIR) + { + // End the expansion for this column, reached the end + break; + } + a_Dest.SetBlockTypeMeta(RelX, y, RelZ, BlockType, BlockMeta); + } // for y + } // for x + } // for z + } } diff --git a/src/Generating/Prefabs/NetherFortPrefabs.cpp b/src/Generating/Prefabs/NetherFortPrefabs.cpp index d2ef5663d..088340391 100644 --- a/src/Generating/Prefabs/NetherFortPrefabs.cpp +++ b/src/Generating/Prefabs/NetherFortPrefabs.cpp @@ -134,7 +134,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 12, 2, 2: 5\n" /* Type 1, direction X+ */ - "1: 0, 2, 2: 4\n" /* Type 1, direction X- */, + "1: 0, 2, 2: 4\n" /* Type 1, direction X- */ + "-1: 12, 2, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 2, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -143,7 +145,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 20, @@ -291,7 +293,10 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 12, 2, 4: 5\n" /* Type 1, direction X+ */ "1: 6, 2, 0: 2\n" /* Type 1, direction Z- */ - "1: 0, 2, 4: 4\n" /* Type 1, direction X- */, + "1: 0, 2, 4: 4\n" /* Type 1, direction X- */ + "-1: 12, 2, 4: 5\n" /* Type -1, direction X+ */ + "-1: 6, 2, 0: 2\n" /* Type -1, direction Z- */ + "-1: 0, 2, 4: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -300,7 +305,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 20, @@ -420,7 +425,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -590,7 +595,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -790,7 +795,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 5, @@ -991,7 +996,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 10, @@ -1085,7 +1090,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -1185,7 +1190,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -1208,7 +1213,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Hitbox (relative to bounding box): 0, 0, 0, // MinX, MinY, MinZ - 4, 6, 15, // MaxX, MaxY, MaxZ + 4, 16, 15, // MaxX, MaxY, MaxZ // Block definitions: ".: 0: 0\n" /* air */ @@ -1364,7 +1369,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 10, @@ -1604,7 +1609,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 5, @@ -1933,7 +1938,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 20, @@ -2052,7 +2057,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 500, @@ -2212,7 +2217,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 10, @@ -2302,7 +2307,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */ - "1: 0, 1, 2: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 10, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -2311,7 +2318,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 300, @@ -2401,7 +2408,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 12, 1, 2: 5\n" /* Type 1, direction X+ */ - "1: 0, 1, 2: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 12, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -2410,7 +2419,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 300, @@ -2494,7 +2503,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 4, 1, 2: 5\n" /* Type 1, direction X+ */ - "1: 0, 1, 2: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 4, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -2503,7 +2514,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 500, @@ -2631,7 +2642,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 2, 1, 10: 3\n" /* Type 1, direction Z+ */ - "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */, + "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */ + "-1: 2, 1, 10: 3\n" /* Type -1, direction Z+ */ + "-1: 10, 1, 2: 5\n" /* Type -1, direction X+ */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -2640,7 +2653,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -2769,7 +2782,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 10, 1, 2: 5\n" /* Type 1, direction X+ */ - "1: 2, 1, 10: 3\n" /* Type 1, direction Z+ */, + "1: 2, 1, 10: 3\n" /* Type 1, direction Z+ */ + "-1: 2, 1, 10: 3\n" /* Type -1, direction Z+ */ + "-1: 10, 1, 2: 5\n" /* Type -1, direction X+ */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -2778,7 +2793,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -2890,7 +2905,11 @@ const cPrefab::sDef g_NetherFortPrefabs[] = "1: 8, 1, 4: 5\n" /* Type 1, direction X+ */ "1: 4, 1, 0: 2\n" /* Type 1, direction Z- */ "1: 4, 1, 8: 3\n" /* Type 1, direction Z+ */ - "1: 0, 1, 4: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 4: 4\n" /* Type 1, direction X- */ + "-1: 8, 1, 4: 5\n" /* Type -1, direction X+ */ + "-1: 4, 1, 8: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 4: 4\n" /* Type -1, direction X- */ + "-1: 4, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -2899,7 +2918,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -3040,7 +3059,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ - "1: 8, 8, 2: 5\n" /* Type 1, direction X+ */, + "1: 8, 8, 2: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */ + "-1: 8, 8, 2: 5\n" /* Type -1, direction X+ */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -3049,7 +3070,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 1000, @@ -3139,7 +3160,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ - "1: 13, 1, 2: 5\n" /* Type 1, direction X+ */, + "1: 13, 1, 2: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */ + "-1: 13, 1, 2: 5\n" /* Type -1, direction X+ */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -3148,7 +3171,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -3393,7 +3416,10 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 0, 6, 7: 4\n" /* Type 1, direction X- */ "1: 9, 1, 14: 3\n" /* Type 1, direction Z+ */ - "1: 9, 1, 0: 2\n" /* Type 1, direction Z- */, + "1: 9, 1, 0: 2\n" /* Type 1, direction Z- */ + "-1: 0, 6, 7: 4\n" /* Type -1, direction X- */ + "-1: 9, 1, 14: 3\n" /* Type -1, direction Z+ */ + "-1: 9, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -3402,7 +3428,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 10, @@ -3722,7 +3748,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 11, 1, 7: 5\n" /* Type 1, direction X+ */ - "1: 0, 9, 7: 4\n" /* Type 1, direction X- */, + "1: 0, 9, 7: 4\n" /* Type 1, direction X- */ + "-1: 11, 1, 7: 5\n" /* Type -1, direction X+ */ + "-1: 0, 9, 7: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -3731,7 +3759,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 10, @@ -4009,7 +4037,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 10, @@ -4186,7 +4214,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 12, 1, 6: 5\n" /* Type 1, direction X+ */ - "1: 0, 1, 6: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 6: 4\n" /* Type 1, direction X- */ + "-1: 12, 1, 6: 5\n" /* Type -1, direction X+ */ + "-1: 0, 1, 6: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -4195,7 +4225,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4338,7 +4368,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4481,7 +4511,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4586,7 +4616,10 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 0, 1, 4: 4\n" /* Type 1, direction X- */ "1: 6, 1, 0: 2\n" /* Type 1, direction Z- */ - "1: 12, 1, 4: 5\n" /* Type 1, direction X+ */, + "1: 12, 1, 4: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 4: 4\n" /* Type -1, direction X- */ + "-1: 12, 1, 4: 5\n" /* Type -1, direction X+ */ + "-1: 6, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -4595,7 +4628,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4712,7 +4745,10 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 0, 1, 6: 4\n" /* Type 1, direction X- */ "1: 6, 1, 0: 2\n" /* Type 1, direction Z- */ - "1: 12, 1, 6: 5\n" /* Type 1, direction X+ */, + "1: 12, 1, 6: 5\n" /* Type 1, direction X+ */ + "-1: 0, 1, 6: 4\n" /* Type -1, direction X- */ + "-1: 6, 1, 0: 2\n" /* Type -1, direction Z- */ + "-1: 12, 1, 6: 5\n" /* Type -1, direction X+ */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -4721,7 +4757,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4806,7 +4842,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 2, 1, 4: 3\n" /* Type 1, direction Z+ */ - "1: 0, 1, 2: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 2, 1, 4: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -4815,7 +4853,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4901,7 +4939,9 @@ const cPrefab::sDef g_NetherFortPrefabs[] = // Connectors: "1: 2, 1, 4: 3\n" /* Type 1, direction Z+ */ - "1: 0, 1, 2: 4\n" /* Type 1, direction X- */, + "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ + "-1: 2, 1, 4: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -4910,7 +4950,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -4996,7 +5036,11 @@ const cPrefab::sDef g_NetherFortPrefabs[] = "1: 4, 1, 2: 5\n" /* Type 1, direction X+ */ "1: 2, 1, 4: 3\n" /* Type 1, direction Z+ */ "1: 0, 1, 2: 4\n" /* Type 1, direction X- */ - "1: 2, 1, 0: 2\n" /* Type 1, direction Z- */, + "1: 2, 1, 0: 2\n" /* Type 1, direction Z- */ + "-1: 4, 1, 2: 5\n" /* Type -1, direction X+ */ + "-1: 2, 1, 4: 3\n" /* Type -1, direction Z+ */ + "-1: 0, 1, 2: 4\n" /* Type -1, direction X- */ + "-1: 2, 1, 0: 2\n" /* Type -1, direction Z- */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -5005,7 +5049,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -5120,7 +5164,7 @@ const cPrefab::sDef g_NetherFortPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, @@ -5314,7 +5358,8 @@ const cPrefab::sDef g_NetherFortStartingPrefabs[] = // Connectors: "0: 6, 1, 0: 2\n" /* Type 0, direction Z- */ - "1: 6, 1, 12: 3\n" /* Type 1, direction Z+ */, + "1: 6, 1, 12: 3\n" /* Type 1, direction Z+ */ + "-1: 6, 1, 12: 3\n" /* Type -1, direction Z+ */, // AllowedRotations: 7, /* 1, 2, 3 CCW rotation allowed */ @@ -5323,7 +5368,7 @@ const cPrefab::sDef g_NetherFortStartingPrefabs[] = cBlockArea::msSpongePrint, // ShouldExtendFloor: - false, + true, // DefaultWeight: 100, diff --git a/src/Items/ItemLilypad.h b/src/Items/ItemLilypad.h index 8fc1d8543..bc650cdbd 100644 --- a/src/Items/ItemLilypad.h +++ b/src/Items/ItemLilypad.h @@ -47,9 +47,9 @@ public: public cBlockTracer::cCallbacks { public: - cCallbacks(cWorld * a_CBWorld) : - m_HasHitFluid(false), - m_World(a_CBWorld) + + cCallbacks(void) : + m_HasHitFluid(false) { } @@ -62,10 +62,9 @@ public: return false; } AddFaceDirection(a_CBBlockX, a_CBBlockY, a_CBBlockZ, BLOCK_FACE_YP); // Always place pad at top of water block - BLOCKTYPE Block = m_World->GetBlock(a_CBBlockX, a_CBBlockY, a_CBBlockZ); if ( - !IsBlockWater(Block) && - cBlockInfo::FullyOccupiesVoxel(Block) + !IsBlockWater(a_CBBlockType) && + cBlockInfo::FullyOccupiesVoxel(a_CBBlockType) ) { // Can't place lilypad on air/in another block! @@ -80,11 +79,10 @@ public: Vector3i m_Pos; bool m_HasHitFluid; - cWorld * m_World; }; - cCallbacks Callbacks(a_World); + cCallbacks Callbacks; cLineBlockTracer Tracer(*a_Player->GetWorld(), Callbacks); Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector()); Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5); diff --git a/src/Items/ItemMinecart.h b/src/Items/ItemMinecart.h index 25500aeb9..4e7d8fcff 100644 --- a/src/Items/ItemMinecart.h +++ b/src/Items/ItemMinecart.h @@ -78,7 +78,7 @@ public: } return true; } - + } ; diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index ff2c2069b..82bec52d4 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -76,6 +76,7 @@ public: case E_BLOCK_STONE_PRESSURE_PLATE: case E_BLOCK_BRICK: case E_BLOCK_COBBLESTONE_STAIRS: + case E_BLOCK_COBBLESTONE_WALL: case E_BLOCK_STONE_BRICK_STAIRS: case E_BLOCK_NETHER_BRICK_STAIRS: case E_BLOCK_CAULDRON: diff --git a/src/Items/ItemThrowable.h b/src/Items/ItemThrowable.h index c6a4e714e..35c2b8731 100644 --- a/src/Items/ItemThrowable.h +++ b/src/Items/ItemThrowable.h @@ -28,15 +28,19 @@ public: virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Dir) override { + Vector3d Pos = a_Player->GetThrowStartPos(); + Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; + + if (a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed) < 0) + { + return false; + } + if (!a_Player->IsGameModeCreative()) { a_Player->GetInventory().RemoveOneEquippedItem(); } - Vector3d Pos = a_Player->GetThrowStartPos(); - Vector3d Speed = a_Player->GetLookVector() * m_SpeedCoeff; - a_World->CreateProjectile(Pos.x, Pos.y, Pos.z, m_ProjectileKind, a_Player, a_Player->GetEquippedItem(), &Speed); - return true; } @@ -127,7 +131,10 @@ public: return false; } - a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()); + if (a_World->CreateProjectile(a_BlockX + 0.5, a_BlockY + 1, a_BlockZ + 0.5, m_ProjectileKind, a_Player, a_Player->GetEquippedItem()) < 0) + { + return false; + } if (!a_Player->IsGameModeCreative()) { diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index f12bd6d49..074063add 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -615,11 +615,7 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_RelBlockX, int a_Re else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us { BLOCKTYPE Type = 0; - if (a_RelBlockY - 1 < 0) - { - continue; - } - if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX, a_RelBlockY - 1, a_RelBlockZ, Type)) + if (!m_Chunk->UnboundedRelGetBlockType(a_RelBlockX + gCrossCoords[i].x, a_RelBlockY, a_RelBlockZ + gCrossCoords[i].z, Type)) { continue; } diff --git a/src/Tracer.cpp b/src/Tracer.cpp index 6da6b2ad7..be42430a5 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -219,6 +219,10 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int return false; } + if ((pos.y < 0) || (pos.y >= cChunkDef::Height)) + { + return false; + } BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); // Block is counted as a collision if we are not doing a line of sight and it is solid, // or if the block is not air and not water. That way mobs can still see underwater. @@ -226,7 +230,7 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int { BlockHitPosition = pos; int Normal = GetHitNormal(a_Start, End, pos ); - if(Normal > 0) + if (Normal > 0) { HitNormal = m_NormalTable[Normal-1]; } diff --git a/src/Vector3.h b/src/Vector3.h index 276bf67c9..fed776018 100644 --- a/src/Vector3.h +++ b/src/Vector3.h @@ -118,11 +118,6 @@ public: return (Abs(x - a_Rhs.x) < a_Eps) && (Abs(y - a_Rhs.y) < a_Eps) && (Abs(z - a_Rhs.z) < a_Eps); } - inline bool operator == (const Vector3<T> & a_Rhs) const - { - return Equals(a_Rhs); - } - inline void Move(T a_X, T a_Y, T a_Z) { x += a_X; @@ -139,6 +134,16 @@ public: // tolua_end + inline bool operator != (const Vector3<T> & a_Rhs) const + { + return !Equals(a_Rhs); + } + + inline bool operator == (const Vector3<T> & a_Rhs) const + { + return Equals(a_Rhs); + } + inline void operator += (const Vector3<T> & a_Rhs) { x += a_Rhs.x; diff --git a/src/World.h b/src/World.h index de0a257f9..86cbb3e7e 100644 --- a/src/World.h +++ b/src/World.h @@ -710,7 +710,9 @@ public: virtual int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType) override; // tolua_export int SpawnMobFinalize(cMonster* a_Monster); - /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise */ + /** Creates a projectile of the specified type. Returns the projectile's EntityID if successful, <0 otherwise + Item parameter used currently for Fireworks to correctly set entity metadata based on item metadata + */ int CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProjectileEntity::eKind a_Kind, cEntity * a_Creator, const cItem & a_Item, const Vector3d * a_Speed = NULL); // tolua_export /** Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! */ diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index 6b317663a..2ac1d7962 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -515,7 +515,7 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster) } case cMonster::mtMagmaCube: { - m_Writer.AddByte("Size", ((const cMagmaCube *)a_Monster)->GetSize()); + m_Writer.AddInt("Size", ((const cMagmaCube *)a_Monster)->GetSize()); break; } case cMonster::mtSheep: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 875093910..a98ed81f7 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1996,7 +1996,10 @@ void cWSSAnvil::LoadMagmaCubeFromNBT(cEntityList & a_Entities, const cParsedNBT { int SizeIdx = a_NBT.FindChildByName(a_TagIdx, "Size"); - if (SizeIdx < 0) { return; } + if (SizeIdx < 0) + { + return; + } int Size = a_NBT.GetInt(SizeIdx); @@ -2154,7 +2157,10 @@ void cWSSAnvil::LoadSlimeFromNBT(cEntityList & a_Entities, const cParsedNBT & a_ { int SizeIdx = a_NBT.FindChildByName(a_TagIdx, "Size"); - if (SizeIdx < 0) { return; } + if (SizeIdx < 0) + { + return; + } int Size = a_NBT.GetInt(SizeIdx); |