Cuberite Forum
Mobs spawning - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: Mobs spawning (/thread-630.html)

Pages: 1 2 3


RE: Mobs spawning - xoft - 11-24-2012

A finisher gets an entity list reference (a_Entities), just fill it with any entities you want to spawn there.
There is currently no example of this - there are no entities generated at all. You might even have to tweak other things, too - one thing that comes to my mind, I think entities need a cWorld in their constructor, this might cause trouble.


RE: Mobs spawning - steven2612 - 11-24-2012

yes ...

void cEntity::Initialize(cWorld * a_World)
{
m_World = a_World;
m_World->AddEntity( this );

MoveToCorrectChunk(true);
}


RE: Mobs spawning - FakeTruth - 11-25-2012

(11-24-2012, 11:27 PM)xoft Wrote: one thing that comes to my mind, I think entities need a cWorld in their constructor, this might cause trouble.

That may not be necessary? Entities receive their cWorld reference in the Initialize function. This is by design because you may not want to add an entity to a world the moment you instantiate one. You might need to set some entity properties first (is on fire, equipment, speed, etc. etc.) before the entity is added to the world.


RE: Mobs spawning - steven2612 - 11-25-2012

ok - in contructor there is no reference to cWorld - but in initialize.

i've now tried:

int x = a_ChunkX+10;
int z = a_ChunkZ+10;
int y = cChunkDef::GetHeight(a_HeightMap, x, z)+2;
cMonster * Monster = new cPig();
Monster->SetPosX(x);
Monster->SetPosY(y);
Monster->SetPosZ(z);
a_Entities.push_back( Monster );

it works except setting the position of the Monster (SetPosX) - when i add those then there is an assert
MCServer: source/Entity.cpp:105: void cEntity::MoveToCorrectChunk(bool): Assertion `0' failed.
Abgebrochen (Speicherabzug geschrieben)

how to i set the position of the entity without cWorld ?




RE: Mobs spawning - xoft - 11-25-2012

Might be best to fix those SetPos...() functions: if they see that the entity has no assigned world, then they shouldn't attempt to MoveToCorrectChunk().
How does it work with normal spawning? I'd have expected it to work similarly - create, set props, initialize.


RE: Mobs spawning - steven2612 - 11-25-2012

ok, i tried:

void cEntity::SetPosition( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
{
m_Pos.Set( a_PosX, a_PosY, a_PosZ );
if (m_World!=NULL) {
MoveToCorrectChunk();
}
m_bDirtyPosition = true;
}

now it compiles fine - but no mobs are created - maybe noone issued the initialize funktion ? The contructor is executed.



RE: Mobs spawning - steven2612 - 11-25-2012

I've now tried many variations to create a Mob within th Finishing Generator - but it seem's i'm missing something it wont spawn any mobs ... Sad
Maybe someone could help with this ?


RE: Mobs spawning - xoft - 11-25-2012

You're probably right - no-one calls the Initialize function. You should add it somewhere to the cChunk::SetAllData() or cChunkMap::SetChunkData() function, wherever it fits better and works. Be carefull though - the chunk may already contain some entities (mobs that have walked off the edge of the loaded map) so you need to be careful with which entities you call Initialize() on. I'm not sure, too, if SetChunkData() isn't too early - the chunk is still not set as valid and calling Initialize might crash then, or deadlock. Well, you'll see Smile


RE: Mobs spawning - steven2612 - 11-25-2012

i've tried already in setchunkdata() and setalldata ... but then it loops endlessly in the generating loop .. i don't know why


RE: Mobs spawning - steven2612 - 12-02-2012

ok, a little bit to myself - missing pieces in code:

cChunkSender::SendChunk
// TODO: Send entity spawn packets


cChunkSender::Entity
// Nothing needed yet, perhaps in the future when we save entities into chunks we'd like to send them upon load, too Wink

WSSAnvil:

virtual void Entity(cEntity * a_Entity) override
{
// TODO: Add entity into NBT:
}


void cWSSAnvil::LoadEntitiesFromNBT(cEntityList & a_Entitites, const cParsedNBT & a_NBT, int a_TagIdx)
{
// TODO: Load the entities
}


cChunk::SetAllData
m_Entities.splice(m_Entities.end(), a_Entities);

I tried to follow the path how a Entity shoud be created.
First in the FinishingGen or WSSAnvil there shoud be created an Entity (or loaded)
Then it is added to a_Entities which goes finally to cChunk::SetAllData.

Within ChunkSender there ar missing Entities functions (TODO) maybe therefore never an Entity get initialized or broadcasted to the Client ?
Where in the Way up the functions should an Entity be initialized ? When generating/loading or within Chunk::SetAllData or within ChunkSender ?

within world.cpp a mob is generated:
[.. generating mob .. ]
Monster->Initialize(this);
Monster->TeleportTo(a_PosX, a_PosY, a_PosZ);
BroadcastSpawn(*Monster);

so i think Bradcastspawn should be called in ChunkSender ?