Jump to content

Recommended Posts

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]

 

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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