mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
LivingEntity Active Item API
API relating to items being actively used by a LivingEntity such as a bow or eating food. == AT == public net/minecraft/world/entity/LivingEntity completeUsingItem()V public net/minecraft/server/level/ServerPlayer completeUsingItem()V Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
parent
dddd41ac34
commit
26c0e7e3d9
1 changed files with 49 additions and 0 deletions
|
@ -884,4 +884,53 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|||
getHandle().setShieldBlockingDelay(delay);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
// Paper start - active item API
|
||||
@Override
|
||||
public void startUsingItem(org.bukkit.inventory.EquipmentSlot hand) {
|
||||
Preconditions.checkArgument(hand != null, "hand must not be null");
|
||||
switch (hand) {
|
||||
case HAND -> getHandle().startUsingItem(InteractionHand.MAIN_HAND);
|
||||
case OFF_HAND -> getHandle().startUsingItem(InteractionHand.OFF_HAND);
|
||||
default -> throw new IllegalArgumentException("hand may only be HAND or OFF_HAND");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeUsingActiveItem() {
|
||||
getHandle().completeUsingItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getActiveItem() {
|
||||
return this.getHandle().getUseItem().asBukkitMirror();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveItemRemainingTime() {
|
||||
return this.getHandle().getUseItemRemainingTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveItemRemainingTime(final int ticks) {
|
||||
Preconditions.checkArgument(ticks >= 0, "ticks must be >= 0");
|
||||
Preconditions.checkArgument(ticks <= this.getHandle().getUseItem().getUseDuration(this.getHandle()), "ticks must be <= item use duration");
|
||||
this.getHandle().useItemRemaining = ticks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveItemUsedTime() {
|
||||
return this.getHandle().getTicksUsingItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasActiveItem() {
|
||||
return this.getHandle().isUsingItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.EquipmentSlot getActiveItemHand() {
|
||||
return org.bukkit.craftbukkit.CraftEquipmentSlot.getHand(this.getHandle().getUsedItemHand());
|
||||
}
|
||||
// Paper end - active item API
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue