Posted December 27, 20231 yr 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); } }
December 28, 20231 yr In minecraft most callbacks get invoked on both the client and server. https://docs.minecraftforge.net/en/latest/concepts/sides/ search this forum for InteractionResult.sidedSuccess or look at how one of the vanilla items handles sides. Edited December 28, 20231 yr by warjort Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
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.