Filloax Posted April 10, 2016 Share Posted April 10, 2016 Hello, I'm trying to make an improved playsound command. I got the packet etc working, only problem is that @a works only when there is one player in LAn or in singleplayer (couldn't test with proper server, but I imagine it's the same). When I try to use the command with @a when tehre are 2 players in LAN, it says "That player cannot be foundr" The only thing different form /playsound with player seems that playsound uses entityplayermp.playerNetServerHandler.sendPacket while I use network.sendTo Code: In command class: public void processCommand(ICommandSender player, String[] input) { if (input.length < 1) { throw new WrongUsageException(this.getCommandUsage(player), new Object[0]); } else { String sound = input[0]; String mode = "normal"; int x = player.getPlayerCoordinates().posX; int y = player.getPlayerCoordinates().posY; int z = player.getPlayerCoordinates().posZ; float vol = 1; float pitch = 1; EntityPlayerMP playerarg = getPlayer(player, "@a"); World world = player.getEntityWorld(); if (input.length > 1) { mode = input[1]; } if (input.length > 2) { playerarg = getPlayer(player, input[2]); } if (input.length > 5) { x = MathHelper.floor_double(func_110666_a(player, (double)x, input[3])); y = MathHelper.floor_double(func_110666_a(player, (double)y, input[4])); z = MathHelper.floor_double(func_110666_a(player, (double)z, input[5])); } if (input.length > 6) { vol = Float.parseFloat(input[6]); } if (input.length > 7) { pitch = Float.parseFloat(input[7]); } Main.network.sendTo(new SoundPacket(sound, mode, x, y, z, vol, pitch), playerarg); System.out.println("Played \'"+sound+"\' to \'"+playerarg.getDisplayName()+"\' at "+x+" "+y+" "+z); } In packet handler: @Override public IMessage onMessage(SoundPacket m, MessageContext ctx) { System.out.println(m.sound+";"+m.mode+";"+m.x+";"+m.y+";"+m.z+";"+m.vol+";"+m.pitch); ChunkCoordinates chunkcoordinates = new ChunkCoordinates(m.x, m.y, m.z); ISound isound = mapSoundPositions.get(chunkcoordinates); System.out.println("isound get"); if (isound != null) { System.out.println("Sound already playing at " + m.x + "/" + m.y + "/" + m.z + "; stopping sound"); Minecraft.getMinecraft().getSoundHandler().stopSound(isound); mapSoundPositions.remove(chunkcoordinates); } if (m.mode.equals("normal")) { System.out.println("Playing sound at " + m.x + "/" + m.y + "/" + m.z + ": " + m.sound); ResourceLocation resource = new ResourceLocation(m.sound); PositionedSoundRecord psr = new PositionedSoundRecord(resource, m.vol, m.pitch, m.x, m.y, m.z); mapSoundPositions.put(chunkcoordinates, psr); Minecraft.getMinecraft().getSoundHandler().playSound(psr); } return null; } Quote Link to comment Share on other sites More sharing options...
Filloax Posted April 10, 2016 Author Share Posted April 10, 2016 Solved, apparently I needed to specify wich arg wasa the username in the isUsernameIndex function. Second time I post an issue which I solve myself today, lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.