Search in sources :

Example 6 with TransactionalCaptureSupplier

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;
    }
}
Also used : LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 7 with TransactionalCaptureSupplier

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);
    }
}
Also used : CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) Inventory(org.spongepowered.api.item.inventory.Inventory) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 8 with TransactionalCaptureSupplier

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);
}
Also used : TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 9 with TransactionalCaptureSupplier

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);
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) Player(net.minecraft.world.entity.player.Player) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)

Example 10 with TransactionalCaptureSupplier

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();
    }
}
Also used : TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)

Aggregations

TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)25 EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)16 Redirect (org.spongepowered.asm.mixin.injection.Redirect)11 Inventory (org.spongepowered.api.item.inventory.Inventory)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)4 ItemStack (net.minecraft.world.item.ItemStack)4 CraftingInventory (org.spongepowered.api.item.inventory.crafting.CraftingInventory)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 InteractionResult (net.minecraft.world.InteractionResult)2 Player (net.minecraft.world.entity.player.Player)2 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)2 Cause (org.spongepowered.api.event.Cause)2 CauseStackManager (org.spongepowered.api.event.CauseStackManager)2 ServerWorld (org.spongepowered.api.world.server.ServerWorld)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Audience (net.kyori.adventure.audience.Audience)1 Component (net.kyori.adventure.text.Component)1