Jump to content

Particles on serverside


Juski

Recommended Posts

So im trying to create an item that will send particles after RMC in the way that a player is looking. But I have a problem that it isn't seen on server. I created a packet.

sendParticles

won't work for me because it just spawns particles without vector speed. And addParticle only seen on client side(?). So is there a way to send particles with vector speed like addParticle so it will be seen on server?

1 minute ago, Juski said:

So im trying to create an item that will send particles after RMC in the way that a player is looking. But I have a problem that it isn't seen on server. I created a packet.

sendParticles

won't work for me because it just spawns particles without vector speed. And addParticle only seen on client side(?). So is there a way to send particles with vector speed like addParticle so it will be seen on server?

[1.20.2]

 

Link to comment
Share on other sites

Posted (edited)
23 minutes ago, dee12452 said:

spawnParticle is an old version of sendPaticles. As I said sendParticles works just as /particle command on vanilla minecraft, you can't set vector speed to it. I didnt put version on topic but i put it in a quote 1.20.2. So yeah it wont work.

 

Edited by Juski
Link to comment
Share on other sites

Brother, sendParticles literally calls addParticle.

This is forge's implementation of handling sendParticle once it gets back to the client

public void handleParticleEvent(ClientboundLevelParticlesPacket p_105026_) {
        PacketUtils.ensureRunningOnSameThread(p_105026_, this, this.minecraft);
        if (p_105026_.getCount() == 0) {
            double d0 = (double)(p_105026_.getMaxSpeed() * p_105026_.getXDist());
            double d2 = (double)(p_105026_.getMaxSpeed() * p_105026_.getYDist());
            double d4 = (double)(p_105026_.getMaxSpeed() * p_105026_.getZDist());

            try {
                this.level.addParticle(p_105026_.getParticle(), p_105026_.isOverrideLimiter(), p_105026_.getX(), p_105026_.getY(), p_105026_.getZ(), d0, d2, d4);
            } catch (Throwable var17) {
                LOGGER.warn("Could not spawn particle effect {}", p_105026_.getParticle());
            }
        } else {
            for(int i = 0; i < p_105026_.getCount(); ++i) {
                double d1 = this.random.nextGaussian() * (double)p_105026_.getXDist();
                double d3 = this.random.nextGaussian() * (double)p_105026_.getYDist();
                double d5 = this.random.nextGaussian() * (double)p_105026_.getZDist();
                double d6 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed();
                double d7 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed();
                double d8 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed();

                try {
                    this.level.addParticle(p_105026_.getParticle(), p_105026_.isOverrideLimiter(), p_105026_.getX() + d1, p_105026_.getY() + d3, p_105026_.getZ() + d5, d6, d7, d8);
                } catch (Throwable var16) {
                    LOGGER.warn("Could not spawn particle effect {}", p_105026_.getParticle());
                    return;
                }
            }
        }

    }

The last 4 of the `ServerLevel#sendParticles` function represent `xDist; yDist; zDist; maxSpeed;` of this ^ respectively. So this should in theory allow for you to mostly set a speed.

 

If you need more control, send a custom clientbound packet over the Network that directly calls level.addParticle the way you need exactly...

Link to comment
Share on other sites

12 minutes ago, dee12452 said:

Brother, sendParticles literally calls addParticle.

This is forge's implementation of handling sendParticle once it gets back to the client

public void handleParticleEvent(ClientboundLevelParticlesPacket p_105026_) {
        PacketUtils.ensureRunningOnSameThread(p_105026_, this, this.minecraft);
        if (p_105026_.getCount() == 0) {
            double d0 = (double)(p_105026_.getMaxSpeed() * p_105026_.getXDist());
            double d2 = (double)(p_105026_.getMaxSpeed() * p_105026_.getYDist());
            double d4 = (double)(p_105026_.getMaxSpeed() * p_105026_.getZDist());

            try {
                this.level.addParticle(p_105026_.getParticle(), p_105026_.isOverrideLimiter(), p_105026_.getX(), p_105026_.getY(), p_105026_.getZ(), d0, d2, d4);
            } catch (Throwable var17) {
                LOGGER.warn("Could not spawn particle effect {}", p_105026_.getParticle());
            }
        } else {
            for(int i = 0; i < p_105026_.getCount(); ++i) {
                double d1 = this.random.nextGaussian() * (double)p_105026_.getXDist();
                double d3 = this.random.nextGaussian() * (double)p_105026_.getYDist();
                double d5 = this.random.nextGaussian() * (double)p_105026_.getZDist();
                double d6 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed();
                double d7 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed();
                double d8 = this.random.nextGaussian() * (double)p_105026_.getMaxSpeed();

                try {
                    this.level.addParticle(p_105026_.getParticle(), p_105026_.isOverrideLimiter(), p_105026_.getX() + d1, p_105026_.getY() + d3, p_105026_.getZ() + d5, d6, d7, d8);
                } catch (Throwable var16) {
                    LOGGER.warn("Could not spawn particle effect {}", p_105026_.getParticle());
                    return;
                }
            }
        }

    }

The last 4 of the `ServerLevel#sendParticles` function represent `xDist; yDist; zDist; maxSpeed;` of this ^ respectively. So this should in theory allow for you to mostly set a speed.

 

If you need more control, send a custom clientbound packet over the Network that directly calls level.addParticle the way you need exactly...

Ok, about sendParticles, why I thought it's just a /particle command.
It has values (particleType,x,y,z,particleCount,xOffset,yOffset,zOffset,speed)
and addParticle(particleType,x,y,z,xSpeed,ySpeed,zSpeed)
And i need those values as xSpeed,ySpeed,zSpeed that's what make particles fly in the directions that player is looking

Quote

If you need more control, send a custom clientbound packet over the Network that directly calls level.addParticle the way you need exactly...

How exactly I can make it, could you help me out with that or just put on the right direction where can I look an information on that topic?
 

Link to comment
Share on other sites

Gotchya, well this will be your best friend then if you're down to read through it and try to understand it. Networking in 1.20.2+ got a fairly large change.

https://docs.minecraftforge.net/en/1.20.x/networking/simpleimpl/

I could post my mod's 1.20.2 networking code with an example but it's going to be a lot because it's a lot to setup. Lemme know if you'd prefer that though, I don't mind.

 

 

Edited by dee12452
phrasing
Link to comment
Share on other sites

I found an answer on side.
For anyone wondering in future, you need to use sendParticles and if you put 0 for particleCount, then xOffset, yOffset, zOffset become xSpeed, ySpeed, zSpeed. And on speed you just put 1.

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



×
×
  • Create New...

Important Information

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