MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create an item that sets night time if it hits a monster in Minecraft forge 1.18.1"
/* Here we are creating a new item class that extends SwordItem. We override the hitEntity method to set the time to night when the item hits a monster. */ public class NightSetterSword extends SwordItem { public NightSetterSword(IItemTier tier, int attackDamageIn, float attackSpeedIn, Item.Properties builder) { super(tier, attackDamageIn, attackSpeedIn, builder); } @Override public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { if (target instanceof Monster) { if (attacker.level instanceof ServerWorld) { ((ServerWorld) attacker.level).setDayTime(13000); } } return super.hurtEnemy(stack, target, attacker); } }