Posted May 14, 20223 yr 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
May 15, 20223 yr 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, 20223 yr by ProfitOrange
May 15, 20223 yr Author 3 hours ago, 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); } thank you, sound worked, but didnt particles
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.