mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
commit
03ff75f685
@ -401,7 +401,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
if (isEating()) {
|
if (isEating()) {
|
||||||
if (time - startEatingTime >= eatingTime) {
|
if (time - startEatingTime >= eatingTime) {
|
||||||
triggerStatus((byte) 9); // Mark item use as finished
|
triggerStatus((byte) 9); // Mark item use as finished
|
||||||
ItemUpdateStateEvent itemUpdateStateEvent = callItemUpdateStateEvent(true, eatingHand);
|
ItemUpdateStateEvent itemUpdateStateEvent = callItemUpdateStateEvent(eatingHand);
|
||||||
|
|
||||||
Check.notNull(itemUpdateStateEvent, "#callItemUpdateStateEvent returned null.");
|
Check.notNull(itemUpdateStateEvent, "#callItemUpdateStateEvent returned null.");
|
||||||
|
|
||||||
@ -1136,6 +1136,15 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
return eatingHand != null;
|
return eatingHand != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the hand which the player is eating from.
|
||||||
|
*
|
||||||
|
* @return the eating hand, null if none
|
||||||
|
*/
|
||||||
|
public @Nullable Hand getEatingHand() {
|
||||||
|
return eatingHand;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the player default eating time.
|
* Gets the player default eating time.
|
||||||
*
|
*
|
||||||
@ -2290,7 +2299,10 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
* @param allowFood true if food should be updated, false otherwise
|
* @param allowFood true if food should be updated, false otherwise
|
||||||
* @return the called {@link ItemUpdateStateEvent},
|
* @return the called {@link ItemUpdateStateEvent},
|
||||||
* null if there is no item to update the state
|
* null if there is no item to update the state
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #callItemUpdateStateEvent(Hand)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(boolean allowFood, @Nullable Hand hand) {
|
public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(boolean allowFood, @Nullable Hand hand) {
|
||||||
if (hand == null)
|
if (hand == null)
|
||||||
return null;
|
return null;
|
||||||
@ -2307,6 +2319,17 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
return itemUpdateStateEvent;
|
return itemUpdateStateEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to call {@link ItemUpdateStateEvent} with the proper item
|
||||||
|
* It does check which hand to get the item to update. Allows food.
|
||||||
|
*
|
||||||
|
* @return the called {@link ItemUpdateStateEvent},
|
||||||
|
* null if there is no item to update the state
|
||||||
|
*/
|
||||||
|
public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(@Nullable Hand hand) {
|
||||||
|
return callItemUpdateStateEvent(true, hand);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the player digging a custom block, see {@link #resetTargetBlock()} to rewind.
|
* Makes the player digging a custom block, see {@link #resetTargetBlock()} to rewind.
|
||||||
*
|
*
|
||||||
|
@ -136,14 +136,18 @@ public class PlayerDiggingListener {
|
|||||||
|
|
||||||
} else if (status == ClientPlayerDiggingPacket.Status.UPDATE_ITEM_STATE) {
|
} else if (status == ClientPlayerDiggingPacket.Status.UPDATE_ITEM_STATE) {
|
||||||
Player.Hand hand = null;
|
Player.Hand hand = null;
|
||||||
if (player.getItemInHand(Player.Hand.OFF).getMaterial().hasState()) {
|
if (player.isEating()) {
|
||||||
|
hand = player.getEatingHand();
|
||||||
|
} else if (player.getItemInHand(Player.Hand.OFF).getMaterial().hasState()) {
|
||||||
hand = Player.Hand.OFF;
|
hand = Player.Hand.OFF;
|
||||||
} else if (player.getItemInHand(Player.Hand.MAIN).getMaterial().hasState()) {
|
} else if (player.getItemInHand(Player.Hand.MAIN).getMaterial().hasState()) {
|
||||||
hand = Player.Hand.MAIN;
|
hand = Player.Hand.MAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.refreshEating(null);
|
player.refreshEating(null);
|
||||||
ItemUpdateStateEvent itemUpdateStateEvent = player.callItemUpdateStateEvent(false, hand);
|
player.triggerStatus((byte) 9);
|
||||||
|
|
||||||
|
ItemUpdateStateEvent itemUpdateStateEvent = player.callItemUpdateStateEvent(hand);
|
||||||
|
|
||||||
if (itemUpdateStateEvent == null) {
|
if (itemUpdateStateEvent == null) {
|
||||||
player.refreshActiveHand(true, false, false);
|
player.refreshActiveHand(true, false, false);
|
||||||
|
@ -50,6 +50,8 @@ public class UseItemListener {
|
|||||||
PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null;
|
PlayerItemAnimationEvent.ItemAnimationType itemAnimationType = null;
|
||||||
boolean riptideSpinAttack = false;
|
boolean riptideSpinAttack = false;
|
||||||
|
|
||||||
|
boolean cancelAnimation = false;
|
||||||
|
|
||||||
if (material == Material.BOW) {
|
if (material == Material.BOW) {
|
||||||
itemAnimationType = PlayerItemAnimationEvent.ItemAnimationType.BOW;
|
itemAnimationType = PlayerItemAnimationEvent.ItemAnimationType.BOW;
|
||||||
} else if (material == Material.CROSSBOW) {
|
} else if (material == Material.CROSSBOW) {
|
||||||
@ -64,9 +66,13 @@ public class UseItemListener {
|
|||||||
// Eating code, contains the eating time customisation
|
// Eating code, contains the eating time customisation
|
||||||
PlayerPreEatEvent playerPreEatEvent = new PlayerPreEatEvent(player, itemStack, hand, player.getDefaultEatingTime());
|
PlayerPreEatEvent playerPreEatEvent = new PlayerPreEatEvent(player, itemStack, hand, player.getDefaultEatingTime());
|
||||||
player.callCancellableEvent(PlayerPreEatEvent.class, playerPreEatEvent, () -> player.refreshEating(hand, playerPreEatEvent.getEatingTime()));
|
player.callCancellableEvent(PlayerPreEatEvent.class, playerPreEatEvent, () -> player.refreshEating(hand, playerPreEatEvent.getEatingTime()));
|
||||||
|
|
||||||
|
if (playerPreEatEvent.isCancelled()) {
|
||||||
|
cancelAnimation = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemAnimationType != null) {
|
if (!cancelAnimation && itemAnimationType != null) {
|
||||||
PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType);
|
PlayerItemAnimationEvent playerItemAnimationEvent = new PlayerItemAnimationEvent(player, itemAnimationType);
|
||||||
player.callCancellableEvent(PlayerItemAnimationEvent.class, playerItemAnimationEvent, () -> {
|
player.callCancellableEvent(PlayerItemAnimationEvent.class, playerItemAnimationEvent, () -> {
|
||||||
player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack);
|
player.refreshActiveHand(true, hand == Player.Hand.OFF, riptideSpinAttack);
|
||||||
|
Loading…
Reference in New Issue
Block a user