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

Hey everyone,

 

I am trying to make particles spawn at a block, and have done it before in a mod I no longer have, but I can't seem to replicate it. My code is as follows:

 

import java.util.Random;

import com.descon.mod.DesconCreativeTabs;
import com.descon.mod.Main;
import com.descon.tileentity.TileEntityCampFire;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class CampfireProp extends BlockContainer{

public CampfireProp(Material material) {
	super(material);

	this.setCreativeTab(DesconCreativeTabs.tabGeneral);
	this.setLightLevel(0.7F);
	this.setHarvestLevel("axe", 1);
	this.setHardness(1F);
	this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F);
	this.setBlockTextureName(Main.modID + ":" + "textures/blocks/campfire.png");
}

 public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_) {

	 float f = (float)p_149734_2_ + 0.5F;
         float f1 = (float)p_149734_3_ + 0.2F + p_149734_5_.nextFloat() * 3.0F / 8.0F;
         float f2 = (float)p_149734_4_ + 0.5F;
         float f3 = 0.0F;
         float f4 = p_149734_5_.nextFloat() * 0.0F - 0.0F;

	 p_149734_1_.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         p_149734_1_.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         
         p_149734_1_.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         p_149734_1_.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         
         p_149734_1_.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         p_149734_1_.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         
         p_149734_1_.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
         p_149734_1_.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
 }


public int getRenderType() {
	return -1;
}

public boolean isOpaqueCube() {
	return false;
}

public boolean renderAsNormalBlock() {
	return false;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityCampFire();
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5));
}

}

 

Do I need to reference it somewhere or add some extra code?

 

Any help would be appreciated,

 

-Whyneb

  • Author

Thanks for your reply, I just tried messing around with that, but found that it didn't help me - particles still aren't appearing

  • Author

It had the green arrow next to it, indicating an Override, but I put one on top anyway - no difference. Thanks anyway though

  • Author

As I am not fluent in Java, or particularly good at Modding (yet  :)), your class file doesn't help me much (also because you seem to be doing something more complicated than I am). I did manage to dig up my old mod - the on the worked with block particles, and launch it with the latest forge, but it doesn't work any more. Is there a new way to do particle effects?

  • Author

I see... Hmm... If you were to make just a super basic block emit particle effects, how would you go about doing it?

well you can have a look at "EntityReddustFX.java" and do magic by c&p that, then add this into your block.java:

@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World w, int x, int y, int z, Random rand) {
	renderParticle(w, x, y, z);
}

private void renderParticle(World w, int x, int y, int z) {
	Random random = w.rand;
	double d0 = 0.0625D;
	for(int l = 0; l < 6; ++l) {
		double d1 = (double)((float)x + random.nextFloat());
		double d2 = (double)((float)y + random.nextFloat());
		double d3 = (double)((float)z + random.nextFloat());
		if(l == 0 && !w.getBlock(x, y + 1, z).isOpaqueCube()) d2 = (double)(y + 1) + d0;
		if(l == 1 && !w.getBlock(x, y - 1, z).isOpaqueCube()) d2 = (double)(y + 0) - d0;
		if(l == 2 && !w.getBlock(x, y, z + 1).isOpaqueCube()) d3 = (double)(z + 1) + d0;    
		if(l == 3 && !w.getBlock(x, y, z - 1).isOpaqueCube()) d3 = (double)(z + 0) - d0;
		if(l == 4 && !w.getBlock(x + 1, y, z).isOpaqueCube()) d1 = (double)(x + 1) + d0;
		if(l == 5 && !w.getBlock(x - 1, y, z).isOpaqueCube()) d1 = (double)(x + 0) - d0;
		if(d1 < (double)x || d1 > (double)(x + 1) || d2 < 0.0D || d2 > (double)(y + 1) || d3 < (double)z || d3 > (double)(z + 1)) {
			OreParticleFX fx= new OreParticleFX(w, d1, d2, d3);
			FMLClientHandler.instance().getClient().effectRenderer.addEffect(fx);
		}
	}
}

And thats basically it

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

  • Author

What would I replace "OreParticleFX" with? Do I have to create a new class and put a flame effect in there? How would I reference that? Sorry for the rapid-fire questions

  • Author

So, this is what I have now:

 

@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World w, int x, int y, int z, Random rand) {
	renderParticle(w, x, y, z, w);
}

private void renderParticle(World w, int x, int y, int z, World world) {
	Random random = w.rand;
	double d0 = 0.0625D;
	for(int l = 0; l < 6; ++l) {
		double d1 = (double)((float)x + random.nextFloat());
		double d2 = (double)((float)y + random.nextFloat());
		double d3 = (double)((float)z + random.nextFloat());
		if(l == 0 && !w.getBlock(x, y + 1, z).isOpaqueCube()) d2 = (double)(y + 1) + d0;
		if(l == 1 && !w.getBlock(x, y - 1, z).isOpaqueCube()) d2 = (double)(y + 0) - d0;
		if(l == 2 && !w.getBlock(x, y, z + 1).isOpaqueCube()) d3 = (double)(z + 1) + d0;    
		if(l == 3 && !w.getBlock(x, y, z - 1).isOpaqueCube()) d3 = (double)(z + 0) - d0;
		if(l == 4 && !w.getBlock(x + 1, y, z).isOpaqueCube()) d1 = (double)(x + 1) + d0;
		if(l == 5 && !w.getBlock(x - 1, y, z).isOpaqueCube()) d1 = (double)(x + 0) - d0;
		if(d1 < (double)x || d1 > (double)(x + 1) || d2 < 0.0D || d2 > (double)(y + 1) || d3 < (double)z || d3 > (double)(z + 1)) {
			world.spawnParticle("flame", x, y, z, 0.0D, 0.0D, 0.0D);
		}
	}
}

 

This doesn't work, and I know I've done something wrong, but I just can't crack it. Thanks for all of your help so far though - much appreciated

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.