1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved How does one convert entity types to/from Skript

Discussion in 'Java' started by jaylawl, Aug 21, 2018.

  1. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    So i'm trying to get the entity type that is being spawned by a mob spawner tile entity.

    Using this will return the Bukkit entity type just fine:
    Code (Java):
    1. BlockState state = block.getState();
    2. CreatureSpawner spawner = (CreatureSpawner) state;
    3. return spawner.getSpawnedType();
    However i'm unsuccessful with converting it to a skript entity type.
    I have found this "method" (which doesn't feel like the right way), which returns the correct Skript entity type IF the name of the entity consists of only one word, otherwise it returns null:
    Code (Java):
    1. import ch.njol.skript.entity.EntityType;
    2.  
    3. BlockState state = block.getState();
    4. CreatureSpawner spawner = (CreatureSpawner) state;
    5. return EntityType.parse(spawner.getSpawnedType().toString());
    So i'm wondering, what's the correct method to convert skript entity type to/from bukkit entity type?

    Cheers

    /edit:
    Doing some messing around, this works, but it feels even more hacky and incorrect:
    Code (Java):
    1. return EntityType.parse(spawner.getSpawnedType().toString().replace("_", " "));
     
    #1 jaylawl, Aug 21, 2018
    Last edited: Aug 21, 2018
  2. Snow-Pyon

    Moderator Resource Staff

    Joined:
    Jan 25, 2017
    Messages:
    1,236
    Likes Received:
    176
    Medals:
    The real question is: why are you trying to convert it to a skript entity?
     
  3. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    Because i'm trying to make an expression for the mob spawned by mob spawner tile entities. The return must be a skript entity type, and the input must be a bukkit entity type (enum).
     
  4. Snow-Pyon

    Moderator Resource Staff

    Joined:
    Jan 25, 2017
    Messages:
    1,236
    Likes Received:
    176
    Medals:
    Code (Java):
    1. return EntityData.fromClass(entityType.getEntityClass());
    The return type must be an EntityData by the way.
     
  5. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    What will this do? So the entire thing has to be EntityData instead of EntityType?

    nevermind the topic
     

Share This Page

Loading...