Jump to content

[1.10.2] [SOLVED] Spawning particles in onBlockActivated


Recommended Posts

Posted (edited)

I want to spawn some fire particles in my block's onBlockActivated method, when a variable in my tile entity is the right value (basically, you have to "activate" the block 3 times within a small window of time before the particles will spawn, and I'm saving the number of times and time elapsed in my tile entity). I have read about a million posts on this, and everything says that you should be able to spawn vanilla particles from the server. I swear I have seen examples of other mods doing this, too, but I can't get it to work. I know the code is running, because the println statement fires.

 

I also tried sending a packet, but it didn't work. I didn't include that code since I don't really think I should have to do that anyway. Please correct me if I'm wrong.

 

I also tried spawning the particles on the client, but even after grabbing a copy of my tile entity from the BlockPos parameter, I can't seem to access the variables (they don't change like they should).

 

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
	EnumCampfireState campfireState = state.getValue(CAMPFIRE_STATE);
	TileEntity tileEntity = world.getTileEntity(pos);
	int stokeTime = ((PrimalTileEntityCampfire) tileEntity).tinderStokeTime;
	int timesBlown = ((PrimalTileEntityCampfire) tileEntity).tinderTimesBlown;

	if (world.isRemote) // client
	{
	// do stuff
	}
	else // server
	{			
		if (heldItem == null && campfireState == EnumCampfireState.TINDER_STOKED)
		{
			if (stokeTime < 40)
			{
				((PrimalTileEntityCampfire) tileEntity).tinderStokeTime = 60;
				((PrimalTileEntityCampfire) tileEntity).tinderTimesBlown += 1;
				PrimalPacketHandler.INSTANCE.sendTo(new PrimalCampfirePacket(player, 0, pos), (EntityPlayerMP) player);
			}
			if (timesBlown > 3)
			{
				System.out.println("Spawning particle");
				world.spawnParticle(EnumParticleTypes.FLAME, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 0.0D, 0.0D, 0.0D, new int[0]);
			}			
		}			
	}
	return true;
}

 

Edited by Daeruin
  • Like 1
Posted (edited)

What version are you using? If it's the latest, you are not overriding onBlockActivated, as there is an extra ItemStack parameter. You should be overriding

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { return false; }

which you can find in the Block class.

Edited by TheMasterGabriel
Posted

I'm using 1.10.2, as stated in the post title. Pretty sure my override is fine, as my version of Block shows this:

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)

 

Posted

That's a good idea, but in this case the block is basically transparent. When I put that exact same call in the block's randomDisplayTick method, I can see the particles just fine.

Posted
  On 2/21/2017 at 1:53 AM, Daeruin said:

I'm using 1.10.2, as stated in the post title

Expand  
 

Whoops, I don't know how I missed that. Apologies

 

From past experience, I'm fairly sure that particles only exist on the client, which is why you are not seeing them. Block#randomDisplayTick fires only on the client side, so it makes sense that you could see them there. Try spawning them on the client side. As for your variable problem, that is also due to the client/server side. In order for tile entity to recognize the variable changes on the client-side, you need to update the number of right clicks on the server side and then send the update to the client-side via a packet. You can read about networking and the side stuff on the Forge docs here.

Posted

World#spawnParticle(EnumParticleTypes, double, double, double, double, double, double, int...) does nothing on the server, it only spawns particles when called on the client. You need to use one of the spawnParticle overloads from WorldServer instead.

  • Like 1

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.

Posted

I have read tutorials and other posts on this forum stating that you can initiate a particle on the server, using world#spawnParticle, and the server will automatically send out the required packets. For example:

 

http://jabelarminecraft.blogspot.com/p/minecraft-forge-1721710-modding-tips.html

 

  Quote

Tip: Initiate the spawn of vanilla particles on the server side,. Even though EntityFX is only a client side class, the server method doesn't instantiate it but rather sends a packet to all the clients (which then instantiate the class). Since you usually want all players to see the particles, the method to initiate the spawn should be invoked on the server side (world.obj.isRemote should be false). 

Expand  

 

I have done a few packets before, but it bugs me to go to that effort when a single line method call should work.

 

I already tried sending a packet to spawn the particle directly on the client, and it didn't work. It will play the sound correctly, and the println statements appear, but it won't spawn the particle. Here's the packet:

 

  Reveal hidden contents

 

Posted
  On 2/21/2017 at 5:12 AM, Choonster said:

World#spawnParticle(EnumParticleTypes, double, double, double, double, double, double, int...) does nothing on the server, it only spawns particles when called on the client. You need to use one of the spawnParticle overloads from WorldServer instead.

Expand  

 

Ninja'd. How do I do that? Do I cast my world parameter to WorldServer?

(On the server side, naturally - !world.isRemote)

Posted (edited)

In your code, you already check if you are on the server side. Because of that, you can cast your world object to a WorldServer object and then use the following method to spawn your particles. It's much easier than the manual packet thing (which I wouldn't have told you about if I'm not oblivious and had read the WorldServer class). Well, knowledge of packets is always good anyways :P

 

/** Spawns the desired particle and sends the necessary packets to the relevant connected players. */
public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int... particleArguments)

 

Edited by TheMasterGabriel
  • Like 2

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • As a stay-at-home dad and a farmer in Kentucky, my primary focus has always been on nurturing my family and managing our land. When Bitcoin began to gain traction, I saw it as a potential opportunity to secure our financial future. With my wife encouragement, I decided to invest $10,000 from our savings into cryptocurrency. Over time, my investment flourished beyond my wildest dreams, eventually soaring to an astonishing $200,000. Just as I began to feel a sense of financial security, disaster struck. In a shocking act of betrayal fueled by jealousy, my wife hacked into my email and gained access to my Bitcoin wallet. The devastation I felt was overwhelming years of careful planning and smart investing were wiped out in an instant. I was left feeling helpless and uncertain, grappling with the fear that I might never recover what I had lost. In the midst of this turmoil, a close friend reached out to me and mentioned RAPID DIGITAL RECOVERY. Desperate for a solution but still holding onto a glimmer of hope, I contacted them, praying for a lifeline. Their team responded promptly, providing both reassurance and a clear plan of action. With remarkable expertise, they tracked down the digital footprints left by the theft and successfully recovered a substantial portion of my stolen funds. But their assistance didn’t end there. Understanding the vulnerability I felt after such a betrayal, they also offered invaluable advice on how to strengthen my digital security to prevent future breaches. Their support was not just technical; it was a source of empowerment that helped me regain my confidence and sense of control over my financial situation. While the betrayal was a painful lesson, it ultimately taught me resilience and the importance of safeguarding my assets. Thanks to RAPID DIGITAL RECOVERY, I didn’t just reclaim my lost Bitcoin; I also regained my peace of mind. This experience has transformed my perspective on both trust and security in the digital age. I now approach investments with a renewed sense of caution and awareness, ensuring that I protect not only my financial future but also my emotional well-being. The journey has been challenging, but it has also been a testament to my strength and determination to rise above adversity as I continue to balance my roles as a dad and a farmer.
    • Same issue without Oculus Flywheel Compat?
    • When i start my game with a shader active the game crashes with this Error: java.lang.NoSuchFieldError: TESSELATION_SHADERS Minecraft java 1.20.1 in forge 47.4.0 crash report in pastebin: https://pastebin.com/6xiwHqZW thanks in advance
    • If you are using AMD/ATI, update your drivers - get the drivers from their website - do not update via system
    • Not sure why this is happening, but I would love some help. The reason I restarted the server was because I was getting an error while trying to join regarding this "Internal Exception: io.netty.handler.codec.DecoderException: io.netty.handler.codec.EncoderException: java.io.IOException: Root tag must be a named compound tag" Im using ServerMiner if thats any help
  • Topics

×
×
  • Create New...

Important Information

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