use of net.minecraft.tileentity.HopperTileEntity in project LoliServer by Loli-Server.
the class VanillaInventoryCodeHooks method insertStack.
/**
* Copied from TileEntityHopper#insertStack and added capability support
*/
private static ItemStack insertStack(TileEntity source, Object destination, IItemHandler destInventory, ItemStack stack, int slot) {
ItemStack itemstack = destInventory.getStackInSlot(slot);
if (destInventory.insertItem(slot, stack, true).isEmpty()) {
boolean insertedItem = false;
boolean inventoryWasEmpty = isEmpty(destInventory);
if (itemstack.isEmpty()) {
destInventory.insertItem(slot, stack, false);
stack = ItemStack.EMPTY;
insertedItem = true;
} else if (ItemHandlerHelper.canItemStacksStack(itemstack, stack)) {
int originalSize = stack.getCount();
stack = destInventory.insertItem(slot, stack, false);
insertedItem = originalSize < stack.getCount();
}
if (insertedItem) {
if (inventoryWasEmpty && destination instanceof HopperTileEntity) {
HopperTileEntity destinationHopper = (HopperTileEntity) destination;
if (!destinationHopper.isOnCustomCooldown()) {
int k = 0;
if (source instanceof HopperTileEntity) {
if (destinationHopper.getLastUpdateTime() >= ((HopperTileEntity) source).getLastUpdateTime()) {
k = 1;
}
}
destinationHopper.setCooldown(8 - k);
}
}
}
}
return stack;
}
use of net.minecraft.tileentity.HopperTileEntity in project Magma-1.16.x by magmafoundation.
the class VanillaInventoryCodeHooks method insertStack.
/**
* Copied from TileEntityHopper#insertStack and added capability support
*/
private static ItemStack insertStack(TileEntity source, Object destination, IItemHandler destInventory, ItemStack stack, int slot) {
ItemStack itemstack = destInventory.getStackInSlot(slot);
if (destInventory.insertItem(slot, stack, true).isEmpty()) {
boolean insertedItem = false;
boolean inventoryWasEmpty = isEmpty(destInventory);
if (itemstack.isEmpty()) {
destInventory.insertItem(slot, stack, false);
stack = ItemStack.EMPTY;
insertedItem = true;
} else if (ItemHandlerHelper.canItemStacksStack(itemstack, stack)) {
int originalSize = stack.getCount();
stack = destInventory.insertItem(slot, stack, false);
insertedItem = originalSize < stack.getCount();
}
if (insertedItem) {
if (inventoryWasEmpty && destination instanceof HopperTileEntity) {
HopperTileEntity destinationHopper = (HopperTileEntity) destination;
if (!destinationHopper.isOnCustomCooldown()) {
int k = 0;
if (source instanceof HopperTileEntity) {
if (destinationHopper.getLastUpdateTime() >= ((HopperTileEntity) source).getLastUpdateTime()) {
k = 1;
}
}
destinationHopper.setCooldown(8 - k);
}
}
}
}
return stack;
}
use of net.minecraft.tileentity.HopperTileEntity 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