1
0

Falling blocks can now be spawned at any position. (#4620)

* Falling blocks can now be spawned at any position.

* Added a /cake command to Debuggers that throws a cake in a nice slow arc.

* Fixed regular falling blocks.
This commit is contained in:
Mattes D 2020-04-09 22:25:20 +02:00 committed by GitHub
parent 23219c4738
commit bdedab15c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 117 additions and 38 deletions

View File

@ -3318,6 +3318,7 @@ function OnAllChunksAvailable()</pre> All return values from the callbacks are i
Notes = "Spawns an {{cExpOrb|experience orb}} at the specified coords, with the given reward. Returns the EntityID of the new experience orb, or {{cEntity#INVALID_ID|cEntity#INVALID_ID}} if no experience orb was created.", Notes = "Spawns an {{cExpOrb|experience orb}} at the specified coords, with the given reward. Returns the EntityID of the new experience orb, or {{cEntity#INVALID_ID|cEntity#INVALID_ID}} if no experience orb was created.",
}, },
SpawnFallingBlock = SpawnFallingBlock =
{
{ {
Params = Params =
{ {
@ -3349,7 +3350,58 @@ function OnAllChunksAvailable()</pre> All return values from the callbacks are i
Type = "number", Type = "number",
}, },
}, },
Notes = "Spawns a {{cFallingBlock|Falling Block}} entity at the specified coords with the given block type/meta. Returns the EntityID of the new falling block, or {{cEntity#INVALID_ID|cEntity#INVALID_ID}} if no falling block was created.", Notes = "OBSOLETE, use the Vector3-based overloads instead. Spawns a {{cFallingBlock|Falling Block}} entity at the specified coords with the given block type/meta. Returns the EntityID of the new falling block, or {{cEntity#INVALID_ID|cEntity#INVALID_ID}} if no falling block was created.",
},
{
Params =
{
{
Name = "BlockPos",
Type = "Vector3i",
},
{
Name = "BlockType",
Type = "number",
},
{
Name = "BlockMeta",
Type = "number",
},
},
Returns =
{
{
Name = "EntityID",
Type = "number",
},
},
Notes = "Spawns a {{cFallingBlock|Falling Block}} entity in the middle of the specified block, with the given block type/meta. Returns the EntityID of the new falling block, or {{cEntity#INVALID_ID|cEntity#INVALID_ID}} if no falling block was created.",
},
{
Params =
{
{
Name = "Pos",
Type = "Vector3d",
},
{
Name = "BlockType",
Type = "number",
},
{
Name = "BlockMeta",
Type = "number",
},
},
Returns =
{
{
Name = "EntityID",
Type = "number",
},
},
Notes = "Spawns a {{cFallingBlock|Falling Block}} entity at exactly the specified coords, with the given block type/meta. Returns the EntityID of the new falling block, or {{cEntity#INVALID_ID|cEntity#INVALID_ID}} if no falling block was created.",
},
}, },
SpawnItemPickup = SpawnItemPickup =
{ {

View File

@ -1567,6 +1567,25 @@ end
function HandleCakeCmd(a_Split, a_Player)
local lookVector = a_Player:GetLookVector()
local pos = a_Player:GetEyePosition() + lookVector
local world = a_Player:GetWorld()
local speed = lookVector * 10
local cakeID = world:SpawnFallingBlock(pos, E_BLOCK_CAKE, 0)
world:DoWithEntityByID(cakeID,
function(a_CBCake)
a_CBCake:SetSpeed(speed)
end
)
a_Player:SendMessage("Your cake is served")
return true
end
function HandleClientVersionCmd(a_Split, a_Player) function HandleClientVersionCmd(a_Split, a_Player)
a_Player:SendMessage("Your client version number is " .. a_Player:GetClientHandle():GetProtocolVersion() ..".") a_Player:SendMessage("Your client version number is " .. a_Player:GetClientHandle():GetProtocolVersion() ..".")
return true return true

View File

@ -37,6 +37,13 @@ g_PluginInfo =
HelpString = "Playes a sound and displays an effect at the player's position", HelpString = "Playes a sound and displays an effect at the player's position",
}, },
["/cake"] =
{
Permission = "debuggers",
Handler = HandleCakeCmd,
HelpString = "Throws a cake in the direction the player's looking, in a slow arc.",
},
["/clientversion"] = ["/clientversion"] =
{ {
Permission = "debuggers", Permission = "debuggers",

View File

@ -11,11 +11,10 @@
cFallingBlock::cFallingBlock(Vector3i a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) : cFallingBlock::cFallingBlock(Vector3d a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta):
super(etFallingBlock, Vector3d(0.5, 0, 0.5) + a_BlockPosition, 0.98, 0.98), super(etFallingBlock, a_Position, 0.98, 0.98),
m_BlockType(a_BlockType), m_BlockType(a_BlockType),
m_BlockMeta(a_BlockMeta), m_BlockMeta(a_BlockMeta)
m_OriginalPosition(a_BlockPosition)
{ {
SetGravity(-16.0f); SetGravity(-16.0f);
SetAirDrag(0.02f); SetAirDrag(0.02f);

View File

@ -20,8 +20,8 @@ public: // tolua_export
CLASS_PROTODEF(cFallingBlock) CLASS_PROTODEF(cFallingBlock)
/** Creates a new falling block. /** Creates a new falling block.
a_BlockPosition is expected in world coords */ a_Position is expected in world coords */
cFallingBlock(Vector3i a_BlockPosition, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); cFallingBlock(Vector3d a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
// tolua_begin // tolua_begin
@ -37,7 +37,6 @@ public: // tolua_export
private: private:
BLOCKTYPE m_BlockType; BLOCKTYPE m_BlockType;
NIBBLETYPE m_BlockMeta; NIBBLETYPE m_BlockMeta;
Vector3i m_OriginalPosition; // Position where the falling block has started, in world coords
} ; // tolua_export } ; // tolua_export

View File

@ -62,12 +62,7 @@ void cSandSimulator::SimulateChunk(std::chrono::milliseconds a_Dt, int a_ChunkX,
); );
*/ */
auto FallingBlock = cpp14::make_unique<cFallingBlock>(Pos, BlockType, a_Chunk->GetMeta(itr->x, itr->y, itr->z)); m_World.SpawnFallingBlock(Pos, BlockType, a_Chunk->GetMeta(itr->x, itr->y, itr->z));
auto FallingBlockPtr = FallingBlock.get();
if (!FallingBlockPtr->Initialize(std::move(FallingBlock), m_World))
{
continue;
}
a_Chunk->SetBlock({itr->x, itr->y, itr->z}, E_BLOCK_AIR, 0); a_Chunk->SetBlock({itr->x, itr->y, itr->z}, E_BLOCK_AIR, 0);
} }
} }

View File

@ -2039,7 +2039,7 @@ UInt32 cWorld::SpawnItemPickup(Vector3d a_Pos, const cItem & a_Item, Vector3f a_
UInt32 cWorld::SpawnFallingBlock(Vector3i a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) UInt32 cWorld::SpawnFallingBlock(Vector3d a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{ {
auto fallingBlock = cpp14::make_unique<cFallingBlock>(a_Pos, a_BlockType, a_BlockMeta); auto fallingBlock = cpp14::make_unique<cFallingBlock>(a_Pos, a_BlockType, a_BlockMeta);
auto fallingBlockPtr = fallingBlock.get(); auto fallingBlockPtr = fallingBlock.get();

View File

@ -564,14 +564,22 @@ public:
/** Spawns an falling block entity at the given position. /** Spawns an falling block entity at the given position.
Returns the UniqueID of the spawned falling block, or cEntity::INVALID_ID on failure. */ Returns the UniqueID of the spawned falling block, or cEntity::INVALID_ID on failure. */
UInt32 SpawnFallingBlock(Vector3i a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); UInt32 SpawnFallingBlock(Vector3d a_Pos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
/** OBSOLETE, use the Vector3i-based overload instead. /** Spawns an falling block entity at the given position.
Returns the UniqueID of the spawned falling block, or cEntity::INVALID_ID on failure. */
UInt32 SpawnFallingBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
// When creating from a block position (Vector3i), move the spawn point to the middle of the block by adding (0.5, 0, 0.5)
return SpawnFallingBlock(Vector3d(0.5, 0, 0.5) + a_BlockPos, a_BlockType, a_BlockMeta);
}
/** OBSOLETE, use the Vector3-based overload instead.
Spawns an falling block entity at the given position. Spawns an falling block entity at the given position.
Returns the UniqueID of the spawned falling block, or cEntity::INVALID_ID on failure. */ Returns the UniqueID of the spawned falling block, or cEntity::INVALID_ID on failure. */
UInt32 SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) UInt32 SpawnFallingBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{ {
return SpawnFallingBlock({a_X, a_Y, a_Z}, a_BlockType, a_BlockMeta); return SpawnFallingBlock(Vector3i{a_X, a_Y, a_Z}, a_BlockType, a_BlockMeta);
} }
/** Spawns an minecart at the given coordinates. /** Spawns an minecart at the given coordinates.