2022-03-27 16:02:14 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
2024-03-30 03:19:54 +01:00
|
|
|
import com.minelittlepony.unicopia.projectile.Projectile;
|
2022-03-27 16:02:14 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2024-03-30 03:19:54 +01:00
|
|
|
abstract class ProjectileItem extends Item implements Projectile {
|
2022-03-27 16:02:14 +02:00
|
|
|
|
|
|
|
private final float projectileDamage;
|
|
|
|
|
|
|
|
public ProjectileItem(Settings settings, float projectileDamage) {
|
|
|
|
super(settings);
|
|
|
|
this.projectileDamage = projectileDamage;
|
2024-03-30 03:19:54 +01:00
|
|
|
Projectile.makeDispensable(this);
|
2022-03-27 16:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
2024-03-30 03:19:54 +01:00
|
|
|
if (isFood() && !player.shouldCancelInteraction()) {
|
2022-03-27 17:47:52 +02:00
|
|
|
return super.use(world, player, hand);
|
2022-03-27 16:02:14 +02:00
|
|
|
}
|
|
|
|
|
2024-03-30 03:19:54 +01:00
|
|
|
return triggerThrow(world, player, hand);
|
2022-03-27 16:02:14 +02:00
|
|
|
}
|
|
|
|
|
2024-03-30 03:19:54 +01:00
|
|
|
@Override
|
|
|
|
public float getProjectileDamage(ItemStack stack) {
|
2022-03-27 16:02:14 +02:00
|
|
|
return projectileDamage;
|
|
|
|
}
|
|
|
|
}
|