Posted July 17, 20232 yr I am trying to add strength to the player on use, along with playing a sound. here's the code: public class DarksteelHornItem extends Item { public DarksteelHornItem(Properties properties) { super(properties); } @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { if(level.isClientSide() && hand == InteractionHand.MAIN_HAND) { level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.RAID_HORN, SoundSource.PLAYERS, 1.0F, 1.0F); player.addEffect(new MobEffectInstance(new MobEffect(), 5)); } return super.use(level, player, hand); } } Edited July 17, 20232 yr by Choccy Biscuit formatting
July 17, 20232 yr addEffect should be run on server-side (level.isClientSide==false). playSound on client-side (isClientSIde==true).
July 17, 20232 yr Author 1 hour ago, MFMods said: addEffect should be run on server-side (level.isClientSide==false). playSound on client-side (isClientSIde==true). I've changed it to this, but I get the error "'MobEffect(net.minecraft.world.effect.MobEffectCategory, int)' has protected access in 'net.minecraft.world.effect.MobEffect'" It also returns the error on run: "required: MobEffectCategory,int found: no arguments reason: actual and formal argument lists differ in length" public class DarksteelHornItem extends Item { public DarksteelHornItem(Properties properties) { super(properties); } @Override public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { if(level.isClientSide() == true && hand == InteractionHand.MAIN_HAND) { level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.RAID_HORN, SoundSource.PLAYERS, 1.0F, 1.0F); if(level.isClientSide() == false && hand == InteractionHand.MAIN_HAND){ player.addEffect(new MobEffectInstance(new MobEffect(),5)); } player.getCooldowns().addCooldown(this,400); } return super.use(level, player, hand); } } Edited July 17, 20232 yr by Choccy Biscuit detail
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.