I'm trying to make a somewhat simple disguise object in my plugin that allows me to extend on and then create better disguises, for example I extend on it to create a sheep disguise and with that I can then make it sheared change colours without having a huge disguise class. From this I know I will need to have three key things which is DataWatchers for the colours in the example (I think) and the packets to send to the players when disguised and the movement packets, at this point I have no clue on how I could achieve this I have never done much with packets if someone can show me examples on how I can use them for the disguising or could tell me what packets I need to create and destroy the disguises it would be much appreciated thanks!
MCCoding Want to know how easy my disguises are? 1) Spawn the animal you want 2) Hide the player 3) Every second teleport the animal to the player. Done <3
ChipDev I'm not asking for that I'm simply asking what packets I need to use and if there is any documentation on how I can use them.
In my plugin, I use: - PacketPlayOutEntityDestroy - PacketPlayOutSpawnEntityLiving - PacketPlayOutEntityLook - PacketPlayOutEntityEquipment - PacketPlayOutEntityHeadRotation
Thanks for that Da_Co0k1eZ and ChipDev, Da_Co0k1eZ how would I update or refresh the created entity with the packets? Do I have to destroy and recreate them every time the player moves or is there a way to update the spawn packets with the movement ones?
fireblast709 Do you know of any examples of it or at least where it is located in the source? Just so I have a reference so I know how I can structure all of this
MCCoding No, you don't recreate the entity, just update the current one. Use PacketPlayOutEntityLiving to spawn it into the world initially, then setup a bukkit runnable to send the packets to update the mob to every player. Usually I store the entity for the mob in an object in order to keep track of it. (Btw, the packet to update all of the mob's movements is PacketPlayOutEntityLook) MCCoding Also, the protocol page ChipDev suggested is a good source for all of the packets and what they do. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Da_Co0k1eZ This is what I have done so far with the spawn packet, but the problem is that I need to use a NMS entity to fill in some of the fields in the PacketPlayOutSpawnEntityLiving packet, there fore I need to have a NMS entity to use for the fields. I'm wondering if there is a better way to do this so in my Disguise object all i can just use new Disguise(Player, DisguiseType). EDIT: Also would the entity be the player getting disguised or the entity of the disguise eg a Blaze which i'm trying to disguise as?
Here, this is the code I use to create my disguises. It would be easier for me to spoon feed than for you to throw a dart randomly at a target and hope that it hits. Code:java private DisguiseType disguise;private UUID player;private EntityLiving entity; public Disguise(DisguiseType d, UUID p) {disguise = d;player = p;Location location = Bukkit.getServer().getPlayer(p).getLocation();switch(disguise) {case ZOMBIE:entity = new EntityZombie(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case WITHER_SKELETON:entity = new EntitySkeleton(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());((EntitySkeleton)entity).setSkeletonType(1);break;case SKELETON:entity = new EntitySkeleton(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case ZOMBIEPIG:entity = new EntityPigZombie(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case BLAZE:entity = new EntityBlaze(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case ENDERMAN:entity = new EntityEnderman(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case CREEPER:entity = new EntityCreeper(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case SPIDER:entity = new EntitySpider(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case WITCH:entity = new EntityWitch(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case WITHER_BOSS:entity = new EntityWither(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case GHAST:entity = new EntityGhast(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;case GIANT:entity = new EntityGiantZombie(((CraftWorld)Bukkit.getServer().getPlayer(p).getWorld()).getHandle());break;}if(d != null) {entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());entity.d(Bukkit.getServer().getPlayer(p).getEntityId());disguiseToAll();}} public Player getPlayer() {return Bukkit.getPlayer(player);} @SuppressWarnings("deprecation")public void removeDisguise() {this.disguise = null;Packet packetDestroy = new PacketPlayOutEntityDestroy(new int[] { Bukkit.getPlayer(player).getEntityId() });PacketPlayOutNamedEntitySpawn packetSpawn = new PacketPlayOutNamedEntitySpawn(((CraftPlayer)getPlayer()).getHandle());for (Player p : Bukkit.getServer().getOnlinePlayers()) {if(p.getUniqueId() != player) {EntityPlayer nmsPlayer = ((CraftPlayer)p).getHandle();nmsPlayer.playerConnection.sendPacket(packetDestroy);nmsPlayer.playerConnection.sendPacket(packetSpawn);}}} public void changeDisguise(DisguiseType d) {removeDisguise();this.disguise = d;disguiseToAll();} @SuppressWarnings("deprecation")public void disguiseToAll() {Packet packetDestroy = new PacketPlayOutEntityDestroy(new int[] { Bukkit.getPlayer(player).getEntityId() });Packet packetSpawn = new PacketPlayOutSpawnEntityLiving(entity);for (Player p : Bukkit.getServer().getOnlinePlayers()) {if(p.getUniqueId() != player) {EntityPlayer nmsPlayer = ((CraftPlayer)p).getHandle();nmsPlayer.playerConnection.sendPacket(packetDestroy);nmsPlayer.playerConnection.sendPacket(packetSpawn);}}new BukkitRunnable() {@Overridepublic void run() {if(disguise == null) {return;}updateDisguise();}}.runTaskTimer(Bukkit.getPluginManager().getPlugin("SurviveTheHorde"), 20L, 20L);} @SuppressWarnings("deprecation")public void updateDisguise() {for(Player observer : Bukkit.getServer().getOnlinePlayers()) {if (!observer.getWorld().equals(Bukkit.getPlayer(player).getWorld())) {return;}if (observer.getUniqueId().equals(player)) {return;}int entityId = Bukkit.getPlayer(player).getEntityId();if(disguise.isBiped()) {Packet[] packets = new Packet[7];Location location = Bukkit.getPlayer(player).getLocation();packets[0] = new PacketPlayOutEntityLook(entityId, (byte)(int)(location.getYaw() * 256.0F / 360.0F), (byte)(int)(location.getPitch() * 256.0F / 360.0F));EntityEquipment equipment = Bukkit.getPlayer(player).getEquipment();packets[1] = new PacketPlayOutEntityEquipment(entityId, 0, CraftItemStack.asNMSCopy(equipment.getItemInHand()));packets[2] = new PacketPlayOutEntityEquipment(entityId, 1, CraftItemStack.asNMSCopy(equipment.getBoots()));packets[3] = new PacketPlayOutEntityEquipment(entityId, 2, CraftItemStack.asNMSCopy(equipment.getLeggings()));packets[4] = new PacketPlayOutEntityEquipment(entityId, 3, CraftItemStack.asNMSCopy(equipment.getChestplate()));packets[5] = new PacketPlayOutEntityEquipment(entityId, 4, CraftItemStack.asNMSCopy(equipment.getHelmet()));Entity entity = ((CraftPlayer)Bukkit.getPlayer(player)).getHandle();packets[6] = new PacketPlayOutEntityHeadRotation(entity, (byte)(int)(location.getYaw() * 256.0F / 360.0F));EntityPlayer nmsplayer = ((CraftPlayer)observer).getHandle();for(int i = 0; i < packets.length; i++) {nmsplayer.playerConnection.sendPacket(packets[I]);[/I][I] }[/I][I] return;[/I][I] }[/I][I] Packet[] packets = new Packet[1];[/I][I] Location location = Bukkit.getPlayer(player).getLocation();[/I][I] packets[0] = new PacketPlayOutEntityLook(entityId, (byte)(int)(location.getYaw() * 256.0F / 360.0F), (byte)(int)(location.getPitch() * 256.0F / 360.0F));[/I][I] Entity entity = ((CraftPlayer)Bukkit.getPlayer(player)).getHandle();[/I][I] packets[1] = new PacketPlayOutEntityHeadRotation(entity, (byte)(int)(location.getYaw() * 256.0F / 360.0F));[/I][I] EntityPlayer nmsplayer = ((CraftPlayer)observer).getHandle();[/I][I] for(int i = 0; i < packets.length; i++) {[/I][I] nmsplayer.playerConnection.sendPacket(packets[I]);[/I][/I][I] }[/I][I] }[/I][I] }[/I] [I] public static enum DisguiseType {[/I][I] ZOMBIE(Type.BIPED), WITHER_SKELETON(Type.BIPED), SKELETON(Type.BIPED), ZOMBIEPIG(Type.BIPED), BLAZE(Type.MOB), ENDERMAN(Type.MOB), CREEPER(Type.MOB), SPIDER(Type.MOB), WITCH(Type.MOB), WITHER_BOSS(Type.MOB), GHAST(Type.MOB), GIANT(Type.MOB);[/I] [I] private Type type;[/I] [I] DisguiseType(Type type) {[/I][I] this.type = type;[/I][I] }[/I] [I] public Type getType() {[/I][I] return type;[/I][I] }[/I] [I] public boolean isBiped() {[/I][I] if(type == Type.BIPED) {[/I][I] return true;[/I][I] }[/I][I] return false;[/I][I] }[/I] [I] public static enum Type {[/I][I] BIPED, MOB;[/I][I] }[/I][I] }[/I]
Da_Co0k1eZ I had figured what I was doing wrong, I was casting the entity to something that would not work with a CraftPlayer, but I have 2 weird bugs/issues you may have a answer to, firstly is when I PacketPlayOutEntityEquipment I have to re-equip armour and change items in hand to show it also when a player flys the mob starts dropping, is there any way to fix these bugs?
MCCoding To fix the mob's equipment, use the setEquipment() method on the entity, and get the equipment from EntityPlayer. As for the mob dropping whenever you fly, I don't think that you can fix that without writing your own packets using protocol lib or something similar.
Da_Co0k1eZ I have managed to fix it all but for some weird reason when you disguise as certain mobs, for instance a Iron Golem it kicks players saying "Internal Exception: net.minecraft.util.io.handler.codec.EncoderException: NullPointerException"