use of org.spongepowered.common.bridge.world.inventory.container.TrackedInventoryBridge in project SpongeCommon by SpongePowered.
the class HopperBlockEntityMixin_Inventory method imlp$throwTransferEventsWhenPullingItems.
@Inject(method = "tryTakeInItemFromSlot", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isEmpty()Z", ordinal = 1))
private static void imlp$throwTransferEventsWhenPullingItems(final Hopper hopper, final Container iInventory, final int index, final Direction direction, final CallbackInfoReturnable<Boolean> cir, final ItemStack itemStack, ItemStack itemStack1, final ItemStack itemStack2) {
// after putStackInInventoryAllSlots if the transfer worked
if (ShouldFire.TRANSFER_INVENTORY_EVENT_POST && itemStack2.isEmpty()) {
// Capture Insert in Origin
final TrackedInventoryBridge capture = InventoryUtil.forCapture(hopper);
SlotTransaction sourceSlotTransaction = InventoryEventFactory.captureTransaction(capture, InventoryUtil.toInventory(iInventory), index, itemStack1);
// Call event
InventoryEventFactory.callTransferPost(capture, InventoryUtil.toInventory(iInventory), InventoryUtil.toInventory(hopper), itemStack1, sourceSlotTransaction);
}
}
use of org.spongepowered.common.bridge.world.inventory.container.TrackedInventoryBridge in project SpongeCommon by SpongePowered.
the class DropperBlockMixin_Inventory method afterDispense.
@Surrogate
private void afterDispense(final ServerLevel worldIn, final BlockPos pos, final CallbackInfo callbackInfo, final BlockSourceImpl proxyblocksource, final DispenserBlockEntity dispensertileentity, final int i, final ItemStack itemstack, final ItemStack itemstack1) {
// after setItem
dispensertileentity.setItem(i, itemstack1);
if (ShouldFire.TRANSFER_INVENTORY_EVENT_POST) {
// Transfer worked if remainder is one less than the original stack
if (itemstack1.getCount() == itemstack.getCount() - 1) {
final TrackedInventoryBridge capture = InventoryUtil.forCapture(dispensertileentity);
final Inventory sourceInv = ((Inventory) dispensertileentity);
SlotTransaction sourceSlotTransaction = InventoryEventFactory.captureTransaction(capture, sourceInv, i, itemstack);
final Direction enumfacing = worldIn.getBlockState(pos).getValue(DispenserBlock.FACING);
final BlockPos blockpos = pos.relative(enumfacing);
final Container iinventory = HopperBlockEntity.getContainerAt(worldIn, blockpos.getX(), blockpos.getY(), blockpos.getZ());
InventoryEventFactory.callTransferPost(capture, sourceInv, ((Inventory) iinventory), itemstack, sourceSlotTransaction);
}
}
// dont call setInventorySlotContents twice
callbackInfo.cancel();
}
use of org.spongepowered.common.bridge.world.inventory.container.TrackedInventoryBridge in project SpongeCommon by SpongePowered.
the class DropperBlockMixin_Inventory method afterDispense.
@Inject(method = "dispenseFrom", cancellable = true, locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/DispenserBlockEntity;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private void afterDispense(final ServerLevel worldIn, final BlockPos pos, final CallbackInfo callbackInfo, final BlockSourceImpl proxyblocksource, final DispenserBlockEntity dispensertileentity, final int i, final ItemStack itemstack, final Direction direction, final Container iinventory, final ItemStack itemstack1) {
// after setItem
dispensertileentity.setItem(i, itemstack1);
if (ShouldFire.TRANSFER_INVENTORY_EVENT_POST) {
// Transfer worked if remainder is one less than the original stack
if (itemstack1.getCount() == itemstack.getCount() - 1) {
final TrackedInventoryBridge capture = InventoryUtil.forCapture(dispensertileentity);
final Inventory sourceInv = ((Inventory) dispensertileentity);
SlotTransaction sourceSlotTransaction = InventoryEventFactory.captureTransaction(capture, sourceInv, i, itemstack);
InventoryEventFactory.callTransferPost(capture, sourceInv, ((Inventory) iinventory), itemstack, sourceSlotTransaction);
}
}
// dont call setItem twice
callbackInfo.cancel();
}
use of org.spongepowered.common.bridge.world.inventory.container.TrackedInventoryBridge in project SpongeCommon by SpongePowered.
the class HopperBlockEntityMixin_Inventory method impl$afterPutStackInSlots.
// Post Captured Transactions
@Inject(method = "ejectItems", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;isEmpty()Z", ordinal = 1))
private void impl$afterPutStackInSlots(final CallbackInfoReturnable<Boolean> cir, final Container iInventory, final Direction enumFacing, final int i, final ItemStack itemStack, ItemStack itemStack1) {
// after putStackInInventoryAllSlots if the transfer worked
if (ShouldFire.TRANSFER_INVENTORY_EVENT_POST && itemStack1.isEmpty()) {
// Capture Insert in Origin
final TrackedInventoryBridge capture = InventoryUtil.forCapture(this);
SlotTransaction sourceSlotTransaction = InventoryEventFactory.captureTransaction(capture, (Inventory) this, i, itemStack);
// Call event
InventoryEventFactory.callTransferPost(capture, (Inventory) this, InventoryUtil.toInventory(iInventory), itemStack, sourceSlotTransaction);
}
}
Aggregations