use of org.spongepowered.api.event.item.inventory.InteractItemEvent in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method callInteractItemEventSecondary.
public static InteractItemEvent callInteractItemEventSecondary(EntityPlayer player, ItemStack stack, EnumHand hand, @Nullable Vector3d hitVec, Object hitTarget) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (hitTarget instanceof Entity) {
Sponge.getCauseStackManager().addContext(EventContextKeys.ENTITY_HIT, ((Entity) hitTarget));
} else if (hitTarget instanceof BlockSnapshot) {
Sponge.getCauseStackManager().addContext(EventContextKeys.BLOCK_HIT, (BlockSnapshot) hitTarget);
}
InteractItemEvent.Secondary event;
if (hand == EnumHand.MAIN_HAND) {
event = SpongeEventFactory.createInteractItemEventSecondaryMainHand(Sponge.getCauseStackManager().getCurrentCause(), HandTypes.MAIN_HAND, Optional.ofNullable(hitVec), ItemStackUtil.snapshotOf(stack));
} else {
event = SpongeEventFactory.createInteractItemEventSecondaryOffHand(Sponge.getCauseStackManager().getCurrentCause(), HandTypes.OFF_HAND, Optional.ofNullable(hitVec), ItemStackUtil.snapshotOf(stack));
}
SpongeImpl.postEvent(event);
return event;
}
}
use of org.spongepowered.api.event.item.inventory.InteractItemEvent in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method callInteractItemEventPrimary.
public static InteractItemEvent callInteractItemEventPrimary(EntityPlayer player, ItemStack stack, EnumHand hand, @Nullable Vector3d hitVec, Object hitTarget) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (hitTarget instanceof Entity) {
Sponge.getCauseStackManager().addContext(EventContextKeys.ENTITY_HIT, ((Entity) hitTarget));
} else if (hitTarget instanceof BlockSnapshot) {
Sponge.getCauseStackManager().addContext(EventContextKeys.BLOCK_HIT, (BlockSnapshot) hitTarget);
}
InteractItemEvent.Primary event;
if (hand == EnumHand.MAIN_HAND) {
event = SpongeEventFactory.createInteractItemEventPrimaryMainHand(Sponge.getCauseStackManager().getCurrentCause(), HandTypes.MAIN_HAND, Optional.ofNullable(hitVec), ItemStackUtil.snapshotOf(stack));
} else {
event = SpongeEventFactory.createInteractItemEventPrimaryOffHand(Sponge.getCauseStackManager().getCurrentCause(), HandTypes.OFF_HAND, Optional.ofNullable(hitVec), ItemStackUtil.snapshotOf(stack));
}
SpongeImpl.postEvent(event);
return event;
}
}
Aggregations