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 everybody, i need to player music for everyone in radius X (let it be 100) from my block. My code you can see below, it works, but cause such a lot of lags that client just stops running.

 

[embed=425,349]package red.windrose.blocks;

 

import java.util.Iterator;

import java.util.List;

import java.util.Random;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.world.World;

/**

*All music blocks must extends this one

*/

public class MusicBlockBase extends Block{

/**

*Audio file which will be played

*/

public String music_file;

public MusicBlockBase(Material material, String music) {

super(material);

this.setCreativeTab(CreativeTabs.tabDecorations);

this.music_file = music;

}

 

    public void onBlockAdded(World world, int x, int y, int z)

    {

            super.onBlockAdded(world, x, y, z);

            world.scheduleBlockUpdate(x, y, z, this, 1);

    }

    public void updateTick(World world, int x, int y, int z, Random rand) {

 

                setPlayerAudio(world, x, y, z, rand, music_file);

    }

/**

*In this method we will play audio file from "music_file" to all players in radius

*/

    @SideOnly(Side.CLIENT)

private void setPlayerAudio(World world, int x, int y, int z, Random rand, String audio)

{

//In this parallelepiped we will search players

            AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB((double)x, (double)y, (double)z, (double)(x + 1), (double)(y + 1), (double)(z + 1)).expand((double)100, (double)100, (double)100);

            axisalignedbb.maxY = (double)world.getHeight();

            //Getting players and put them in the list

            List list = world.getEntitiesWithinAABB(EntityPlayer.class, axisalignedbb);

            Iterator iterator = list.iterator();

            System.out.println(list);//Just for debug

            EntityPlayer entityplayer;

           

            //For each player...

            while (iterator.hasNext())

            {

                entityplayer = (EntityPlayer)iterator.next();

              System.out.println("I found player " + entityplayer.getDisplayName() + " in my radius");

            }

}

}

[/embed]

 

First of all, don't ever use @SideOnly.

 

Secondly, there is a method to play sounds at a radius in the world class. I don't have my IDE open right now, but I'm sure you can find it with some looking.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

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.