Jump to content

Recommended Posts

Posted (edited)

I've been trying to get this to work for a few days without much success. Every example I find doesn't work properly and I can't figure out why.

 

public void onUpdate()
{
    --this.fuse;
    if (this.fuse <= 0)
    {
        this.setDead();

        if (!this.world.isRemote)
        {
            world.setBlockState(pos, Blocks.AIR.getDefaultState());
            world.createExplosion(null, this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, 4.f, true);
        }
    }
    else
    {
        Main.proxy.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D);
    }
        
        
        
    if(world.getBlockState(pos).getBlock() instanceof BlockAir) 
    {
        this.setDead();
    }
}
//Client proxy
@Override
public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed)
{
	MINECRAFT.world.spawnParticle(particleType, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed);
}

^ This is the only code that has worked at all, however it doesn't spawn particles in LAN or multiplayer.

 

this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D);

When I try to use this like in EntityTNTPrimed it doesn't work at all. I also experimented with using WorldServer instead of WorldClient, but that resulted in server crashes.

Also, using else if(!this.world.isRemote) instead of just else didn't effect the code.

Edited by dalobstah
Posted

Particles are a client-side thing. Calling the spawn particle method on the server does nothing.

You also do not need a proxy to spawn a particle. The spawning method is present on both sides, but only the client actually does something, the server has a noop implementation.

Blocks spawn particle in a special method Block#randomDisplayTick that is called on the client only.

If you need to spawn particles for every player either make sure that the data for those players stays consistent so their clients are aware of when to spawn particles or use packets.

Posted
  On 10/24/2018 at 6:33 PM, V0idWa1k3r said:

Particles are a client-side thing. Calling the spawn particle method on the server does nothing.

You also do not need a proxy to spawn a particle. The spawning method is present on both sides, but only the client actually does something, the server has a noop implementation.

Blocks spawn particle in a special method Block#randomDisplayTick that is called on the client only.

If you need to spawn particles for every player either make sure that the data for those players stays consistent so their clients are aware of when to spawn particles or use packets.

Expand  

I'm spawning the particles on an entity. Nothing I've tried outside of the client proxy has spawned particles. EntityTNTPrimed spawns particles for every player with just this.world.spawnParticle, however that doesn't work at all for me. How would I go about getting the clients aware of particles or using packets?

Posted
  On 10/24/2018 at 7:19 PM, V0idWa1k3r said:

You either need the data to be consistent for the client with DataParameter variables or use packets.

Expand  

Do you know why this works

Minecraft MINECRAFT = Minecraft.getMinecraft();
MINECRAFT.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D);

but this doesn't

this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 0.0D, 0.0D, 0.0D);

It works in vanilla code and in other 1.12.2 mods source code I've looked at, but it doesn't work in my code. Is there a reason?

Posted

You might be calling the second method on the server and so nothing happens. The first implementation ensures that the particles are spawned on the client. However it is also the case that you might be reaching across logical sides there. Basically I think that whenever you are calling these methods the actions actually happen on a server, not on the client. However because you are running the physical client and not the server the proxy being injected is the client proxy. And in that proxy you are explicitly using the client world for spawning your particles. This way the particles work since you are spawning them through a client world and you see them because it is the physical client but what is actually happening is you are reaching for the client from a server thread - and that is called reaching across logical sides and must never be done.

And the reason the second method isn't called on the client is likely because some kind of condition isn't satisfied on the client but is satisfied on the server. For example vanilla uses data parameters to sync the fuse timer of the TNT to the client so it is always aware of the fuse and is able to do client-related stuff according to it, like the flashing animation. You need to satisfy that condition on the client by using a DataParameter or packets, as I've told you twice already.

  • Thanks 1
Posted

Thank you for the help. I got it to work with packets. I'll put the code below for any future googlers

@Override
public void onUpdate()
{
	setFuse(--this.fuse);
		
    if (getFuse() <= 0)
    {
        this.setDead();

        if (!this.world.isRemote)
        {
            	
            world.setBlockState(pos, Blocks.AIR.getDefaultState());
            world.createExplosion(null, this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, 4.f, true);
        }
    }
    else
    {
        ParticlePacket particlePacket = new ParticlePacket(this.posX, this.posY, this.posZ);
        	
        NetworkRegistry.TargetPoint target = new TargetPoint(world.provider.getDimension(), this.posX + 0.5D, this.posY + 1.0D, this.posZ + 0.5D, 20.d);
        CommonProxy.simpleNetworkWrapper.sendToAllAround(particlePacket, target);
    }
        
        
        
    if(world.getBlockState(pos).getBlock() instanceof BlockAir) 
    {
        this.setDead();
    }
}

 

//Message and client handler
public class ParticlePacket implements IMessage
{

	private boolean messageValid;
	
	private double x, y, z;
	
	public ParticlePacket()
	{
		this.messageValid = false;
	}
	
	public ParticlePacket(double x, double y, double z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
		
		this.messageValid = true;
	}
	
	@Override
	public void fromBytes(ByteBuf buf)
	{
		try
		{
			this.x = buf.readDouble();
			this.y = buf.readDouble();
			this.z = buf.readDouble();
		}
		catch(IndexOutOfBoundsException ioe)
		{
			return;
		}
	}

	@Override
	public void toBytes(ByteBuf buf)
	{
		if(!this.messageValid)
			return;
		
		buf.writeDouble(x);
		buf.writeDouble(y);
		buf.writeDouble(z);
	}
	
	
	public static class Handler implements IMessageHandler<ParticlePacket, IMessage>
	{

		@Override
		public IMessage onMessage(ParticlePacket message, MessageContext ctx)
		{
			if(!message.messageValid && ctx.side != Side.CLIENT)
			{
				return null;
			}
			
			
			Minecraft minecraft = Minecraft.getMinecraft();
		    final WorldClient worldClient = minecraft.world;
			
		    minecraft.addScheduledTask(() -> processMessage(message, worldClient));
		    
			return null;
		}
		
		void processMessage(ParticlePacket message, WorldClient worldClient)
		{
			worldClient.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, message.x + 0.5D, message.y + 1.0D, message.z + 0.5D, 0.0D, 0.0D, 0.0D);
		}
		
	}
}

 

//ClientProxy
public static void preInitClientOnly()
{
	CommonProxy.simpleNetworkWrapper.registerMessage(ParticlePacket.Handler.class, ParticlePacket.class, CommonProxy.FUSE_SMOKE, Side.CLIENT);
}

//CommonProxy
public static final byte FUSE_SMOKE = 88;
public static SimpleNetworkWrapper simpleNetworkWrapper;
	
public static void preInitCommon()
{
	simpleNetworkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("TestChannel");
	simpleNetworkWrapper.registerMessage(ServerHandlerDummy.class, ParticlePacket.class, FUSE_SMOKE, Side.SERVER);
}

 

//Server handler
public class ServerHandlerDummy implements IMessageHandler<ParticlePacket, IMessage>
{

	@Override
	public IMessage onMessage(ParticlePacket message, MessageContext ctx)
	{
		return null;
	}

}

 

  • Like 1
  • Thanks 1

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

    • But your Launcher does not find it   Java path is: /run/user/1000/doc/3f910b8/java Checking Java version... Java checker returned some invalid data we don't understand: Check the Azul Zulu site and select your OS and download the latest Java 8 build for Linux https://www.azul.com/downloads/?version=java-8-lts&package=jre#zulu After installation, check the path and put this path into your Launcher Java settings (Java Executable)
    • Try other builds of pehkui and origins++ until you find a working combination
    • Some Create addons are only compatible with Create 6 or Create 5 - so not both versions at the same time Try older builds of Create Stuff and Additions This is the last build before the Create 6 update: https://www.curseforge.com/minecraft/mc-mods/create-stuff-additions/files/6168370
    • ✅ Crobo Coupon Code: 51k3b0je — Get Your \$25 Amazon Gift Card Bonus! If you’re new to Crobo and want to make the most out of your first transaction, you’ve come to the right place. The **Crobo coupon code: 51k3b0je** is a fantastic way to get started. By using this code, you can unlock an exclusive **\$25 Amazon gift card** after completing your first eligible transfer. Let’s dive deep into how the **Crobo coupon code: 51k3b0je** works, why you should use it, and how to claim your reward. --- 🌟 What is Crobo? Crobo is a trusted, modern platform designed for **international money transfers**. It offers fast, secure, and low-cost transactions, making it a favorite choice for individuals and businesses alike. Crobo is committed to transparency, low fees, and competitive exchange rates. And with promo deals like the **Crobo coupon code: 51k3b0je**, it becomes even more attractive. Crobo focuses on providing customers with: * Quick transfer speeds * Minimal fees * Safe, encrypted transactions * Great referral and promo code rewards When you choose Crobo, you’re choosing a platform that values your time, money, and loyalty. And now with the **Crobo coupon code: 51k3b0je**, you can start your Crobo journey with a **bonus reward**! ---# 💥 What is the Crobo Coupon Code: 51k3b0je? The **Crobo coupon code: 51k3b0je** is a **special promotional code** designed for new users. By entering this code during signup, you’ll be eligible for: ✅ A **\$25 Amazon gift card** after your first qualifying transfer. ✅ Access to Crobo’s referral system to earn more rewards. ✅ The ability to combine with future seasonal Crobo discounts. Unlike generic promo codes that just offer small fee reductions, the **Crobo coupon code: 51k3b0je** directly gives you a tangible, valuable reward — perfect for online shopping or gifting. --- ### 🎯 Why Use Crobo Coupon Code: 51k3b0je? There are many reasons why users choose to apply the **Crobo coupon code: 51k3b0je**: 🌟 **Free bonus reward** — Your first transfer can instantly earn you a \$25 Amazon gift card. 🌟 **Trusted platform** — Crobo is known for secure, fast, and affordable transfers. 🌟 **Easy to apply** — Simply enter **Crobo coupon code: 51k3b0je** at signup — no complicated steps. 🌟 **Referral opportunities** — Once you’ve used **Crobo coupon code: 51k3b0je**, you can invite friends and earn more rewards. 🌟 **Stackable savings** — Pair **Crobo coupon code: 51k3b0je** with Crobo’s ongoing offers or holiday deals for even more benefits. --- ### 📝 How to Use Crobo Coupon Code: 51k3b0je Getting started with **Crobo coupon code: 51k3b0je** is quick and easy. Just follow these steps: 1️⃣ **Download the Crobo app** (available on Google Play Store and Apple App Store) or visit the official Crobo website. 2️⃣ **Start the sign-up process** by entering your basic details (name, email, phone number, etc.). 3️⃣ When prompted, enter **Crobo coupon code: 51k3b0je** in the promo code or coupon code field. 4️⃣ Complete your first transaction — be sure to meet the minimum amount required to qualify for the reward (usually specified in Crobo’s promo terms). 5️⃣ After the transaction is verified, receive your **\$25 Amazon gift card** directly via email or within your Crobo account. --- ### 💡 Tips to Maximize Your Crobo Coupon Code: 51k3b0je Bonus 👉 **Transfer the minimum qualifying amount or more** — this ensures you meet the conditions for the gift card. 👉 **Refer friends after your signup** — Crobo allows users who’ve signed up with codes like **Crobo coupon code: 51k3b0je** to share their own code for extra bonuses. 👉 **Check for additional Crobo promotions** — sometimes Crobo offers seasonal or regional deals that stack with the coupon code. 👉 **Complete your transaction soon after signup** — many bonuses have time limits, so act quickly! --- ### 🚀 Frequently Asked Questions about Crobo Coupon Code: 51k3b0je **Q: Can I use Crobo coupon code: 51k3b0je if I already have a Crobo account?** A: No — the **Crobo coupon code: 51k3b0je** is intended for **new users only**. It must be applied during the initial registration process. --- **Q: How long does it take to get the \$25 Amazon gift card after using Crobo coupon code: 51k3b0je?** A: Typically, the gift card is sent **within a few business days** after your first qualifying transfer is completed and verified. --- **Q: Are there hidden fees when using Crobo coupon code: 51k3b0je?** A: No — Crobo is transparent about its fees. The **Crobo coupon code: 51k3b0je** simply adds a bonus reward without increasing your costs. --- **Q: Can I combine Crobo coupon code: 51k3b0je with other promo codes?** A: The **Crobo coupon code: 51k3b0je** is generally applied as a standalone signup bonus. However, Crobo often offers **ongoing promotions** that may apply to future transactions. ---  📌 Reference Crobo promo code: {51k3b0je} Crobo discount code: {51k3b0je} --- # 🌍 Final Thoughts If you want to enjoy safe, fast, and affordable money transfers with an added bonus, **Crobo coupon code: 51k3b0je** is your best option. Not only will you experience excellent service, but you’ll also earn a **\$25 Amazon gift card** — a reward that you can use immediately for shopping or gifts. 👉 **Don’t wait — sign up today using Crobo coupon code: 51k3b0je and claim your bonus!**
  • Topics

×
×
  • Create New...

Important Information

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