Search in sources :

Example 1 with IInventoryBridge

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);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) DispenserTileEntity(net.minecraft.tileentity.DispenserTileEntity) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest) InventoryMoveItemEvent(org.bukkit.event.inventory.InventoryMoveItemEvent) Direction(net.minecraft.util.Direction) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with IInventoryBridge

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;
}
Also used : ComposterBlock(net.minecraft.block.ComposterBlock) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) CraftBlockInventoryHolder(org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with IInventoryBridge

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);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) InventoryView(org.bukkit.inventory.InventoryView) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) ContainerBridge(io.izzel.arclight.common.bridge.inventory.container.ContainerBridge)

Example 4 with IInventoryBridge

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);
    }
}
Also used : IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with IInventoryBridge

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;
}
Also used : IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) Inventory(net.minecraft.inventory.Inventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

IInventoryBridge (io.izzel.arclight.common.bridge.inventory.IInventoryBridge)7 Redirect (org.spongepowered.asm.mixin.injection.Redirect)4 DoubleSidedInventory (net.minecraft.inventory.DoubleSidedInventory)3 IInventory (net.minecraft.inventory.IInventory)3 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest)3 CraftItemStack (org.bukkit.craftbukkit.v.inventory.CraftItemStack)3 InventoryMoveItemEvent (org.bukkit.event.inventory.InventoryMoveItemEvent)3 Inventory (org.bukkit.inventory.Inventory)3 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)1 ContainerBridge (io.izzel.arclight.common.bridge.inventory.container.ContainerBridge)1 ComposterBlock (net.minecraft.block.ComposterBlock)1 ProxyBlockSource (net.minecraft.dispenser.ProxyBlockSource)1 HopperMinecartEntity (net.minecraft.entity.item.minecart.HopperMinecartEntity)1 Inventory (net.minecraft.inventory.Inventory)1 ItemStack (net.minecraft.item.ItemStack)1 DispenserTileEntity (net.minecraft.tileentity.DispenserTileEntity)1 HopperTileEntity (net.minecraft.tileentity.HopperTileEntity)1 Direction (net.minecraft.util.Direction)1 CraftBlockInventoryHolder (org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder)1 CraftInventoryView (org.bukkit.craftbukkit.v.inventory.CraftInventoryView)1