Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
	}

  • Author

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.