Solved Spawn invisible glowing shulker with NMS

Discussion in 'Spigot Plugin Development' started by Nemo_64, Feb 15, 2020.

  1. I want to be able to spawn a shulker that is invisible and doesn't glow and make it that only a specific player can see it. I know this is posible with packets but I don't know how to start. Could you guide me?
     
  2. Will it be persistent? Unless you dont need it there everytime a simple spawn and some packet work is much easyer
     
  3. How could I do that?
     
  4. Here's a little example:

    Code (Java):
    final World world = ...; // You'll need to get a handle to the NMS-world
    final EntityShulker shulker = new EntityShulker(EntityTypes.SHULKER, world); // instanciate the entity (in this case, the shulker)

    final Location loc = ...; // where to spawn the shulker at
    shulker.setLocation(loc.getBlockX() + 0.5, loc.getBlockY(), loc.getBlockZ() + 0.5, 0, 0); // set it's location. In this example, I used the player location so I want to add 0.5 to x-and z in order to place the shulker on top of a block
    shulker.setInvisible(true); // set the shulker invisible
    shulker.h(true); // and glowing
    // all of these use the DataWatcher-object. You can directly interface it using shulker.getDataWatcher().set(obj, value)
    // for the case of a flag, use shulker.setFlag(int i, boolean flag)
    // for example, i=5 is responsible for the invisibility, i=6 is responsible for glowing

    PacketPlayOutSpawnEntityLiving packetSpawn = new PacketPlayOutSpawnEntityLiving(shulker); // instanciate the spawn-packet
    PacketPlayOutEntityMetadata packetMetadata = new PacketPlayOutEntityMetadata(shulker.getId(), shulker.getDataWatcher(), true); // instanciate the metadata-packet that takes the DataWatcher as an argument

    final PlayerConnection playerConnection = player.playerConnection; // get the PlayerConnection, note that player is the NMS-player
    playerConnection.sendPacket(packetSpawn); // and finally send the spawn packet
    playerConnection.sendPacket(packetMetadata); // and the metadada-packet
     
    #4 Schottky, Feb 15, 2020
    Last edited: Feb 15, 2020
    • Winner Winner x 1
  5. [​IMG]

    I don't know why but I love that look. Thanks for the code it works perfecty but I have 3 more questions:
    1- Can I get rid of the head?
    2- How can I remove it whenevr I want
    3- To use packets I have to import classes speficit for a version (net.minecraft.server.v1_13_R2.World) for example. I have seen people make it to work with every version, how can I do that?
     
  6. Unfortunately, the head has to be there, that's just the way the client renders that.
    To get rid of the shulker, you'll have to send this:
    Code (Java):
    PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(shulker.getId());
    You'll probably have to store the id somewhere to despawn the right shulker, it's unique for every entity
     
  7. Ok, that is no problem.
    Can you help me with the third question?
     
  8. I have never done this (since I try to avoid working with packets as much as possible due to problem pointed out in the third question) so I can only repeat what I have heard/seen other people do:

    1) Use ProtocolLib
    2) Use Reflection to access the correct Packets
    3) Provide an interface (by that I don't necessarily mean a Java-interface) for every distinct version
     
  9. If you just want to display a glowing square, you can try applying it to an invisible fallingblock ?
     
    • Like Like x 1
  10. Is also an option but the shulker works well for me
    But thanks for the coment
     
    • Like Like x 1