So I'm trying to make a custom fishing rod by extending FishingRodItem. Everything seems alright in the code and the texture, but whenever I right click with it in hand I see the fishing hook entity shoot out, but it disappears instantly. I'm thinking that it's only alive for about 1 tick until it leaves, the rod never changes to the casted texture either. I tried making to make my own custom FishingHook entity instead of the default one to shoot out, but a lot of the fields are private and the custom fishing hook class I made didn't seem to change anything (Was having the same problem) so I'm not sure what could be the issue. Just need a push in the right direction.
Here's the code for my fishing rod, thank you in advance!
public class ItemIronRod extends FishingRodItem {
public ItemIronRod(Properties props) {
super(props);
}
private static final String NAME = "ironrod";
public static final Item SELF = new ItemIronRod(ModItemList.defaultItemProperties()).setRegistryName(NAME);
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack currentstack = player.getItemInHand(hand);
int lurespeed;
//if player is fishing
if (player.fishing != null) {
if (!level.isClientSide) {
lurespeed = player.fishing.retrieve(currentstack);
currentstack.hurtAndBreak(lurespeed, player, (p) -> {
p.broadcastBreakEvent(hand);
});
}
level.playSound((Player)null, player.getX(), player.getY(), player.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0F, 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F));
level.gameEvent(player, GameEvent.FISHING_ROD_REEL_IN, player);
}
else //if player is not fishing
{
if (!level.isClientSide)
{
lurespeed = EnchantmentHelper.getFishingSpeedBonus(currentstack);
int luck = EnchantmentHelper.getFishingLuckBonus(currentstack);
level.addFreshEntity(new FishingHook(player, level, luck, lurespeed));
//level.playSound((Player)null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 0.5F, 0.4F / (level.getRandom().nextFloat() * 0.4F + 0.8F));
}
player.awardStat(Stats.ITEM_USED.get(this));
level.gameEvent(player, GameEvent.FISHING_ROD_CAST, player);
}
return InteractionResultHolder.sidedSuccess(currentstack, level.isClientSide());
}
}