Feroov Posted August 21, 2022 Posted August 21, 2022 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? Quote
warjort Posted August 21, 2022 Posted August 21, 2022 Where do you think those particles are spawning? Quote 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.
Feroov Posted August 21, 2022 Author Posted August 21, 2022 27 minutes ago, warjort said: Where do you think those particles are spawning? Well no where I assume, even though I tweak the numbers still nothing is present Quote
Feroov Posted August 21, 2022 Author Posted August 21, 2022 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); } } } } } Quote
Luis_ST Posted August 21, 2022 Posted August 21, 2022 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. Quote
Feroov Posted August 21, 2022 Author Posted August 21, 2022 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 Quote
Luis_ST Posted August 21, 2022 Posted August 21, 2022 Please post the full code (at least the method), just a piece of code is not helpful. Quote
Feroov Posted August 21, 2022 Author Posted August 21, 2022 I'll send in the full class it might be more useful https://pastebin.com/RuREdFYj Quote
Luis_ST Posted August 21, 2022 Posted August 21, 2022 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. Quote
Feroov Posted August 21, 2022 Author Posted August 21, 2022 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 Quote
warjort Posted August 21, 2022 Posted August 21, 2022 Entity.getViewVector() tells you the direction it is looking. Entity.getPosition() or Entity.getEyePosition() tells you where they are. Then its just vector arithmetic. Quote 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.
Feroov Posted August 21, 2022 Author Posted August 21, 2022 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 Quote
warjort Posted August 21, 2022 Posted August 21, 2022 (edited) 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 August 21, 2022 by warjort Quote 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.
Feroov Posted August 22, 2022 Author Posted August 22, 2022 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 Quote
Recommended Posts
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.