use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class AbstractContainerMenuMixin_Inventory method inventory$wrapDoClickWithTransaction.
@Redirect(method = "clicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AbstractContainerMenu;doClick(IILnet/minecraft/world/inventory/ClickType;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/item/ItemStack;"))
private ItemStack inventory$wrapDoClickWithTransaction(final AbstractContainerMenu menu, final int slotId, final int dragType, final ClickType clickType, final Player player) {
if (((LevelBridge) player.level).bridge$isFake()) {
return this.shadow$doClick(slotId, dragType, clickType, player);
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
try (final EffectTransactor ignored = transactor.logClickContainer(menu, slotId, dragType, clickType, player)) {
this.impl$isClicking = true;
return this.shadow$doClick(slotId, dragType, clickType, player);
} finally {
this.impl$isClicking = false;
}
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class CraftingMenuMixin_Inventory method beforeSlotChangedCraftingGrid.
// Crafting Preview
@Redirect(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private static void beforeSlotChangedCraftingGrid(final ResultContainer resultContainer, final int slotId, final ItemStack itemStack, final int param0, final Level param1, final Player player, final CraftingContainer craftingContainer, final ResultContainer resultcontainer) {
resultContainer.setItem(slotId, itemStack);
final Inventory inv = ((Inventory) player.containerMenu).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class));
if (!(inv instanceof CraftingInventory)) {
SpongeCommon.logger().warn("Detected crafting but Sponge could not get a CraftingInventory for " + player.containerMenu.getClass().getName());
return;
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
if (!context.isRestoring()) {
final TransactionalCaptureSupplier transactor = context.getTransactor();
transactor.logCraftingPreview((ServerPlayer) player, (CraftingInventory) inv, craftingContainer);
}
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin_Inventory method impl$beforeRemoveItem.
@Override
protected void impl$beforeRemoveItem(final boolean param0, final CallbackInfoReturnable<Boolean> cir) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
this.inventory$effectTransactor = transactor.logDropFromPlayerInventory((ServerPlayer) (Object) this, param0);
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin_Inventory method impl$beforeSetItemSlot.
// -- Overrides from PlayerMixin_Inventory
@Override
protected void impl$beforeSetItemSlot(final EquipmentSlot param0, final ItemStack param1, final CallbackInfo ci) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
this.inventory$effectTransactor = transactor.logPlayerInventoryChangeWithEffect((Player) (Object) this, PlayerInventoryTransaction.EventCreator.STANDARD);
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin_Vanilla method vanilla$onElytraUse.
// override from LivingEntityMixin_Vanilla
@Override
protected void vanilla$onElytraUse(final CallbackInfo ci) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer) (Object) this;
try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.STANDARD)) {
// capture
player.inventoryMenu.broadcastChanges();
}
}
Aggregations