Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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 by ProfitOrange

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.