use of io.izzel.arclight.common.bridge.inventory.IInventoryBridge in project Arclight by IzzelAliz.
the class DropperBlockMixin method dispense.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void dispense(World worldIn, BlockPos pos) {
ProxyBlockSource proxyblocksource = new ProxyBlockSource(worldIn, pos);
DispenserTileEntity dispensertileentity = proxyblocksource.getBlockTileEntity();
int i = dispensertileentity.getDispenseSlot();
if (i < 0) {
worldIn.playEvent(1001, pos, 0);
} else {
ItemStack itemstack = dispensertileentity.getStackInSlot(i);
if (!itemstack.isEmpty() && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, dispensertileentity, i, itemstack)) {
Direction direction = worldIn.getBlockState(pos).get(DispenserBlock.FACING);
IInventory iinventory = HopperTileEntity.getInventoryAtPosition(worldIn, pos.offset(direction));
ItemStack itemstack1;
if (iinventory == null) {
itemstack1 = DISPENSE_BEHAVIOR.dispense(proxyblocksource, itemstack);
} else {
ItemStack split = itemstack.copy().split(1);
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(split);
Inventory destinationInventory;
// Have to special case large chests as they work oddly
if (iinventory instanceof DoubleSidedInventory) {
destinationInventory = new CraftInventoryDoubleChest((DoubleSidedInventory) iinventory);
} else {
destinationInventory = ((IInventoryBridge) iinventory).getOwner().getInventory();
}
InventoryMoveItemEvent event = new InventoryMoveItemEvent(((IInventoryBridge) dispensertileentity).getOwner().getInventory(), craftItemStack, destinationInventory, true);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
itemstack1 = HopperTileEntity.putStackInInventoryAllSlots(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite());
if (event.getItem().equals(craftItemStack) && itemstack1.isEmpty()) {
itemstack1 = itemstack.copy();
itemstack1.shrink(1);
} else {
itemstack1 = itemstack.copy();
}
}
dispensertileentity.setInventorySlotContents(i, itemstack1);
}
}
}
use of io.izzel.arclight.common.bridge.inventory.IInventoryBridge in project Arclight by IzzelAliz.
the class ComposterBlockMixin method arclight$newEmpty.
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "createInventory", at = @At(value = "NEW", target = "()Lnet/minecraft/block/ComposterBlock$EmptyInventory;"))
public ComposterBlock.EmptyInventory arclight$newEmpty(BlockState blockState, IWorld world, BlockPos blockPos) {
ComposterBlock.EmptyInventory inventory = new ComposterBlock.EmptyInventory();
((IInventoryBridge) inventory).setOwner(new CraftBlockInventoryHolder(world, blockPos, inventory));
return inventory;
}
use of io.izzel.arclight.common.bridge.inventory.IInventoryBridge in project Arclight by IzzelAliz.
the class ContainerMixin method transferTo.
public void transferTo(Container other, CraftHumanEntity player) {
InventoryView source = this.getBukkitView();
InventoryView destination = ((ContainerBridge) other).bridge$getBukkitView();
((IInventoryBridge) ((CraftInventory) source.getTopInventory()).getInventory()).onClose(player);
((IInventoryBridge) ((CraftInventory) source.getBottomInventory()).getInventory()).onClose(player);
((IInventoryBridge) ((CraftInventory) destination.getTopInventory()).getInventory()).onOpen(player);
((IInventoryBridge) ((CraftInventory) destination.getBottomInventory()).getInventory()).onOpen(player);
}
use of io.izzel.arclight.common.bridge.inventory.IInventoryBridge in project Arclight by IzzelAliz.
the class HopperTileEntityMixin method arclight$pickupItem.
@Inject(method = "captureItem", cancellable = true, at = @At("HEAD"))
private static void arclight$pickupItem(IInventory inventory, ItemEntity itemEntity, CallbackInfoReturnable<Boolean> cir) {
InventoryPickupItemEvent event = new InventoryPickupItemEvent(((IInventoryBridge) inventory).getOwner().getInventory(), (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cir.setReturnValue(false);
}
}
use of io.izzel.arclight.common.bridge.inventory.IInventoryBridge in project Arclight by IzzelAliz.
the class AbstractHorseEntityMixin method arclight$createInv.
@Redirect(method = "initHorseChest", at = @At(value = "NEW", target = "net/minecraft/inventory/Inventory"))
private Inventory arclight$createInv(int slots) {
Inventory inventory = new Inventory(slots);
((IInventoryBridge) inventory).setOwner((InventoryHolder) this.getBukkitEntity());
return inventory;
}
Aggregations