private void dispense(CartMechanismBlocks blocks, Inventory inv, CartType type) {
Location location = BukkitUtil.center(blocks.rail.getLocation());
if(minecartDispenserLegacy) {
BlockFace direction = SignUtil.getFront(blocks.sign).getOppositeFace();
location = blocks.rail.getRelative(direction).getLocation();
}
if(minecartDispenserAntiSpam && EntityUtil.isEntityOfTypeInBlock(location.getBlock(), EntityType.MINECART))
return;
if (inv != null) {
if (type.equals(CartType.Minecart)) {
if (!inv.contains(Material.MINECART)) return;
inv.removeItem(new ItemStack(Material.MINECART, 1));
} else if (type.equals(CartType.StorageMinecart)) {
if (!inv.contains(Material.STORAGE_MINECART)) return;
inv.removeItem(new ItemStack(Material.STORAGE_MINECART, 1));
} else if (type.equals(CartType.PoweredMinecart)) {
if (!inv.contains(Material.POWERED_MINECART)) return;
inv.removeItem(new ItemStack(Material.POWERED_MINECART, 1));
} else if (type.equals(CartType.TNTMinecart)) {
if (!inv.contains(Material.EXPLOSIVE_MINECART)) return;
inv.removeItem(new ItemStack(Material.EXPLOSIVE_MINECART, 1));
} else if (type.equals(CartType.HopperMinecart)) {
if (!inv.contains(Material.HOPPER_MINECART)) return;
inv.removeItem(new ItemStack(Material.HOPPER_MINECART, 1));
}
}
Minecart cart = blocks.rail.getWorld().spawn(location, type.toClass());
if(minecartDispenserPropel) {
BlockFace dir = SignUtil.getBack(blocks.sign);
Vector vel = new Vector(dir.getModX(), dir.getModY(), dir.getModZ());
cart.setVelocity(vel.normalize());
}
}