Jump to content

richaed

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by richaed

  1. Hello, im kind of a newbie on creating mods, and i been trying to make simples mods so far, Right now, i'm creating a mod which detect an specific type of mob and kill it if reach a certain number, by far the mod is detecting the mob and counting them but at the time it reach the limit number, it don't do anything. The Game don't tweak, don't crash, just i't don't run the method i call, which is kill(). public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { final var TotalCows = pLevel.getNearbyEntities(Cow.class, TargetingConditions.forNonCombat(), pPlayer, pPlayer.getBoundingBox().inflate(5)); if(pLevel.isClientSide){ if(pPlayer.getItemInHand(InteractionHand.MAIN_HAND).getItem() == this.asItem()){ if(!TotalCows.isEmpty()){ if(TotalCows.get(0).isAlive()){ TotalCows.get(0).kill(); } }else{ pPlayer.sendSystemMessage(Component.literal("No hay vacas")); } } } The sendSystemMessage is get triggered, and when i change the method .kill() by any other like send a message it got called, can i get some tips, and a clue of what i'm missing
  2. 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.