Search in sources :

Example 1 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin_Inventory method impl$onHandleUseItem.

@Redirect(method = "handleUseItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItem(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;"))
private InteractionResult impl$onHandleUseItem(final ServerPlayerGameMode serverPlayerGameMode, final ServerPlayer param0, final Level param1, final ItemStack param2, final InteractionHand param3) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    final InteractionResult result = serverPlayerGameMode.useItem(param0, param1, param2, param3);
    try (EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(this.player, PlayerInventoryTransaction.EventCreator.STANDARD)) {
        // capture
        this.player.inventoryMenu.broadcastChanges();
    }
    return result;
// TrackingUtil.processBlockCaptures called by UseItemPacketState
}
Also used : InteractionResult(net.minecraft.world.InteractionResult) 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 2 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin_Inventory method impl$onBroadcastCreativeActionResult.

@Redirect(method = "handleSetCreativeModeSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/InventoryMenu;broadcastChanges()V"))
private void impl$onBroadcastCreativeActionResult(final InventoryMenu inventoryMenu, final ServerboundSetCreativeModeSlotPacket packetIn) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    final ItemStack itemstack = packetIn.getItem();
    // TODO handle vanilla sending a bunch of creative events (previously ignoring events within 100ms)
    try (final EffectTransactor ignored = transactor.logCreativeClickContainer(packetIn.getSlotNum(), ItemStackUtil.snapshotOf(itemstack), this.player)) {
    }
    inventoryMenu.broadcastChanges();
}
Also used : TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) ItemStack(net.minecraft.world.item.ItemStack) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin_Inventory method impl$onBroadcastCreativeActionResult.

@Redirect(method = "handleSetCreativeModeSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;drop(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/world/entity/item/ItemEntity;"))
private ItemEntity impl$onBroadcastCreativeActionResult(final ServerPlayer serverPlayer, final ItemStack stack, final boolean param1) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    try (final EffectTransactor ignored = transactor.logCreativeClickContainer(-1, ItemStackUtil.snapshotOf(stack), this.player)) {
        return serverPlayer.drop(stack, param1);
    }
}
Also used : 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 4 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin_Inventory method impl$onHandlePlayerCommandOpenInventory.

@Redirect(method = "handlePlayerCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;openInventory(Lnet/minecraft/world/entity/player/Player;)V"))
private void impl$onHandlePlayerCommandOpenInventory(final AbstractHorse abstractHorse, final Player player) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    try (final EffectTransactor ignored = context.getTransactor().logOpenInventory(player)) {
        abstractHorse.openInventory(player);
        context.getTransactor().logContainerSet(player);
    }
}
Also used : EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with EffectTransactor

use of org.spongepowered.common.event.tracking.context.transaction.EffectTransactor in project SpongeCommon by SpongePowered.

the class ItemEntityMixin_Inventory method spongeImpl$throwPickupEventForAddItem.

@Redirect(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;add(Lnet/minecraft/world/item/ItemStack;)Z"))
private boolean spongeImpl$throwPickupEventForAddItem(final Inventory inventory, final ItemStack itemStack, final Player player) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    final boolean added;
    try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.PICKUP)) {
        added = inventory.add(itemStack);
    }
    if (!TrackingUtil.processBlockCaptures(context)) {
        // if PickupEvent was cancelled return false
        return false;
    }
    return added;
}
Also used : 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)

Aggregations

EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)24 TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)16 Redirect (org.spongepowered.asm.mixin.injection.Redirect)13 ResultingTransactionBySideEffect (org.spongepowered.common.event.tracking.context.transaction.ResultingTransactionBySideEffect)4 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)3 Inventory (org.spongepowered.api.item.inventory.Inventory)3 LevelBridge (org.spongepowered.common.bridge.world.level.LevelBridge)3 ServerLevel (net.minecraft.server.level.ServerLevel)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 ItemStack (net.minecraft.world.item.ItemStack)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 CraftingInventory (org.spongepowered.api.item.inventory.crafting.CraftingInventory)2 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)2 EffectResult (org.spongepowered.common.event.tracking.context.transaction.effect.EffectResult)2 Audience (net.kyori.adventure.audience.Audience)1 Component (net.kyori.adventure.text.Component)1 MutableComponent (net.minecraft.network.chat.MutableComponent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1