Use Item only at night

Started by CyberAk on

Topic category: Help with modding (Java Edition)

Last seen on 20:23, 7. Jan 2024
Joined Jan 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use Item only at night

I am trying to make it so that upon right click "IF" it is night time "THEN" item applies potion effects,  "ELSE" Message player "Not Night Time Yet" 

I just cannot figure out how to set up if statement right please help

 

 

public class Artefact5RightclickedProcedure {

public static void execute(Entity entity) {
if (entity == null)
return;
if (true) {
if (entity instanceof LivingEntity _entity)
_entity.addEffect(new MobEffectInstance(MobEffects.NIGHT_VISION, 500, 4));
if (entity instanceof LivingEntity _entity)
_entity.addEffect(new MobEffectInstance(MobEffects.INVISIBILITY, 500, 4));
if (entity instanceof Player _player)
_player.getCooldowns().addCooldown(DungeonsRpgMcModItems.ARTEFACT_5.get(), 600);
} else {
if (entity instanceof Player _player && !_player.level.isClientSide())
_player.displayClientMessage(new TextComponent("It not dark yet"), (true));
}
}
}