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.

[1.8]Spawning particles around all entities within a radius around the player

Featured Replies

Posted

I want to spawn particles around every living entity within a radius around the player, only if they have a certain headgear equipped. That being said, I don't want them visible to other players not wearing the headgear. I think the simplest way to do this would be to spawn them on the client-side only.

Now to the problem. I tried coding this, and it was a failure. The player couldn't see the particles. Now for my code:

In my FMLEvents.class, which is registered to the FML Event bus:

 

 

@SideOnly(Side.CLIENT)

@SubscribeEvent

public void onRenderTick(RenderTickEvent t){

if(Minecraft.getMinecraft().thePlayer != null)

if(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4) != null)

if(MiscTools.areItemStacksEqual(new ItemStack(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem()), new ItemStack(UnLogicII.crystal_eye_headband))){

byte i = 0;

if(i < 40){

i++;

}else{

List entities = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABBExcludingEntity(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().thePlayer.getBoundingBox().expand(8, 8, 8));

for(int j=0;j<entities.size();j++){

Random rand = new Random();

Entity entity = (Entity)entities.get(j);

Minecraft.getMinecraft().theWorld.spawnParticle(EnumParticleTypes.SPELL_MOB, entity.posX, entity.posY, entity.posZ, (rand.nextDouble() - 0.5D) * (double)entity.width, rand.nextDouble() * (double)entity.height, (rand.nextDouble() - 0.5D) * (double)entity.width, null);

}

i = 0;

}

}

}

 

 

 

Am I doing this completely wrong, or have I just messed up a small portion of it? Any help is appreciated.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

I'm not sure what your MiscTools#areItemStacksEqual implementation is like (or why you would even need one when the ItemStack class itself already offers several ways to check equality), but if your headgear can be damaged, I highly doubt it will ever return true.

 

Not only that, but unless your item requires stack damage or NBT to determine equality, you are wasting a lot of effort.

// this monstrosity:
MiscTools.areItemStacksEqual(new ItemStack(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem()), new ItemStack(UnLogicII.crystal_eye_headband)

// should be rewriten as:
Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem() == UnLogicII.crystal_eye_headband

Also, why not store a reference to Minecraft, either in your class or locally in the method, so you don't have such long-winded statements?

 

Finally, this:

byte i = 0;
      if(i < 40){
         i++;
      } else {

What are you expecting to happen there? You initialize i to zero EVERY SINGLE TIME the method is called, so i++ is completely pointless and your 'else' statement is never called.

  • Author

I'm not sure what your MiscTools#areItemStacksEqual implementation is like (or why you would even need one when the ItemStack class itself already offers several ways to check equality), but if your headgear can be damaged, I highly doubt it will ever return true.

 

Not only that, but unless your item requires stack damage or NBT to determine equality, you are wasting a lot of effort.

// this monstrosity:
MiscTools.areItemStacksEqual(new ItemStack(Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem()), new ItemStack(UnLogicII.crystal_eye_headband)

// should be rewriten as:
Minecraft.getMinecraft().thePlayer.getEquipmentInSlot(4).getItem() == UnLogicII.crystal_eye_headband

Also, why not store a reference to Minecraft, either in your class or locally in the method, so you don't have such long-winded statements?

 

Finally, this:

byte i = 0;
      if(i < 40){
         i++;
      } else {

What are you expecting to happen there? You initialize i to zero EVERY SINGLE TIME the method is called, so i++ is completely pointless and your 'else' statement is never called.

The first part, I figured out in the time I was waiting for a response. The second part, I didn't notice, I put the byte in the wrong spot. Thanks.

 

Now, for anyone else trying to do this, here is my completed, working code:

byte i = 0;
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onRenderTick(RenderTickEvent t){
	Minecraft mc = Minecraft.getMinecraft();
	if(mc.inGameHasFocus){
		if(mc.thePlayer.getHeldItem() != null)
			if(mc.thePlayer.getHeldItem().getItem() == Item.getItemFromBlock(UnLogicII.coal_gun) || mc.thePlayer.getHeldItem().getItem() == Item.getItemFromBlock(UnLogicII.smart_coal_gun)){
				mc.ingameGUI.drawString(Minecraft.getMinecraft().fontRendererObj, StatCollector.translateToLocal("info.coal_type")+": "+StatCollector.translateToLocal(EnumAmmo.getItem(ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer).getAmmoType()).getUnlocalizedName()+".name"), 1, 1, 16777215);
			}
	}
	if(mc.thePlayer != null)
	if(mc.thePlayer.getEquipmentInSlot(4) != null)
	if(mc.thePlayer.getEquipmentInSlot(4).getItem() == UnLogicII.crystal_eye_headband){
	if(i < 40){
		i++;
	}else{
		World world = mc.thePlayer.worldObj;
		AxisAlignedBB aabb = mc.thePlayer.getEntityBoundingBox().expand(8, 8, ;
		List entities = world.getEntitiesWithinAABBExcludingEntity(mc.thePlayer, aabb);
		for(int j=0;j<entities.size();j++){
			Random rand = new Random();
			Entity entity = (Entity)entities.get(j);
			mc.theWorld.spawnParticle(EnumParticleTypes.SPELL_MOB, entity.posX, entity.posY, entity.posZ, (rand.nextDouble() - 0.5D) * (double)entity.width, rand.nextDouble() * (double)entity.height, (rand.nextDouble() - 0.5D) * (double)entity.width, null);
		}
		i = 0;
	}
	}
}

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Guest
This topic is now closed to further replies.

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.