Search in sources :

Example 1 with UnwindingPhaseContext

use of org.spongepowered.common.event.tracking.UnwindingPhaseContext in project SpongeCommon by SpongePowered.

the class TransactionSink method logSlotTransaction.

/**
 * Called with a created {@link SlotTransaction} that's been created and
 * possibly already recorded by {@link TrackedContainerBridge#bridge$detectAndSendChanges(boolean)}
 * performing transaction handling and submitting to be recorded through
 * here. The caveat with this system is that since it's reliant on having
 * the transactions created as a side effect of {@link AbstractContainerMenu#broadcastChanges()},
 * it's possible that certain transactions are "too late" or remain uncaptured
 * until the next tick.
 *
 * @param phaseContext The context
 * @param newTransaction The slot transaction in relation to the menu
 * @param abstractContainerMenu The container menu
 */
/*
     Non-Javadoc: Known areas where we are keeping transactions recorded:
     - commands - during CommandPhaseContext see below
     - place/use ServerPlayerGameModeMixin_Tracker#useItemOn
     - Dispenser equip PlayerEntityMixin_Inventory#setItemSlot
     - eating etc. LivingEntityMixin_Inventory#completeUsingItem
     - throw/use ServerGamePacketListenerImplMixin_Inventory#impl$onHandleUseItem
     - breaking blocks ServerPlayerGameModeMixin_Tracker#impl$onMineBlock
     - exp pickup with mending PlayerEntityMixin_Inventory#inventory$onTouch
     - attack PlayerMixin#attack
     - armor/shield damage LivingEntityMixin#bridge$damageEntity
     - elytra damage LivingEntityMixin#inventory$onElytraUse
     - consume arrow (BowItem#releaseUsing - shrink on stack) LivingEntityMixin#impl$onStopPlayerUsing
     - villager trade select ServerGamePacketListenerImplMixin_Inventory#impl$onHandleSelectTrade
     - close inventory adding back to inventory ServerPlayerEntityMixin_Inventory#impl$onCloseContainer
     - use on entity - ServerGamePacketListenerImplMixin_Inventory#impl$onInteractAt/impl$onInteractOn
     */
default void logSlotTransaction(final PhaseContext<@NonNull ?> phaseContext, final SlotTransaction newTransaction, final AbstractContainerMenu abstractContainerMenu) {
    // Inventory change during command
    if (abstractContainerMenu instanceof InventoryMenu) {
        if (phaseContext instanceof CommandPhaseContext) {
            this.logPlayerInventoryChange(((InventoryMenuAccessor) abstractContainerMenu).accessor$owner(), PlayerInventoryTransaction.EventCreator.STANDARD);
        }
        if (phaseContext instanceof UnwindingPhaseContext) {
            return;
        }
        if (phaseContext instanceof EntityTickContext) {
            // TODO remove warning when we got all cases covered
            SpongeCommon.logger().warn("Ignoring slot transaction on InventoryMenu during {}. {}\nNo Event will be fired for this", phaseContext.getClass().getSimpleName(), newTransaction);
            return;
        }
    }
    final ContainerSlotTransaction transaction = new ContainerSlotTransaction(abstractContainerMenu, newTransaction);
    this.logTransaction(transaction);
}
Also used : EntityTickContext(org.spongepowered.common.event.tracking.phase.tick.EntityTickContext) InventoryMenu(net.minecraft.world.inventory.InventoryMenu) CommandPhaseContext(org.spongepowered.common.event.tracking.phase.general.CommandPhaseContext) ContainerSlotTransaction(org.spongepowered.common.event.tracking.context.transaction.inventory.ContainerSlotTransaction) UnwindingPhaseContext(org.spongepowered.common.event.tracking.UnwindingPhaseContext)

Aggregations

InventoryMenu (net.minecraft.world.inventory.InventoryMenu)1 UnwindingPhaseContext (org.spongepowered.common.event.tracking.UnwindingPhaseContext)1 ContainerSlotTransaction (org.spongepowered.common.event.tracking.context.transaction.inventory.ContainerSlotTransaction)1 CommandPhaseContext (org.spongepowered.common.event.tracking.phase.general.CommandPhaseContext)1 EntityTickContext (org.spongepowered.common.event.tracking.phase.tick.EntityTickContext)1