use of org.spongepowered.api.event.item.inventory.UseItemStackEvent in project SpongeCommon by SpongePowered.
the class LivingEntityMixin method impl$onSetActiveItemStack.
// Data delegated methods
// Start implementation of UseItemstackEvent
@Inject(method = "startUsingItem", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/LivingEntity;useItem:Lnet/minecraft/world/item/ItemStack;"))
private void impl$onSetActiveItemStack(final InteractionHand hand, final CallbackInfo ci, final ItemStack stack) {
if (this.level.isClientSide) {
return;
}
final UseItemStackEvent.Start event;
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(stack);
final HandType handType = (HandType) (Object) hand;
this.impl$addSelfToFrame(frame, snapshot, handType);
final Ticks useDuration = Ticks.of(stack.getUseDuration());
event = SpongeEventFactory.createUseItemStackEventStart(PhaseTracker.getCauseStackManager().currentCause(), useDuration, useDuration, snapshot);
}
if (SpongeCommon.post(event)) {
ci.cancel();
} else {
this.useItemRemaining = (int) event.remainingDuration().ticks();
}
}
Aggregations