Jump to content

richaed

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by richaed

  1. Hi i have this custom item i made is simple, its just one that when u right-click on a mob it shows u his information, but there is two things i still didnt made up. First. When i right-click on a mob and the item is used the method is called twice occurring on a print duplication Second. I still didnt get chatFormatting Format that put my text on a column way. Here i leave my code to get helped, it just a simple one right now. public class Life_detector extends Item { public Life_detector(Properties pProperties) { super(pProperties); } @Override public boolean canAttackBlock(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer) { return false; } @Override public InteractionResult interactLivingEntity(ItemStack pStack, Player pPlayer, LivingEntity pInteractionTarget, InteractionHand pUsedHand) { if(pStack.getItem()==ModItems.LIFE_CHECKER.get()){ checkLife(pInteractionTarget,pPlayer); } return InteractionResult.SUCCESS; } private void checkLife(LivingEntity livingEntity, Player player){ if(livingEntity instanceof Mob mob){ player.sendSystemMessage(Component.literal("Name: "+mob.getName().getString()).withStyle(ChatFormatting.DARK_RED)); } } public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag flag) { tooltip.add(Component.literal("Right-click to get the info of a mob").withStyle(ChatFormatting.GOLD)); super.appendHoverText(stack, world, tooltip, flag); } }
×
×
  • Create New...

Important Information

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