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?
Will it be persistent? Unless you dont need it there everytime a simple spawn and some packet work is much easyer
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
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?
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
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