Jump to content

edit nbt to spawned entity


Takato

Recommended Posts

I was trying to spawn an entity like for example an mine cart chest or even the mine cart mob spawner

 

I can get them to spawn fine but I not sure how to edit the nbt data for them.  I wanted to be able to spawn mine cart chests with an item in it  or able to spawn minecart mob spawners that would spawn other stuff I tried to do it this way but it's not working lol I'm really new to this so I don't know how to edit the nbt the right way.

          EntityMinecart entitySpawnCart = EntityMinecart.createMinecart(par1World, par1, par2, par3, 4);
          NBTTagCompound nbt = entitySpawnCart.getEntityData();
          nbt.setString("EntityId", "SnowMan");
          entitySpawnCart.writeToNBT(nbt);
          par1World.spawnEntityInWorld(entitySpawnCart);

 

Link to comment
Share on other sites

I was trying to spawn an entity like for example an mine cart chest or even the mine cart mob spawner

 

I can get them to spawn fine but I not sure how to edit the nbt data for them.  I wanted to be able to spawn mine cart chests with an item in it  or able to spawn minecart mob spawners that would spawn other stuff I tried to do it this way but it's not working lol I'm really new to this so I don't know how to edit the nbt the right way.

          EntityMinecart entitySpawnCart = EntityMinecart.createMinecart(par1World, par1, par2, par3, 4);
          NBTTagCompound nbt = entitySpawnCart.getEntityData();
          nbt.setString("EntityId", "SnowMan");
          entitySpawnCart.writeToNBT(nbt);
          par1World.spawnEntityInWorld(entitySpawnCart);

 

Link to comment
Share on other sites

getEntityData() doesn't guarantee that you'll get the data you want. In fact forge code:

public NBTTagCompound getEntityData()
    {
        if (customEntityData == null)
        {
            customEntityData = new NBTTagCompound();
        }
        return customEntityData;
    }

this means you don't get any data aside from a new tag compound. the easiest way to work around this though is to pseudo load the entity ie

EnitytMineCart e =  yadda yadda initialization stuff;
NBTTagCompound data = new NBTTagCompound();
e.writeToNBT(data);
data.setString("EntityId", "SnowMan");
e.readFromNBT(data);
w.spawnEntityInWorld(e);

 

I think its my java of the variables.

Link to comment
Share on other sites

getEntityData() doesn't guarantee that you'll get the data you want. In fact forge code:

public NBTTagCompound getEntityData()
    {
        if (customEntityData == null)
        {
            customEntityData = new NBTTagCompound();
        }
        return customEntityData;
    }

this means you don't get any data aside from a new tag compound. the easiest way to work around this though is to pseudo load the entity ie

EnitytMineCart e =  yadda yadda initialization stuff;
NBTTagCompound data = new NBTTagCompound();
e.writeToNBT(data);
data.setString("EntityId", "SnowMan");
e.readFromNBT(data);
w.spawnEntityInWorld(e);

 

I think its my java of the variables.

Link to comment
Share on other sites

thanks well right I don't know how use packets yet, but if I did I don't know what packet data I would need to send and what to do with it on the client side for it to update tell what do do to she the right mob in the mine cart spawner. I'll take a look at some tutorials when I get time but I don't know if any will teach me any more that how to send and handle the packets.

 

so any pointers or links you can give  I'll be sure to check out. thanks again.

Link to comment
Share on other sites

thanks well right I don't know how use packets yet, but if I did I don't know what packet data I would need to send and what to do with it on the client side for it to update tell what do do to she the right mob in the mine cart spawner. I'll take a look at some tutorials when I get time but I don't know if any will teach me any more that how to send and handle the packets.

 

so any pointers or links you can give  I'll be sure to check out. thanks again.

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.