Jump to content

[1.6.4]How to spawn a mob using data available ingame


skullywag

Recommended Posts

Hey all,

 

Im having some issues in regards to spawning mobs using the data available ingame.

 

My issue is that I have been using:

 

Entity entity = EntityList.createEntityByName(this.getEntityNameToSpawn(), this.getSpawnerWorld());

 

To spawn mobs, im killing said mobs and storing their info in an item and passing the name of the mob to it, the issue is not all mobs return an entity when passing the name thats available ingame. As an example I know all the Twilight Forest mobs require "TwlightForest." in front of what "mobentity.getEntityName()" will return. So I get "Wild Boar" ingame, but it wants "TwilightForest.Wild Boar". I dont want to write internal rules for each custom mod that has its own mobs, id rather this was kept as dynamic as possible.

 

Ive tried creating from IDs, from NBT, nothing I do seems to work.

 

The only thing I can think might lead me to a solution is to use mobentity.getClass() in some way but my brain refuses to come up with the solution.

 

EntityList doesnt seem to have the required method I need.

 

Can someone here come up with a way of achieving this, or point out my stupidity (its probably this, its been a long night...)

Link to comment
Share on other sites

EntityRegistry doesnt give me any methods that seems useful in this regard. Looked in .instance() as well, the only thing that looks like a possibility is:

 

EntityRegistry.instance().lookupModSpawn

 

but theres 2 versions of it,  that I cant bend my head around what they need, ill look into these, but any other help is appreciated.

 

Thanks for your help so far, I hate getting stuck on things like this, you would think there would be something on the mob to track back...

Link to comment
Share on other sites

Hi

 

I have to admit I'm a bit confused now about how you're using this.

I had assumed:

(1) when you hit a mob with your item, it copies the "name" (or other unique identifier) of the mob into the item.\

(2) later, when you "use" the item, it spawns the mob again using the "name".

 

If that's the case, I don't really understand why you couldn't use the "name" that you get from EntityList to create the mob again (using EntityList).

 

Likewise, lookupModSpawn(mobEntity, someDummyBoolean) will give you an EntityRegistration for that entity, which should give you all the info you need to spawn it?

 

Perhaps if you show us how you're trying to spawn your entity?

 

-TGG

Link to comment
Share on other sites

ok, some detail required.

 

Entities in game drop a custom xp orb type entity when killed, this entity holds the unique identifier which is written on death of the entity (using a forge living death event to write to NBT of the orb entity, ive tried entityID,and enitityName). When you collect these orbs they "fill" an item on your hotbar and transfer the identifier to it, you then (once the item is full) right click it on a block (a custom mob spawner) the mob spawner uses pretty similar code to vanilla to spawn the entity.

 

The key part is the transfer of the identifier to the mob spawning block:

 

spawner.getSpawnerLogic().setMobName(mobtospawn);

 

This sets a String in the mob spawners logic, that is returned in getEntityNameToSpawn() below.

 

So if I were to kill a Thaumcraft "Angry Zombie" thats what would be passed to the setMobName. The spawner block then uses the code i put above:

 

Entity entity = EntityList.createEntityByName(this.getEntityNameToSpawn(), this.getSpawnerWorld());

 

to create the entity and spawn it (once I have the entity here the rest of my code is fine), Everything works perfectly if the mob name and the registration name are the same. I even have 2 custom mob entities (zombie and skeleton with burn in sun disabled) that I can call by passing their entity name, they work fine as their name is also the name I used when registering them.

 

Im looking for a sure fire way of getting the right entity whether its vanilla or custom mobs.

 

So it seems I have 2 options, either I change what im passing as the identifier or I change how I lookup the mob entity. Im pretty sure this is gonna be a really simple thing in the end, I just cannot find the 1 piece of info im missing.

Link to comment
Share on other sites

Hi

 

OK, so if I understand correctly, the problem is that the unique identifier you're reading (in the living death event) doesn't match the unique identifier you need for your mob spawner.

 

Just to be 100% clear -

in living death you have used

string myUniqueName = EntityList.getEntityString(livingDeathEvent.source);

 

and in your spawner you have tried

Entity entity = EntityList.createEntityByName(myUniqueName, this.getSpawnerWorld());

 

But the names don't match-?

 

I don't understand that at all, EntityList should map those symmetrically as far as I can tell.

 

-TGG

Link to comment
Share on other sites

God Dammit, that was my problem, Why the hell didnt I think to use the same bloody method at both ends. I was using mobentity.getEntityName() on the death, which is OBVIOUSLY not the same as the one in EntityList, I said it would end up being something stupidly simple, hate being right when I say that.

 

Thank you muchly and apologies for wasting your time on something that should have been entirely straight forward. Its almost 3am here think I need some sleep.

 

Oh and if it wasnt obvious its working beautifully.

 

*goes to bed mumbling about how daft he is*

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.