Posted October 22, 201411 yr 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]
October 22, 201411 yr 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. 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.