[Solved] Way to get a player eating sound?

Discussion in 'Plugin Development' started by devilquak, Aug 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    devilquak

    I know you can get certain effects and sounds with .playEffect, but there are only about 5-6 sounds in there and they're very selective sounds that aren't of much use to me, like doors opening and closing and arrow fire sounds.

    I just need the sound of a player eating something. I've looked all over and I can't seem to find anything, so I'm beginning to think I can only do it through complicated packet procedures which I'd rather not have to do if it's not necessary.

    Does anyone know if this is possible?
     
  2. Offline

    Chiller

    I'm pretty sure the sound of chewing is client side...
     
  3. Offline

    Deleted user

    It is.
     
  4. Offline

    devilquak

    It might be, yes. I'm also wondering how to get all the other sounds that aren't part of .playEffect, like mob sounds for example. I've seen plenty of plugins that use mob sounds, and I'm just wondering if there's any API for it or if I would just have to use modified packets.

    But all I really care about right now are the eating sounds.
     
  5. kroltan likes this.
  6. Offline

    devilquak

  7. Offline

    Icyene

    The nerd way: open up net.minecraft.server and find a class where it is called, maybe EntityPlayer or EntityPlayerMP, and see how its done. If I remember correctly its net.minecraft.server.World.a(//somethings. a is basically playEffect of NMS)

    AHA!

    Code:
    worldObj.a(this, "random.eat", 0.5F + 0.5F * (float)rand.nextInt(2), (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
    
    Should work. Its in EntityPlayer. So to use it for a player you'd do:

    ((CraftWorld)(player.getWorld())).getHandle().a(player.getHandle(), "random.eat", 0.5F + 0.5F * (float)rand.nextInt(2), (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);

    Or something like that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  8. Offline

    devilquak

    Thank you so much for your help. One more real quick question...

    On the (player.getHandle(), part, it gives me an error saying "the method getHandle() is undefined for the type player". If I change it to (((CraftWorld) player).getHandle(), then the error will go away. Not very sure if I'm supposed to do this though.

    And for the three "rand"s in there, the errors all say "rand cannot be resolved". What can I do to fix this?

    Edit: Nevermind, I fixed it. Thank you guys so much again.
     
  9. Offline

    flyingtacoz

    Can you please tell me how, you fixed this?
     
  10. Offline

    kroltan

    (CraftPlayer)player
    Maybe?
     
  11. Offline

    devilquak

    See my post on another thread, it goes into more detail there.
     
    kroltan likes this.
  12. Offline

    flyingtacoz

    Thanks! Is there a way to implement it into event listeners? I tried adding it into a blockbreak event to test it, but it looks like it needs to extend JavaPlugin or the plugin will not load. And i'm not sure how to extend it into JavaPlugin and Listener. Sorry if I may seem confusing, and I know i'm doing something wrong..
     
  13. Offline

    devilquak

    No, it's fine, I think I can tell what you're trying to do. If you'd like me to help you, just post your code here in the
    [ code ] (Post here) [ /code ] format and I'll help you get it working.

    Also, with this you need to reference CraftBukkit along with Bukkit, since the normal Bukkit API doesn't have these methods.
     
  14. Offline

    flyingtacoz

    Yeah I referenced CraftBukkit, and there was no errors shown in eclipse.
    I also put these imports in.
    import net.minecraft.server.Packet62NamedSoundEffect;
    import org.bukkit.craftbukkit.entity.CraftPlayer;


    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
        Player p = e.getPlayer();
        Location pLoc = p.getLocation();
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.hasItem() && e.getItem().getType() == Material.MOB_SPAWNER) {
        Packet62NamedSoundEffect packet = new Packet62NamedSoundEffect("random.old_explode", pLoc.getBlockX(), pLoc.getBlockY(), pLoc.getBlockZ(), 1.0F, 1.0F);
        ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(packet);
        e.setCancelled(false);
        }
    }  
     
  15. Offline

    devilquak

    The code looks fine to me off the top of my head, but one thing to know is that if you're not literally clicking a block with this code, it won't run, like if you're clicking the air. If you're still clicking the block and nothing's happening, try to add a check, like sending the player a message when they successfully click the block, just to see if the event is actually going through. If it is, you know the problem is with the sound code.

    Otherwise, could you tell me specifically what's going wrong?
     
  16. Offline

    flyingtacoz

    Whenever I try to start the server with the plugin, I get something like this:

    Code:
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:154)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:242)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:218)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:44)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:143)
        ... 9 more
    
     
  17. Offline

    devilquak

    Alright, can you show me all of your code then? It's probably a problem with just the basic plugin stuff, so I'd need to see your whole class to find the problem.
     
  18. Offline

    flyingtacoz

    Code:
    package me.taco.rocks;
     
    import net.minecraft.server.Packet62NamedSoundEffect;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.EventHandler;
    import me.taco.rocks.main;
     
    public class EventListener implements Listener {
       
        private static main plugin;
       
        public EventListener(main instance) {
            EventListener.plugin = instance;
        }
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
        Player p = e.getPlayer();
        Location pLoc = p.getLocation();
        if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.hasItem() && e.getItem().getType() == Material.MOB_SPAWNER) {
        Packet62NamedSoundEffect packet = new Packet62NamedSoundEffect("random.old_explode", pLoc.getBlockX(), pLoc.getBlockY(), pLoc.getBlockZ(), 1.0F, 1.0F);
        ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(packet);
        e.setCancelled(false);
        }
    }
    }
     
  19. Offline

    devilquak

    Alright, can you show me your main class too? And have you made your plugin.yml correctly? That's a biggie, a lot of times that's what peoples' problems are.
     
  20. Offline

    KeybordPiano459

    Well if the plugin.yml was incorrect it would say [SEVERE] Invalid plugin.yml or whatever that crap is in the stack trace.
     
    devilquak likes this.
  21. Offline

    flyingtacoz

    Everything worked before trying to add the sounds, and plugin.yml is fine :p
    My main class is really big so i'll just put the main things.
    Code:
    package me.taco.rocks;
     
    import java.io.File;
    import java.io.PrintStream;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Stack;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import me.tacos.main.EventListener;
     
    public class main extends JavaPlugin {
    private EventListener plugin = new EventListener(this);
     
    public void onEnable()
    {
    // Register events
    plugin = new EventListener(this);
    PluginManager pm = Bukkit.getServer().getPluginManager();
    pm.registerEvents(this.plugin, this);
    }
     
  22. Offline

    devilquak

    Alright, two things. First, how are you trying to get the event to run? When a player is holding a mob spawner, when they have a mob spawner in their inventory, or when they click a mob spawner? Because your code is doing something odd there, and I want to make sure you're doing what you want.

    Second, show me the error you get when you try and use your plugin, and tell me when you get it. Don't give me a few lines of it, I need to see the whole thing, from where the error ends all the way to where it begins.
     
  23. Offline

    flyingtacoz

    It was for when you right clicked with a mob spawner, so practically trying to place a mob spawner.
    Heres the full error:
    Code:
    00:36:00 [SEVERE]
    Could not load 'plugins/taco.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: me.taco.rocks.main
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:154)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:242)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:218)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:50)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:377)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.ClassNotFoundException: me.taco.rocks.main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:44)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:143)
        ... 9 more
    
     
  24. Offline

    devilquak


    Okay, well first of all I would just use this to register the events:

    put
    Code:
    public<LISTENERCLASS>(<MAINCLASS> plugin)
    {
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    }
    in your listener class, and in your main class simply put
    Code:
    newLoginListener(this);
    inside onEnable(), and see what that does. It seems your plugin doesn't think your main class exists, and this might help.


    Also, if you want to see if a player is holding an item in their hand, use
    Code:
    event.getPlayer().getItemInHand().getType() == Material.MOB_SPAWNER
    . So in your situation, it would be
    Code:
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK&&event.getPlayer().getItemInHand().getType() == Material.MOB_SPAWNER)
    .

    Try these things and see if it works, and tell me what errors you get if it doesn't.
     
  25. Offline

    Squirtle771

    Looks to me like the error's not in eclipse because it is being caused by your file of 'me.taco.rocks.main' not existing or not being in the right place.
     
  26. Offline

    devilquak

    His main file is right there, he posted it above my last comment and it's named "me.taco.rocks.main", so it's there and his plugin used to work correctly. Code errors can give the class not found exception easily, and I suspect it might be the event registers he used or just the way he handled the mob spawner checking.
     
  27. Offline

    flyingtacoz

    Sorry, fell asleep on you last night, Anyways I got it working now! :D
    Thanks so much !
    Last question, is there a way to cancel the current flesh hurt sound, and instead use the old hurt sound ?
     
  28. Offline

    devilquak

    From my understanding, the way it plays sounds is sort of wonky. I use the eating sounds, and there are about 3 eating sounds that exist, named eat1, eat2, and eat3. All I can use in the code is "eat", and it seems to randomly choose one of the 3 eating sounds every time the method is called.

    I don't know if it works this way for every sound, but from my testing, that's all I can do. If anyone finds a way to do this , that'd be great, since I want to be able to do this too. I'll look into it in an hour or two for you, but I can't guarantee I'll find anything.

    If I'm wrong and the API has changed since I last used it, forgive me, however I'm pretty sure it's the same.
     
Thread Status:
Not open for further replies.

Share This Page