[Question]EntityType With an Array as a reference? General usage?

Discussion in 'Plugin Development' started by Flash619, May 14, 2012.

  1. Offline

    Flash619

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yes, I have look at the java doc's. But I have some questions, I have made a few plugins, but never really have ever done anything with entities, or spawning entities/creatures of any kind. So really, don't know how any of it works. -_- I'm doing my best to figure it out but the java doc's just gives very basic usage and doesn't actually show any bare bone examples.

    Aside from that, I was also trying to do something like:
    Code:java
    1.  
    2. public static EntityType[] MountType = new EntityType[]{
    3. WOLF,
    4. SPIDER,
    5. PIG,
    6. SHEEP,
    7. COW
    8. };
    9.  

    Originally this was a String[] but upon trying to set a creature spawn, I noticed it needed to receive a EntityType variable and couldn't convert to a string. So I just tried switching it to a EntityType
    Which obviously was a very failed attempt but wanted to use something similar to that for this:

    Code:java
    1.  
    2. EntityType CreatureType = MountType[getMountListPosition(ID)];
    3.  

    Which would then look at a position in the list, and return the proper entity type as "used to be a string" EntityType.

    So... I'm not entirely sure where to go from here, or really sure on how spawning Entities with a EntityType variable even works. So if anyone could give me a very very basic tutorial to go off of, that would be fantastic. :) Or any general help would also be good. :D

    Does each EntityType have to be connected to a separate method? It seems, hard to understand the way that the java doc's shows it.

    @Father Of Time

    EDIT
    Also it would be nice if upon spawn, I could get that entities ID or set that entities ID. It would be extremely useful. But I'm not sure how, do I just spawn it at a location, then get the id of the entity at that location?

    Sorry if I seem like I'm asking a lot of questions....

    EDIT

    I also suppose it may help to discribe what my goal is.

    All I want to do is spawn a entity "Lets say, a wolf" at a specific location, and be able to reference it with some sort of id "Not sure if that's possible". But I need to know its id to make a listener that listens for a entity damage caused by that entity event, if that makes any sense.

    This post has been edited 5 times. It was last edited by Flash619 May 14, 2012.
  2. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    If I read your post, making an array of the enum might not be what you want. Since you already have an array of strings, why don't you simply get the enum from that name?
    Code:
    String yourType = types[1]; // I assume types is your String[] and 1 is an existing index
    EntityType type = EntityType.fromName(yourType); // You could also use .fromId() if you only have the id
    LivingEntity entity = world.spawnCreature(location, type); // When you spawn a mob you'll get the mob instance
    What you do afterwards with the entity is up to you. As you asked, you could use .getEntityId() to get the ID if you want to. But I'm not entirely sure if you can get an entity just by it's id.

    This post has been edited 1 time. It was last edited by kumpelblase2 May 14, 2012.
  3. Offline

    Flash619

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Well all I need the entity ID for is things like setting move routes like, telling it where to go, seeing if the entity ID of the damager matches the one put in a hashmap, and removing that entity, or seeing if its still even there.

    I will try that code quick to see if it works. :)

    It looks like that will work! :D I wish I would have known I could have used a .fromName but now I do. :) Thank you.

    What does that last line of code do tho? Does that spawn it? *noob

    Because currently for attempting to spawn it I am using.

    Code:java
    1.  
    2. org.bukkit.World.spawnCreature(location,Mounts.getMountDurRef(ID));
    3.  


    But of course it gives me a error saying
    :/

    This post has been edited 4 times. It was last edited by Flash619 May 14, 2012.
  4. Offline

    Flash619

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Anyone know how to spawn it?
  5. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You need the instance of the world you want to spawn the mob in. If you already have the location you can just use .getWorld() to get the instance of it. Then just use the spawnCreature method.
  6. Offline

    Flash619

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Then lets say, if I wanted to make the specific entity go somewhere. You can see that someone gave me a nice how to here:
    http://forums.bukkit.org/threads/setting-new-direction-for-creatures-to-go-in.74489/

    But I'm slightly confused as to how I plug that creature into the first line at:
    Code:java
    1.  
    2. Mob mob; //"Mob" needs to be the type of creature you wish to control
    3. Location location; //set your location
    4. EntityCreature ec = ((CraftCreature)mob).getHandle();
    5. Navigation nav = ec.al();
    6. nav.a(location.getX(),location.getY(),location.getZ(),float);
    7.  


    I know you didn't write it, but how would I tell it that that newly spawned mount needs to go somewhere? *confused*

    It all seems simpler when you explain it, so, this really is the last thing that I have to figure out for today. ^_^
  7. Offline

    Flash619

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Ok I'm completely confused now. How do I use getEntityID if I never set one in the first place? How do I reference the mob that I spawn with

    location.getWorld().spawnCreature(location, Mounts.getMountDurRef(ID));

    If I don't know the entity to use for getEntityId?

    *lost

    I need to know how I can find the spawned entity, and link to it some way. I mean, it has to have some sort of an id, but how do I even find it?

    EDIT

    Would I have to set up a custom event to listen to a special spawn event and then get the ID from that? :confused: Seems like a bit of work for a ID...

    This post has been edited 2 times. It was last edited by Flash619 May 15, 2012.
  8. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    When you use the spawnCreature method you get back the entity (which is an instance of a LivingEntity) that was spawned - null if something went wrong -, meaning you can get the id, which is generated by the server, or cast it to a creature, if the type is a creature, and then just use the code provided. I haven't found a method getting the entitiy by its id, you probably need to get all entities with the type of that entity, loop through them and check the ids separately.

    This post has been edited 1 time. It was last edited by kumpelblase2 May 15, 2012.
  9. Offline

    Flash619

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    So say I wanted to get its ID then, how would I do that by using the spawnCreature method? I wasn't aware that it returned anything. What variable type is the ID ?

    Would it be like Variable = SpawnCreatureCode ?
  10. Offline

    kumpelblase2

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Like I said, you get a LivingEntity as a return value. Since the LivingEntity is an instance of an entity you can, like I said as well, use the .getEntityId() method to get the id, which is an integer.

  11. Offline

    Father Of Time

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yikes, looks like I was late to this party (catching up on my notifications).

    Hmm, it appears as if you both have resolved your issue, however if this isn't the case simply respond back and we will do what we can to get you back on track. Luckily kumpel stepped up, so you are in good hands. :D

    Good luck with the remainder of your project!

Share This Page