auriny Posted May 14, 2022 Posted May 14, 2022 howdy! i ran into a problem. it lies in the fact that I wrote such a code that should work, but there are no sounds and particles on entity hits. public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker, World world) { if (!attacker.world.isRemote()) { target.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 45, 1)); world.playSound(null, attacker.getPosX(), attacker.getPosY(), attacker.getPosZ(), SoundEvents.BLOCK_ANCIENT_DEBRIS_BREAK, SoundCategory.PLAYERS, 1, 1); world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, Blocks.ANCIENT_DEBRIS.getDefaultState()), true, target.getPosX(), target.getPosY() + 0.5D, target.getPosZ(), 0, 1, 0); } return super.hitEntity(stack, target, attacker); } as I understand it, the problem is that there is no world in the return, but it is impossible to embed it there, because. the hitEntity method initially did not have such a parameter. how to be? snapshot mappings Quote
ProfitOrange Posted May 15, 2022 Posted May 15, 2022 (edited) Particles are client sided, so by having the if(!attacker.world.isRemote()), they won't appear. Since you have the world parameter, the method won't run unless you have called it from somewhere else, you can simply just get the world from the attacker and remove the world parameter. Below is an example. public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) { World world = attacker.world(); //get the world from the attacker if (!world.isRemote()) { target.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 45, 1)); world.playSound(null, attacker.getPosX(), attacker.getPosY(), attacker.getPosZ(), SoundEvents.BLOCK_ANCIENT_DEBRIS_BREAK, SoundCategory.PLAYERS, 1, 1); } else { world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, Blocks.ANCIENT_DEBRIS.getDefaultState()), true, target.getPosX(), target.getPosY() + 0.5D, target.getPosZ(), 0, 1, 0); } return super.hitEntity(stack, target, attacker); } Edited May 15, 2022 by ProfitOrange Quote
auriny Posted May 15, 2022 Author Posted May 15, 2022 On 5/15/2022 at 1:49 AM, ProfitOrange said: Particles are client sided, so by having the if(!attacker.world.isRemote()), they won't appear. Since you have the world parameter, the method won't run unless you have called it from somewhere else, you can simply just get the world from the attacker and remove the world parameter. Below is an example. public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) { World world = attacker.world(); //get the world from the attacker if (!world.isRemote()) { target.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 45, 1)); world.playSound(null, attacker.getPosX(), attacker.getPosY(), attacker.getPosZ(), SoundEvents.BLOCK_ANCIENT_DEBRIS_BREAK, SoundCategory.PLAYERS, 1, 1); } else { world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, Blocks.ANCIENT_DEBRIS.getDefaultState()), true, target.getPosX(), target.getPosY() + 0.5D, target.getPosZ(), 0, 1, 0); } return super.hitEntity(stack, target, attacker); } Expand thank you, sound worked, but didnt particles 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.