Search in sources :

Example 1 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest 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 CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest in project Arclight by IzzelAliz.

the class ChestContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventory inventory;
    if (this.lowerChestInventory instanceof PlayerInventory) {
        inventory = new CraftInventoryPlayer((PlayerInventory) this.lowerChestInventory);
    } else if (this.lowerChestInventory instanceof DoubleSidedInventory) {
        inventory = new CraftInventoryDoubleChest((DoubleSidedInventory) this.lowerChestInventory);
    } else {
        inventory = new CraftInventory(this.lowerChestInventory);
    }
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Container(net.minecraft.inventory.container.Container) ChestContainer(net.minecraft.inventory.container.ChestContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) CraftInventoryPlayer(org.bukkit.craftbukkit.v.inventory.CraftInventoryPlayer) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) PlayerInventory(net.minecraft.entity.player.PlayerInventory) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest)

Example 3 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest in project Arclight by IzzelAliz.

the class HopperTileEntityMixin method arclight$moveItem.

@Redirect(method = "transferItemsOut", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;"))
public ItemStack arclight$moveItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) {
    CraftItemStack original = CraftItemStack.asCraftMirror(stack);
    Inventory destinationInventory;
    // Have to special case large chests as they work oddly
    if (destination instanceof DoubleSidedInventory) {
        destinationInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) destination));
    } else {
        destinationInventory = ((IInventoryBridge) destination).getOwner().getInventory();
    }
    InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), original.clone(), destinationInventory, true);
    Bukkit.getPluginManager().callEvent(event);
    if (arclight$moveItem = event.isCancelled()) {
        // Delay hopper checks
        this.setTransferCooldown(8);
        return null;
    }
    return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest) InventoryMoveItemEvent(org.bukkit.event.inventory.InventoryMoveItemEvent) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest in project Arclight by IzzelAliz.

the class HopperTileEntityMixin method arclight$pullItem.

@Redirect(method = "pullItemFromSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;"))
private static ItemStack arclight$pullItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) {
    CraftItemStack original = CraftItemStack.asCraftMirror(stack);
    Inventory sourceInventory;
    // Have to special case large chests as they work oddly
    if (source instanceof DoubleSidedInventory) {
        sourceInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) source));
    } else {
        sourceInventory = ((IInventoryBridge) source).getOwner().getInventory();
    }
    InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, original.clone(), ((IInventoryBridge) destination).getOwner().getInventory(), false);
    Bukkit.getPluginManager().callEvent(event);
    if (arclight$moveItem = event.isCancelled()) {
        if (destination instanceof HopperTileEntity) {
            // Delay hopper checks
            ((HopperTileEntity) destination).setTransferCooldown(8);
        } else if (destination instanceof HopperMinecartEntity) {
            // Delay hopper minecart checks
            ((HopperMinecartEntity) destination).setTransferTicker(4);
        }
        return null;
    }
    return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) HopperTileEntity(net.minecraft.tileentity.HopperTileEntity) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest) InventoryMoveItemEvent(org.bukkit.event.inventory.InventoryMoveItemEvent) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

DoubleSidedInventory (net.minecraft.inventory.DoubleSidedInventory)4 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest)4 IInventoryBridge (io.izzel.arclight.common.bridge.inventory.IInventoryBridge)3 IInventory (net.minecraft.inventory.IInventory)3 CraftItemStack (org.bukkit.craftbukkit.v.inventory.CraftItemStack)3 InventoryMoveItemEvent (org.bukkit.event.inventory.InventoryMoveItemEvent)3 Inventory (org.bukkit.inventory.Inventory)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)1 ProxyBlockSource (net.minecraft.dispenser.ProxyBlockSource)1 HopperMinecartEntity (net.minecraft.entity.item.minecart.HopperMinecartEntity)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 ChestContainer (net.minecraft.inventory.container.ChestContainer)1 Container (net.minecraft.inventory.container.Container)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 CraftInventory (org.bukkit.craftbukkit.v.inventory.CraftInventory)1 CraftInventoryPlayer (org.bukkit.craftbukkit.v.inventory.CraftInventoryPlayer)1