Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: WakelessSloth56 <wsloth56@foxmail.com>
- Loading branch information
1 parent
fb59141
commit cdadf54
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/main/java/org/auioc/mcmod/arnicalib/api/game/item/UsableItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.auioc.mcmod.arnicalib.api.game.item; | ||
|
||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.UseAnim; | ||
import net.minecraft.world.level.Level; | ||
|
||
public class UsableItem extends Item { | ||
|
||
protected final int useDuration; | ||
protected final UseAnim useAnim; | ||
|
||
public UsableItem(Properties properties, int useDuration, UseAnim useAnim) { | ||
super(properties); | ||
this.useDuration = useDuration; | ||
this.useAnim = useAnim; | ||
} | ||
|
||
public UsableItem(Properties properties, int useDuration) { | ||
this(properties, useDuration, UseAnim.NONE); | ||
} | ||
|
||
public UsableItem(Properties properties) { | ||
this(properties, 32); | ||
} | ||
|
||
@Override | ||
public int getUseDuration(ItemStack itemStack) { | ||
return this.useDuration; | ||
} | ||
|
||
@Override | ||
public UseAnim getUseAnimation(ItemStack itemStack) { | ||
return this.useAnim; | ||
} | ||
|
||
@Override | ||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { | ||
ItemStack itemStack = player.getItemInHand(hand); | ||
|
||
if (canUse(level, player, hand, itemStack)) { | ||
player.startUsingItem(hand); | ||
return InteractionResultHolder.consume(itemStack); | ||
} | ||
|
||
return InteractionResultHolder.pass(itemStack); | ||
} | ||
|
||
public boolean canUse(Level level, Player player, InteractionHand hand, ItemStack itemStack) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onUsingTick(ItemStack stack, LivingEntity livingEntity, int remainingTicks) {} | ||
|
||
@Override | ||
public void releaseUsing(ItemStack itemStack, Level level, LivingEntity livingEntity, int remainingTicks) {} | ||
|
||
@Override | ||
public ItemStack finishUsingItem(ItemStack itemStack, Level level, LivingEntity livingEntity) { | ||
return itemStack; | ||
} | ||
|
||
} |