Invisible Entities

Discussion in 'Plugin Development' started by Typ, Sep 25, 2016.

Thread Status:
Not open for further replies.
  1. Hello
    how Can I create invisible Entities, especially minecarts? BUT The user has to be able to sit in there!
    Hopefulle someone Can help me, cause I really found nothing in google :(

    greetings Typ
     
  2. @Typ
    It really isn't possible to make a minecart invisible and make users be able to sit in it, unless you do some manual trickery using the PlayerInteractEvent.

    If you just want to be able to sit on something invisible I'd recommend making an invisible Horse.
     
  3. Ok, thank you for The fast answer!
    I want to make a chair plugin, so I think it's better to use a chicken then, or something else what is not as high like as horse ;)

    Now HOW Can I do this, because I didnt find a possibility to make a entity invisible... Or do I have to use a livingentity?
     
  4. @Typ
    The thing is, there is no way in bukkit to just make an entity invisible and still have it be interactable, that's why I suggested horses, because if you set a Horse's Variant to -1 it will be invisible. Here's how I would do it (includes some other useful properties too):
    Code:java
    1. Horse horse = World.spawnEntity....
    2. // Setting the Variant to -1 to make it invisible.
    3. ((CraftHorse) horse).getHandle().setVariant(-1)
    4. // Make the horse invulnerable to avoid suffocation/player damage
    5. horse.setInvulnerable(true)
    6. // Make the horse have no AI so it doesn't move
    7. horse.setAI(false)
    8. // We don't want baby horses.
    9. horse.setAdult()
    10. // Prevent pushing
    11. horse.setCollidable(false)
    12. // Tame the Horse so it's ridable with items in your hand
    13. horse.setTamed(true)
    14. // Disable gravity so it can be placed precisely inside blocks.
    15. horse.setGravity(false)
    That will give us an invisible immovable horse which we can sit upon which can be placed inside a block to achieve a sitting effect for the player. There is however one problem. The Horse still makes noise, which is quite annoying. You could solve this by using ProtocolLib to prevent certain sound packets from being sent. Or, you could create a custom NMS Entity which will stop the sound packets being sent in the first place.
     
    Typ likes this.
  5. Ok, thank you very much! That helped me a lot! :D
     
  6. Offline

    Zombie_Striker

    @Typ
    If your problem has been solved, mark this thread as solved.
     
  7. Another stupid question: Whats the second Argument of line 1? Because EntityType.HORSE doesn't work D: I'm really sry, but I didn't work that much with entities, yet :/
     
  8. Offline

    Zombie_Striker

    @Typ
    First, you should have use your IDE to check the parameters. Just go back to the "world" variable, type in a period ( . ), and the list for all the methods and parameters should come up.

    Onto your actual question, the first value is the location you want to spawn the entity. The second value should be the entity type.
     
  9. Yes, I know that. The Problem is the following: Required is org.bukkit.entity.Horse and found is org.bukkit.entity.Entity?! I have now idea, how to get a org.bukkit.entity.horse.

    Edit: Found the error, I had to cast it ;)

    Thank you!
     
    Last edited: Sep 25, 2016
    Zombie_Striker likes this.
  10. @Typ
    Just cast it to Horse. IE:
    Code:java
    1. (Horse) world.spawnEntity(..args...)
     
  11. I know that I nerve, but org.bukkit.craftbukkit.v1_10_R1.entity.CraftHorse, what you Need for ((craftHorse) horse).getHandle().setVariant(-1) does not exist?
     
  12. @Typ
    It needs to be spelled CraftHorse, not craftHorse.
     
  13. Yeah, I got that, this is not the Problem ;) The Problem is, the error which Comes when compiling:
     
  14. @Typ
    Are you developing with the Bukkit.jar or CraftBukkit.jar/Spigot.jar?
     
  15. CraftBukkit.jar, do I Need Bukkit.jar?
     
  16. @Typ
    No, CraftBukkit.jar should contain the org.bukkit.craftbukkit package.

    Are you sure you have added the CraftBukkit.jar to your project?
     
  17. Yes of Course, else all the other commands wouldn't work, too, I think...
    And in the Editor, there's no error noted, ist only, when I try to compile it.
     
  18. @Typ
    What Minecraft version are you running?
     
  19. Minecraft: 1.10.2
    And Craftbukkit is 1.10.2, too
     
  20. Offline

    Zombie_Striker

    @AlvinB
    If you're worried about the horse making a sound, add the following line:
    Code:
             horse.setSilent(true);
    @Typ
    What this line is stating is that it could not find the object at this location. You should notice three things about this error message:
    1. All classes start with an uppercase letter, so there is no reason for this class to exist.
    2. There is no Entity class in the craftbukkit directory.
    3. This has nothing to do with the horse.
    Are you sure this is an issue with your plugin, and if so, are you sure this is an issue with that line? Also, have you checked the imports? Are they correct?
     
  21. @Zombie_Striker
    I think you have misread the error message. It says it cannot find the package "org.bukkit.craftbukkit.v1_10_R1.entity", and the CraftHorse path is "org.bukkit.craftbukkit.v1_10_R1.entity.CraftHorse".

    Also, handy method with the silent thing, I'll remember that in the future.
     
    Zombie_Striker likes this.
  22. Yeah, all Imports and that stuff is correct, I think.
    The Problem is at this lin :
    Code:
    import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHorse
     
  23. Offline

    RenditionsRule

    Is it possible that you're using the wrong server version? I believe it needs to be running on the same version that you used in your build path.
     
  24. No, I've got craftbukkit 1.10.2, in the buildpath AND the Server.
    And out of this, the error comes not when running the Server, but when I try to compile it ^^
     
  25. Offline

    JanTuck

    @Typ
    Which ide do you use?
     
  26. @Typ
    What if you remove and re-add the CraftBukkit.jar to your project?

    Project Structure Menu (Ctrl + Alt + Shift + S) -> Modules -> Dependencies -> select CraftBukkit.jar and click the little red minus in the top right -> Click the green plus and add it again.
     
  27. No, didn't work. sry :(
     
  28. @Typ
    What if you use BuildTools to obtain an entirey new CraftBukkit.jar?
     
  29. Oh damn, even this didn't work, too :(
    I have no idea how to fix this...
     
Thread Status:
Not open for further replies.

Share This Page