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();
}
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);
}
}
}
}
}
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);
}
}
Aggregations