Jump to content

[Unsolved] Spawning Particles Visible to All Players?


DanielDawn

Recommended Posts

I was currently using the OnArmorTick method to spawn particles to create a sort of particle trail. It only shows up for me, how can I make it visible to all players?

 

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
	player.addPotionEffect(new PotionEffect(Potion.jump.getId(), 0, 1));
	player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 0, 4));
	for (int count = 0; count < 2; count++){
		double X = player.posX;
		double Y = player.posY;
		double Z = player.posZ;
		Random random = player.worldObj.rand;
		for (int i = 0; i < 10; ++i)
		{
			int j1 = MathHelper.getRandomIntegerInRange(random, 0, 3);
			if(j1 == 0){
				player.worldObj.spawnParticle("reddust", (double)((float)X + random.nextFloat()), (double)Y - 1.5, (double)((float)Z + random.nextFloat()), 0, 0, 0);
			}
			if(j1 == 1){
				player.worldObj.spawnParticle("reddust", (double)((float)X - random.nextFloat()), (double)Y - 1.5, (double)((float)Z + random.nextFloat()), 0, 0, 0);
			}
			if(j1 == 2){
				player.worldObj.spawnParticle("reddust", (double)((float)X + random.nextFloat()), (double)Y - 1.5, (double)((float)Z - random.nextFloat()), 0, 0, 0);
			}
			if(j1 == 3){
				player.worldObj.spawnParticle("reddust", (double)((float)X - random.nextFloat()), (double)Y - 1.5, (double)((float)Z - random.nextFloat()), 0, 0, 0);
			}
		}	
	}
}

Link to comment
Share on other sites

Try using the world parameter passed into the method and if that doesn't work you will need to use a custom packet.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

As said above you need to send a packet to nearby players and since there is a tutorial about it take this it is by Cool Alias he does a really good job a explaining things. :3

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Always specify the Minecraft version you're using in the thread title. Judging by the

PotionEffect

constructor you're using, I'd guess you're on 1.8.9.

 

If you look at the implementation of

World#spawnParticle

, you'll see that it does nothing on the server and spawns the specified particle on the client. You need to send a packet from the server to all nearby players telling their clients to spawn the particles. You could do this with your own packet, but Minecraft already provides the

WorldServer#spawnParticle

method to do this for you.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Funny, I was testing out if I could do this on the Event Handler, but the player wearing my armor sees particle effects below their feet. Other players see the particle effects two blocks below.

 

@SubscribeEvent
public void playerTickEvent(PlayerTickEvent event) {
	if(event.player.getCurrentArmor(3) != null){
		ItemStack helmet = event.player.getCurrentArmor(3);
		if(helmet.getItem() == SmallEnhancements.charm_mobility){

			for (int count = 0; count < 2; count++){
				double X = event.player.posX;
				double Y = event.player.posY;
				double Z = event.player.posZ;
				Random random = event.player.getEntityWorld().rand;
				for (int i = 0; i < 10; ++i)
				{
					int j1 = MathHelper.getRandomIntegerInRange(random, 0, 3);
					if(j1 == 0){
						event.player.getEntityWorld().spawnParticle("reddust", (double)((float)X + random.nextFloat()), (double)Y - 1.5, (double)((float)Z + random.nextFloat()), 0, 0.74901960784, 0.89803921568);
					}
					if(j1 == 1){
						event.player.getEntityWorld().spawnParticle("reddust", (double)((float)X - random.nextFloat()), (double)Y - 1.5, (double)((float)Z + random.nextFloat()), 0, 0.74901960784, 0.89803921568);
					}
					if(j1 == 2){
						event.player.getEntityWorld().spawnParticle("reddust", (double)((float)X + random.nextFloat()), (double)Y - 1.5, (double)((float)Z - random.nextFloat()), 0, 0.74901960784, 0.89803921568);
					}
					if(j1 == 3){
						event.player.getEntityWorld().spawnParticle("reddust", (double)((float)X - random.nextFloat()), (double)Y - 1.5, (double)((float)Z - random.nextFloat()), 0, 0.74901960784, 0.89803921568);
					}
				}	
			}
		}
	}
}

 

Also I use 1.7.10

Link to comment
Share on other sites

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.