NaturesAura/src/main/java/de/ellpeck/naturesaura/items/ItemLightStaff.java

30 lines
1.2 KiB
Java
Raw Normal View History

2020-04-27 18:30:44 +02:00
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.entities.EntityLightProjectile;
import de.ellpeck.naturesaura.entities.ModEntities;
2021-12-15 16:24:53 +01:00
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
2020-04-27 18:30:44 +02:00
public class ItemLightStaff extends ItemImpl {
2021-12-15 16:24:53 +01:00
2020-04-27 18:30:44 +02:00
public ItemLightStaff() {
super("light_staff");
}
@Override
2021-12-15 16:24:53 +01:00
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
2021-12-15 16:30:22 +01:00
var stack = playerIn.getItemInHand(handIn);
2021-12-04 15:40:09 +01:00
if (!levelIn.isClientSide && NaturesAuraAPI.instance().extractAuraFromPlayer(playerIn, 1000, false)) {
2021-12-15 16:30:22 +01:00
var projectile = new EntityLightProjectile(ModEntities.LIGHT_PROJECTILE, playerIn, levelIn);
2021-12-15 16:24:53 +01:00
projectile.shootFromRotation(playerIn, playerIn.getXRot(), playerIn.getYRot(), 0, 1.5F, 0);
levelIn.addFreshEntity(projectile);
2020-04-27 18:30:44 +02:00
}
2021-12-15 16:24:53 +01:00
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
2020-04-27 18:30:44 +02:00
}
}