Search in sources :

Example 6 with IMixinInventory

use of org.spongepowered.common.interfaces.IMixinInventory in project SpongeCommon by SpongePowered.

the class MixinBlockDropper method afterDispense.

@Surrogate
private void afterDispense(World worldIn, BlockPos pos, CallbackInfo callbackInfo, BlockSourceImpl blocksourceimpl, TileEntityDispenser tileentitydispenser, int i, ItemStack itemstack, ItemStack itemstack1) {
    // after setInventorySlotContents
    tileentitydispenser.setInventorySlotContents(i, itemstack1);
    // Transfer worked if remainder is one less than the original stack
    if (itemstack1.getCount() == itemstack.getCount() - 1) {
        IMixinInventory capture = forCapture(tileentitydispenser);
        Inventory sourceInv = toInventory(tileentitydispenser);
        SpongeCommonEventFactory.captureTransaction(capture, sourceInv, i, itemstack);
        EnumFacing enumfacing = (EnumFacing) worldIn.getBlockState(pos).getValue(BlockDispenser.FACING);
        BlockPos blockpos = pos.offset(enumfacing);
        IInventory iinventory = TileEntityHopper.getInventoryAtPosition(worldIn, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ());
        SpongeCommonEventFactory.callTransferPost(capture, sourceInv, toInventory(iinventory));
    }
    callbackInfo.cancel();
}
Also used : IInventory(net.minecraft.inventory.IInventory) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IMixinInventory(org.spongepowered.common.interfaces.IMixinInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) IMixinInventory(org.spongepowered.common.interfaces.IMixinInventory) Surrogate(org.spongepowered.asm.mixin.injection.Surrogate)

Example 7 with IMixinInventory

use of org.spongepowered.common.interfaces.IMixinInventory in project SpongeForge by SpongePowered.

the class MixinVanillaInventoryCodeHooks method afterPutStackInSlots.

// Post Captured Transactions
@Inject(method = "insertHook", locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 1))
private static void afterPutStackInSlots(TileEntityHopper hopper, CallbackInfoReturnable<Boolean> cir, EnumFacing hopperFacing, Pair<IItemHandler, Object> destinationResult, IItemHandler itemHandler, Object destination, int i, ItemStack originalSlotContents, ItemStack insertStack, ItemStack remainder) {
    if (ShouldFire.CHANGE_INVENTORY_EVENT_TRANSFER_POST) {
        // after putStackInInventoryAllSlots
        if (remainder.isEmpty()) {
            IMixinInventory capture = InventoryUtil.forCapture(hopper);
            if (capture == null) {
                return;
            }
            Inventory sInv = InventoryUtil.toInventory(hopper, null);
            Inventory dInv = InventoryUtil.toInventory(destination, itemHandler);
            SpongeCommonEventFactory.captureTransaction(capture, sInv, i, originalSlotContents);
            if (SpongeCommonEventFactory.callTransferPost(capture, sInv, dInv)) {
                if (originalSlotContents.isEmpty()) {
                    cir.setReturnValue(true);
                }
            }
        }
    }
}
Also used : IMixinInventory(org.spongepowered.common.interfaces.IMixinInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) IMixinInventory(org.spongepowered.common.interfaces.IMixinInventory) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 8 with IMixinInventory

use of org.spongepowered.common.interfaces.IMixinInventory in project SpongeForge by SpongePowered.

the class MixinVanillaInventoryCodeHooks method afterDispense.

@Inject(remap = false, method = "dropperInsertHook", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "RETURN", ordinal = 1))
private static void afterDispense(World world, BlockPos pos, TileEntityDispenser dropper, int slot, ItemStack stack, CallbackInfoReturnable<Boolean> cir, EnumFacing enumFacing, BlockPos blockPos, Pair<IItemHandler, Object> destinationResult, IItemHandler itemHandler, Object destination, ItemStack dispensedStack, ItemStack remainder) {
    if (ShouldFire.CHANGE_INVENTORY_EVENT_TRANSFER_POST) {
        // after setInventorySlotContents if return false
        IMixinInventory capture = InventoryUtil.forCapture(dropper);
        Inventory source = InventoryUtil.toInventory(dropper, null);
        Inventory destInv = InventoryUtil.toInventory(destination, itemHandler);
        SpongeCommonEventFactory.captureTransaction(capture, source, slot, stack);
        SpongeCommonEventFactory.callTransferPost(capture, source, destInv);
    }
}
Also used : IMixinInventory(org.spongepowered.common.interfaces.IMixinInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) IMixinInventory(org.spongepowered.common.interfaces.IMixinInventory) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Inventory (org.spongepowered.api.item.inventory.Inventory)8 IMixinInventory (org.spongepowered.common.interfaces.IMixinInventory)8 IInventory (net.minecraft.inventory.IInventory)6 Inject (org.spongepowered.asm.mixin.injection.Inject)5 Slot (net.minecraft.inventory.Slot)2 SPacketSetSlot (net.minecraft.network.play.server.SPacketSetSlot)2 CraftingInventory (org.spongepowered.api.item.inventory.crafting.CraftingInventory)2 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)2 CarriedInventory (org.spongepowered.api.item.inventory.type.CarriedInventory)2 OrderedInventory (org.spongepowered.api.item.inventory.type.OrderedInventory)2 SpongeCommonEventFactory.toInventory (org.spongepowered.common.event.SpongeCommonEventFactory.toInventory)2 CustomInventory (org.spongepowered.common.item.inventory.custom.CustomInventory)2 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1 Surrogate (org.spongepowered.asm.mixin.injection.Surrogate)1