Skip to content

Commit

Permalink
Moved growing from cWorld / cChunk to cBlockHandler descendants.
Browse files Browse the repository at this point in the history
  • Loading branch information
madmaxoft committed Oct 28, 2019
1 parent f4bf025 commit 61904af
Show file tree
Hide file tree
Showing 42 changed files with 1,513 additions and 1,300 deletions.
1 change: 1 addition & 0 deletions Server/Plugins/APIDump/APIDesc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17718,6 +17718,7 @@ end
"cLuaWindow.__cItemGrid__cListener__",
"Globals._CuberiteInternal_.*",
"Globals.esMax",
"Globals.E_BLOCK_*",
},
IgnoreVariables =
{
Expand Down
61 changes: 48 additions & 13 deletions Server/Plugins/APIDump/Classes/World.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ function OnAllChunksAvailable()</pre> All return values from the callbacks are i
Type = "number",
},
},
Notes = "Grows a cactus block at the specified coords, by up to the specified number of blocks. Adheres to the world's maximum cactus growth (GetMaxCactusHeight()). Returns the amount of blocks the cactus grew inside this call.",
Notes = "OBSOLETE, use GrowPlantAt instead. Grows a cactus block at the specified coords, by up to the specified number of blocks. Adheres to the world's maximum cactus growth (GetMaxCactusHeight()). Returns the amount of blocks the cactus grew inside this call.",
},
GrowMelonPumpkin =
{
Expand Down Expand Up @@ -2095,36 +2095,71 @@ function OnAllChunksAvailable()</pre> All return values from the callbacks are i
Type = "boolean",
},
},
Notes = "Grows a melon or pumpkin, based on the stem block type specified (assumed to be at the coords provided). Checks for normal melon / pumpkin growth conditions - stem not having another produce next to it and suitable ground below. Returns true if the melon or pumpkin grew successfully.",
Notes = "OBSOLETE, use GrowPlantAt instead. Grows a melon or pumpkin, based on the stem block type specified (assumed to be at the coords provided). Checks for normal melon / pumpkin growth conditions - stem not having another produce next to it and suitable ground below. Returns true if the melon or pumpkin grew successfully.",
},
GrowRipePlant =
GrowPlantAt =
{
Params =
{
{
Name = "BlockX",
Type = "number",
Name = "BlockPos",
Type = "Vector3i",
},
{
Name = "BlockY",
Name = "NumStages",
Type = "number",
},
},
Returns =
{
{
Name = "BlockZ",
Type = "number",
},
},
Notes = "Grows the plant at the specified block by the specified number of stages. Returns the number of stages actually grown. Returns zero for non-growable blocks.",
},
GrowRipePlant =
{
{
Params =
{
Name = "IsByBonemeal",
Type = "boolean",
{
Name = "BlockX",
Type = "number",
},
{
Name = "BlockY",
Type = "number",
},
{
Name = "BlockZ",
Type = "number",
},
},
Returns =
{
{
Type = "boolean",
},
},
Notes = "OBSOLETE, use the Vector3-based overload instead. Grows the plant at the specified coords to its full. Returns true if the plant was grown, false if not.",
},
Returns =
{
Params =
{
Type = "boolean",
{
Name = "BlockPos",
Type = "number",
},
},
Returns =
{
{
Type = "boolean",
},
},
Notes = "Grows the plant at the specified coords to its full. Returns true if the plant was grown, false if not.",
},
Notes = "Grows the plant at the specified coords. If IsByBonemeal is true, checks first if the specified plant type is bonemealable in the settings. Returns true if the plant was grown, false if not.",
},
GrowSugarcane =
{
Expand Down Expand Up @@ -2153,7 +2188,7 @@ function OnAllChunksAvailable()</pre> All return values from the callbacks are i
Type = "number",
},
},
Notes = "Grows a sugarcane block at the specified coords, by up to the specified number of blocks. Adheres to the world's maximum sugarcane growth (GetMaxSugarcaneHeight()). Returns the amount of blocks the sugarcane grew inside this call.",
Notes = "OBSOLETE, use GrowPlantAt instead. Grows a sugarcane block at the specified coords, by up to the specified number of blocks. Adheres to the world's maximum sugarcane growth (GetMaxSugarcaneHeight()). Returns the amount of blocks the sugarcane grew inside this call.",
},
GrowTree =
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlockEntities/DispenserEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
Vector3i dispRelCoord(GetRelPos());
auto meta = a_Chunk.GetMeta(dispRelCoord);
AddDropSpenserDir(dispRelCoord, meta);
auto dispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(dispRelCoord.x, dispRelCoord.z);
auto dispChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(dispRelCoord);
if (dispChunk == nullptr)
{
// Would dispense into / interact with a non-loaded chunk, ignore the tick
Expand Down
6 changes: 3 additions & 3 deletions src/BlockEntities/HopperEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ bool cHopperEntity::MoveItemsOut(cChunk & a_Chunk, Int64 a_CurrentTick)

// Convert coords to relative:
auto relCoord = a_Chunk.AbsoluteToRelative(out.second);
auto destChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(relCoord.x, relCoord.z);
auto destChunk = a_Chunk.GetRelNeighborChunkAdjustCoords(relCoord);
if (destChunk == nullptr)
{
// The destination chunk has been unloaded, don't tick
Expand Down Expand Up @@ -379,7 +379,7 @@ bool cHopperEntity::MoveItemsFromChest(cChunk & a_Chunk)
for (const auto & ofs: neighborOfs)
{
auto neighborRelCoord = ofs.addedXZ(m_RelX, m_RelZ);
auto neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(neighborRelCoord.x, neighborRelCoord.z);
auto neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(neighborRelCoord);
if (neighbor == nullptr)
{
continue;
Expand Down Expand Up @@ -543,7 +543,7 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, Vector3i a_Coords)
for (const auto & ofs: neighborOfs)
{
auto otherHalfRelCoord = relCoord + ofs;
auto neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(otherHalfRelCoord.x, otherHalfRelCoord.z);
auto neighbor = a_Chunk.GetRelNeighborChunkAdjustCoords(otherHalfRelCoord);
if (neighbor == nullptr)
{
continue;
Expand Down
36 changes: 18 additions & 18 deletions src/BlockEntities/MobSpawnerEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,36 @@ void cMobSpawnerEntity::SpawnEntity(void)
break;
}

int RelX = m_RelX + static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0);
int RelY = m_Pos.y + Random.RandInt(-1, 1);
int RelZ = m_RelZ + static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0);

cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelX, RelZ);
if ((Chunk == nullptr) || !Chunk->IsValid())
Vector3i spawnRelPos(GetRelPos());
spawnRelPos += Vector3i(
static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0),
Random.RandInt(-1, 1),
static_cast<int>((Random.RandReal<double>() - Random.RandReal<double>()) * 4.0)
);

auto chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(spawnRelPos);
if ((chunk == nullptr) || !chunk->IsValid())
{
continue;
}
EMCSBiome Biome = Chunk->GetBiomeAt(RelX, RelZ);
EMCSBiome Biome = chunk->GetBiomeAt(spawnRelPos.x, spawnRelPos.z);

if (cMobSpawner::CanSpawnHere(Chunk, RelX, RelY, RelZ, MobType, Biome))
if (cMobSpawner::CanSpawnHere(chunk, spawnRelPos, MobType, Biome))
{
double PosX = Chunk->GetPosX() * cChunkDef::Width + RelX;
double PosZ = Chunk->GetPosZ() * cChunkDef::Width + RelZ;

auto Monster = cMonster::NewMonsterFromType(MobType);
if (Monster == nullptr)
auto absPos = chunk->RelativeToAbsolute(spawnRelPos);
auto monster = cMonster::NewMonsterFromType(MobType);
if (monster == nullptr)
{
continue;
}

Monster->SetPosition(PosX, RelY, PosZ);
Monster->SetYaw(Random.RandReal(360.0f));
if (Chunk->GetWorld()->SpawnMobFinalize(std::move(Monster)) != cEntity::INVALID_ID)
monster->SetPosition(absPos);
monster->SetYaw(Random.RandReal(360.0f));
if (chunk->GetWorld()->SpawnMobFinalize(std::move(monster)) != cEntity::INVALID_ID)
{
HaveSpawnedEntity = true;
m_World->BroadcastSoundParticleEffect(
EffectID::PARTICLE_MOBSPAWN,
Vector3d(PosX, RelY, PosZ).Floor(),
absPos,
0
);
NearbyEntities++;
Expand Down
3 changes: 2 additions & 1 deletion src/BlockID.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ enum ENUM_BLOCK_ID : BLOCKTYPE
E_BLOCK_DIAMOND_BLOCK = 57,
E_BLOCK_CRAFTING_TABLE = 58,
E_BLOCK_WORKBENCH = 58,
E_BLOCK_CROPS = 59,
E_BLOCK_WHEAT = 59,
E_BLOCK_CROPS = E_BLOCK_WHEAT,
E_BLOCK_FARMLAND = 60,
E_BLOCK_FURNACE = 61,
E_BLOCK_LIT_FURNACE = 62,
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlockBed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
PillowDirection = MetaDataToDirection(Meta & 0x3);
if (a_ChunkInterface.GetBlock(Coords + PillowDirection) == E_BLOCK_BED) // Must always use pillow location for sleeping
{
a_WorldInterface.GetBroadcastManager().BroadcastUseBed(a_Player, Vector3i{ a_BlockX, a_BlockY, a_BlockZ } + PillowDirection);
a_WorldInterface.GetBroadcastManager().BroadcastUseBed(a_Player, Vector3i{a_BlockX, a_BlockY, a_BlockZ} + PillowDirection);
}
}

Expand Down Expand Up @@ -127,7 +127,7 @@ bool cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
}
);
a_WorldInterface.SetTimeOfDay(0);
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x0b); // Clear the "occupied" bit of the bed's block
a_ChunkInterface.SetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}, Meta & 0x0b); // Clear the "occupied" bit of the bed's block
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/BlockBed.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class cBlockBedHandler :



static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, const Vector3i & a_BedPosition, bool a_IsOccupied)
static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, Vector3i a_BedPosition, bool a_IsOccupied)
{
auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition);
if (a_IsOccupied)
Expand All @@ -87,7 +87,7 @@ class cBlockBedHandler :
Meta &= 0x0b; // Clear the "occupied" bit of the bed's block
}

a_ChunkInterface.SetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z, Meta);
a_ChunkInterface.SetBlockMeta(a_BedPosition, Meta);
}


Expand Down
11 changes: 8 additions & 3 deletions src/Blocks/BlockBigFlower.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
class cBlockBigFlowerHandler :
public cBlockHandler
{
using super = cBlockHandler;

public:
typedef cBlockHandler super;

cBlockBigFlowerHandler(BLOCKTYPE a_BlockType)
: cBlockHandler(a_BlockType)
cBlockBigFlowerHandler(BLOCKTYPE a_BlockType):
super(a_BlockType)
{
}





virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) override
{
if (IsMetaTopPart(a_Meta))
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/BlockButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class cBlockButtonHandler :
// Set p the ON bit to on
Meta |= 0x08;

a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta, false);
a_ChunkInterface.SetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}, Meta, false);
a_WorldInterface.WakeUpSimulators(Pos);
a_WorldInterface.GetBroadcastManager().BroadcastSoundEffect("block.stone_button.click_on", SoundPos, 0.5f, 0.6f);

Expand Down
Loading

0 comments on commit 61904af

Please sign in to comment.