src/main/java/de/dosmike/sponge/megamenus/impl/util/SlotChange.java
public static SlotChange from(SlotTransaction transaction) {
        SlotChange change = new SlotChange();

        change.transaction = transaction;
        //change.position = transaction.getSlot().getInventoryProperty(SlotPos.class).orElse(null);
        Integer index = transaction.getSlot().getInventoryProperty(SlotIndex.class).map(AbstractInventoryProperty::getValue).orElse(null);
        if (index != null) {
            change.position = new SlotPos(index % 9, index / 9);
        }
        ItemStackSnapshot slotAfter = transaction.getFinal();
        ItemStackSnapshot slotBefore = transaction.getOriginal();
        if (slotBefore.getType().equals(slotAfter.getType()) ||
                slotBefore.isEmpty() || slotAfter.isEmpty()) {
            int amount = slotAfter.getQuantity()-slotBefore.getQuantity();
            boolean take = amount < 0;
            ItemStackSnapshot deltaStack = ItemStack.builder().fromSnapshot(
                    take?slotBefore:slotAfter
            ).quantity(Math.abs(amount)).build().createSnapshot();
            if (take) {
                change.take = deltaStack;
                change.put = null;
            } else {
                change.take = null;
                change.put = deltaStack;
            }
        } else {
            change.take = slotBefore;
            change.put = slotAfter;
        }

        return change;
    }
/**
     * Builder method for SlotChanges from {@link SlotTransaction}s<br>
     * Will determine the taken and put items and construct a new SlotChange.
     * @param transaction the SlotTransaction to build upon
     * @return the SlotChange representation
     */
Builder method for SlotChanges from  SlotTransactions
Will determine the taken and put items and construct a new SlotChange.
@param transaction the SlotTransaction to build upon
@return the SlotChange representation
Builder method for SlotChanges from SlotTransactions Will determine the taken and put items and construct a new SlotChange . @param transaction the SlotTransaction to build upon @return the SlotChange representation
public static SlotChange from(SlotTransaction transaction) {
        SlotChange change = new SlotChange();
        change.transaction = transaction;
        Integer index = transaction.getSlot().getInventoryProperty(SlotIndex.class).map(AbstractInventoryProperty::getValue).orElse(null);
        if (index != null) {
            change.position = new SlotPos(index % 9, index / 9);
        }
        ItemStackSnapshot slotAfter = transaction.getFinal();
        ItemStackSnapshot slotBefore = transaction.getOriginal();
        if (slotBefore.getType().equals(slotAfter.getType()) ||
                slotBefore.isEmpty() || slotAfter.isEmpty()) {
            int amount = slotAfter.getQuantity()-slotBefore.getQuantity();
            boolean take = amount < 0;
            ItemStackSnapshot deltaStack = ItemStack.builder().fromSnapshot(
                    take?slotBefore:slotAfter
            ).quantity(Math.abs(amount)).build().createSnapshot();
            if (take) {
                change.take = deltaStack;
                change.put = null;
            } else {
                change.take = null;
                change.put = deltaStack;
            }
        } else {
            change.take = slotBefore;
            change.put = slotAfter;
        }
        return change;
    }
public static SlotChange from ( SlotTransaction transaction ) { SlotChange change = new SlotChange ( ) ; change . transaction = transaction ; Integer index = transaction . getSlot ( ) . getInventoryProperty ( SlotIndex . class ) . map ( AbstractInventoryProperty :: getValue ) . orElse ( null ) ; if ( index != null ) { change . position = new SlotPos ( index % 9 , index / 9 ) ; } ItemStackSnapshot slotAfter = transaction . getFinal ( ) ; ItemStackSnapshot slotBefore = transaction . getOriginal ( ) ; if ( slotBefore . getType ( ) . equals ( slotAfter . getType ( ) ) || slotBefore . isEmpty ( ) || slotAfter . isEmpty ( ) ) { int amount = slotAfter . getQuantity ( ) - slotBefore . getQuantity ( ) ; boolean take = amount < 0 ; ItemStackSnapshot deltaStack = ItemStack . builder ( ) . fromSnapshot ( take ? slotBefore : slotAfter ) . quantity ( Math . abs ( amount ) ) . build ( ) . createSnapshot ( ) ; if ( take ) { change . take = deltaStack ; change . put = null ; } else { change . take = null ; change . put = deltaStack ; } } else { change . take = slotBefore ; change . put = slotAfter ; } return change ; }
Builder method for SlotChanges from {@link SlotTransaction}s<br>
 Will determine the taken and put items and construct a new SlotChange.
Builder method for SlotChanges from { @link SlotTransaction } s<br > Will determine the taken and put items and construct a new SlotChange .
//change.position = transaction.getSlot().getInventoryProperty(SlotPos.class).orElse(null);