Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10] Spawning Particles on a block
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
Whyneb360

[1.7.10] Spawning Particles on a block

By Whyneb360, January 8, 2015 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
Share on other sites

The_SlayerMC    7

The_SlayerMC

The_SlayerMC    7

  • Creeper Killer
  • The_SlayerMC
  • Members
  • 7
  • 201 posts
Posted January 8, 2015

You could have a look at the redstone ore class, thats what i used for my ores: fMjwQaP.png

  • Quote

Share this post


Link to post
Share on other sites

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
Share on other sites

The_SlayerMC    7

The_SlayerMC

The_SlayerMC    7

  • Creeper Killer
  • The_SlayerMC
  • Members
  • 7
  • 201 posts
Posted January 8, 2015

Try putting an @Override over your display tick method. See if you're overriding it

  • Quote

Share this post


Link to post
Share on other sites

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
Share on other sites

The_SlayerMC    7

The_SlayerMC

The_SlayerMC    7

  • Creeper Killer
  • The_SlayerMC
  • Members
  • 7
  • 201 posts
Posted January 8, 2015

Well you can have a look at my ore class to see if it will help!

  • Quote

Share this post


Link to post
Share on other sites

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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?

  • Quote

Share this post


Link to post
Share on other sites

The_SlayerMC    7

The_SlayerMC

The_SlayerMC    7

  • Creeper Killer
  • The_SlayerMC
  • Members
  • 7
  • 201 posts
Posted January 8, 2015

Not really... And there is nothing "special" to what my ores are doing really... Aha

  • Quote

Share this post


Link to post
Share on other sites

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
Share on other sites

The_SlayerMC    7

The_SlayerMC

The_SlayerMC    7

  • Creeper Killer
  • The_SlayerMC
  • Members
  • 7
  • 201 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
Share on other sites

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
Share on other sites

The_SlayerMC    7

The_SlayerMC

The_SlayerMC    7

  • Creeper Killer
  • The_SlayerMC
  • Members
  • 7
  • 201 posts
Posted January 8, 2015

If you want to use a vanilla particle, such as the flame:

world.spawnParticle("flame", x, y, z, 0.0D, 0.0D, 0.0D);

  • Quote

Share this post


Link to post
Share on other sites

Whyneb360    0

Whyneb360

Whyneb360    0

  • Stone Miner
  • Whyneb360
  • Members
  • 0
  • 84 posts
Posted January 8, 2015

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

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Filip4223
      [1.12.2] How can I close GUI in Forge?

      By Filip4223 · Posted 1 minute ago

      I did it, but I think it's only clientside prevention. I gotta send real packet "close gui" to trigger serverside InventoryCloseEvent (or something like that).
    • diesieben07
      [1.12.2] How can I close GUI in Forge?

      By diesieben07 · Posted 11 minutes ago

      To prevent the GUI from opening in GuiOpenEvent you need to cancel the event.
    • diesieben07
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By diesieben07 · Posted 13 minutes ago

      The only way to make data persist is to write to to some form of file. Whether you do it explicitly, or implicitly. You cannot persist data by wishing really hard.
    • Filip4223
      [1.12.2] How can I close GUI in Forge?

      By Filip4223 · Posted 16 minutes ago

      I am trying to write an Minecraft Forge (1.12.2) mod. It should work like that: OnGuiOpen: If GUI title is equals to constant string value then close GUI (like ESC). That must be known by the server exactly like closing a GUI by clicking E/ESC.   My code (doesn't work - I'm seeing 'Turning off' in console but gui is still turned on)   public class ModEventHandler { @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { if(event.getGui() instanceof GuiContainer) { checkGui((GuiContainer) event.getGui()); } } private void checkGui(GuiContainer gui) { if(gui.inventorySlots instanceof ContainerChest) { ContainerChest _gui = (ContainerChest)gui.inventorySlots; String text = _gui.getLowerChestInventory().getDisplayName().getUnformattedText().toString(); if(text.contains(" ")) { System.out.println("Turning off"); Minecraft.getMinecraft().player.closeScreen(); Minecraft.getMinecraft().displayGuiScreen(null); KeyBinding.onTick(Keyboard.KEY_ESCAPE); } } } }   Thank u in advance for help
    • Differentiation
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By Differentiation · Posted 38 minutes ago

      The thing is I was trying to figure out if there's any way to accomplish this without having to save data to a file.
  • Topics

    • Filip4223
      2
      [1.12.2] How can I close GUI in Forge?

      By Filip4223
      Started 17 minutes ago

    • Differentiation
      12
      [SOLVED] [1.12.2] Modifying player capabilities for offline players?

      By Differentiation
      Started 8 hours ago

    • DragonITA
      4
      [1.14.4] How to get Minecraft Horse model/texture to make a custom unicorn?

      By DragonITA
      Started 2 hours ago

    • LachM
      5
      Issue loading 1.14.4 Server (No Issue with Client)

      By LachM
      Started 1 hour ago

    • RunKeish
      3
      Forge 14.4 crashes on statup

      By RunKeish
      Started 1 hour ago

  • Who's Online (See full list)

    • Legenes
    • saxon564
    • Filip4223
    • diesieben07
    • Differentiation
    • Enterman
    • zacisrelatable
    • LachM
    • Choonster
    • Lea9ue
    • MightyAhmed
    • KolonilGamer
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.7.10] Spawning Particles on a block
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community