Set Villager Yaw Not Working?

Discussion in 'Spigot Plugin Development' started by Raydond123, Jul 5, 2015.

  1. Hello there! Right now I'm creating villagers using this API.
    I was wonder if there was a way I could remove the villagers' "huh" noise.
    Also, when I set the locations yaw that the villager would spawn at, it wouldn't affect it. The pitch worked perfectly though. I've also tried teleporting it to the location again after I've spawned it, that didn't work.

    Code (Text):
               for(String raw : plugin.getConfig().getStringList("locations")) {

                String[] data = raw.split(", ");
                World world = Bukkit.getWorld(data[0]);
                double x = Double.valueOf(data[1]);
                double y = Double.valueOf(data[2]);
                double z = Double.valueOf(data[3]);
                Location location = new Location(world, x, y, z);
                locations.add(location);
                location.setPitch(0);
                location.setYaw(90);

                CustomEntityVillager villager = CustomEntities.getNewCustomEntityVillager(location);
                villager.removeGoalSelectorPathfinderGoalAll();
                villager.setPushable(false);
                villager.setUnableToMove();
                villager.setUntradeable();
                villager.setProfession(3);
                entityIDs.add(villager.getBukkitEntity().getEntityId());
                villager.getBukkitEntity().teleport(location);

            }
    Thanks in advance,
    Ray
     
    #1 Raydond123, Jul 5, 2015
    Last edited: Jul 5, 2015
  2. Any console errors when spawning a villager? Maybe the api is spawning at a default yaw because yours has an error? And I have no clue about the sounds sorry
     
  3. There are no errors upon spawning the villager. Even if the API is spawning at a default yaw, it would've been fixed because I got the entity that the API spawned and teleported it to the same location that had the changed yaw.
     
  4. The location might be different to the yaw? Maybe let me do a bit of researxh
     
  5. 1. Check your code 5 times over, backwards
    2. Try teleporting the entity using your own method AND/OR using the custom entities api method
    3. Check to make sure you are using the right API Version
    4. Check you have all the files needdd for the api to work
    5. If all else fails... try contact the api maker themselves or try posting another thread on spigot or bukkit
     
  6. Hm... if it helps, I've posted the way I make the Villager on the OP.
     
  7. Try villager.teleportTo(location);
     
  8. That for some reason throws an error...

    Code (Text):
    [07:19:22 ERROR]: "Silently" catching entity tracking error.
    net.minecraft.server.v1_7_R4.ReportedException: Adding entity to track
            at net.minecraft.server.v1_7_R4.EntityTracker.addEntity(EntityTracker.ja
    va:122) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.EntityTracker.track(EntityTracker.java:7
    3) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.WorldManager.a(WorldManager.java:18) [sp
    igot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.World.a(World.java:1147) [spigot.jar:git
    -Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.WorldServer.a(WorldServer.java:836) [spi
    got.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.World.addEntity(World.java:1140) [spigot
    .jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.World.addEntity(World.java:1066) [spigot
    .jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.PlayerList.repositionEntity(PlayerList.j
    ava:799) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.Entity.teleportTo(Entity.java:1852) [spi
    got.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _25]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _25]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_25]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
            at me.dablakbandit.customentitiesapi.entities.CustomEntity.teleportTo(Cu
    stomEntity.java:108) [CustomEntitiesAPI.jar:?]
            at me.raydond123.nullpvp.EntityHandler.spawnEntities(EntityHandler.java:
    55) [NullPvP.jar:?]
            at me.raydond123.nullpvp.NullPvP.onEnable(NullPvP.java:49) [NullPvP.jar:
    ?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) [sp
    igot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:332) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:412) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.jav
    a:476) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.
    java:394) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:3
    60) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:3
    34) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:2
    90) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.jav
    a:210) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :458) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    Caused by: java.lang.IllegalStateException: Entity is already tracked!
            at net.minecraft.server.v1_7_R4.EntityTracker.addEntity(EntityTracker.ja
    va:102) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            ... 26 more
     
  9. Some more insight on removing the villager sound...
    I tried using ProtocolLib and PacketWrapper, but the wrapper for the packet doesn't seem to have the villager sound in it...

    You can take a look at the wrapper for the packet here.

    Code (Text):
           plugin.protocolManager.addPacketListener(
                new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.NAMED_SOUND_EFFECT) {
                    @Override
                    public void onPacketSending(PacketEvent event) {
                        WrapperPlayServerNamedSoundEffect named = new WrapperPlayServerNamedSoundEffect(event.getPacket());

                        if(named.getSoundName().equals("villagerSoundNameHere")) {

                                event.setCancelled(true);

                       }

                    }
                }
            );
    Edit: I removed the check for a villager sound and made it so that no matter what. the event will always be cancelled. Somehow, the villager noises stopped... Does that mean that the villager noises are somewhere in there? Because, I can't find them.
    I looked at the JavaDocs for Spigot and looked into Sounds. There are villager sounds. There just aren't any in the PacketWrapper...
     
    #9 Raydond123, Jul 5, 2015
    Last edited: Jul 5, 2015
  10. Okay, I fixed the sound problem. Turns out, the name of the sound was "mob.villager.idle". The way I figured it out was by simply making it broadcast the name of the sound whenever the server sent one.

    This leaves one last problem... the very peculiar yaw bug.
     
  11. Its saying entity is already tracked? Im not familiar with entity tracking but if you are doing it, remove it or maybe if the villager isnt spawning in the right location when you use the spawn(location) method from that api then your best option is to ask again or contact the api maker
     
  12. In some 1.7 versions, the yaw of a custom entity don't change which is a bug. It's fixed in newer versions though. What version are you using?
     
  13. I'm pretty sure I'm using the latest version. Let me double check/
     
  14. So if I'm using the spigot 1.8 protocol hack, I should be using the CustomEntitiesAPI v1.7 right?
     
  15. Okay, now I'm getting a weird bug upon trying to disable villager sounds...
    Code (Text):
    [08:48:14 INFO]: [NullPvP] Enabling NullPvP v1.0
    [08:48:14 ERROR]: Error occurred while enabling NullPvP v1.0 (Is it up to date?)

    java.lang.NullPointerException
            at me.raydond123.nullpvp.EntityHandler.disableSound(EntityHandler.java:6
    8) ~[?:?]
            at me.raydond123.nullpvp.NullPvP.onEnable(NullPvP.java:56) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[s
    pigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:332) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:412) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.jav
    a:476) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.
    java:394) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:3
    60) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:3
    34) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:2
    90) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.jav
    a:210) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :458) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g6a8d903]
    What's weird about this is that if I reload the plugin with a plugin manager after the server is done starting up, no errors are thrown and the sounds are disabled...

    Here's my EntityHandler class.
    Code (Text):
    package me.raydond123.nullpvp;

    import com.comphenix.protocol.PacketType;
    import com.comphenix.protocol.events.ListenerPriority;
    import com.comphenix.protocol.events.PacketAdapter;
    import com.comphenix.protocol.events.PacketEvent;
    import me.dablakbandit.customentitiesapi.entities.CustomEntities;
    import me.dablakbandit.customentitiesapi.entities.CustomEntityVillager;
    import me.raydond123.nullpvp.utils.WrapperPlayServerNamedSoundEffect;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Villager;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityInteractEvent;
    import org.bukkit.event.player.PlayerInteractAtEntityEvent;
    import org.bukkit.event.player.PlayerInteractEntityEvent;

    import java.util.ArrayList;
    import java.util.List;

    public class EntityHandler implements Listener {

        NullPvP plugin;

        public EntityHandler(NullPvP plugin) {

            this.plugin = plugin;

        }

        List<Integer> entityIDs = new ArrayList<Integer>();
        List<Location> locations = new ArrayList<Location>();

        public void spawnEntities() {

            for(String raw : plugin.getConfig().getStringList("locations")) {

                String[] data = raw.split(", ");
                World world = Bukkit.getWorld(data[0]);
                double x = Double.valueOf(data[1]);
                double y = Double.valueOf(data[2]);
                double z = Double.valueOf(data[3]);
                Location location = new Location(world, x, y, z);
                locations.add(location);
                location.setPitch(0);
                location.setYaw(-90);

                CustomEntityVillager villager = CustomEntities.getNewCustomEntityVillager(location);
                villager.removeGoalSelectorPathfinderGoalAll();
                villager.setPushable(false);
                villager.setUnableToMove();
                villager.setUntradeable();
                villager.setProfession(3);
                entityIDs.add(villager.getBukkitEntity().getEntityId());

                villager.getBukkitEntity().teleport(location);

            }

        }

        public void disableSound() {

            plugin.protocolManager.addPacketListener(
                    new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.NAMED_SOUND_EFFECT) {
                        @Override
                        public void onPacketSending(PacketEvent event) {
                            WrapperPlayServerNamedSoundEffect named = new WrapperPlayServerNamedSoundEffect(event.getPacket());

                            if(named.getSoundName().equals("mob.villager.idle")) {
                                event.setCancelled(true);
                            }

                        }
                    }
            );

        }

        public void despawnEntities() {

            for(Entity entity : Bukkit.getWorld("world").getEntitiesByClass(Villager.class)) {

                if(entityIDs.contains(entity.getEntityId())) {

                    entityIDs.remove(entityIDs.indexOf(entity.getEntityId()));
                    entity.remove();

                }

            }

        }

        @EventHandler
        public void onHit(EntityDamageByEntityEvent e) {

            if(e.getEntity() instanceof Villager) {

                Entity entity = e.getEntity();

                if(!entityIDs.contains(entity.getEntityId())) {
                    return;
                }
                if(!locations.contains(entity.getLocation())) {
                    return;
                }
                e.setCancelled(true);
                Location location = entity.getLocation();

                if(location == locations.get(0)) {

                } else if(location == locations.get(1)) {

                } else if(location == locations.get(2)) {

                } else if(location == locations.get(3)) {

                } else if(location == locations.get(4)) {

                }

            }

        }

        @EventHandler
        public void onRClick(PlayerInteractEntityEvent e) {

            if(e.getRightClicked() instanceof Villager) {

                Entity entity = e.getRightClicked();

                if(!entityIDs.contains(entity.getEntityId())) {
                    return;
                }
                if(!locations.contains(entity.getLocation())) {
                    return;
                }
                e.setCancelled(true);
                Location location = entity.getLocation();

                if(location == locations.get(0)) {

                } else if(location == locations.get(1)) {

                } else if(location == locations.get(2)) {

                } else if(location == locations.get(3)) {

                } else if(location == locations.get(4)) {

                }

            }

        }

    }
     
     
  16. I don't think it's even possible to set the yaw when using a version that still has that bug. I remember back when Mineplex was using the protocol hack and all of their custom entities were facing south (default position).
     
  17. Oh... hm.. :/
     
  18. So, weird bug when I try to disable the sound...
    It throws a NullPointerException when I try to run this on startup.
    Code (Text):
                   plugin.protocolManager.addPacketListener(
                    new PacketAdapter(plugin, ListenerPriority.HIGH, PacketType.Play.Server.NAMED_SOUND_EFFECT) {
                        [USER=32110]@Override[/USER]
                        public void onPacketSending(PacketEvent event) {
                            WrapperPlayServerNamedSoundEffect named = new WrapperPlayServerNamedSoundEffect(event.getPacket());

                            if(named.getSoundName().equals("mob.villager.idle")) {
                                event.setCancelled(true);
                            }

                        }
                    }
            );
    More specifically, this line.
    Code (Text):
                   plugin.protocolManager.addPacketListener(
     
  19. Unfortunatly, asking more questions inside a thread is highly not reccommended so probably create a new thread for that
     
  20. Will do.