Jump to content

[1.19.2] How to spawn particle inside releaseUsing


Feroov

Recommended Posts

As the title says I got a custom ranged weapon, and I would like to spawn a particle once the item is been used lets say

 

I tried using

                    for(int i = 0; i < 2; ++i) {
                        level.addParticle(ParticleTypes.FLASH, 0d, 0d, 0d, 0d, 0d, 0d);
                    }

No luck, any ideas?

Link to comment
Share on other sites

Where do you think those particles are spawning?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

37 minutes ago, Luis_ST said:

Show more of your code.

 

 

This is what I have so far

@Override
    public void releaseUsing(ItemStack stack, Level level, LivingEntity livingEntity, int timeLeft)
    {
        if (livingEntity instanceof Player) {
            Player playerentity = (Player) livingEntity;
            if (stack.getDamageValue() < (stack.getMaxDamage() - 1))
            {
                playerentity.getCooldowns().addCooldown(this, 4);

                if (!level.isClientSide)
                {
                    NineMMBullet nineMMBullet = createArrow(level, stack, playerentity);
                    nineMMBullet.shootFromRotation(playerentity, playerentity.getXRot(), playerentity.getYRot(),
                            0.0F, 3.0F, 2.0F);

                    nineMMBullet.isNoGravity();
                    nineMMBullet.isNoPhysics();

                    stack.hurtAndBreak(1, livingEntity, p -> p.broadcastBreakEvent(livingEntity.getUsedItemHand()));
                    level.addFreshEntity(nineMMBullet);

                    level.playSound((Player) null, playerentity.getX(), playerentity.getY(), playerentity.getZ(),
                            ModSoundEvents.PISTOL.get(), SoundSource.PLAYERS, 1.0F, 1.0F);

                    if (!level.isClientSide)
                    {
                        final int id = GeckoLibUtil.guaranteeIDForStack(stack, (ServerLevel) level);
                        final PacketDistributor.PacketTarget target = PacketDistributor.TRACKING_ENTITY_AND_SELF
                                .with(() -> playerentity);
                        GeckoLibNetwork.syncAnimation(target, this, id, STATE);
                    }
                }
            }
        }
    }

 

Link to comment
Share on other sites

In the code you never spawn particles. But I suspect you are calling Level#addParticle server side, which will perform no action since there is no server side implementation.
If you want to call the particle spawn code server side you need to use ServerLevel#sendParticles.

Link to comment
Share on other sites

53 minutes ago, Luis_ST said:

In the code you never spawn particles. But I suspect you are calling Level#addParticle server side, which will perform no action since there is no server side implementation.
If you want to call the particle spawn code server side you need to use ServerLevel#sendParticles.

 

Am I calling it correctly inside the releaseUsing method?
 

serverLevel.sendParticles(ParticleTypes.FLASH, x, y, z, 2, 0.2D, 0.2D, 0.2D, 0.0D);

because now the gun wont shoot pretty much

Link to comment
Share on other sites

You now check first if you're on server, then check if your on client (which will never be true since your on already on server).
Inside the client only block you call the Particle code from server and client, that's not how it's work.

In addition you create a Field in your Item class which is never be initialized, remove these Field your Item is a singleton the Data will be shared between all Items.

Your code is server side so you only need to call ServerLevel#sendParticles.
You can get the ServerLevel from casting the Level which is given in the method, after a server side check.

Link to comment
Share on other sites

4 hours ago, Luis_ST said:

You now check first if you're on server, then check if your on client (which will never be true since your on already on server).
Inside the client only block you call the Particle code from server and client, that's not how it's work.

In addition you create a Field in your Item class which is never be initialized, remove these Field your Item is a singleton the Data will be shared between all Items.

Your code is server side so you only need to call ServerLevel#sendParticles.
You can get the ServerLevel from casting the Level which is given in the method, after a server side check.

 

Yes I got it to work now with this:

 

                    double x = playerentity.getX();
                    double y = playerentity.getY();
                    double z = playerentity.getZ();


                    if (level instanceof ServerLevel _level)
                    {
                        _level.sendParticles(ParticleTypes.FLAME, x, y + 1.5, z + 0.5, 1, 1, 0, 0, 0);
                        _level.sendParticles(ParticleTypes.SMOKE, x, y + 1.5, z +0.5, 1, 1, 0, 0, 0);
                    }

 

The only issue is the particles spawn on the specific location/area, so if I shoot from X cordinate I see the particles if I turn around and shoot well they spawn behind me then, now heres my question, how can I make it so that the particles only spawn/appear in front of the player no matter what

Link to comment
Share on other sites

Entity.getViewVector() tells you the direction it is looking.

Entity.getPosition() or Entity.getEyePosition() tells you where they are.

Then its just vector arithmetic.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

24 minutes ago, warjort said:

Entity.getViewVector() tells you the direction it is looking.

Entity.getPosition() or Entity.getEyePosition() tells you where they are.

Then its just vector arithmetic.

 

Could you please guide/show me the way to do it, I'd really appreciate it, still trying to grasp the logic

Link to comment
Share on other sites

34 minutes ago, Feroov said:

 

Could you please guide/show me the way to do it, I'd really appreciate it, still trying to grasp the logic

No you aren't, you spent maximum 25 minutes thinking about/researching it. I would guess it was probably a lot less. 🙂 

 

Anyway, look at something like Panda.afterSneeze()

It uses the body rotation (instead of the view rotation) fields, which might be what you actually want?

Otherwise you will have to use the view rotation fields from the entity instead.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

10 hours ago, warjort said:

No you aren't, you spent maximum 25 minutes thinking about/researching it. I would guess it was probably a lot less. 🙂 

 

Anyway, look at something like Panda.afterSneeze()

It uses the body rotation (instead of the view rotation) fields, which might be what you actually want?

Otherwise you will have to use the view rotation fields from the entity instead.

 

 

It is what I actually needed THANK YOU :D, had to tweak some math arithmetics and all is good now, have a great rest of your day/night cheers

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.

Announcements



×
×
  • Create New...

Important Information

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