1.8.8 Wither problem?

Discussion in 'Spigot Plugin Development' started by YogurtSmudge, Jan 19, 2020.

  1. I'm experimenting with the EntityWither class and I ran into an issue that surprised me a bit.

    I'm currently using this code:
    Code (Java):
    EntityWither wither = new EntityWither(((CraftWorld) loc.getWorld()).getHandle());

    wither.getBukkitEntity().teleport(loc); // This is needed otherwise a wither wouldn't even spawn. Could use setPosition aswell.

    PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(wither);

    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); // Packet sending
    The result? The wither spawns with no ai, and is stationary, it takes no damage, as if it has no objective, it does not move, not make any sounds, no gravity. I tried making my own Custom Wither class, only with the super method and the same result persists.

    What am I doing wrong?
     
  2. Have you tried with
    Code (Java):

    loc.getWorld().spawnEntity(loc, EntityType.WITHER);
     
     
  3. I'm trying to create a custom entity, one I can tinker with its properties, and override them.
     
  4. Code (Java):
    world.spawn(location, YourCustomEntity.class)
    where YourCustomEntity extends WitherEntity for example
     
  5. I'm a bit confused by this..?

    upload_2020-1-19_2-49-7.png

    upload_2020-1-19_2-49-57.png

    Remember the issue is not spawning the wither in.
    It's the fact that the wither spawns in with no properties, no goal selectors, no nothing. It's a wither that is immune, with no ai, and no objective.

    Plus, I am trying to get only the player specified to see the wither, not everyone.
     
    #5 YogurtSmudge, Jan 19, 2020
    Last edited: Jan 19, 2020
  6. You also need to send the PacketPlayOutEntityMetadata-packet
    Other than that, you would have to update the position manually every time the wither does something.
    I would suggest to spawn it using NMS (Entity#setPosition, world#addEntity#) since that sends out these packets automatically.
    You can get a Bukkit-copy of the entity using CraftLivingEntity#getEntity()
     
  7. That didn't work.
    I'm trying to find the issue but I can't even spawn a rabbit using this:

    Code (Java):
    Location loc = p.getLocation();
    World world = loc.getWorld();
    WorldServer ws = (((CraftWorld) world).getHandle());

    EntityRabbit rabbit = new EntityRabbit(ws);

    PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(rabbit);

    rabbit.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0F, 0F);

    (((CraftPlayer) p).getHandle()).playerConnection.sendPacket(packet);
    p.sendMessage("sent");
    I get the "sent" message but no rabbit appears? I'm so confused.
     
  8. I had a similar issue, but I'm not sure if it's entirely the same. It was because I screwed up the extends and the super method in my custom entity class. Could we see your custom wither class?
     
  9. It was one of the images a couple replies ago.
    It's really odd because if it set a custom name it works, however, if I try anything with targetSelector or goalSelector, it looks like it completely ignores it as the wither still has no goals or targets.
     
  10. Did you try setting the location before you send out the packet?
    If I‘m not mistaken the packet copies stuff like the entity id and location and sends out that...
     
  11. i think you forgot for entities to show ai they need to be added to the world like this:
    world.addEntity(the custom entity, SpawnReason.IFYOUWANT);
    where 'world' is the nms world
     
  12. So I added this:
    Code (Java):
    ((CraftWorld) world).addEntity(wither, CreatureSpawnEvent.SpawnReason.CUSTOM);
    Weird. This resulted in an invisible wither with ai, goals and sounds. However it was not registered.

    When I did register it, it not longer spawned in?
    I'm using this to register my custom class.

    Code (Java):
    registerEntity("Wither", 64, EntityWither.class, CustomWither.class);
    Code (Java):
        private void registerEntity(String name, int id, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass){
            try {

                List<Map<?, ?>> dataMap = new ArrayList<>();
                for (Field f : EntityTypes.class.getDeclaredFields()){
                    if (f.getType().getSimpleName().equals(Map.class.getSimpleName())){
                        f.setAccessible(true);
                        dataMap.add((Map<?, ?>) f.get(null));
                    }
                }

                if (dataMap.get(2).containsKey(id)){
                    dataMap.get(0).remove(name);
                    dataMap.get(2).remove(id);
                }

                Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                method.setAccessible(true);
                method.invoke(null, customClass, name, id);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
  13. Weird because i just worked with a custom wither just recently and it seemed to work well, but i'm not sure what you want to achieve by registering
     
  14. I thought you needed to register any custom entities?

    I’ve never fiddled with custom entities until now.
     
  15. world.addentity always worked to me so its strange when i see 40 lines to register directly into the entity types + reflections
     
  16. addEntity did work. I'm just confused on the invisible wither part.
     
  17. do you send spawning packet? if so remove it
     
  18. I removed the PacketPlayOutSpawnEntityLiving however, it no longer spawns.

    @Fr33style mind sending me the wither class you used and how you used it, if you dont mind?
     
    #18 YogurtSmudge, Jan 19, 2020
    Last edited: Jan 19, 2020
  19. Something like this:

    Code (Text):
        public CustomWither(Location loc) {
            super(EntityTypes.WITHER, ((CraftWorld) loc.getWorld()).getHandle());
            setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            world.addEntity(this, SpawnReason.CUSTOM);
        }
     
  20. I used what I could from that and the wither is still invisible. Shoots wither skulls, has sound, kills entities, but no visible wither and no boss bar either. I tried both with and without the packet sending.

    EDIT: Anyone know why literally any entity I try to spawn with the PacketPlayOutSpawnEntityLiving packet has no ai, and is an actual statue?

    This is very odd.
    I've seen other threads of other people using packets like the one below, yet it doesn't work for me?

    Code (Java):

            Player p = e.getPlayer();
            Location loc = p.getLocation();
            World world = loc.getWorld();
            WorldServer ws = ((CraftWorld) world).getHandle();

            final EntityHorse horse = new EntityHorse(ws);
            horse.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            horse.setCustomName("test");

            final PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(horse);
            PlayerConnection pc = ((CraftPlayer) p).getHandle().playerConnection;

            pc.sendPacket(packet);
     
    #20 YogurtSmudge, Jan 19, 2020
    Last edited: Jan 19, 2020