use of org.bukkit.event.inventory.InventoryMoveItemEvent 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 org.bukkit.event.inventory.InventoryMoveItemEvent in project WindSpigot by Wind-Development.
the class TileEntityHopper method a.
private static boolean a(IHopper ihopper, IInventory iinventory, int i, EnumDirection enumdirection) {
ItemStack itemstack = iinventory.getItem(i);
if (itemstack != null && b(iinventory, itemstack, i, enumdirection)) {
ItemStack itemstack1 = itemstack.cloneItemStack();
// ItemStack itemstack2 = addItem(ihopper, iinventory.splitStack(i, 1),
// (EnumDirection) null);
// CraftBukkit start - Call event on collection of items from inventories into
// the hopper
CraftItemStack oitemstack = CraftItemStack.asCraftMirror(// Spigot
iinventory.splitStack(i, ihopper.getWorld().spigotConfig.hopperAmount));
// TacoSpigot start - add an option to turn of InventoryMoveItemEvent
final org.bukkit.inventory.ItemStack stack;
if (HopperHelper.isFireInventoryMoveItemEvent(ihopper)) {
// TacoSpigot end
Inventory sourceInventory;
// Have to special case large chests as they work oddly
if (iinventory instanceof InventoryLargeChest) {
sourceInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
} else {
sourceInventory = iinventory.getOwner().getInventory();
}
InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false);
ihopper.getWorld().getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
iinventory.setItem(i, itemstack1);
if (ihopper instanceof TileEntityHopper) {
// Spigot
((TileEntityHopper) ihopper).d(ihopper.getWorld().spigotConfig.hopperTransfer);
} else if (ihopper instanceof EntityMinecartHopper) {
// Spigot
((EntityMinecartHopper) ihopper).m(ihopper.getWorld().spigotConfig.hopperTransfer / 2);
}
return false;
}
// TacoSpigot start
stack = event.getItem();
// handle cases where the event is not fired
} else {
stack = oitemstack;
}
// Spigot
int origCount = stack.getAmount();
ItemStack itemstack2 = addItem(ihopper, CraftItemStack.asNMSCopy(stack), null);
if (itemstack2 == null || itemstack2.count == 0) {
if (stack.equals(oitemstack)) {
iinventory.update();
} else {
iinventory.setItem(i, itemstack1);
}
// CraftBukkit end
return true;
}
// Spigot
itemstack1.count -= origCount - itemstack2.count;
iinventory.setItem(i, itemstack1);
}
return false;
}
use of org.bukkit.event.inventory.InventoryMoveItemEvent in project NachoSpigot by CobbleSword.
the class BlockDropper method dispense.
public void dispense(World world, BlockPosition blockposition) {
SourceBlock sourceblock = new SourceBlock(world, blockposition);
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) sourceblock.getTileEntity();
if (tileentitydispenser != null) {
int i = tileentitydispenser.m();
if (i < 0) {
world.triggerEffect(1001, blockposition, 0);
} else {
ItemStack itemstack = tileentitydispenser.getItem(i);
if (itemstack != null) {
EnumDirection enumdirection = (EnumDirection) world.getType(blockposition).get(BlockDropper.FACING);
BlockPosition blockposition1 = blockposition.shift(enumdirection);
IInventory iinventory = TileEntityHopper.b(world, (double) blockposition1.getX(), (double) blockposition1.getY(), (double) blockposition1.getZ());
ItemStack itemstack1;
if (iinventory == null) {
itemstack1 = this.P.a(sourceblock, itemstack);
if (itemstack1 != null && itemstack1.count <= 0) {
itemstack1 = null;
}
} else {
// CraftBukkit start - Fire event when pushing items into other inventories
CraftItemStack oitemstack = CraftItemStack.asCraftMirror(itemstack.cloneItemStack().cloneAndSubtract(1));
org.bukkit.inventory.Inventory destinationInventory;
// Have to special case large chests as they work oddly
if (iinventory instanceof InventoryLargeChest) {
destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory);
} else {
destinationInventory = iinventory.getOwner().getInventory();
}
InventoryMoveItemEvent event = new InventoryMoveItemEvent(tileentitydispenser.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true);
world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
itemstack1 = TileEntityHopper.addItem(iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection.opposite());
if (event.getItem().equals(oitemstack) && itemstack1 == null) {
// CraftBukkit end
itemstack1 = itemstack.cloneItemStack();
if (--itemstack1.count <= 0) {
itemstack1 = null;
}
} else {
itemstack1 = itemstack.cloneItemStack();
}
}
tileentitydispenser.setItem(i, itemstack1);
}
}
}
}
use of org.bukkit.event.inventory.InventoryMoveItemEvent 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);
}
use of org.bukkit.event.inventory.InventoryMoveItemEvent 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);
}
Aggregations