[Solved] Corpses

Discussion in 'Spigot Plugin Development' started by Virizion, Nov 8, 2014.

  1. I'm trying to make corpse like bodies on my server. This is the code I'm currently using, but there is a problem that the bodies float.
    Code (Text):
    public void spawnCorpse(Player player) {
            PacketPlayOutNamedEntitySpawn npc = new PacketPlayOutNamedEntitySpawn(
                    ((CraftPlayer) player).getHandle());
            PacketPlayOutBed sleep = new PacketPlayOutBed();
            PacketPlayOutEntityEquipment helmet = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 1, CraftItemStack.asNMSCopy(player
                            .getInventory().getHelmet()));
            PacketPlayOutEntityEquipment chestplate = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 2, CraftItemStack.asNMSCopy(player
                            .getInventory().getChestplate()));
            PacketPlayOutEntityEquipment leggings = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 3, CraftItemStack.asNMSCopy(player
                            .getInventory().getLeggings()));
            PacketPlayOutEntityEquipment boots = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 4, CraftItemStack.asNMSCopy(player
                            .getInventory().getBoots()));
            try {
                Field npca = npc.getClass().getDeclaredField("a");
                npca.setAccessible(true);
                npca.setInt(npc, this.currentEntId);
                npca.setAccessible(!npca.isAccessible());
                Field npch = npc.getClass().getDeclaredField("h");
                npch.setAccessible(true);
                npch.setInt(npc, Item.getId(Item.getItemOf(Blocks.RED_ROSE)));
                npch.setAccessible(!npch.isAccessible());
                Field sleepa = sleep.getClass().getDeclaredField("a");
                sleepa.setAccessible(true);
                sleepa.setInt(sleep, this.currentEntId);
                sleepa.setAccessible(!sleepa.isAccessible());
                Field sleepb = sleep.getClass().getDeclaredField("b");
                sleepb.setAccessible(true);
                sleepb.setInt(sleep, (int) player.getLocation().getX());
                sleepb.setAccessible(!npca.isAccessible());
                Field sleepc = sleep.getClass().getDeclaredField("c");
                sleepc.setAccessible(true);
                sleepc.setInt(sleep, (int) player.getLocation().getY());
                sleepc.setAccessible(!sleepc.isAccessible());
                Field sleepd = sleep.getClass().getDeclaredField("d");
                sleepd.setAccessible(true);
                sleepd.setInt(sleep, (int) player.getLocation().getZ());
                sleepd.setAccessible(!sleepd.isAccessible());
                Field npcf = npc.getClass().getDeclaredField("f");
                npcf.setAccessible(true);
                npcf.setByte(npc, (byte) (145 * 256.0F / 360.0F));
                npcf.setAccessible(!npcf.isAccessible());
                Field npcg = npc.getClass().getDeclaredField("g");
                npcg.setAccessible(true);
                npcg.setByte(npc, (byte) 0);
                npcg.setAccessible(!npcg.isAccessible());
            } catch (Exception x) {
                x.printStackTrace();
            }
            for (Player p : player.getWorld().getPlayers()) {
                if (p != player) {
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(npc);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(helmet);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(chestplate);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(leggings);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(boots);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(sleep);
                }
            }
            this.currentEntId++;
        }
    It looks like this:
    [​IMG]
    The problem is it floats on the ground. I've seen servers make it on the ground like this: [​IMG]
    Does anyone know how to make it like this?
     
    #1 Virizion, Nov 8, 2014
    Last edited: Nov 9, 2014
    • Useful Useful x 1
  2. Set the location of the npc down a block?

    Code (Text):
     sleepc.setInt(sleep, (int) player.getLocation().getY()-1);
     
  3. I tried that today. Either the corpses don't spawn or they're in the ground completely.
    [​IMG]
     
  4. That wouldn't make a difference because PacketPlayOutBed takes integers that aren't fixed-point AFAIK.

    EDIT:
    I did it on a real player and moved the player and I got this:
    [​IMG]
    I think it's something with move packets.
     
    #5 Virizion, Nov 8, 2014
    Last edited: Nov 9, 2014
  5. are you planning to release this as a plugin? or just using it for personal use? because i think it would get alot of attention for what it is and does
     
    • Like Like x 1
  6. I was making it for a custom mini-game for a server, but I can release a normal corpse plugin too.
     
    • Like Like x 1
  7. I solved it with PacketPlayOutRelEntityMove and I got the corpse on the ground!
    Anyone that wants to look at the code it's here.
    Code (Text):
    public void spawnCorpse(Player player) {
            PacketPlayOutNamedEntitySpawn npc = new PacketPlayOutNamedEntitySpawn(
                    ((CraftPlayer) player).getHandle());
            PacketPlayOutBed sleep = new PacketPlayOutBed();
            PacketPlayOutEntityEquipment helmet = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 1, CraftItemStack.asNMSCopy(player
                            .getInventory().getHelmet()));
            PacketPlayOutEntityEquipment chestplate = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 2, CraftItemStack.asNMSCopy(player
                            .getInventory().getChestplate()));
            PacketPlayOutEntityEquipment leggings = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 3, CraftItemStack.asNMSCopy(player
                            .getInventory().getLeggings()));
            PacketPlayOutEntityEquipment boots = new PacketPlayOutEntityEquipment(
                    this.currentEntId, 4, CraftItemStack.asNMSCopy(player
                            .getInventory().getBoots()));
            PacketPlayOutRelEntityMove move = new PacketPlayOutRelEntityMove(
                    this.currentEntId, (byte) 0, (byte) ((player.getLocation()
                            .getY() - 1.7 - player.getLocation().getY()) * 32),
                    (byte) 0, false);
            try {
                Field npca = npc.getClass().getDeclaredField("a");
                npca.setAccessible(true);
                npca.setInt(npc, this.currentEntId);
                npca.setAccessible(!npca.isAccessible());
                Field npch = npc.getClass().getDeclaredField("h");
                npch.setAccessible(true);
                npch.setInt(npc, Item.getId(Item.getItemOf(Blocks.RED_ROSE)));
                npch.setAccessible(!npch.isAccessible());
                Field npcd = npc.getClass().getDeclaredField("d");
                npcd.setAccessible(true);
                npcd.setInt(npc, MathHelper.floor((player.getLocation().getY() + 2) * 32));
                npcd.setAccessible(!npcd.isAccessible());
                Field sleepa = sleep.getClass().getDeclaredField("a");
                sleepa.setAccessible(true);
                sleepa.setInt(sleep, this.currentEntId);
                sleepa.setAccessible(!sleepa.isAccessible());
                Field sleepb = sleep.getClass().getDeclaredField("b");
                sleepb.setAccessible(true);
                sleepb.setInt(sleep, (int) player.getLocation().getX());
                sleepb.setAccessible(!npca.isAccessible());
                Field sleepc = sleep.getClass().getDeclaredField("c");
                sleepc.setAccessible(true);
                sleepc.setInt(sleep, (int) player.getLocation().getY());
                sleepc.setAccessible(!sleepc.isAccessible());
                Field sleepd = sleep.getClass().getDeclaredField("d");
                sleepd.setAccessible(true);
                sleepd.setInt(sleep, (int) player.getLocation().getZ());
                sleepd.setAccessible(!sleepd.isAccessible());
                Field npcf = npc.getClass().getDeclaredField("f");
                npcf.setAccessible(true);
                npcf.setByte(npc, (byte) (145 * 256.0F / 360.0F));
                npcf.setAccessible(!npcf.isAccessible());
                Field npcg = npc.getClass().getDeclaredField("g");
                npcg.setAccessible(true);
                npcg.setByte(npc, (byte) 0);
                npcg.setAccessible(!npcg.isAccessible());
            } catch (Exception x) {
                x.printStackTrace();
            }
            for (Player p : player.getWorld().getPlayers()) {
                if (p != player) {
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(npc);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(helmet);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(chestplate);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(leggings);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(boots);
                    ((CraftPlayer) p).getHandle().playerConnection
                            .sendPacket(sleep);
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(move);
                }
            }
            this.currentEntId++;
        }
     
    #8 Virizion, Nov 9, 2014
    Last edited: Nov 9, 2014
    • Useful Useful x 1
  8. How would you remove the corpse?
     
  9. Im not 100% sure if it works but you coud try and save it when u spawn it and remove it with a shedueler
     
  10. @TimothyLampen just send a PacketPlayOutEntityDestroy packet with the entity ID used in the PacketPlayOutNamedEntitySpawn
     
    • Agree Agree x 1
  11. Yeah this packet would destroy it on the client.